[CORD-2138] add ansible-playbook file to make interface.cfg file and cp_config.cfg in NGIC
Change-Id: Ide66538a6c953051637edf5c493c1a0673e43f7d
(cherry picked from commit 46af225591159539c9bdb51ded672005aa3fc194)
diff --git a/xos/synchronizer/steps/roles/interface_config/tasks/main.yml b/xos/synchronizer/steps/roles/interface_config/tasks/main.yml
new file mode 100644
index 0000000..fa8b2f4
--- /dev/null
+++ b/xos/synchronizer/steps/roles/interface_config/tasks/main.yml
@@ -0,0 +1,30 @@
+# 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: create config directory for interface config file
+ file:
+ path: "{{source_path}}"
+ state: directory
+ mode: 0755
+
+- name: make interface config file
+ template:
+ src=interface.cfg.j2
+ dest="{{source_path}}/interface.cfg"
+
+- name: make cp_config config file
+ template:
+ src=cp_config.cfg.j2
+ dest="{{source_path}}/cp_config.cfg"
\ No newline at end of file
diff --git a/xos/synchronizer/steps/roles/interface_config/templates/cp_config.cfg.j2 b/xos/synchronizer/steps/roles/interface_config/templates/cp_config.cfg.j2
new file mode 100644
index 0000000..bb4a7df
--- /dev/null
+++ b/xos/synchronizer/steps/roles/interface_config/templates/cp_config.cfg.j2
@@ -0,0 +1,10 @@
+{% set date = ansible_date_time['date'] ~ '_' ~ ansible_date_time['hour'] ~ '_' ~ ansible_date_time['minute'] %}
+NOW={{ date }}
+FILE="logs/cp_{{ date }}.log"
+S11_SGW_IP={{ s11_sgw_ip }}
+S11_MME_IP={{ s11_mme_ip }}
+S1U_SGW_IP={{ s1u_sgw_ip }}
+IP_POOL_IP=16.0.0.0
+IP_POOL_MASK=255.0.0.0
+APN=apn1
+MEMORY=1024
diff --git a/xos/synchronizer/steps/roles/interface_config/templates/interface.cfg.j2 b/xos/synchronizer/steps/roles/interface_config/templates/interface.cfg.j2
new file mode 100644
index 0000000..6fb91d1
--- /dev/null
+++ b/xos/synchronizer/steps/roles/interface_config/templates/interface.cfg.j2
@@ -0,0 +1,51 @@
+; 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.
+
+; scenario: {{ scenario }}
+
+[0]
+; please refer to INSTALL.MD for complete description of these parameters
+zmq_protocol = tcp
+
+; zmq publisher and subscriber ip:port. To be configured to an available ip
+; on the FPC Host. The port values are defined by the FPC Project.
+; These values are unused when DSDN_ODL_BUILD CFLAG not defined in
+; ng-core_cfg.mk
+zmq_sub_ip = {{ zmq_sub_ip }}
+zmq_sub_port = 5560
+zmq_pub_ip = {{ zmq_pub_ip }}
+zmq_pub_port = 5559
+
+; DP and CP communication ip:port: To be configured to available ip:ports on
+; the DP and CP Hosts respectively. Used for messages to communicate over UDP
+; including table creation, table entries; and when DSDN_ODL_BUILD CFLAG is NOT
+; defined, session establishment, modification, deletion, etc.
+dp_comm_ip = {{ dp_comm_ip }}
+dp_comm_port = 20
+cp_comm_ip = {{ cp_comm_ip }}
+cp_comm_port = 21
+
+; FPC ip:port: To be configured to an available IP of FPC host. The fpc_port
+; is defined by the FPC project.
+; These values are unused when DSDN_ODL_BUILD CFLAG not defined in
+; ng-core_cfg.mk
+fpc_ip = {{ fpc_ip }}
+fpc_port = 8181
+
+; The CP Northbound server ip:port: May be configured to any available ip:port
+; on the CP Host.
+; These values are unused when DSDN_ODL_BUILD CFLAG not defined in
+; ng-core_cfg.mk
+cp_nb_server_ip = {{ cp_nb_server_ip }}
+cp_nb_server_port = 9997
diff --git a/xos/synchronizer/steps/sync_vspgwctenant.py b/xos/synchronizer/steps/sync_vspgwctenant.py
index 3fecbf4..5fa2c08 100644
--- a/xos/synchronizer/steps/sync_vspgwctenant.py
+++ b/xos/synchronizer/steps/sync_vspgwctenant.py
@@ -35,27 +35,110 @@
def __init__(self, *args, **kwargs):
super(SyncVSPGWCTenant, self).__init__(*args, **kwargs)
- # Gets the attributes that are used by the Ansible template but are not
- # part of the set of default attribtues.
- #def get_extra_attributes(self, o):
- # fields = {}
- # shared_net_id = Network.objects.get(name='shared_network').id
+ def get_extra_attributes(self, o):
+ if self.get_scenario() == 'manual':
+ return self.get_extra_attributes_for_manual()
- #try:
- # fields['sgwc_shared_ip'] = Port.objects.get(network_id=shared_net_id, instance_id=o.instance_id).ip
- # except Exception:
- # print '{} does not have an instance'.format(o.name)
+ fields = {}
+ fields['scenario'] = self.get_scenario()
+ # for interface.cfg file
+ fields['zmq_sub_ip'] = self.get_ip_address('sbi_network', SDNControllerServiceInstance, 'zmq_sub_ip')
+ fields['zmq_pub_ip'] = self.get_ip_address('sbi_network', SDNControllerServiceInstance, 'zmq_pub_ip')
+ fields['dp_comm_ip'] = self.get_ip_address('sbi_network', VSPGWUTenant, 'dp_comm_ip')
+ fields['cp_comm_ip'] = self.get_ip_address('nbi_network', VSPGWCTenant, 'cp_comm_ip')
+ fields['fpc_ip'] = self.get_ip_address('nbi_network', SDNControllerServiceInstance, 'fpc_ip')
+ fields['cp_nb_server_ip'] = self.get_ip_address('nbi_network', VSPGWCTenant, 'cp_nb_server_ip')
- # try:
- # mme = TenantWithContainer.objects.get(provider_service_id=Service.objects.get(name='vmme').id, subscriber_tenant_id=o.subscriber_tenant_id)
- # fields['mme_shared_ip'] = Port.objects.get(network_id=shared_net_id, instance_id=mme.instance_id).ip
- #except Exception:
- # print '{} does not have a VMME instance'.format(o.subscriber_tenant.name)
+ # for cp_config.cfg file
+ fields['s11_sgw_ip'] = self.get_ip_address('s11_network', VSPGWCTenant, 's11_sgw_ip')
+ fields['s1u_sgw_ip'] = self.get_ip_address('s1u_network', VSPGWUTenant, 's1u_sgw_ip')
- # try:
- # sgwu = TenantWithContainer.objects.get(provider_service_id=Service.objects.get(name='vspgwu').id, subscriber_tenant_id=o.subscriber_tenant_id)
- # fields['sgwu_shared_ip'] = Port.objects.get(network_id=shared_net_id, instance_id=sgwu.instance_id).ip
- # except Exception:
- # print '{} does not have a VSPGWU instance'.format(o.subscriber_tenant.name)
+ # the parameter 's11_mme_ip' depends on scenarios
+ if self.get_scenario() == 'ng4t':
+ fields['s11_mme_ip'] = self.get_ip_address('s11_network', VMMETenant, 's11_mme_ip')
+ elif self.get_scenario() == 'spirent':
+ fields['s11_mme_ip'] = self.get_ip_address('s11_network', VENBServiceInstance, 's11_mme_ip')
+ else:
+ fields['s11_mme_ip'] = "scenario_error"
- # return fields
+ return fields
+
+ # fields for manual case
+ def get_extra_attributes_for_manual(self):
+ fields = {}
+ fields['scenario'] = self.get_scenario()
+ # for interface.cfg file
+ fields['zmq_sub_ip'] = "manual"
+ fields['zmq_pub_ip'] = "manual"
+ fields['dp_comm_ip'] = "manual"
+ fields['cp_comm_ip'] = "manual"
+ fields['fpc_ip'] = "manual"
+ fields['cp_nb_server_ip'] = "manual"
+
+ # for cp_config.cfg file
+ fields['s11_sgw_ip'] = "manual"
+ fields['s11_mme_ip'] = "manual"
+ fields['s1u_sgw_ip'] = "manual"
+
+ return fields
+
+ def has_venb(self):
+ # try get vMME instance
+ try:
+ instance_id = self.get_instance_id(VENBServiceInstance)
+ except Exception:
+ print 'cannot get VENBServiceInstance'
+ return False
+
+ return True
+
+ def has_vmme(self):
+ # try get vMME instance
+ try:
+ instance_id = self.get_instance_id(VMMETenant)
+ except Exception:
+ print 'cannot get VMMETenant'
+ return False
+
+ return True
+
+
+ # Which scenario does it use among Spirent or NG4T?
+ def get_scenario(self):
+ # try get vENB instance: one of both Spirent and NG4T
+ venb_flag = self.has_venb()
+ vmme_flag = self.has_vmme()
+
+ if vmme_flag:
+ return 'ng4t'
+ else:
+ if venb_flag:
+ return 'spirent'
+ else:
+ return 'manual'
+
+ def get_ip_address(self, network_name, service_instance, parameter):
+
+ if self.get_scenario() == 'manual':
+ return "manual"
+
+ 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/vspgwctenant_playbook.yaml b/xos/synchronizer/steps/vspgwctenant_playbook.yaml
index 94b1403..818ef6a 100644
--- a/xos/synchronizer/steps/vspgwctenant_playbook.yaml
+++ b/xos/synchronizer/steps/vspgwctenant_playbook.yaml
@@ -19,5 +19,17 @@
user: ubuntu
sudo: yes
vars:
+ - source_path: /var/tmp/config
+ - zmq_sub_ip: {{ zmq_sub_ip }}
+ - zmq_pub_ip: {{ zmq_pub_ip }}
+ - dp_comm_ip: {{ dp_comm_ip }}
+ - cp_comm_ip: {{ cp_comm_ip }}
+ - fpc_ip: {{ fpc_ip }}
+ - cp_nb_server_ip: {{ cp_nb_server_ip }}
+ - s11_sgw_ip: {{ s11_sgw_ip }}
+ - s11_mme_ip: {{ s11_mme_ip }}
+ - s1u_sgw_ip: {{ s1u_sgw_ip }}
+ - scenario: {{ scenario }}
roles:
+ - interface_config