blob: fd3889422a889fbb2be4591892f23a4e6c6ea016 [file] [log] [blame]
JianHao4a9550f2017-10-19 11:05:14 +08001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16import sys
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080017import time
JianHao4a9550f2017-10-19 11:05:14 +080018from django.db.models import Q, F
19from synchronizers.new_base.modelaccessor import *
20from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
21
22parentdir = os.path.join(os.path.dirname(__file__), "..")
23sys.path.insert(0, parentdir)
24
Sapan Bhatia28b75602017-11-28 14:18:21 -050025class ServiceGraphException(Exception):
26 pass
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050027
JianHao4a9550f2017-10-19 11:05:14 +080028class SyncVSPGWCTenant(SyncInstanceUsingAnsible):
JianHao4a9550f2017-10-19 11:05:14 +080029 observes = VSPGWCTenant
JianHao4a9550f2017-10-19 11:05:14 +080030 template_name = "vspgwctenant_playbook.yaml"
JianHao4a9550f2017-10-19 11:05:14 +080031 service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
32
33 def __init__(self, *args, **kwargs):
34 super(SyncVSPGWCTenant, self).__init__(*args, **kwargs)
35
Woojoong Kimf000eda2017-10-20 15:00:43 -070036 def get_extra_attributes(self, o):
JianHao4a9550f2017-10-19 11:05:14 +080037
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050038 scenario = self.get_scenario(o)
JianHao4a9550f2017-10-19 11:05:14 +080039
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080040 if scenario == 'normal_scenario':
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050041 return self.get_values_for_normal_scenario(o)
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080042 elif scenario == 'normal_scenario_without_sdncontroller':
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050043 return self.get_values_for_normal_scenario_wo_sdncontroller(o)
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080044 elif scenario == 'emulator_scenario':
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050045 return self.get_values_for_emulator_scenario(o)
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080046 elif scenario == 'emulator_scenario_without_sdncontroller':
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050047 return self.get_values_for_emulator_scenario_wo_sdncontroller(o)
Woojoong Kim313d35c2017-12-18 17:15:46 -080048 elif scenario == 'hardware_scenario':
49 return self.get_values_for_hardware_scenario(o)
50 elif scenario == 'hardware_scenario_without_sdncontroller':
51 return self.get_values_for_hardware_scenario_wo_sdncontroller(o)
Woojoong Kimf000eda2017-10-20 15:00:43 -070052 else:
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050053 return self.get_extra_attributes_for_manual(o)
Woojoong Kimf000eda2017-10-20 15:00:43 -070054
55 # fields for manual case
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050056 def get_extra_attributes_for_manual(self, o):
Woojoong Kimf000eda2017-10-20 15:00:43 -070057 fields = {}
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050058 fields['scenario'] = self.get_scenario(o)
Woojoong Kimf000eda2017-10-20 15:00:43 -070059 # for interface.cfg file
60 fields['zmq_sub_ip'] = "manual"
61 fields['zmq_pub_ip'] = "manual"
62 fields['dp_comm_ip'] = "manual"
63 fields['cp_comm_ip'] = "manual"
64 fields['fpc_ip'] = "manual"
65 fields['cp_nb_server_ip'] = "manual"
66
67 # for cp_config.cfg file
68 fields['s11_sgw_ip'] = "manual"
69 fields['s11_mme_ip'] = "manual"
70 fields['s1u_sgw_ip'] = "manual"
71
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080072 # for rules setup in ONOS
73 fields['sgi_as_ip'] = "manual"
74 fields['sgi_spgwu_ip'] = "manual"
75
Woojoong Kimf000eda2017-10-20 15:00:43 -070076 return fields
77
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050078 def get_values_for_normal_scenario(self, o):
Woojoong Kim1a1e3702017-10-27 13:26:34 -070079 fields = {}
Woojoong Kim4f09cbf2017-11-19 21:25:37 -080080 fields['scenario'] = "normal_scenario"
Woojoong Kim1a1e3702017-10-27 13:26:34 -070081 # for interface.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050082 fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050083 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050084 fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050085 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050086 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050087 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050088 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050089 'nbi_network', o, o, 'cp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050090 fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050091 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050092 fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050093 'nbi_network', o, o, 'cp_nb_server_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -070094
95 # for cp_config.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050096 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050097 's11_network', o, o, 's11_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -050098 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -050099 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500100 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500101 's11_network', "VMMETenant", o, 's11_mme_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700102
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800103 # for rules setup in ONOS
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500104 fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500105 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500106 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500107 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800108
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700109 return fields
110
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500111 def get_values_for_normal_scenario_wo_sdncontroller(self, o):
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700112 fields = {}
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800113 fields['scenario'] = "normal_scenario_without_sdncontroller"
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700114 # for interface.cfg file
115 fields['zmq_sub_ip'] = "127.0.0.1"
116 fields['zmq_pub_ip'] = "127.0.0.1"
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500117 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500118 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500119 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500120 'spgw_network', o, o, 'cp_comm_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700121 fields['fpc_ip'] = "127.0.0.1"
122 fields['cp_nb_server_ip'] = "127.0.0.1"
123
124 # for cp_config.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500125 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500126 's11_network', o, o, 's11_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500127 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500128 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500129 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500130 's11_network', "VMMETenant", o, 's11_mme_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700131
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800132 # for rules setup in ONOS
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500133 fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500134 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500135 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500136 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800137
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700138 return fields
139
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500140 def get_values_for_emulator_scenario(self, o):
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700141 fields = {}
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800142 fields['scenario'] = "emulator_scenario"
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700143 # for interface.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500144 fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500145 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500146 fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500147 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500148 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500149 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500150 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500151 'nbi_network', o, o, 'cp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500152 fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500153 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500154 fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500155 'nbi_network', o, o, 'cp_nb_server_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700156
157 # for cp_config.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500158 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500159 's11_network', o, o, 's11_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500160 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500161 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500162 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500163 's11_network', "VENBServiceInstance", o, 's11_mme_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700164
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800165 # for rules setup in ONOS
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500166 fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500167 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500168 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500169 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800170
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700171 return fields
172
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500173 def get_values_for_emulator_scenario_wo_sdncontroller(self, o):
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700174 fields = {}
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800175 fields['scenario'] = "emulator_scenario_without_sdncontroller"
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700176 # for interface.cfg file
177 fields['zmq_sub_ip'] = "127.0.0.1"
178 fields['zmq_pub_ip'] = "127.0.0.1"
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500179 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500180 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500181 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500182 'spgw_network', o, o, 'cp_comm_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700183 fields['fpc_ip'] = "127.0.0.1"
184 fields['cp_nb_server_ip'] = "127.0.0.1"
185
186 # for cp_config.cfg file
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500187 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500188 's11_network', o, o, 's11_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500189 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500190 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500191 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500192 's11_network', "VENBServiceInstance", o, 's11_mme_ip')
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700193
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800194 # for rules setup in ONOS
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500195 fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500196 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip')
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500197 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia97536292017-11-27 21:35:34 -0500198 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800199
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700200 return fields
201
Woojoong Kim313d35c2017-12-18 17:15:46 -0800202 def get_values_for_hardware_scenario(self, o):
203 fields = {}
204 fields['scenario'] = "hardware_scenario"
205
206 # for interface.cfg file
207 fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance(
208 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip')
209 fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance(
210 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip')
211 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
212 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip')
213 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
214 'nbi_network', o, o, 'cp_comm_ip')
215 fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance(
216 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip')
217 fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance(
218 'nbi_network', o, o, 'cp_nb_server_ip')
219
220 # for cp_config.cfg file
221 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
222 's11_network', o, o, 's11_sgw_ip')
223 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
224 'flat_network_s1u', "VSPGWUTenant", o, 's1u_sgw_ip')
225 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
226 's11_network', "VMMETenant", o, 's11_mme_ip')
227
228 # for rules setup in ONOS
229 fields['sgi_as_ip'] = "manual"
230 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
231 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
232
233 return fields
234
235 def get_values_for_hardware_scenario_wo_sdncontroller(self, o):
236 fields = {}
237 fields['scenario'] = "hardware_scenario_without_sdncontroller"
238
239 # for interface.cfg file
240 fields['zmq_sub_ip'] = "127.0.0.1"
241 fields['zmq_pub_ip'] = "127.0.0.1"
242 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
243 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip')
244 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
245 'spgw_network', o, o, 'cp_comm_ip')
246 fields['fpc_ip'] = "127.0.0.1"
247 fields['cp_nb_server_ip'] = "127.0.0.1"
248
249 # for cp_config.cfg file
250 fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance(
251 's11_network', o, o, 's11_sgw_ip')
252 fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance(
253 'flat_network_s1u', "VSPGWUTenant", o, 's1u_sgw_ip')
254 fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance(
255 's11_network', "VMMETenant", o, 's11_mme_ip')
256
257 # for rules setup in ONOS
258 fields['sgi_as_ip'] = "manual"
259 fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance(
260 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip')
261
262 return fields
263
264
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500265 def get_scenario(self, o):
266 venb_flag = self.has_instance("VENBServiceInstance", o)
267 vmme_flag = self.has_instance("VMMETenant", o)
268 sdncontroller_flag = self.has_instance(
269 "SDNControllerServiceInstance", o)
270 vspgwu_flag = self.has_instance("VSPGWUTenant", o)
271 internetemulator_flag = self.has_instance(
272 "SDNControllerServiceInstance", o)
Woojoong Kim4f09cbf2017-11-19 21:25:37 -0800273
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700274 if vmme_flag and venb_flag and sdncontroller_flag and vspgwu_flag and internetemulator_flag:
Woojoong Kim33209062017-11-21 15:46:09 -0800275 return 'normal_scenario'
Woojoong Kimf000eda2017-10-20 15:00:43 -0700276
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700277 if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwu_flag and internetemulator_flag:
Woojoong Kim33209062017-11-21 15:46:09 -0800278 return 'normal_scenario_without_sdncontroller'
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700279
280 if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag):
Woojoong Kim33209062017-11-21 15:46:09 -0800281 return 'emulator_scenario'
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700282
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500283 if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwu_flag and (
284 not internetemulator_flag):
Woojoong Kim33209062017-11-21 15:46:09 -0800285 return 'emulator_scenario_without_sdncontroller'
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700286
Woojoong Kim313d35c2017-12-18 17:15:46 -0800287 if vmme_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag):
288 return 'hardware_scenario'
289
290 if vmme_flag and (not sdncontroller_flag) and vspgwu_flag and (not internetemulator_flag):
291 return 'hardware_scenario_without_sdncontroller'
292
Woojoong Kim1a1e3702017-10-27 13:26:34 -0700293 return 'manual'
294
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500295 def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None):
296 peer_si = self.get_peer_serviceinstance_of_type(sitype, o)
Sapan Bhatia97536292017-11-27 21:35:34 -0500297 return self.get_ip_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter)
Woojoong Kimf000eda2017-10-20 15:00:43 -0700298
Sapan Bhatia97536292017-11-27 21:35:34 -0500299 def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter=None):
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500300 try:
301 net_id = self.get_network_id(network_name)
Sapan Bhatia97536292017-11-27 21:35:34 -0500302 ins_id = peer_si.leaf_model.instance_id
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500303 ip_address = Port.objects.get(
304 network_id=net_id, instance_id=ins_id).ip
305 except Exception:
306 self.log.error("Failed to fetch parameter",
307 parameter=parameter,
308 network_name=network_name)
Sapan Bhatia97536292017-11-27 21:35:34 -0500309 self.defer_sync(o, "Waiting for parameters to become available")
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500310
311 return ip_address
312
313 def get_peer_serviceinstance_of_type(self, sitype, o):
314 prov_link_set = ServiceInstanceLink.objects.filter(
315 subscriber_service_instance_id=o.id)
316
317 try:
318 peer_service = next(
Sapan Bhatia97536292017-11-27 21:35:34 -0500319 p.provider_service_instance for p in prov_link_set if p.provider_service_instance.leaf_model_name == sitype)
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500320 except StopIteration:
321 sub_link_set = ServiceInstanceLink.objects.filter(
322 provider_service_instance_id=o.id)
323 try:
324 peer_service = next(
Sapan Bhatia97536292017-11-27 21:35:34 -0500325 s.subscriber_service_instance for s in sub_link_set if s.subscriber_service_instance.leaf_model_name == sitype)
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500326 except StopIteration:
327 self.log.error(
328 'Could not find service type in service graph', service_type=sitype, object=o)
Sapan Bhatia28b75602017-11-28 14:18:21 -0500329 raise ServiceGraphException(
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500330 "Synchronization failed due to incomplete service graph")
Sapan Bhatia97536292017-11-27 21:35:34 -0500331
332 return peer_service
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500333
Woojoong Kimf000eda2017-10-20 15:00:43 -0700334 # To get each network id
335 def get_network_id(self, network_name):
336 return Network.objects.get(name=network_name).id
337
338 # To get service_instance (assumption: there is a single instance for each service)
339 def get_instance_id(self, serviceinstance):
340 instances = serviceinstance.objects.all()
341 instance_id = instances[0].instance_id
342 return instance_id
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500343
344 def has_instance(self, sitype, o):
Sapan Bhatia28b75602017-11-28 14:18:21 -0500345 try:
346 i = self.get_peer_serviceinstance_of_type(sitype, o)
347 except ServiceGraphException:
Sapan Bhatiaa1fbd382017-11-22 13:18:11 -0500348 self.log.info("Missing in ServiceInstance graph",
349 serviceinstance=sitype)
350 return False
351
Woojoong Kim38d84882017-11-28 15:38:39 -0800352 return i.leaf_model.instance_id