Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/model_policies/model_policy_Instance.py b/xos/model_policies/model_policy_Instance.py
index ffc9847..dd1a8d5 100644
--- a/xos/model_policies/model_policy_Instance.py
+++ b/xos/model_policies/model_policy_Instance.py
@@ -6,7 +6,7 @@
         if instance.deleted:
             return
 
-        if (instance.isolation in ["container"]):
+        if (instance.isolation in ["container"]) and (instance.slice.network not in ["host", "bridged"]):
             # Our current docker-on-metal network strategy requires that there be some
             # VM on the server that connects to the networks, so that
             # the containers can piggyback off of that configuration.
diff --git a/xos/observers/onos/steps/sync_onosapp.py b/xos/observers/onos/steps/sync_onosapp.py
index 97bb8a6..0feb2e5 100644
--- a/xos/observers/onos/steps/sync_onosapp.py
+++ b/xos/observers/onos/steps/sync_onosapp.py
@@ -106,14 +106,23 @@
         self.write_configs(o)
 
     def get_extra_attributes(self, o):
+        instance = self.get_instance(o)
+
         fields={}
         fields["files_dir"] = o.files_dir
         fields["appname"] = o.name
-        fields["nat_ip"] = self.get_instance(o).get_ssh_ip()
+        fields["nat_ip"] = instance.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"
+        if o.dependencies:
+            fields["dependencies"] = [x.strip() for x in o.dependencies.split(",")]
+        else:
+            fields["dependencies"] = []
+
+        if (instance.isolation=="container"):
+            fields["ONOS_container"] = "%s-%s" % (instance.slice.name, str(instance.id))
+        else:
+            fields["ONOS_container"] = "ONOS"
         return fields
 
     def sync_fields(self, o, fields):
diff --git a/xos/observers/onos/steps/sync_onosapp.yaml b/xos/observers/onos/steps/sync_onosapp.yaml
index 9105a2e..496fad0 100644
--- a/xos/observers/onos/steps/sync_onosapp.yaml
+++ b/xos/observers/onos/steps/sync_onosapp.yaml
@@ -2,7 +2,7 @@
 - hosts: {{ instance_name }}
   gather_facts: False
   connection: ssh
-  user: ubuntu
+  user: {{ username }}
   sudo: yes
   vars:
     appname: {{ appname }}
@@ -17,6 +17,20 @@
 
   tasks:
 
+  - name: Get Docker IP
+    script: /opt/xos/observers/onos/scripts/dockerip.sh {{ ONOS_container }}
+    register: onosaddr
+
+  - name: Wait for ONOS to come up
+    wait_for:
+      host={{ '{{' }} onosaddr.stdout {{ '}}' }}
+      port={{ '{{' }} item {{ '}}' }}
+      state=present
+    with_items:
+    - 8101
+    - 8181
+    - 9876
+
   - name: Config file directory
     file:
       path=/home/ubuntu/{{ appname }}/
@@ -49,9 +63,10 @@
   - name: Wait for ONOS to install the apps
     wait_for: timeout=15
 
+{% if dependencies %}
   - name: Add dependencies to ONOS
     uri:
-      url: http://localhost:8181/onos/v1/applications/{{ '{{' }} item {{ '}}' }}/active
+      url: http://{{ '{{' }} onosaddr.stdout {{ '}}' }}:8181/onos/v1/applications/{{ '{{' }} item {{ '}}' }}/active
       method: POST
       user: karaf
       password: karaf
@@ -59,13 +74,14 @@
         {% for dependency in dependencies %}
         - {{ dependency }}
         {% endfor %}
+{% endif %}
 
 {% if rest_configs %}
 # Do this after services have been activated, or it will cause an exception.
 # vOLT will re-read its net config; vbng may not.
   - name: Add ONOS configuration values
     uri:
-      url: http://localhost:8181/{{ '{{' }} item.endpoint {{ '}}' }} #http://localhost:8181/onos/v1/network/configuration/
+      url: http://{{ '{{' }} onosaddr.stdout {{ '}}' }}:8181/{{ '{{' }} item.endpoint {{ '}}' }} #http://localhost:8181/onos/v1/network/configuration/
       body: "{{ '{{' }} item.body {{ '}}' }}"
       body_format: raw
       method: POST
diff --git a/xos/observers/onos/steps/sync_onosservice.py b/xos/observers/onos/steps/sync_onosservice.py
index 65fa44e..420904a 100644
--- a/xos/observers/onos/steps/sync_onosservice.py
+++ b/xos/observers/onos/steps/sync_onosservice.py
@@ -63,10 +63,14 @@
 
     def sync_fields(self, o, fields):
         # the super causes the playbook to be run
-
         super(SyncONOSService, self).sync_fields(o, fields)
 
     def run_playbook(self, o, fields):
+        instance = self.get_instance(o)
+        if (instance.isolation=="container"):
+            # If the instance is already a container, then we don't need to
+            # install ONOS.
+            return
         super(SyncONOSService, self).run_playbook(o, fields)
 
     def delete_record(self, m):
diff --git a/xos/tosca/samples/vtn.yaml b/xos/tosca/samples/vtn.yaml
new file mode 100644
index 0000000..9cb7c95
--- /dev/null
+++ b/xos/tosca/samples/vtn.yaml
@@ -0,0 +1,83 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup CORD-related services -- vOLT, vCPE, vBNG.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    service_ONOS_VTN:
+      type: tosca.nodes.ONOSService
+      requirements:
+      properties:
+          kind: onos
+          view_url: /admin/onos/onosservice/$id$/
+          public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
+      artifacts:
+          pubkey: /opt/xos/observers/onos/onos_key.pub
+
+    VTN_ONOS_app:
+      type: tosca.nodes.ONOSvBNGApp
+      requirements:
+          - onos_tenant:
+              node: service_ONOS_VTN
+              relationship: tosca.relationships.TenantOfService
+      properties:
+#          dependencies: org.onosproject.proxyarp, org.onosproject.virtualbng, org.onosproject.openflow, org.onosproject.fwd
+
+    # docker image for vcpe containers
+    docker-onos:
+      # TODO: need to attach this to mydeployment
+      type: tosca.nodes.Image
+      properties:
+        kind: container
+        container_format: na
+        disk_format: na
+        path: onosproject/onos
+
+    mysite:
+      type: tosca.nodes.Site
+
+    mysite_onos_vtn:
+      description: ONOS Controller Slice for VTN
+      type: tosca.nodes.Slice
+      requirements:
+          - ONOS:
+              node: service_ONOS_VTN
+              relationship: tosca.relationships.MemberOfService
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
+          - onos_docker_image:
+              node: docker-onos
+              relationship: tosca.relationships.UsesImage
+      properties:
+          network: bridged
+          default_isolation: container
+
+    # Virtual machines
+    onos_app_vtn:
+      type: tosca.nodes.Compute.Container
+      capabilities:
+        # Host container properties
+        host:
+         properties:
+           num_cpus: 1
+           disk_size: 10 GB
+           mem_size: 4 MB
+        # Guest Operating System properties
+        os:
+          properties:
+            # host Operating System image properties
+            architecture: x86_64
+            type: linux
+            distribution: Ubuntu
+            version: 14.10
+      requirements:
+          - slice:
+                node: mysite_onos_vtn
+                relationship: tosca.relationships.MemberOfSlice
+          - image:
+                node: docker-onos
+                relationship: tosca.relationships.UsesImage