Fixes to make ACORD service-profile work in devstack mitaka backend-part1

Change-Id: Ie0d2e8dc6d3a9a92506e21a23c7bc6df73deca9e
diff --git a/acord/Makefile b/acord/Makefile
index e9b234c..07d49b5 100644
--- a/acord/Makefile
+++ b/acord/Makefile
@@ -1,20 +1,67 @@
-SETUPDIR:=../setup
+include ../common/Makedefs
+
 MYIP:=$(shell hostname -i)
+CONFIG_DIR:=$(shell pwd)
+DOCKER_COMPOSE_YML=./onboarding-docker-compose/docker-compose.yml
+BOOTSTRAP_YML=./docker-compose-bootstrap.yml
+DOCKER_PROJECT=acord
+BOOTSTRAP_PROJECT=acordbs
+XOS_BOOTSTRAP_PORT=9998
+XOS_UI_PORT=9999
+ADMIN_USERNAME=padmin@vicci.org
+ADMIN_PASSWORD=letmein
+RUN_TOSCA_BOOTSTRAP=python ../common/run_tosca.py $(XOS_BOOTSTRAP_PORT) $(ADMIN_USERNAME) $(ADMIN_PASSWORD)
+RUN_TOSCA=python ../common/run_tosca.py $(XOS_UI_PORT) $(ADMIN_USERNAME) $(ADMIN_PASSWORD)
 
-cloudlab: common_cloudlab cloudlab_ceilometer_custom_images ceilometer_cloudlab_cord_plugins acord
+cloudlab: download_xos common_cloudlab local_containers xos
 
-devstack: upgrade_pkgs common_devstack devstack_net_fix devstack_images ceilometer_devstack_cord_plugins acord
+devstack: download_xos upgrade_pkgs common_devstack local_containers xos devstack_net_fix
 
-cord: 
-	sudo MYIP=$(MYIP) docker-compose up -d
-	bash ../common/wait_for_xos.sh
-	sudo MYIP=$(MYIP) 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 none /opt/xos/configurations/common/mydeployment.yaml
-	sudo MYIP=$(MYIP) docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/cloudlab-openstack.yaml
-	sudo MYIP=$(MYIP) docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/nodes.yaml
+xos: dirs download_services bootstrap onboarding develconfig
 
-acord: cord exampleservice
-	sudo MYIP=$(MYIP) docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/acord/ceilometer.yaml
+dirs:
+	# if this directory doesn't exist, then docker-compose will create it with root permission
+	mkdir -p key_import
+	mkdir -p onboarding-docker-compose
+
+download_xos:
+	make -f ../common/Makefile.services xos_core
+
+download_services:
+	make -f ../common/Makefile.services
+
+bootstrap:
+	echo "[BOOTSTRAP]"
+	sudo rm -f onboarding-docker-compose/docker-compose.yml
+	sudo CONFIG_DIR=$(CONFIG_DIR) MYIP=$(MYIP) docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) up -d
+	bash ../common/wait_for_xos_port.sh $(XOS_BOOTSTRAP_PORT)
+	sudo docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py none - < ../common/fixtures.yaml
+	sudo docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) run xos_bootstrap_ui python /opt/xos/tosca/run.py none - < ../common/mydeployment.yaml
+	$(RUN_TOSCA_BOOTSTRAP) xos.yaml
+
+onboarding:
+	echo "[ONBOARDING]"
+	# on-board any services here
+	bash ../common/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) xos
+	bash ../common/wait_for_xos_port.sh $(XOS_UI_PORT)
+
+develconfig:
+	$(RUN_TOSCA) ../common/cloudlab-openstack.yaml
+	$(RUN_TOSCA) ../setup/nodes.yaml
+
+cord-monitoringservice: devstack_ceilometer_custom_images onboard-monitoringservice ceilometer_devstack_cord_plugins
+	$(RUN_TOSCA) ceilometer.yaml
+
+onboard-monitoringservice: download-monitoringservice
+	sudo cp ~/.ssh/id_rsa key_import/monitoringservice_rsa
+	sudo cp ~/.ssh/id_rsa.pub key_import/monitoringservice_rsa.pub
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/monitoring/xos/monitoring-onboard.yaml
+	bash ../common/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) services/monitoring
+	bash ../common/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) xos
+	bash ../common/wait_for_xos_port.sh $(XOS_UI_PORT)
+
+download-monitoringservice:
+	make -f ../common/Makefile.services monitoring_services
 
 exampleservice:
 	#Ensure exampleservice is enabled in xos/tools/xos-manage and xos/settings.py file before uncommenting below lines
@@ -30,6 +77,9 @@
 common_devstack:
 	make -C ../common -f Makefile.devstack
 
+local_containers:
+	make -f ../common/Makefile.containers update_certs xos_base xos_devel synchronizer onboarding_synchronizer
+
 ceilometer_cloudlab_cord_plugins:
 	if [ -d ./ceilometer-plugins ]; then rm -fr ./ceilometer-plugins; fi
 	git clone https://github.com/srikanthvavila/ceilometer-plugins.git
@@ -44,12 +94,12 @@
 	sudo service ceilometer-agent-central restart
 
 ceilometer_devstack_cord_plugins:
-	if [ -d ./ceilometer-plugins ]; then rm -fr ./ceilometer-plugins; fi
-	git clone https://github.com/srikanthvavila/ceilometer-plugins.git
-	sudo cp -r ceilometer-plugins/network/ext_services /opt/stack/ceilometer/ceilometer/network/
-	sudo cp ceilometer-plugins/entry_points.txt /opt/stack/ceilometer/ceilometer*egg-info/
-	sudo cp ceilometer-plugins/pipeline.yaml /etc/ceilometer/
-	echo "Remember to restart ceilometer-anotification ceilometer-acentral screens"
+	#if [ -d ./ceilometer-plugins ]; then rm -fr ./ceilometer-plugins; fi
+	#git clone https://github.com/srikanthvavila/ceilometer-plugins.git
+	#sudo cp -r ceilometer-plugins/network/ext_services /opt/stack/ceilometer/ceilometer/network/
+	#sudo cp ceilometer-plugins/entry_points.txt /opt/stack/ceilometer/ceilometer*egg-info/
+	#sudo cp ceilometer-plugins/pipeline.yaml /etc/ceilometer/
+	#echo "Remember to restart ceilometer-anotification ceilometer-acentral screens"
 
 ceilometer_pub_sub:
 	if [ -d ./pub-sub ]; then rm -fr ./pub-sub; fi
@@ -59,21 +109,26 @@
 	cd ../..
 
 stop:
-	sudo MYIP=$(MYIP) docker-compose stop
+	test ! -s $(DOCKER_COMPOSE_YML) || sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) stop
+	sudo docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) stop
 
 rm: stop
-	sudo MYIP=$(MYIP) docker-compose rm
+	test ! -s $(DOCKER_COMPOSE_YML) || sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) rm -f
+	sudo docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) rm -f
 
 showlogs:
-	sudo MYIP=$(MYIP) docker-compose logs
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) logs
 
-ps:
-	sudo MYIP=$(MYIP) docker-compose ps
+showlogs_bootstrap:
+	sudo docker-compose -p $(BOOTSTRAP_PROJECT) -f $(BOOTSTRAP_YML) logs
 
 cleanup: stop rm
 	./cleanup.sh
 	bash -c "source ../setup/admin-openrc.sh; nova list --all-tenants; neutron net-list"
 
+ps:
+	sudo MYIP=$(MYIP) docker-compose ps
+
 devstack_net_fix:
 	sudo ../common/devstack/net-fix.sh
 	sudo bash -c "source ../setup/admin-openrc.sh; neutron subnet-update private-subnet --dns-nameservers list=true 8.8.8.8 8.8.4.4"
@@ -87,8 +142,10 @@
 rebuild_synchronizer:
 	make -C ../../../containers/synchronizer
 
-devstack_images:
-	bash -c "source ../setup/admin-openrc.sh; glance image-show ceilometer-trusty-server-multi-nic || ! mkdir -p /opt/stack/images || ! wget http://www.vicci.org/cord/ceilometer-trusty-server-multi-nic.compressed.qcow2 -P /opt/stack/images || glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /opt/stack/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare"
+devstack_ceilometer_custom_images:
+	#Assuming Openstack Mitaka backend. The glance commands require --os-image-api-version 1 to be passed to use v1 version of glance APIs
+	bash -c "source ../setup/admin-openrc.sh; glance --os-image-api-version 1 image-show ceilometer-trusty-server-multi-nic || ! mkdir -p /opt/stack/images || ! wget http://www.vicci.org/cord/ceilometer-trusty-server-multi-nic.compressed.qcow2 -P /opt/stack/images || glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /opt/stack/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare"
 
 cloudlab_ceilometer_custom_images:
-	bash -c "source ../setup/admin-openrc.sh; glance image-show ceilometer-trusty-server-multi-nic || if test -f /proj/xos-PG0/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 ; then glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /proj/xos-PG0/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare ; else mkdir -p /tmp/images && wget http://www.vicci.org/cord/ceilometer-trusty-server-multi-nic.compressed.qcow2 -P /tmp/images && glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /tmp/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare ; fi "
+	bash -c "source ../setup/admin-openrc.sh; glance image-show --os-image-api-version 1 ceilometer-trusty-server-multi-nic || if test -f /proj/xos-PG0/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 ; then glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /proj/xos-PG0/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare ; else mkdir -p /tmp/images && wget http://www.vicci.org/cord/ceilometer-trusty-server-multi-nic.compressed.qcow2 -P /tmp/images && glance image-create --name ceilometer-trusty-server-multi-nic --disk-format qcow2 --file /tmp/images/ceilometer-trusty-server-multi-nic.compressed.qcow2 --container-format bare ; fi "
+
diff --git a/acord/ceilometer.yaml b/acord/ceilometer.yaml
index 089837d..43ca71a 100644
--- a/acord/ceilometer.yaml
+++ b/acord/ceilometer.yaml
@@ -120,21 +120,22 @@
       type: tosca.nodes.CeilometerService
       requirements:
       properties:
-          view_url: /admin/ceilometer/ceilometerservice/$id$/
+          view_url: /admin/monitoring/ceilometerservice/$id$/
           kind: ceilometer
           ceilometer_pub_sub_url: http://130.127.133.58:4455/
           public_key: { get_artifact: [ SELF, pubkey, LOCAL_FILE] }
+          private_key_fn: /opt/xos/services/monitoring/keys/monitoringservice_rsa
       artifacts:
-          pubkey: /opt/xos/synchronizers/monitoring_channel/monitoring_channel_public_key
+          pubkey: /opt/xos/services/monitoring/keys/monitoringservice_rsa.pub
 
-    service_sflow:
-      type: tosca.nodes.SFlowService
-      requirements:
-      properties:
-          view_url: /admin/ceilometer/sflowservice/$id$/
-          kind: sflow
-          sflow_port: 6343
-          sflow_api_port: 33333
+#    service_sflow:
+#      type: tosca.nodes.SFlowService
+#      requirements:
+#      properties:
+#          view_url: /admin/ceilometer/sflowservice/$id$/
+#          kind: sflow
+#          sflow_port: 6343
+#          sflow_api_port: 33333
 
     Private:
       type: tosca.nodes.NetworkTemplate
@@ -183,27 +184,25 @@
           - m1.small:
                 node: m1.small
                 relationship: tosca.relationships.DefaultFlavor
-      properties:
-          max_instances: 2
 
-    mysite_sflow:
-      description: Slice for sFlow service
-      type: tosca.nodes.Slice
-      requirements:
-          - sflow_service:
-              node: service_sflow
-              relationship: tosca.relationships.MemberOfService
-          - site:
-              node: mysite
-              relationship: tosca.relationships.MemberOfSite
-          - default_image:
-                node: trusty-server-multi-nic
-                relationship: tosca.relationships.DefaultImage
-          - m1.small:
-                node: m1.small
-                relationship: tosca.relationships.DefaultFlavor
-      properties:
-          max_instances: 2
+#    mysite_sflow:
+#      description: Slice for sFlow service
+#      type: tosca.nodes.Slice
+#      requirements:
+#          - sflow_service:
+#              node: service_sflow
+#              relationship: tosca.relationships.MemberOfService
+#          - site:
+#              node: mysite
+#              relationship: tosca.relationships.MemberOfSite
+#          - default_image:
+#                node: trusty-server-multi-nic
+#                relationship: tosca.relationships.DefaultImage
+#          - m1.small:
+#                node: m1.small
+#                relationship: tosca.relationships.DefaultFlavor
+#      properties:
+#          max_instances: 2
 
     my_ceilometer_tenant:
       description: Ceilometer Service default Tenant
@@ -213,28 +212,28 @@
               node: service_ceilometer
               relationship: tosca.relationships.MemberOfService
        
-    # Virtual machines
-    sflow_service_instance:
-      type: tosca.nodes.Compute
-      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_sflow
-                relationship: tosca.relationships.MemberOfSlice
+#    # Virtual machines
+#    sflow_service_instance:
+#      type: tosca.nodes.Compute
+#      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_sflow
+#                relationship: tosca.relationships.MemberOfSlice
 
     Ceilometer:
       type: tosca.nodes.DashboardView
diff --git a/acord/docker-compose-bootstrap.yml b/acord/docker-compose-bootstrap.yml
new file mode 100644
index 0000000..dc2b2af
--- /dev/null
+++ b/acord/docker-compose-bootstrap.yml
@@ -0,0 +1,58 @@
+xos_db:
+    image: xosproject/xos-postgres
+    expose:
+        - "5432"
+
+xos_bootstrap_ui:
+    image: xosproject/xos
+    command: python /opt/xos/manage.py runserver 0.0.0.0:9998 --insecure --makemigrations
+    environment:
+        - CONFIG_DIR
+    ports:
+        - "9998:9998"
+    links:
+        - xos_db
+    volumes:
+      - ../setup:/root/setup:ro
+      - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config
+      - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
+      - ../../xos_services:/opt/xos_services
+
+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_synchronizer_openstack:
+    command: bash -c "sleep 120; python /opt/xos/synchronizers/openstack/xos-synchronizer.py"
+    image: xosproject/xos-synchronizer-openstack
+    labels:
+        org.xosproject.kind: synchronizer
+        org.xosproject.target: openstack
+    links:
+        - xos_db
+    extra_hosts:
+        - ctl:${MYIP}
+    volumes:
+        - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
+        - ../setup:/root/setup:ro
+        - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
+        - ./images:/opt/xos/images:ro
+    log_driver: "json-file"
+    log_opt:
+            max-size: "100k"
+            max-file: "5"
diff --git a/acord/docker-compose.yml b/acord/docker-compose.yml
index da9562e..9ef6fc7 100644
--- a/acord/docker-compose.yml
+++ b/acord/docker-compose.yml
@@ -4,8 +4,8 @@
         - "5432"
 
 xos_synchronizer_openstack:
-    command: bash -c "sleep 120; python /opt/xos/synchronizers/openstack/xos-synchronizer.py"
     image: xosproject/xos-synchronizer-openstack
+    command: bash -c "sleep 120; python /opt/xos/synchronizers/openstack/xos-synchronizer.py"
     labels:
         org.xosproject.kind: synchronizer
         org.xosproject.target: openstack
@@ -15,35 +15,7 @@
         - ctl:${MYIP}
     volumes:
         - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-        - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
-        - ../setup:/root/setup:ro
-
-xos_synchronizer_monitoring_channel:
-    image: xosproject/xos-synchronizer-openstack
-    command: bash -c "sleep 120; python /opt/xos/synchronizers/monitoring_channel/monitoring_channel_synchronizer.py -C /opt/xos/synchronizers/monitoring_channel/monitoring_channel_synchronizer_config"
-    labels:
-        org.xosproject.kind: synchronizer
-        org.xosproject.target: monitoring_channel
-    links:
-        - xos_db
-    extra_hosts:
-        - ctl:${MYIP}
-    volumes:
-        - ../setup/id_rsa:/opt/xos/synchronizers/monitoring_channel/monitoring_channel_private_key:ro  # private key
-
-#Ensure exampleservice is enabled in xos/tools/xos-manage and xos/settings.py file before uncommenting below lines
-#xos_synchronizer_exampleservice:
-#    image: xosproject/xos-synchronizer-openstack
-#    command: bash -c "sleep 120; python /opt/xos/synchronizers/exampleservice/exampleservice-synchronizer.py -C /opt/xos/synchronizers/exampleservice/exampleservice_config"
-#    labels:
-#        org.xosproject.kind: synchronizer
-#        org.xosproject.target: exampleservice
-#    links:
-#        - xos_db
-#    volumes:
-#        - ../setup:/root/setup:ro
-#        - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-#        - ../setup/id_rsa:/opt/xos/synchronizers/exampleservice/exampleservice_private_key:ro
+        - ./images:/opt/xos/images:ro
 
 # FUTURE
 #xos_swarm_synchronizer:
@@ -62,6 +34,3 @@
     volumes:
       - ../setup:/root/setup:ro
       - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-      - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
-      - ../setup/id_rsa.pub:/opt/xos/synchronizers/monitoring_channel/monitoring_channel_public_key:ro
-#      - ../setup/id_rsa.pub:/opt/xos/synchronizers/exampleservice/exampleservice_public_key:ro
diff --git a/acord/xos.yaml b/acord/xos.yaml
new file mode 100644
index 0000000..a38a6f9
--- /dev/null
+++ b/acord/xos.yaml
@@ -0,0 +1,46 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Onboard the exampleservice
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    xos:
+      type: tosca.nodes.XOS
+      properties:
+        ui_port: 9999
+        bootstrap_ui_port: 9998
+        docker_project_name: acord
+        db_container_name: acordbs_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: false
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/xos_configuration/xos_cord_config:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, xos_cord_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, ../setup, ENV_VAR ] }
+          read_only: false
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS