Changes to support globalxos profile

Change-Id: I7718be0a63deb829ef25053861937ec5457dff80
diff --git a/common/Makedefs b/common/Makedefs
index 73c6bfb..419a594 100644
--- a/common/Makedefs
+++ b/common/Makedefs
@@ -68,3 +68,6 @@
 
 NG_XOS_LIB_BRANCH ?= $(DEFAULT_BRANCH)
 NG_XOS_LIB_URL ?= $(CORD_BASE_GIT_URL)/ng-xos-lib.git
+
+GLOBALXOS_BRANCH ?= $(DEFAULT_BRANCH)
+GLOBALXOS_GIT_URL ?= $(CORD_BASE_GIT_URL)/globalxos.git
diff --git a/common/Makefile b/common/Makefile
index 13f7bf8..48d9277 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -107,6 +107,9 @@
 $(SERVICE_DIR)/openstack:
 	git -C $(SERVICE_DIR) $(GITOPTS) clone -b $(OPENSTACK_BRANCH) $(OPENSTACK_GIT_URL)
 
+$(SERVICE_DIR)/globalxos:
+	git -C $(SERVICE_DIR) $(GITOPTS) clone -b $(GLOBALXOS_BRANCH) $(GLOBALXOS_GIT_URL)
+
 update_services:
 	git -C $(SERVICE_DIR)/exampleservice pull
 	git -C $(SERVICE_DIR)/olt pull
diff --git a/globalxos/Makefile b/globalxos/Makefile
new file mode 100644
index 0000000..9f06064
--- /dev/null
+++ b/globalxos/Makefile
@@ -0,0 +1,34 @@
+# globalxos/Makefile
+
+CONFIG_DIR         := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
+COMMON_DIR         := $(abspath ../common )
+
+.DEFAULT_GOAL      := opencloud
+
+DOCKER_PROJECT     ?= globalxos
+BOOTSTRAP_PROJECT  ?= globalxosbs
+
+XOS_BOOTSTRAP_PORT ?= 9998
+XOS_UI_PORT        ?= 9999
+
+# Include common functions
+include $(COMMON_DIR)/Makefile
+
+opencloud: prereqs config_dirs xos_download bootstrap onboarding opencloudconfig globalxos
+
+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)
+
+opencloudconfig:
+	@echo "[OPENCLOUDCONFIG]"
+	$(RUN_TOSCA) opencloud.yaml
+	$(RUN_TOSCA) dashboard.yaml
+
+globalxos: $(SERVICE_DIR) $(SERVICE_DIR)/globalxos
+	$(RUN_TOSCA_BOOTSTRAP) $(SERVICE_DIR)/globalxos/xos/globalxos-onboard.yaml
+	bash ../common/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) services/globalxos
+	bash ../common/wait_for_onboarding_ready.sh $(XOS_BOOTSTRAP_PORT) xos
+	bash ../common/wait_for_xos_port.sh $(XOS_UI_PORT)
diff --git a/globalxos/README.md b/globalxos/README.md
new file mode 100644
index 0000000..5956113
--- /dev/null
+++ b/globalxos/README.md
@@ -0,0 +1,56 @@
+# Global XOS
+
+This configuration launches an XOS that can control multiple CORD PODs.
+Each POD is configured as a separate Site in Global XOS.
+
+*** FIX FROM HERE ***
+
+## Getting Started
+
+- Navigate to `/service-profile/globalxos` folder
+- Run `make` command
+
+You'll be able to visit XOS at `0.0.0.0:9999`.
+
+### Using Vagrant
+
+A Vagrant environment is provided with an ubuntu_14.04 box (ubuntu/trusty64).
+There are two boxes: `global` and `arizona`.  The `global` box runs Global XOS
+while the `arizona` box runs a sample L-XOS site.
+
+The `global` XOS is available on `localhost:9999`.
+The `arizona` XOS is available on `localhost:9990`.
+
+It will also share the `service-profile` and `xos` folders with the Vagrant box.
+These two directories are intended to be side by side.
+
+How to set it up:
+- Checkout the `service-profile` and `xos` repositories from Vagrant
+- `cd service-profile/globalxos/`
+- Start the Vagrant boxes: `vagrant up`
+- Enter `arizona` Vagrant box: `vagrant ssh arizona`
+- Start a frontend XOS: `cd service-profile/frontend; make local_containers; make; make mock-cord-pod`
+- Exit `arizona` Vagrant box
+- Enter `global` Vagrant box: `vagrant ssh global`
+- Start Global XOS: `cd service-profile/globalxos; make local_containers; make`
+
+If all goes well, the Global XOS should now be able to configure the frontend
+XOS running in the `arizona` box.
+
+### Docker Helpers
+
+Stop the containers: `make stop`
+
+Restart the containers: `make stop; make`
+
+Delete the containers and relaunch them: `make rm; make`
+
+Build the containers from scratch using the local XOS source tree: `make local_containers`
+
+View logs: `make showlogs`
+
+See what containers are running: `make ps`
+
+## Docs
+
+You can find Swagger documentation at: `http://0.0.0.0:9999/docs/`
diff --git a/globalxos/Vagrantfile b/globalxos/Vagrantfile
new file mode 100644
index 0000000..45df252
--- /dev/null
+++ b/globalxos/Vagrantfile
@@ -0,0 +1,40 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.configure(2) do |config|
+
+  config.vm.box = "ubuntu/trusty64"
+
+  config.vm.synced_folder "../", "/home/vagrant/service-profile"
+  config.vm.synced_folder "../../xos", "/home/vagrant/xos", create: true
+  config.vm.synced_folder "../../xos_services", "/home/vagrant/xos_services", create: true
+  config.vm.synced_folder ".", "/vagrant", disabled: true
+
+  config.vm.define "arizona" do |d|
+    d.vm.network "forwarded_port", guest: 9999, host: 9990
+    d.vm.network "private_network", ip: "192.168.33.10"
+    d.vm.provider "virtualbox" do |vb|
+       vb.memory = "1024"
+    end
+  end
+
+  config.vm.define "global" do |d|
+    d.vm.network "forwarded_port", guest: 9999, host: 9999
+    d.vm.network "private_network", ip: "192.168.33.2"
+    d.vm.provider "virtualbox" do |vb|
+       vb.memory = "1024"
+    end
+  end
+
+  config.vm.provision "shell", privileged: false, inline: <<-SHELL
+    sudo apt-get update
+    sudo apt-get install -y apt-transport-https ca-certificates git
+    sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
+    echo deb https://apt.dockerproject.org/repo ubuntu-trusty main | sudo tee /etc/apt/sources.list.d/docker.list
+    sudo apt-get update
+    sudo apt-get install -y git docker-engine python-pip
+    sudo pip install docker-compose
+    sudo groupadd docker
+    sudo usermod -aG docker vagrant
+  SHELL
+end
diff --git a/globalxos/dashboard.yaml b/globalxos/dashboard.yaml
new file mode 100644
index 0000000..9b1b4a2
--- /dev/null
+++ b/globalxos/dashboard.yaml
@@ -0,0 +1,27 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+    * Some sample data to populate the demo frontend
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+
+# You can use this recipe to load the dashboard in the system:
+    GlobalXos:
+      type: tosca.nodes.DashboardView
+      properties:
+        url: template:xosGlobalXos
+
+# And this recipe to activate the dashboard for a user:
+    padmin@vicci.org:
+      type: tosca.nodes.User
+      properties:
+        no-create: true
+        no-delete: true
+      requirements:
+        - globalXos_dashboard:
+            node: GlobalXos
+            relationship: tosca.relationships.UsesDashboard
diff --git a/globalxos/docker-compose-bootstrap.yml b/globalxos/docker-compose-bootstrap.yml
new file mode 100644
index 0000000..57e5355
--- /dev/null
+++ b/globalxos/docker-compose-bootstrap.yml
@@ -0,0 +1,49 @@
+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:
+      - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config
+      - ../cord-pod/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
+      - ../../xos/xos/api/utility:/opt/xos/api/utility
+      - ../../xos/xos/templates:/opt/xos/templates
+      - ../../xos/xos/core/templatetags:/opt/xos/core/templatetags
+      - ../../xos/xos/core/xoslib/dashboards:/opt/xos/core/xoslib/dashboards
+      - ../../xos/xos/core/xoslib/static/css:/opt/xos/core/xoslib/static/css
+      - ../../xos/xos/core/xoslib/static/images:/opt/xos/core/xoslib/static/images
+      - ../../xos/xos/core/xoslib/static/js:/opt/xos/core/xoslib/static/js
+      
+      # The following volumes are sometimes used in development,
+      # but they are not tested and they can break part of the system, handle with care.
+      # - ../../xos_services:/opt/xos_services
+      # - ../../xos/xos/core/models:/opt/xos/core/models
+      # - ../../xos/xos/tosca:/opt/xos/tosca
+      # - ../../xos/xos/xos:/opt/xos/xos
+
+xos_synchronizer_onboarding:
+    image: xosproject/xos
+    command: bash -c "cd /opt/xos/synchronizers/onboarding; ./run.sh"
+    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"
diff --git a/globalxos/opencloud.yaml b/globalxos/opencloud.yaml
new file mode 100644
index 0000000..4586e8c
--- /dev/null
+++ b/globalxos/opencloud.yaml
@@ -0,0 +1,101 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Adds OpenCloud Sites, Deployments, and Controllers.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+
+# Nodes
+    trusty-server-multi-nic:
+      type: tosca.nodes.Image
+      properties:
+         disk_format: QCOW2
+         container_format: BARE
+
+    campus:
+      type: tosca.nodes.Deployment
+      properties:
+          flavors: m1.large, m1.medium, m1.small
+      requirements:
+          - image:
+              node: trusty-server-multi-nic
+              relationship: tosca.relationships.SupportsImage
+
+# controllers
+    campus-arizona:
+      type: tosca.nodes.Controller
+      requirements:
+          - deployment:
+              node: campus
+              relationship: tosca.relationships.ControllerDeployment
+      properties:
+          backend_type: CORD
+          version: 1.1
+          auth_url: http://192.168.33.10:9999/
+          admin_user: padmin@vicci.org
+          admin_password: letmein
+          admin_tenant: admin
+          domain: Default
+
+# Sites
+    arizona:
+      type: tosca.nodes.Site
+      properties:
+          display_name: Arizona
+          site_url: http://opencloud.us/
+          hosts_nodes: false 
+      requirements:
+          - deployment:
+               node: campus
+               relationship: tosca.relationships.MemberOfDeployment
+          - controller:
+               node: campus-arizona
+               relationship: tosca.relationships.UsesController
+
+# Users
+    padmin@vicci.org:
+      type: tosca.nodes.User
+      requirements:
+          - site:
+              node: arizona
+              relationship: tosca.relationships.MemberOfSite
+      properties:
+          is_admin: true
+          is_active: true
+          firstname: XOS
+          lastname: admin
+          password: letmein
+
+    acb@cs.princeton.edu:
+      type: tosca.nodes.User
+      requirements:
+          - site:
+              node: arizona
+              relationship: tosca.relationships.MemberOfSite
+      properties:
+          is_admin: true
+          is_active: true
+          firstname: Andy
+          lastname: Bavier
+          password: letmein
+
+# Slices
+    arizona_myslice:
+      description: A test slice at the Arizona site
+      type: tosca.nodes.Slice
+      properties:
+          network: noauto
+      requirements:
+          - site:
+              node: arizona
+              relationship: tosca.relationships.MemberOfSite
+          - privilege:
+              node: acb@cs.princeton.edu
+              relationship: tosca.relationships.AccessPrivilege
+          - image:
+              node: trusty-server-multi-nic
+              relationship: tosca.relationships.DefaultImage
+# Services
diff --git a/globalxos/rebuild.sh b/globalxos/rebuild.sh
new file mode 100755
index 0000000..50ff7d1
--- /dev/null
+++ b/globalxos/rebuild.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+docker stop globalxos_xos_synchronizer_globalxos_1
+docker rm globalxos_xos_synchronizer_globalxos_1
+docker rmi xosproject/xos-synchronizer-globalxos
+pushd ~/xos_services/globalxos; git pull
+popd; make rebuild
diff --git a/globalxos/xos-cord-branding.yaml b/globalxos/xos-cord-branding.yaml
new file mode 100644
index 0000000..6761f7e
--- /dev/null
+++ b/globalxos/xos-cord-branding.yaml
@@ -0,0 +1,25 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Adds volume to make the cord branding config file available
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    xos:
+      type: tosca.nodes.XOS
+      properties:
+        no-create: True
+        no-delete: True
+        no-update: True
+
+    /opt/xos/xos_configuration/xos_cord_config:
+      type: tosca.nodes.XOSVolume
+      properties:
+          host_path: { path_join: [ SELF, CONFIG_DIR, ../cord-pod/xos_cord_config, ENV_VAR ] }
+          read_only: false
+      requirements:
+          - xos:
+             node: xos
+             relationship: tosca.relationships.UsedByXOS
diff --git a/globalxos/xos.yaml b/globalxos/xos.yaml
new file mode 100644
index 0000000..d7f84c5
--- /dev/null
+++ b/globalxos/xos.yaml
@@ -0,0 +1,130 @@
+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: globalxos
+        db_container_name: globalxosbs_xos_db_1
+        frontend_only: false
+
+    /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/core/templatetags:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/templatetags/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/core/xoslib/dashboards:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/xoslib/dashboards/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/core/xoslib/static/css:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/xoslib/static/css/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/core/xoslib/static/images:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/xoslib/static/images/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/core/xoslib/static/js:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/xoslib/static/js/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    /opt/xos/templates:
+          type: tosca.nodes.XOSVolume
+          properties:
+              host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/templates/, ENV_VAR ] }
+              read_only: false
+          requirements:
+              - xos:
+                  node: xos
+                  relationship: tosca.relationships.UsedByXOS
+
+    # The following volumes are sometimes used in development,
+    # but they are not tested and they can break part of the system, handle with care.
+
+    # /opt/xos/tosca:
+    #       type: tosca.nodes.XOSVolume
+    #       properties:
+    #           host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/tosca/, ENV_VAR ] }
+    #           read_only: false
+    #       requirements:
+    #           - xos:
+    #               node: xos
+    #               relationship: tosca.relationships.UsedByXOS
+
+    # /opt/xos/xos:
+    #       type: tosca.nodes.XOSVolume
+    #       properties:
+    #           host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/xos/, ENV_VAR ] }
+    #           read_only: false
+    #       requirements:
+    #           - xos:
+    #               node: xos
+    #               relationship: tosca.relationships.UsedByXOS
+
+    # /opt/xos/core/models:
+    #       type: tosca.nodes.XOSVolume
+    #       properties:
+    #           host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/core/models/, ENV_VAR ] }
+    #           read_only: false
+    #       requirements:
+    #           - xos:
+    #               node: xos
+    #               relationship: tosca.relationships.UsedByXOS
+
+    # /opt/xos/api/utility:
+    #       type: tosca.nodes.XOSVolume
+    #       properties:
+    #           host_path: { path_join: [ SELF, CONFIG_DIR, ../../xos/xos/api/utility/, ENV_VAR ] }
+    #           read_only: false
+    #       requirements:
+    #           - xos:
+    #               node: xos
+    #               relationship: tosca.relationships.UsedByXOS