Initial checkin for fabric synchronizer
diff --git a/xos/configurations/cord-pod/Makefile b/xos/configurations/cord-pod/Makefile
index 878797c..a7c5a10 100644
--- a/xos/configurations/cord-pod/Makefile
+++ b/xos/configurations/cord-pod/Makefile
@@ -2,19 +2,23 @@
 xos: up bootstrap
 
 up:
-	sudo docker-compose up -d
+	touch id_rsa id_rsa.pub
+	sudo docker-compose up -d db xos xos_synchronizer_fabric
 	../common/wait_for_xos_port.sh 80
 
 bootstrap: nodes.yaml images.yaml
 	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 none /opt/xos/configurations/common/mydeployment.yaml
 	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/setup.yaml
-	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/nodes.yaml
+	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
 	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/images.yaml
 
 vtn: vtn-external.yaml
 	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/vtn-external.yaml
 
+fabric: fabric.yaml
+	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/fabric.yaml
+
 cord: vsg_custom_images
 	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/mgmt-net.yaml
 	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /root/setup/cord-vtn-vsg.yaml
@@ -34,6 +38,9 @@
 vtn-external.yaml:
 	export SETUPDIR=.; bash ./make-vtn-external-yaml.sh
 
+fabric.yaml:
+	export SETUPDIR=.; bash ./fabric-yaml.sh
+
 virtualbng_json:
 	export SETUPDIR=.; bash ./make-virtualbng-json.sh
 
@@ -79,4 +86,3 @@
 	done
 	cd ../../../containers/xos; make devel
 	cd ../../../containers/synchronizer; make
-
diff --git a/xos/configurations/cord-pod/cord-vtn-vsg.yaml b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
index bb603fe..99ec101 100644
--- a/xos/configurations/cord-pod/cord-vtn-vsg.yaml
+++ b/xos/configurations/cord-pod/cord-vtn-vsg.yaml
@@ -69,12 +69,6 @@
               node: addresses_exampleservice-public
               relationship: tosca.relationships.ProvidesAddresses
 
-    service#fabric:
-      type: tosca.nodes.FabricService
-      properties:
-          view_url: /admin/fabric/fabricservice/$id$/
-          replaces: service_fabric
-
     Private:
       type: tosca.nodes.NetworkTemplate
 
diff --git a/xos/configurations/cord-pod/docker-compose.yml b/xos/configurations/cord-pod/docker-compose.yml
index fa8660a..b9006b0 100644
--- a/xos/configurations/cord-pod/docker-compose.yml
+++ b/xos/configurations/cord-pod/docker-compose.yml
@@ -101,6 +101,21 @@
             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:
     command: python /opt/xos/manage.py runserver 0.0.0.0:80 --insecure --makemigrations
     image: xosproject/xos
@@ -120,4 +135,3 @@
     log_opt:
             max-size: "100k"
             max-file: "5"
-
diff --git a/xos/configurations/cord-pod/make-fabric-yaml.sh b/xos/configurations/cord-pod/make-fabric-yaml.sh
new file mode 100644
index 0000000..5d771c9
--- /dev/null
+++ b/xos/configurations/cord-pod/make-fabric-yaml.sh
@@ -0,0 +1,72 @@
+FN=$SETUPDIR/vtn-external.yaml
+
+rm -f $FN
+
+cat >> $FN <<EOF
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+imports:
+   - custom_types/xos.yaml
+
+description: generate fabric configuration
+
+topology_template:
+  node_templates:
+
+    service#ONOS_Fabric:
+      type: tosca.nodes.ONOSService
+      requirements:
+      properties:
+          kind: onos
+          view_url: /admin/onos/onosservice/\$id$/
+          no_container: true
+          rest_hostname: onos-fabric
+          replaces: service_ONOS_Fabric
+
+    service#fabric:
+      type: tosca.nodes.FabricService
+      properties:
+          view_url: /admin/fabric/fabricservice/$id$/
+          replaces: service_fabric
+
+
+EOF
+
+NODES=$( bash -c "source $SETUPDIR/admin-openrc.sh ; nova host-list" |grep compute|awk '{print $2}' )
+I=0
+for NODE in $NODES; do
+    echo $NODE
+    cat >> $FN <<EOF
+    $NODE:
+      type: tosca.nodes.Node
+
+    # Fabric location field for node $NODE
+    ${NODE}_location_tag:
+      type: tosca.nodes.Tag
+      properties:
+          name: location
+          value: of:0000000000000001/1
+      requirements:
+          - target:
+              node: $NODE
+              relationship: tosca.relationships.TagsObject
+          - service:
+              node: service#ONOS_Fabric
+              relationship: tosca.relationships.MemberOfService
+EOF
+done
+
+cat >> $FN <<EOF
+    Fabric_ONOS_app:
+      type: tosca.nodes.ONOSFabricApp
+      requirements:
+          - onos_tenant:
+              node: service#ONOS_Fabric
+              relationship: tosca.relationships.TenantOfService
+          - fabric_service:
+              node: service#fabric
+              relationship: tosca.relationships.UsedByService
+      properties:
+          dependencies:
+          autogenerate: fabric-network-cfg
+EOF
diff --git a/xos/synchronizers/fabric/fabric-synchronizer.py b/xos/synchronizers/fabric/fabric-synchronizer.py
new file mode 100755
index 0000000..84bec4f
--- /dev/null
+++ b/xos/synchronizers/fabric/fabric-synchronizer.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+# This imports and runs ../../xos-observer.py
+
+import importlib
+import os
+import sys
+observer_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../synchronizers/base")
+sys.path.append(observer_path)
+mod = importlib.import_module("xos-synchronizer")
+mod.main()
diff --git a/xos/synchronizers/fabric/fabric_synchronizer_config b/xos/synchronizers/fabric/fabric_synchronizer_config
new file mode 100644
index 0000000..9d6119f
--- /dev/null
+++ b/xos/synchronizers/fabric/fabric_synchronizer_config
@@ -0,0 +1,10 @@
+[observer]
+name=vtn
+dependency_graph=/opt/xos/synchronizers/fabric/model-deps
+steps_dir=/opt/xos/synchronizers/fabric/steps
+sys_dir=/opt/xos/synchronizers/fabric/sys
+deleters_dir=/opt/xos/synchronizers/fabric/deleters
+log_file=console
+driver=openstack
+pretend=False
+backoff_disabled=True
diff --git a/xos/synchronizers/fabric/model-deps b/xos/synchronizers/fabric/model-deps
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/xos/synchronizers/fabric/model-deps
@@ -0,0 +1 @@
+{}
diff --git a/xos/synchronizers/fabric/run.sh b/xos/synchronizers/fabric/run.sh
new file mode 100755
index 0000000..4e0c214
--- /dev/null
+++ b/xos/synchronizers/fabric/run.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+python fabric-synchronizer.py  -C $XOS_DIR/synchronizers/fabric/fabric_synchronizer_config
diff --git a/xos/synchronizers/fabric/start.sh b/xos/synchronizers/fabric/start.sh
new file mode 100755
index 0000000..8d02bf3
--- /dev/null
+++ b/xos/synchronizers/fabric/start.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+nohup python fabric-synchronizer.py  -C $XOS_DIR/synchronizers/fabric/fabric_synchronizer_config > /dev/null 2>&1 &
diff --git a/xos/synchronizers/fabric/steps/sync_vsgtenant.py b/xos/synchronizers/fabric/steps/sync_vsgtenant.py
new file mode 100644
index 0000000..9c1b65e
--- /dev/null
+++ b/xos/synchronizers/fabric/steps/sync_vsgtenant.py
@@ -0,0 +1,53 @@
+import os
+import base64
+from collections import defaultdict
+from django.db.models import F, Q
+from xos.config import Config
+from synchronizers.base.openstacksyncstep import OpenStackSyncStep
+from synchronizers.base.syncstep import *
+from core.models import Controller
+from core.models import Image, ControllerImages
+from xos.logger import observer_logger as logger
+from synchronizers.base.ansible import *
+import json
+
+class SyncVSGTenant(SyncStep):
+    provides=[VSGTenant]
+    observes = VSGTenant
+    requested_interval=30
+    playbook='sync_vsgtenant.yaml'
+
+    def fetch_pending(self, deleted):
+        if (not deleted):
+            objs = VSGTenant.get_tenant_objects().filter(Q(lazy_blocked=False))
+        else:
+            objs = VSGTenant.get_deleted_tenant_objects()
+
+        return objs
+
+    def map_sync_inputs(self, vsgtenant):
+
+        rest_hostname = "onos-fabric"
+        rest_port = 8181
+
+        wan_ip = vsgtenant.wan_container_ip
+        wan_mac = vsgtenant.wan_container_mac
+
+        # Look up location - it's tagged on the nodes
+
+        # Figure out: is it a POST or DELETE?
+
+        # Create JSON
+        rest_json = ""
+
+        image_fields = {
+                        'rest_hostname': rest_hostname,
+                        'rest_port': rest_port,
+                        'rest_json': rest_json,
+                        'ansible_tag': '%s@%s'%(vsgtenant.name), # name of ansible playbook
+                        }
+
+	return image_fields
+
+    def map_sync_outputs(self, controller_image, res):
+        pass
diff --git a/xos/synchronizers/fabric/steps/sync_vsgtenant.yaml b/xos/synchronizers/fabric/steps/sync_vsgtenant.yaml
new file mode 100644
index 0000000..81fdb99
--- /dev/null
+++ b/xos/synchronizers/fabric/steps/sync_vsgtenant.yaml
@@ -0,0 +1,17 @@
+---
+- hosts: 127.0.0.1
+  connection: local
+  vars:
+    rest_hostname: {{ rest_hostname }}
+    rest_port: {{ rest_port }}
+    rest_json: {{ rest_json }}
+
+  tasks:
+  - name: Call Fabric REST API
+    uri:
+      url: http://{{ '{{' }} rest_hostname {{ '}}' }}:{{ '{{' }} rest_port {{ '}}' }}/{{ '{{' }} item.endpoint {{ '}}' }} #http://localhost:8181/onos/v1/network/configuration/
+      body: "{{ '{{' }} rest_json {{ '}}' }}"
+      body_format: raw
+      method: POST
+      user: karaf
+      password: karaf
diff --git a/xos/synchronizers/fabric/stop.sh b/xos/synchronizers/fabric/stop.sh
new file mode 100755
index 0000000..d35b057
--- /dev/null
+++ b/xos/synchronizers/fabric/stop.sh
@@ -0,0 +1 @@
+pkill -9 -f fabric-synchronizer.py