Merge "ngic dynamic config" into cord-3.0
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
deleted file mode 100644
index 30b0124..0000000
--- a/xos/synchronizer/manifest
+++ /dev/null
@@ -1,8 +0,0 @@
-model-deps
-manifest
-run.sh
-stop.sh
-vsgwu-synchronizer.py
-vsgwu_config
-steps/sync_vsgwu.py
-steps/sync_vsgwu.yaml
diff --git a/xos/synchronizer/steps/roles/ngic_config/tasks/main.yml b/xos/synchronizer/steps/roles/ngic_config/tasks/main.yml
new file mode 100644
index 0000000..c10582d
--- /dev/null
+++ b/xos/synchronizer/steps/roles/ngic_config/tasks/main.yml
@@ -0,0 +1,11 @@
+---
+- name: create config directory for dp_config file
+  file:
+    path: /var/tmp/config
+    state: directory
+    mode: 0755
+
+- name: save control plane configuration information in vSGWU VM
+  template:
+    src=dp_config.cfg.j2
+    dest=/var/tmp/config/dp_config.cfg
diff --git a/xos/synchronizer/steps/roles/ngic_config/templates/dp_config.cfg.j2 b/xos/synchronizer/steps/roles/ngic_config/templates/dp_config.cfg.j2
new file mode 100644
index 0000000..eaee7b5
--- /dev/null
+++ b/xos/synchronizer/steps/roles/ngic_config/templates/dp_config.cfg.j2
@@ -0,0 +1,14 @@
+{% set date = ansible_date_time['date'] ~ '_' ~ ansible_date_time['hour'] ~ '_' ~ ansible_date_time['minute'] %}
+NOW={{ date }}
+FILE="logs/dp_{{ date }}.log"
+PORT0=0000:03:00.0
+PORT1=0000:03:00.1
+
+S1U_IP={{ sgwu_shared_ip }}
+S1U_MAC={{ sgwu_shared_mac }}
+
+SGI_IP={{ pgwu_wan_ip }}
+SGI_MAC={{ pgwu_wan_mac }}
+
+NUM_WORKER=1
+MEMORY=4096
diff --git a/xos/synchronizer/steps/sync_vsgwutenant.py b/xos/synchronizer/steps/sync_vsgwutenant.py
index 331a923..719ca18 100644
--- a/xos/synchronizer/steps/sync_vsgwutenant.py
+++ b/xos/synchronizer/steps/sync_vsgwutenant.py
@@ -14,20 +14,42 @@
 
     requested_interval = 0
 
-    template_name = "vpgwutenant_playbook.yaml"
+    template_name = "vsgwutenant_playbook.yaml"
 
     service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
 
     def __init__(self, *args, **kwargs):
         super(SyncVSGWUTenant, self).__init__(*args, **kwargs)
 
-    def fetch_pending(self, deleted):
-        if (not deleted):
-            objs = VSGWUTenant.get_tenant_objects().filter(
-                Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
-        else:
-            # If this is a deletion we get all of the deleted tenants..
-            objs = VSGWUTenant.get_deleted_tenant_objects()
+#    def fetch_pending(self, deleted):
+#        if (not deleted):
+#            objs = VSGWUTenant.get_tenant_objects().filter(
+#                Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
+#        else:
+#            # If this is a deletion we get all of the deleted tenants..
+#            objs = VSGWUTenant.get_deleted_tenant_objects()
+#
+#        return objs
 
-        return objs
+    # Gets the attributes that are used by the Ansible template but are not
+    # part of the set of default attributes
+    def get_extra_attributes(self, o):
+        fields = {}
+        shared_net_id = Network.objects.get(name='shared_network').id
+        wan_net_id = Network.objects.get(name='wan_network').id
 
+        try:
+            sgwu = Port.objects.get(network_id=shared_net_id, instance_id=o.instance_id)
+            fields['sgwu_shared_ip'] = sgwu.ip
+            fields['sgwu_shared_mac'] = sgwu.mac
+        except Exception:
+            print '{} does not have an instance'.format(o.name)
+
+        try:
+            pgwu = TenantWithContainer.objects.get(provider_service_id=Service.objects.get(name='vpgwu').id, subscriber_tenant_id=o.subscriber_tenant_id)
+            fields['pgwu_wan_ip'] = Port.objects.get(network_id=wan_net_id, instance_id=pgwu.instance_id).ip
+            fields['pgwu_wan_mac'] = Port.objects.get(network_id=wan_net_id, instance_id=pgwu.instance_id).mac
+        except Exception:
+            print '{} does not have a VPGWU instance'.format(o.subscriber_tenant.name)
+
+        return fields 
diff --git a/xos/synchronizer/steps/vsgwutenant_playbook.yaml b/xos/synchronizer/steps/vsgwutenant_playbook.yaml
index 4d6f0dc..5d8fac1 100644
--- a/xos/synchronizer/steps/vsgwutenant_playbook.yaml
+++ b/xos/synchronizer/steps/vsgwutenant_playbook.yaml
@@ -1,9 +1,14 @@
 ---
 - hosts: {{ instance_name }}
-  gather_facts: False
+  gather_facts: True
   connection: ssh
   user: ubuntu
   sudo: yes
-  tasks:
   vars:
-  
+    - sgwu_shared_ip: {{ sgwu_shared_ip }}
+    - sgwu_shared_mac: {{ sgwu_shared_mac }}
+    - pgwu_wan_ip: {{ pgwu_wan_ip }}
+    - pgwu_wan_mac: {{ pgwu_wan_mac }}
+  roles:
+    - ngic_config  
+
diff --git a/xos/synchronizer/stop.sh b/xos/synchronizer/stop.sh
deleted file mode 100644
index 2fc4f94..0000000
--- a/xos/synchronizer/stop.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-# Kill the observer
-pkill -9 -f vsgwu-synchronizer.py