reorg to use common/tosca/ directory for shared TOSCA files, update of opencloud service-profile
unified config into common/Makedefs, included common/Makefile
strip last path component to get directory
clarify container target names, dependency fixes on service dir
fix test-standalone
converted other configs, added .DEFAULT_GOAL's
immediately set paths, run docker under sudo
port and cleanup fixes
fixes after testing cord-pod
follow log files, fix typo metronetwork/xos.yaml

Change-Id: I3e28d10ffd37a22c4a2927288924db453ed6ec44
diff --git a/opencloud/Makefile b/opencloud/Makefile
index 03168ed..0424950 100644
--- a/opencloud/Makefile
+++ b/opencloud/Makefile
@@ -1,36 +1,45 @@
-xos:
-	sudo docker-compose up -d
-	bash ./wait_for_xos.sh
-	sudo docker-compose run xos python /opt/xos/tosca/run.py none /opt/xos/configurations/common/fixtures.yaml
-	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/opencloud/opencloud.yaml
+# opencloud/Makefile
 
-containers:
-	cd ../../../containers/xos; make devel
-	cd ../../../containers/synchronizer; make
+CONFIG_DIR         := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+COMMON_DIR         := $(abspath ../common )
 
-stop:
-	sudo docker-compose stop
+.DEFAULT_GOAL      := xos
 
-showlogs:
-	sudo docker-compose logs
+DOCKER_PROJECT     ?= oc
+BOOTSTRAP_PROJECT  ?= ocb
 
-rm: stop
-	sudo docker-compose rm
+# Include common functions
+include $(COMMON_DIR)/Makefile
 
-ps:
-	sudo docker-compose ps
+xos: prereqs config_dirs xos_download opencloud_services bootstrap onboarding podconfig
 
-enter-xos:
-	sudo docker exec -it devel_xos_1 bash
+opencloud_services: $(SERVICE_DIR) \
+	$(SERVICE_DIR)/onos-service \
+	$(SERVICE_DIR)/openstack \
+	$(SERVICE_DIR)/vrouter \
+	$(SERVICE_DIR)/vtn
 
-enter-synchronizer:
-	sudo docker exec -it devel_xos_synchronizer_openstack_1 bash
+onboarding: synchronizers.yaml id_rsa id_rsa.pub
+	@echo "[ONBOARDING]"
+	bash $(COMMON_DIR)/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) xos
+	$(RUN_TOSCA_BOOTSTRAP) $(COMMON_DIR)/tosca/disable-onboarding.yaml
+	sudo cp id_rsa key_import/onos_rsa
+	sudo cp id_rsa.pub key_import/onos_rsa.pub
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/openstack/xos/openstack-onboard.yaml
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/vrouter/xos/vrouter-onboard.yaml
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/vtn/xos/vtn-onboard.yaml
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/onos-service/xos/onos-onboard.yaml
+	$(RUN_TOSCA_BOOTSTRAP) synchronizers.yaml
+	$(RUN_TOSCA_BOOTSTRAP) $(COMMON_DIR)/tosca/enable-onboarding.yaml
+	bash $(COMMON_DIR)/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) services/vrouter
+	bash $(COMMON_DIR)/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) services/vtn
+	bash $(COMMON_DIR)/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) services/onos
+	bash $(COMMON_DIR)/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) xos
+	bash $(COMMON_DIR)/wait_for_xos_port.sh $(XOS_UI_PORT)
 
-upgrade_pkgs:
-	sudo pip install httpie --upgrade
+podconfig: nodes.yaml images.yaml
+	@echo "[PODCONFIG]"
+	$(RUN_TOSCA) $(COMMON_DIR)/tosca/setup.yaml
+	$(RUN_TOSCA) nodes.yaml
+	$(RUN_TOSCA) images.yaml
 
-rebuild_xos:
-	make -C ../../../containers/xos devel
-
-rebuild_synchronizer:
-	make -C ../../../containers/synchronizer
diff --git a/opencloud/docker-compose-bootstrap.yml b/opencloud/docker-compose-bootstrap.yml
new file mode 100644
index 0000000..8a4c7b2
--- /dev/null
+++ b/opencloud/docker-compose-bootstrap.yml
@@ -0,0 +1,48 @@
+xos_db:
+    image: xosproject/xos-postgres
+    expose:
+        - "5432"
+
+xos_redis:
+    image: redis
+    log_driver: "json-file"
+    log_opt:
+            max-size: "100k"
+            max-file: "5"
+
+xos_synchronizer_onboarding:
+    image: xosproject/xos-synchronizer-onboarding
+    command: bash -c "cd /opt/xos/synchronizers/onboarding; ./run.sh"
+    #command: sleep 86400
+    labels:
+        org.xosproject.kind: synchronizer
+        org.xosproject.target: onboarding
+    links:
+        - xos_db
+    volumes:
+        - /var/run/docker.sock:/var/run/docker.sock
+        - ./key_import:/opt/xos/key_import:ro
+        - ./onboarding-docker-compose:/opt/xos/synchronizers/onboarding/docker-compose
+        - ../../xos_services:/opt/xos_services
+    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
+    environment:
+        - CONFIG_DIR
+    image: xosproject/xos
+    links:
+        - xos_db
+    ports:
+        - "81:81"
+    volumes:
+        - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
+        - ./files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
+        - ../../xos_services:/opt/xos_services
+    log_driver: "json-file"
+    log_opt:
+            max-size: "100k"
+            max-file: "5"
diff --git a/opencloud/files/xos_vtn_config b/opencloud/files/xos_vtn_config
new file mode 100644
index 0000000..5dfd459
--- /dev/null
+++ b/opencloud/files/xos_vtn_config
@@ -0,0 +1,2 @@
+[networking]
+use_vtn=True
diff --git a/opencloud/images/.gitignore b/opencloud/images/.gitignore
new file mode 100644
index 0000000..6949d1f
--- /dev/null
+++ b/opencloud/images/.gitignore
@@ -0,0 +1,3 @@
+*.img
+*.qcow2
+*.qcow
diff --git a/opencloud/images/README.md b/opencloud/images/README.md
new file mode 100644
index 0000000..aca55a9
--- /dev/null
+++ b/opencloud/images/README.md
@@ -0,0 +1,5 @@
+# VM images for XOS
+
+Any Cloud image files placed in this directory (with suffix .img) will be automatically
+imported by XOS and added to Glance (OpenStack's image repository).  For instance, the image
+`trusty-server-multi-nic.img` will be imported with name `trusty-server-multi-nic`.
diff --git a/opencloud/cdn-content.yaml b/opencloud/legacy/cdn-content.yaml
similarity index 100%
rename from opencloud/cdn-content.yaml
rename to opencloud/legacy/cdn-content.yaml
diff --git a/opencloud/cdn-opencloud.yaml b/opencloud/legacy/cdn-opencloud.yaml
similarity index 100%
rename from opencloud/cdn-opencloud.yaml
rename to opencloud/legacy/cdn-opencloud.yaml
diff --git a/opencloud/cdn-syndicate-content.yaml b/opencloud/legacy/cdn-syndicate-content.yaml
similarity index 100%
rename from opencloud/cdn-syndicate-content.yaml
rename to opencloud/legacy/cdn-syndicate-content.yaml
diff --git a/opencloud/docker-compose.yml b/opencloud/legacy/docker-compose.yml
similarity index 100%
rename from opencloud/docker-compose.yml
rename to opencloud/legacy/docker-compose.yml
diff --git a/opencloud/opencloud.yaml b/opencloud/legacy/opencloud.yaml
similarity index 100%
rename from opencloud/opencloud.yaml
rename to opencloud/legacy/opencloud.yaml
diff --git a/opencloud/files/xos_opencloud_config b/opencloud/legacy/xos_opencloud_config
similarity index 100%
rename from opencloud/files/xos_opencloud_config
rename to opencloud/legacy/xos_opencloud_config
diff --git a/opencloud/synchronizers.yaml b/opencloud/synchronizers.yaml
new file mode 100644
index 0000000..b75b0e5
--- /dev/null
+++ b/opencloud/synchronizers.yaml
@@ -0,0 +1,14 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: This recipe provides additional configuration for the onboarded services.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    servicecontroller#openstack:
+      type: tosca.nodes.ServiceController
+      properties:
+        no-create: true
+        synchronizer_config: /root/setup/files/openstack_synchronizer_config
diff --git a/opencloud/wait_for_xos.sh b/opencloud/wait_for_xos.sh
deleted file mode 100644
index 4f486af..0000000
--- a/opencloud/wait_for_xos.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#! /bin/bash
-echo "Waiting for XOS to come up"
-until http 0.0.0.0:80 &> /dev/null
-do
-    sleep 1
-    RUNNING_CONTAINER=`sudo docker ps|grep "xos"|awk '{print $$NF}'`
-    if [[ $RUNNING_CONTAINER == "" ]]; then
-        echo Container may have failed. check with \"make showlogs\'
-        exit 1
-    fi
-done
-echo "XOS is ready"
diff --git a/opencloud/xos.yaml b/opencloud/xos.yaml
new file mode 100644
index 0000000..6fd072d
--- /dev/null
+++ b/opencloud/xos.yaml
@@ -0,0 +1,57 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: bootstrap XOS for OpenCloud
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    xos:
+      type: tosca.nodes.XOS
+      properties:
+        ui_port: 80
+        bootstrap_ui_port: 81
+        docker_project_name: oc
+        db_container_name: ocb_xos_db_1
+
+    /opt/xos/xos_configuration/xos_common_config:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, ../common/xos_common_config, ENV_VAR ] }
+          read_only: true
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/xos_configuration/xos_vtn_config:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, files/xos_vtn_config, ENV_VAR ] }
+          read_only: true
+      requirements:
+          - xos:
+              node: xos
+              relationship: tosca.relationships.UsedByXOS
+
+    /root/setup:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, ., ENV_VAR ] }
+          read_only: true
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/images:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, images, ENV_VAR ] }
+          read_only: true
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS
+