Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/configurations/cord-pod/Makefile b/xos/configurations/cord-pod/Makefile
index 5c290cd..9d038f6 100644
--- a/xos/configurations/cord-pod/Makefile
+++ b/xos/configurations/cord-pod/Makefile
@@ -27,16 +27,22 @@
 	sudo cp id_rsa.pub key_import/volt_rsa.pub
 	sudo cp id_rsa key_import/onos_rsa
 	sudo cp id_rsa key_import/onos_rsa.pub
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/vrouter/vrouter-onboard.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/volt/volt-onboard.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/vsg/vsg-onboard.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/vtn/vtn-onboard.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/onos/onos-onboard.yaml
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/fabric/fabric-onboard.yaml
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/onboard/vtr/vtr-onboard.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/configurations/cord-pod/synchronizers.yaml
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py None /opt/xos/configurations/cord-pod/enable-onboarding.yaml
+	bash ../common/wait_for_onboarding_ready.sh 81 services/vrouter
 	bash ../common/wait_for_onboarding_ready.sh 81 services/volt
 	bash ../common/wait_for_onboarding_ready.sh 81 services/vsg
 	bash ../common/wait_for_onboarding_ready.sh 81 services/vtn
 	bash ../common/wait_for_onboarding_ready.sh 81 services/onos
+	bash ../common/wait_for_onboarding_ready.sh 81 services/fabric
+	bash ../common/wait_for_onboarding_ready.sh 81 services/vtr
 	bash ../common/wait_for_onboarding_ready.sh 81 xos
 	bash ../common/wait_for_xos_port.sh 80
 
diff --git a/xos/configurations/cord-pod/docker-compose-bootstrap.yml b/xos/configurations/cord-pod/docker-compose-bootstrap.yml
index 9243491..83bb685 100644
--- a/xos/configurations/cord-pod/docker-compose-bootstrap.yml
+++ b/xos/configurations/cord-pod/docker-compose-bootstrap.yml
@@ -119,20 +119,20 @@
 #            max-size: "100k"
 #            max-file: "5"
 
-xos_synchronizer_fabric:
-    image: xosproject/xos-synchronizer-openstack
-    command: bash -c "sleep 120; python /opt/xos/synchronizers/fabric/fabric-synchronizer.py -C /opt/xos/synchronizers/fabric/fabric_synchronizer_config"
-    labels:
-        org.xosproject.kind: synchronizer
-        org.xosproject.target: fabric
-    links:
-        - xos_db
-    volumes:
-        - .:/root/setup:ro
-    log_driver: "json-file"
-    log_opt:
-            max-size: "100k"
-            max-file: "5"
+#xos_synchronizer_fabric:
+#    image: xosproject/xos-synchronizer-openstack
+#    command: bash -c "sleep 120; python /opt/xos/synchronizers/fabric/fabric-synchronizer.py -C /opt/xos/synchronizers/fabric/fabric_synchronizer_config"
+#    labels:
+#        org.xosproject.kind: synchronizer
+#        org.xosproject.target: fabric
+#    links:
+#        - xos_db
+#    volumes:
+#        - .:/root/setup:ro
+#    log_driver: "json-file"
+#    log_opt:
+#            max-size: "100k"
+#            max-file: "5"
 
 xos_bootstrap_ui:
     command: python /opt/xos/manage.py runserver 0.0.0.0:81 --insecure --makemigrations
diff --git a/xos/configurations/cord-pod/files/vtr_synchronizer_config b/xos/configurations/cord-pod/files/vtr_synchronizer_config
index 2c9140a..223ab00 100644
--- a/xos/configurations/cord-pod/files/vtr_synchronizer_config
+++ b/xos/configurations/cord-pod/files/vtr_synchronizer_config
@@ -36,7 +36,7 @@
 # set proxy_ssh to false on cloudlab
 full_setup=True
 proxy_ssh=True
-proxy_ssh_key=/opt/xos/synchronizers/vtr/node_key
+proxy_ssh_key=/root/setup/node_key
 proxy_ssh_user=root
 
 [networking]
diff --git a/xos/configurations/cord-pod/synchronizers.yaml b/xos/configurations/cord-pod/synchronizers.yaml
index 1e001b7..02035e3 100644
--- a/xos/configurations/cord-pod/synchronizers.yaml
+++ b/xos/configurations/cord-pod/synchronizers.yaml
@@ -1,6 +1,6 @@
 tosca_definitions_version: tosca_simple_yaml_1_0
 
-description: Onboard the exampleservice
+description: This recipe provides additional configuration for the onboarded services.
 
 imports:
    - custom_types/xos.yaml
@@ -12,3 +12,8 @@
       properties:
         no-create: true
         synchronizer_config: /root/setup/files/vcpe_synchronizer_config
+    servicecontroller#vtr:
+      type: tosca.nodes.ServiceController
+      properties:
+        no-create: true
+        synchronizer_config: /root/setup/files/vtr_synchronizer_config
diff --git a/xos/core/admin.py b/xos/core/admin.py
index c5e36be..4c46d81 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1060,7 +1060,7 @@
 class ServiceControllerAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "name",)
     list_display_links = ('backend_status_icon', 'name',)
-    fieldList = ["backend_status_text", "name", "xos", "base_url"]
+    fieldList = ["backend_status_text", "name", "xos", "base_url", "synchronizer_run", "synchronizer_config"]
     fieldsets = [
         (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     inlines = [ServiceControllerResourceInline]
diff --git a/xos/services/fabric/admin.py b/xos/onboard/fabric/admin.py
similarity index 100%
rename from xos/services/fabric/admin.py
rename to xos/onboard/fabric/admin.py
diff --git a/xos/onboard/fabric/fabric-onboard.yaml b/xos/onboard/fabric/fabric-onboard.yaml
new file mode 100644
index 0000000..e0f0fa7
--- /dev/null
+++ b/xos/onboard/fabric/fabric-onboard.yaml
@@ -0,0 +1,24 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the fabric
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    servicecontroller#fabric:
+      type: tosca.nodes.ServiceController
+      properties:
+          base_url: file:///opt/xos/onboard/fabric/
+          # The following will concatenate with base_url automatically, if
+          # base_url is non-null.
+          models: models.py
+          admin: admin.py
+          admin_template: templates/fabricadmin.html
+          synchronizer: synchronizer/manifest
+          synchronizer_run: fabric-synchronizer.py
+          tosca_resource: tosca/resources/fabricservice.py
+          #private_key: file:///opt/xos/key_import/vsg_rsa
+          #public_key: file:///opt/xos/key_import/vsg_rsa.pub
+
diff --git a/xos/services/fabric/models.py b/xos/onboard/fabric/models.py
similarity index 100%
rename from xos/services/fabric/models.py
rename to xos/onboard/fabric/models.py
diff --git a/xos/synchronizers/fabric/fabric-synchronizer.py b/xos/onboard/fabric/synchronizer/fabric-synchronizer.py
similarity index 100%
rename from xos/synchronizers/fabric/fabric-synchronizer.py
rename to xos/onboard/fabric/synchronizer/fabric-synchronizer.py
diff --git a/xos/synchronizers/fabric/fabric_synchronizer_config b/xos/onboard/fabric/synchronizer/fabric_synchronizer_config
similarity index 100%
rename from xos/synchronizers/fabric/fabric_synchronizer_config
rename to xos/onboard/fabric/synchronizer/fabric_synchronizer_config
diff --git a/xos/onboard/fabric/synchronizer/manifest b/xos/onboard/fabric/synchronizer/manifest
new file mode 100644
index 0000000..62a0722
--- /dev/null
+++ b/xos/onboard/fabric/synchronizer/manifest
@@ -0,0 +1,9 @@
+manifest
+fabric_synchronizer_config
+steps/sync_host.yaml
+steps/sync_vroutertenant.py
+start.sh
+stop.sh
+model-deps
+run.sh
+fabric-synchronizer.py
diff --git a/xos/synchronizers/fabric/model-deps b/xos/onboard/fabric/synchronizer/model-deps
similarity index 100%
rename from xos/synchronizers/fabric/model-deps
rename to xos/onboard/fabric/synchronizer/model-deps
diff --git a/xos/synchronizers/fabric/run.sh b/xos/onboard/fabric/synchronizer/run.sh
similarity index 100%
rename from xos/synchronizers/fabric/run.sh
rename to xos/onboard/fabric/synchronizer/run.sh
diff --git a/xos/synchronizers/fabric/start.sh b/xos/onboard/fabric/synchronizer/start.sh
similarity index 100%
rename from xos/synchronizers/fabric/start.sh
rename to xos/onboard/fabric/synchronizer/start.sh
diff --git a/xos/synchronizers/fabric/steps/sync_host.yaml b/xos/onboard/fabric/synchronizer/steps/sync_host.yaml
similarity index 100%
rename from xos/synchronizers/fabric/steps/sync_host.yaml
rename to xos/onboard/fabric/synchronizer/steps/sync_host.yaml
diff --git a/xos/synchronizers/fabric/steps/sync_vroutertenant.py b/xos/onboard/fabric/synchronizer/steps/sync_vroutertenant.py
similarity index 100%
rename from xos/synchronizers/fabric/steps/sync_vroutertenant.py
rename to xos/onboard/fabric/synchronizer/steps/sync_vroutertenant.py
diff --git a/xos/synchronizers/fabric/stop.sh b/xos/onboard/fabric/synchronizer/stop.sh
similarity index 100%
rename from xos/synchronizers/fabric/stop.sh
rename to xos/onboard/fabric/synchronizer/stop.sh
diff --git a/xos/services/fabric/templates/fabricadmin.html b/xos/onboard/fabric/templates/fabricadmin.html
similarity index 100%
rename from xos/services/fabric/templates/fabricadmin.html
rename to xos/onboard/fabric/templates/fabricadmin.html
diff --git a/xos/tosca/resources/fabricservice.py b/xos/onboard/fabric/tosca/resources/fabricservice.py
similarity index 100%
rename from xos/tosca/resources/fabricservice.py
rename to xos/onboard/fabric/tosca/resources/fabricservice.py
diff --git a/xos/services/vrouter/admin.py b/xos/onboard/vrouter/admin.py
similarity index 100%
rename from xos/services/vrouter/admin.py
rename to xos/onboard/vrouter/admin.py
diff --git a/xos/services/vrouter/models.py b/xos/onboard/vrouter/models.py
similarity index 96%
rename from xos/services/vrouter/models.py
rename to xos/onboard/vrouter/models.py
index 05b57e2..d302b13 100644
--- a/xos/services/vrouter/models.py
+++ b/xos/onboard/vrouter/models.py
@@ -15,8 +15,12 @@
 class ConfigurationError(Exception):
     pass
 
+
 VROUTER_KIND = "vROUTER"
 
+# NOTE: don't change VROUTER_KIND unless you also change the reference to it
+#   in tosca/resources/network.py
+
 CORD_USE_VTN = getattr(Config(), "networking_use_vtn", False)
 
 class VRouterService(Service):
diff --git a/xos/services/vrouter/templates/vrouteradmin.html b/xos/onboard/vrouter/templates/vrouteradmin.html
similarity index 100%
rename from xos/services/vrouter/templates/vrouteradmin.html
rename to xos/onboard/vrouter/templates/vrouteradmin.html
diff --git a/xos/tosca/resources/vrouterservice.py b/xos/onboard/vrouter/tosca/resources/vrouterservice.py
similarity index 100%
rename from xos/tosca/resources/vrouterservice.py
rename to xos/onboard/vrouter/tosca/resources/vrouterservice.py
diff --git a/xos/onboard/vrouter/vrouter-onboard.yaml b/xos/onboard/vrouter/vrouter-onboard.yaml
new file mode 100644
index 0000000..e956c96
--- /dev/null
+++ b/xos/onboard/vrouter/vrouter-onboard.yaml
@@ -0,0 +1,20 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the vRouter SErvice
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    servicecontroller#vrouter:
+      type: tosca.nodes.ServiceController
+      properties:
+          base_url: file:///opt/xos/onboard/vrouter/
+          # The following will concatenate with base_url automatically, if
+          # base_url is non-null.
+          models: models.py
+          admin: admin.py
+          admin_template: templates/vrouteradmin.html
+          tosca_resource: tosca/resources/vrouterservice.py
+
diff --git a/xos/onboard/vtr/synchronizer/steps/sync_vtrtenant.py b/xos/onboard/vtr/synchronizer/steps/sync_vtrtenant.py
index 1932d70..f0f7ef3 100644
--- a/xos/onboard/vtr/synchronizer/steps/sync_vtrtenant.py
+++ b/xos/onboard/vtr/synchronizer/steps/sync_vtrtenant.py
@@ -9,7 +9,7 @@
 from synchronizers.base.ansible import run_template_ssh
 from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
 from core.models import Service, Slice, Tag
-from services.vsg.models import VSGService
+from services.vsg.models import VSGService, VCPE_KIND
 from services.vtr.models import VTRService, VTRTenant
 from services.hpc.models import HpcService, CDNPrefix
 from xos.logger import Logger, logging
@@ -27,7 +27,7 @@
     observes=VTRTenant
     requested_interval=0
     template_name = "sync_vtrtenant.yaml"
-    service_key_name = "/opt/xos/synchronizers/vtr/vcpe_private_key"
+    #service_key_name = "/opt/xos/services/vtr/vcpe_private_key"
 
     def __init__(self, *args, **kwargs):
         super(SyncVTRTenant, self).__init__(*args, **kwargs)
@@ -66,6 +66,15 @@
         else:
             return None
 
+    def get_key_name(self, instance):
+        if instance.slice.service and (instance.slice.service.kind==VCPE_KIND):
+            # We need to use the vsg service's private key. Onboarding won't
+            # by default give us another service's private key, so let's assume
+            # onboarding has been configured to add vsg_rsa to the vtr service.
+            return "/opt/xos/services/vtr/keys/vsg_rsa"
+        else:
+            raise Exception("VTR doesn't know how to get the private key for this instance")
+
     def get_extra_attributes(self, o):
         vtr_service = self.get_vtr_service(o)
         vcpe_service = self.get_vcpe_service(o)
diff --git a/xos/synchronizers/base/SyncInstanceUsingAnsible.py b/xos/synchronizers/base/SyncInstanceUsingAnsible.py
index 49ca23b..dd7e5c6 100644
--- a/xos/synchronizers/base/SyncInstanceUsingAnsible.py
+++ b/xos/synchronizers/base/SyncInstanceUsingAnsible.py
@@ -82,6 +82,21 @@
     def get_node_key(self, node):
         return "/root/setup/node_key"
 
+    def get_key_name(self, instance):
+        if instance.isolation=="vm":
+            if (instance.slice) and (instance.slice.service) and (instance.slice.service.private_key_fn):
+                key_name = instance.slice.service.private_key_fn
+            else:
+                raise Exception("Make sure to set private_key_fn in the service")
+        elif instance.isolation=="container":
+            node = self.get_node(instance)
+            key_name = self.get_node_key(node)
+        else:
+            # container in VM
+            key_name = instance.parent.slice.service.private_key_fn
+
+        return key_name
+
     def get_ansible_fields(self, instance):
         # return all of the fields that tell Ansible how to talk to the context
         # that's setting up the container.
@@ -95,10 +110,7 @@
                        "username": "ubuntu",
                        "ssh_ip": instance.get_ssh_ip(),
                      }
-            if (instance.slice) and (instance.slice.service) and (instance.slice.service.private_key_fn):
-                key_name = instance.slice.service.private_key_fn
-            else:
-                raise Exception("Make sure to set private_key_fn in the service")
+
         elif (instance.isolation == "container"):
             # container on bare metal
             node = self.get_node(instance)
@@ -110,7 +122,6 @@
                        "container_name": "%s-%s" % (instance.slice.name, str(instance.id))
                        # ssh_ip is not used for container-on-metal
                      }
-            key_name = self.get_node_key(node)
         else:
             # container in a VM
             if not instance.parent:
@@ -128,8 +139,8 @@
                        "ssh_ip": instance.parent.get_ssh_ip(),
                        "container_name": "%s-%s" % (instance.slice.name, str(instance.id))
                          }
-            key_name = instance.parent.slice.service.private_key_fn
 
+        key_name = self.get_key_name(instance)
         if not os.path.exists(key_name):
             raise Exception("Node key %s does not exist" % key_name)
 
diff --git a/xos/tools/xos-manage b/xos/tools/xos-manage
index 8871c12..1a3961f 100755
--- a/xos/tools/xos-manage
+++ b/xos/tools/xos-manage
@@ -147,9 +147,9 @@
 #    python ./manage.py makemigrations onos
     python ./manage.py makemigrations openvpn
 #    python ./manage.py makemigrations vtr
-    python ./manage.py makemigrations vrouter
+#    python ./manage.py makemigrations vrouter
 #    python ./manage.py makemigrations vtn
-    python ./manage.py makemigrations fabric
+#    python ./manage.py makemigrations fabric
     #python ./manage.py makemigrations servcomp
 
     if [[ -e /opt/xos/xos/xosbuilder_migration_list ]]; then
diff --git a/xos/tosca/resources/network.py b/xos/tosca/resources/network.py
index fc143d0..8672b76 100644
--- a/xos/tosca/resources/network.py
+++ b/xos/tosca/resources/network.py
@@ -72,8 +72,8 @@
             if existing_tenancy:
                 self.info("Tenancy relationship from %s to %s already exists" % (str(obj), str(provider_service)))
             else:
-                from services.vrouter.models import VROUTER_KIND, VRouterService
-                if provider_service.kind == VROUTER_KIND:
+                if provider_service.kind == "vROUTER":
+                    from services.vrouter.models import VRouterService
                     tenancy = VRouterService.objects.get(id=provider_service.id).get_tenant(address_pool_name="addresses_"+obj.name, subscriber_network=obj)
                     tenancy.save()
                     obj.subnet = tenancy.cidr
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index 417caa0..c292432 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -189,9 +189,9 @@
     'services.syndicate_storage',
     'services.openvpn',
 #    'services.vtr',
-    'services.vrouter',
+#    'services.vrouter',
 #    'services.vtn',
-    'services.fabric',
+#    'services.fabric',
     'geoposition',
     'rest_framework_swagger',
 )