[CORD-1985] add venb playbook for TS config

Change-Id: Ib94fd44da090bb543626e640407e02c88eb135fa
(cherry picked from commit 90e65dcb450122aa63c7670a99bf234767bb06c3)
diff --git a/xos/synchronizer/steps/.gitignore b/xos/synchronizer/steps/.gitignore
deleted file mode 100644
index c96a04f..0000000
--- a/xos/synchronizer/steps/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
\ No newline at end of file
diff --git a/xos/synchronizer/steps/roles/ts_config/tasks/main.yaml b/xos/synchronizer/steps/roles/ts_config/tasks/main.yaml
new file mode 100644
index 0000000..76e2fdc
--- /dev/null
+++ b/xos/synchronizer/steps/roles/ts_config/tasks/main.yaml
@@ -0,0 +1,43 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+- name: check flat_network interface
+  shell: ifconfig | grep -B1 "inet addr:{{ ts_ip }}" | awk '$1!="inet" && $1!="--" {print $1}'
+  args:
+    executable: /bin/bash
+  register: iface
+
+- name: disable TAS process
+  command: disable-tas
+
+- name: enable TS process
+  command: enable-ts
+
+- name: test response to test.py
+  expect:
+    command: ipcfg
+    responses:
+      Configure now?: "n"
+      Do you wish to Continue: "yes"
+      Designate management port: "{{ iface.stdout_lines }}"
+      IP Address: "{{ ts_ip }}"
+      Network Mask: "{{ ts_ip_mask }}"
+      Auto Negotiate: "yes"
+      IP Gateway: "{{ ts_gw }}"
+      Host Name: "{{ ts_host_name }}"
+      TAS IP Address: "{{ tas_ip }}"
+      NTP Server IP: "{{ ntp_ip }}"
+      System must be rebooted: "yes"
+    echo: yes
\ No newline at end of file
diff --git a/xos/synchronizer/steps/sync_venbserviceinstance.py b/xos/synchronizer/steps/sync_venbserviceinstance.py
new file mode 100644
index 0000000..3e4a107
--- /dev/null
+++ b/xos/synchronizer/steps/sync_venbserviceinstance.py
@@ -0,0 +1,66 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+from django.db.models import Q, F
+from synchronizers.new_base.modelaccessor import *
+from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncVENBServiceInstance(SyncInstanceUsingAnsible):
+    provides = [VENBServiceInstance]
+
+    observes = VENBServiceInstance
+
+    requested_interval = 0
+
+    template_name = "venbserviceinstance_playbook.yaml"
+
+    service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
+
+    def __init__(self, *args, **kwargs):
+        super(SyncVENBServiceInstance, self).__init__(*args, **kwargs)
+
+    def get_extra_attributes(self, o):
+
+        fields = {}
+        fields['flat_ip'] = self.get_ip_address('flat_network', VENBServiceInstance, 'get_venb_flat_ip')
+
+        return fields
+
+    def get_ip_address(self, network_name, service_instance, parameter):
+
+        try:
+            net_id = self.get_network_id(network_name)
+            ins_id = self.get_instance_id(service_instance)
+            ip_address = Port.objects.get(network_id=net_id, instance_id=ins_id).ip
+
+        except Exception:
+            ip_address = "error"
+            print "get failed -- %s" % (parameter)
+
+        return ip_address
+
+    # To get each network id
+    def get_network_id(self, network_name):
+        return Network.objects.get(name=network_name).id
+
+    # To get service_instance (assumption: there is a single instance for each service)
+    def get_instance_id(self, serviceinstance):
+        instances = serviceinstance.objects.all()
+        instance_id = instances[0].instance_id
+        return instance_id
diff --git a/xos/synchronizer/steps/venbserviceinstance_playbook.yaml b/xos/synchronizer/steps/venbserviceinstance_playbook.yaml
new file mode 100644
index 0000000..c127603
--- /dev/null
+++ b/xos/synchronizer/steps/venbserviceinstance_playbook.yaml
@@ -0,0 +1,33 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+- hosts: {{ instance_name }}
+  gather_facts: True
+  connection: ssh
+  user: cfguser
+  sudo: yes
+  vars:
+    - ts_ip: {{ flat_ip }}
+    - ts_mask: "255.255.255.0"
+    - ts_gateway: "103.0.0.1"
+    - ts_host_name: "spirent_ts"
+
+    # wait for static IP
+    - tas_ip: ""
+
+    - ntp_ip: "192.168.0.201"
+  roles:
+    - ts_config
+