Merge pull request #118 from davidkbainbridge/docker-changes

Docker changes
diff --git a/xos/observers/onos/steps/sync_onosapp.py b/xos/observers/onos/steps/sync_onosapp.py
index 8c97391..9b32298 100644
--- a/xos/observers/onos/steps/sync_onosapp.py
+++ b/xos/observers/onos/steps/sync_onosapp.py
@@ -75,6 +75,7 @@
 
     def write_configs(self, o):
         o.config_fns = []
+        o.rest_configs = []
         o.files_dir = self.get_files_dir(o)
 
         if not os.path.exists(o.files_dir):
@@ -85,6 +86,16 @@
                 fn = attr.name[7:] # .replace("_json",".json")
                 o.config_fns.append(fn)
                 file(os.path.join(o.files_dir, fn),"w").write(attr.value)
+            if attr.name.startswith("rest_"):
+                fn = attr.name[5:].replace("/","_")
+                endpoint = attr.name[5:]
+                # Ansible goes out of it's way to make our life difficult. If
+                # 'lookup' sees a file that it thinks contains json, then it'll
+                # insist on parsing and return a json object. We just want
+                # a string, so prepend a space and then strip the space off
+                # later.
+                file(os.path.join(o.files_dir, fn),"w").write(" " +attr.value)
+                o.rest_configs.append( {"endpoint": endpoint, "fn": fn} )
 
     def prepare_record(self, o):
         self.write_configs(o)
@@ -95,6 +106,7 @@
         fields["appname"] = o.name
         fields["nat_ip"] = self.get_instance(o).get_ssh_ip()
         fields["config_fns"] = o.config_fns
+        fields["rest_configs"] = o.rest_configs
         fields["dependencies"] = [x.strip() for x in o.dependencies.split(",")]
         fields["ONOS_container"] = "ONOS"
         return fields
diff --git a/xos/observers/onos/steps/sync_onosapp.yaml b/xos/observers/onos/steps/sync_onosapp.yaml
index ad3718c..9ee2513 100644
--- a/xos/observers/onos/steps/sync_onosapp.yaml
+++ b/xos/observers/onos/steps/sync_onosapp.yaml
@@ -7,6 +7,13 @@
   vars:
     appname: {{ appname }}
     dependencies: {{ dependencies }}
+{% if rest_configs %}
+    rest_configs:
+{% for rest_config in rest_configs %}
+       - endpoint: {{ rest_config.endpoint }}
+         body: "{{ '{{' }} lookup('file', '{{ files_dir }}/{{ rest_config.fn }}') {{ '}}' }}"
+{% endfor %}
+{% endif %}
 
   tasks:
 
@@ -38,6 +45,18 @@
         {% endfor %}
 {% endif %}
 
+{% if rest_configs %}
+  - name: Add ONOS configuration values
+    uri:
+      url: http://localhost:8181/{{ '{{' }} item.endpoint {{ '}}' }} #http://localhost:8181/onos/v1/network/configuration/
+      body: "{{ '{{' }} item.body {{ '}}' }}"
+      body_format: raw
+      method: POST
+      user: karaf
+      password: karaf
+    with_items: "rest_configs"
+{% endif %}
+
   # Don't know how to check for this condition, just wait
   - name: Wait for ONOS to install the apps
     wait_for: timeout=15
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 4f726fc..d4e96ce 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -143,6 +143,9 @@
             config_network-cfg.json:
                 type: string
                 required: false
+            rest_onos/v1/network/configuration/:
+                type: string
+                required: false
 
     tosca.nodes.VCPEService:
         description: >
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 246c922..0c20211 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -165,6 +165,9 @@
             config_network-cfg.json:
                 type: string
                 required: false
+            rest_onos/v1/network/configuration/:
+                type: string
+                required: false
 
     tosca.nodes.VCPEService:
         description: >
diff --git a/xos/tosca/resources/onosapp.py b/xos/tosca/resources/onosapp.py
index 648bb09..7ed47d7 100644
--- a/xos/tosca/resources/onosapp.py
+++ b/xos/tosca/resources/onosapp.py
@@ -57,6 +57,8 @@
             v = d.value
             if k.startswith("config_"):
                 self.set_tenant_attr(obj, k, v)
+            elif k.startswith("rest_"):
+                self.set_tenant_attr(obj, k, v)
 
     def can_delete(self, obj):
         return super(XOSONOSApp, self).can_delete(obj)