blob: 0ae14fee20899775643b5f71eb657b989652c846 [file] [log] [blame]
Wei-Yu Chenba043592017-10-18 17:08:51 +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
17from django.db.models import Q, F
Wei-Yu Chenba043592017-10-18 17:08:51 +080018from synchronizers.new_base.modelaccessor import *
19from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
20
21parentdir = os.path.join(os.path.dirname(__file__), "..")
22sys.path.insert(0, parentdir)
23
Sapan Bhatia15721932017-12-08 15:36:33 -050024
Sapan Bhatiafc9f6b32017-11-28 14:13:31 -050025class ServiceGraphException(Exception):
26 pass
Sapan Bhatia968f28f2017-11-22 12:00:01 -050027
Sapan Bhatia15721932017-12-08 15:36:33 -050028
Wei-Yu Chenba043592017-10-18 17:08:51 +080029class SyncVSPGWUTenant(SyncInstanceUsingAnsible):
Wei-Yu Chenba043592017-10-18 17:08:51 +080030 observes = VSPGWUTenant
Wei-Yu Chenba043592017-10-18 17:08:51 +080031 template_name = "vspgwutenant_playbook.yaml"
Wei-Yu Chenba043592017-10-18 17:08:51 +080032 service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
33
34 def __init__(self, *args, **kwargs):
35 super(SyncVSPGWUTenant, self).__init__(*args, **kwargs)
36
Woojoong Kimf002aec2017-10-25 14:43:37 -070037 def get_extra_attributes(self, o):
38
Sapan Bhatia968f28f2017-11-22 12:00:01 -050039 scenario = self.get_scenario(o)
Woojoong Kimf002aec2017-10-25 14:43:37 -070040
Woojoong Kim04d12162017-11-27 10:59:08 -080041 if scenario == 'normal_scenario':
42 return self.get_values_for_normal_scenario(o)
43 elif scenario == 'normal_scenario_without_sdncontroller':
44 return self.get_values_for_normal_scenario_wo_sdncontroller(o)
45 elif scenario == 'emulator_scenario':
46 return self.get_values_for_emulator_scenario(o)
47 elif scenario == 'emulator_scenario_without_sdncontroller':
48 return self.get_values_for_emulator_scenario_wo_sdncontroller(o)
Woojoong Kimf002aec2017-10-25 14:43:37 -070049 else:
Sapan Bhatia968f28f2017-11-22 12:00:01 -050050 return self.get_extra_attributes_for_manual(o)
Woojoong Kimf002aec2017-10-25 14:43:37 -070051
52 # fields for manual case
Sapan Bhatia968f28f2017-11-22 12:00:01 -050053 def get_extra_attributes_for_manual(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -070054 fields = {}
Sapan Bhatia968f28f2017-11-22 12:00:01 -050055 fields['scenario'] = self.get_scenario(o)
Woojoong Kimf002aec2017-10-25 14:43:37 -070056 # for interface.cfg file
57 fields['zmq_sub_ip'] = "manual"
58 fields['zmq_pub_ip'] = "manual"
59 fields['dp_comm_ip'] = "manual"
60 fields['cp_comm_ip'] = "manual"
61 fields['fpc_ip'] = "manual"
62 fields['cp_nb_server_ip'] = "manual"
63
64 # for dp_config.cfg file
65 fields['s1u_ip'] = "manual"
66 fields['sgi_ip'] = "manual"
67
Woojoong Kim04d12162017-11-27 10:59:08 -080068 # for static_arp.cfg file
69 fields['as_sgi_ip'] = "manual"
70 fields['as_sgi_mac'] = "manual"
71 fields['enb_s1u_ip'] = "manual"
72 fields['enb_s1u_mac'] = "manual"
73
Woojoong Kimf002aec2017-10-25 14:43:37 -070074 return fields
75
Woojoong Kim04d12162017-11-27 10:59:08 -080076 def get_values_for_normal_scenario(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -070077 fields = {}
Woojoong Kim04d12162017-11-27 10:59:08 -080078 fields['scenario'] = "normal_scenario"
Woojoong Kimf002aec2017-10-25 14:43:37 -070079 # for interface.cfg file
Sapan Bhatia968f28f2017-11-22 12:00:01 -050080 fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050081 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -050082 fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050083 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -050084 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050085 'sbi_network', o, o, 'dp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -050086 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050087 'nbi_network', "VSPGWCTenant", o, 'cp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -050088 fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050089 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -050090 fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050091 'nbi_network', "VSPGWCTenant", o, 'cp_nb_server_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -070092
93 # for dp_config.cfg file
Sapan Bhatia968f28f2017-11-22 12:00:01 -050094 fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -050095 's1u_network', o, o, 's1u_ip')
Sapan Bhatia15721932017-12-08 15:36:33 -050096 fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance(
97 'sgi_network', o, o, 'sgi_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -070098
Woojoong Kim04d12162017-11-27 10:59:08 -080099 # for static_arp.cfg file
Sapan Bhatia15721932017-12-08 15:36:33 -0500100 fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance(
101 'sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_ip')
102 fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance(
103 'sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_mac')
104 fields['enb_s1u_ip'] = self.get_ip_address_from_peer_service_instance(
105 's1u_network', "VENBServiceInstance", o, 'enb_s1u_ip')
106 fields['enb_s1u_mac'] = self.get_mac_address_from_peer_service_instance(
107 's1u_network', "VENBServiceInstance", o, 'enb_s1u_mac')
Woojoong Kim04d12162017-11-27 10:59:08 -0800108
Woojoong Kimf002aec2017-10-25 14:43:37 -0700109 return fields
110
Woojoong Kim04d12162017-11-27 10:59:08 -0800111 def get_values_for_normal_scenario_wo_sdncontroller(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -0700112 fields = {}
Woojoong Kim04d12162017-11-27 10:59:08 -0800113 fields['scenario'] = "normal_scenario_without_sdncontroller"
Woojoong Kimf002aec2017-10-25 14:43:37 -0700114 # for interface.cfg file
115 fields['zmq_sub_ip'] = "127.0.0.1"
116 fields['zmq_pub_ip'] = "127.0.0.1"
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500117 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500118 'spgw_network', o, o, 'dp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500119 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500120 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -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 Bhatia968f28f2017-11-22 12:00:01 -0500125 fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500126 's1u_network', o, o, 's1u_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500127 fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500128 'sgi_network', o, o, 'sgi_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -0700129
Woojoong Kim04d12162017-11-27 10:59:08 -0800130 # for static_arp.cfg file
Sapan Bhatia15721932017-12-08 15:36:33 -0500131 fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance(
132 'sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_ip')
133 fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance(
134 'sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_mac')
135 fields['enb_s1u_ip'] = self.get_ip_address_from_peer_service_instance(
136 's1u_network', "VENBServiceInstance", o, 'enb_s1u_ip')
137 fields['enb_s1u_mac'] = self.get_mac_address_from_peer_service_instance(
138 's1u_network', "VENBServiceInstance", o, 'enb_s1u_mac')
Woojoong Kim04d12162017-11-27 10:59:08 -0800139
Woojoong Kimf002aec2017-10-25 14:43:37 -0700140 return fields
141
Woojoong Kim04d12162017-11-27 10:59:08 -0800142 def get_values_for_emulator_scenario(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -0700143 fields = {}
Woojoong Kim04d12162017-11-27 10:59:08 -0800144 fields['scenario'] = "emulator_scenario"
Woojoong Kimf002aec2017-10-25 14:43:37 -0700145 # for interface.cfg file
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500146 fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500147 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500148 fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500149 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500150 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500151 'sbi_network', o, o, 'dp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500152 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500153 'nbi_network', "VSPGWCTenant", o, 'cp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500154 fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500155 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500156 fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500157 'nbi_network', "VSPGWCTenant", o, 'cp_nb_server_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -0700158
159 # for dp_config.cfg file
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500160 fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500161 's1u_network', o, o, 's1u_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500162 fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500163 'sgi_network', o, o, 'sgi_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -0700164
Woojoong Kim04d12162017-11-27 10:59:08 -0800165 # for static_arp.cfg file
Sapan Bhatia15721932017-12-08 15:36:33 -0500166 fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance(
167 'sgi_network', "VENBServiceInstance", o, 'as_sgi_ip')
168 fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance(
169 'sgi_network', "VENBServiceInstance", o, 'as_sgi_mac')
170 fields['enb_s1u_ip'] = self.get_ip_address_from_peer_service_instance(
171 's1u_network', "VENBServiceInstance", o, 'enb_s1u_ip')
172 fields['enb_s1u_mac'] = self.get_mac_address_from_peer_service_instance(
173 's1u_network', "VENBServiceInstance", o, 'enb_s1u_mac')
Woojoong Kim04d12162017-11-27 10:59:08 -0800174
Woojoong Kimf002aec2017-10-25 14:43:37 -0700175 return fields
176
Woojoong Kim04d12162017-11-27 10:59:08 -0800177 def get_values_for_emulator_scenario_wo_sdncontroller(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -0700178 fields = {}
Woojoong Kim04d12162017-11-27 10:59:08 -0800179 fields['scenario'] = "emulator_scenario_without_sdncontroller"
Woojoong Kimf002aec2017-10-25 14:43:37 -0700180 # for interface.cfg file
181 fields['zmq_sub_ip'] = "127.0.0.1"
182 fields['zmq_pub_ip'] = "127.0.0.1"
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500183 fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500184 'spgw_network', o, o, 'dp_comm_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500185 fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500186 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -0700187 fields['fpc_ip'] = "127.0.0.1"
188 fields['cp_nb_server_ip'] = "127.0.0.1"
189
190 # for cp_config.cfg file
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500191 fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500192 's1u_network', o, o, 's1u_ip')
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500193 fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500194 'sgi_network', o, o, 'sgi_ip')
Woojoong Kimf002aec2017-10-25 14:43:37 -0700195
Woojoong Kim04d12162017-11-27 10:59:08 -0800196 # for static_arp.cfg file
Sapan Bhatia15721932017-12-08 15:36:33 -0500197 fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance(
198 'sgi_network', "VENBServiceInstance", o, 'as_sgi_ip')
199 fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance(
200 'sgi_network', "VENBServiceInstance", o, 'as_sgi_mac')
201 fields['enb_s1u_ip'] = self.get_ip_address_from_peer_service_instance(
202 's1u_network', "VENBServiceInstance", o, 'enb_s1u_ip')
203 fields['enb_s1u_mac'] = self.get_mac_address_from_peer_service_instance(
204 's1u_network', "VENBServiceInstance", o, 'enb_s1u_mac')
Woojoong Kim04d12162017-11-27 10:59:08 -0800205
Woojoong Kimf002aec2017-10-25 14:43:37 -0700206 return fields
207
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500208 def has_instance(self, sitype, o):
Sapan Bhatiafc9f6b32017-11-28 14:13:31 -0500209 try:
210 i = self.get_peer_serviceinstance_of_type(sitype, o)
211 except ServiceGraphException:
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500212 self.log.info("Missing in ServiceInstance graph",
213 serviceinstance=sitype)
Woojoong Kimf002aec2017-10-25 14:43:37 -0700214 return False
215
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500216 return i.leaf_model.instance_id
Woojoong Kimf002aec2017-10-25 14:43:37 -0700217
218 # Which scenario does it use among Spirent or NG4T?
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500219 def get_scenario(self, o):
Woojoong Kimf002aec2017-10-25 14:43:37 -0700220 # try get vENB instance: one of both Spirent and NG4T
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500221 venb_flag = self.has_instance("VENBServiceInstance", o)
222 vmme_flag = self.has_instance("VMMETenant", o)
223 sdncontroller_flag = self.has_instance(
224 "SDNControllerServiceInstance", o)
Sapan Bhatia15721932017-12-08 15:36:33 -0500225 vspgwc_flag = self.has_instance("VSPGWCTenant", o)
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500226 internetemulator_flag = self.has_instance(
227 "SDNControllerServiceInstance", o)
Woojoong Kimf002aec2017-10-25 14:43:37 -0700228
Sapan Bhatia15721932017-12-08 15:36:33 -0500229 # wait until vspgwc and env are comming up
230 if (not vspgwc_flag):
231 self.defer_sync(o, "Waiting for vSPGWc to come up")
Woojoong Kim04d12162017-11-27 10:59:08 -0800232
233 if (not venb_flag):
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500234 self.defer_sync(o, "Waiting for vENB to come up")
Woojoong Kim04d12162017-11-27 10:59:08 -0800235
Sapan Bhatia15721932017-12-08 15:36:33 -0500236 if vmme_flag and venb_flag and sdncontroller_flag and vspgwc_flag and internetemulator_flag:
Woojoong Kim04d12162017-11-27 10:59:08 -0800237 return 'normal_scenario'
Woojoong Kimf002aec2017-10-25 14:43:37 -0700238
Sapan Bhatia15721932017-12-08 15:36:33 -0500239 if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwc_flag and internetemulator_flag:
Woojoong Kim04d12162017-11-27 10:59:08 -0800240 return 'normal_scenario_without_sdncontroller'
Woojoong Kimf002aec2017-10-25 14:43:37 -0700241
Sapan Bhatia15721932017-12-08 15:36:33 -0500242 if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwc_flag and (not internetemulator_flag):
Woojoong Kim04d12162017-11-27 10:59:08 -0800243 return 'emulator_scenario'
Woojoong Kimf002aec2017-10-25 14:43:37 -0700244
Sapan Bhatia15721932017-12-08 15:36:33 -0500245 if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwc_flag and (not internetemulator_flag):
Woojoong Kim04d12162017-11-27 10:59:08 -0800246 return 'emulator_scenario_without_sdncontroller'
Woojoong Kimf002aec2017-10-25 14:43:37 -0700247
248 return 'manual'
249
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500250 def get_peer_serviceinstance_of_type(self, sitype, o):
251 prov_link_set = ServiceInstanceLink.objects.filter(
252 subscriber_service_instance_id=o.id)
Woojoong Kimf002aec2017-10-25 14:43:37 -0700253
254 try:
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500255 peer_service = next(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500256 p.provider_service_instance for p in prov_link_set if p.provider_service_instance.leaf_model_name == sitype)
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500257 except StopIteration:
258 sub_link_set = ServiceInstanceLink.objects.filter(
259 provider_service_instance_id=o.id)
260 try:
261 peer_service = next(
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500262 s.subscriber_service_instance for s in sub_link_set if s.subscriber_service_instance.leaf_model_name == sitype)
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500263 except StopIteration:
264 self.log.error(
265 'Could not find service type in service graph', service_type=sitype, object=o)
Sapan Bhatiafc9f6b32017-11-28 14:13:31 -0500266 raise ServiceGraphException(
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500267 "Synchronization failed due to incomplete service graph")
268
269 return peer_service
270
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500271 # Maybe merge the two pairs of functions into one, with an address type "mac" or "ip" - SB
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500272 def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None):
273 peer_si = self.get_peer_serviceinstance_of_type(sitype, o)
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500274 return self.get_ip_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter)
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500275
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500276 def get_mac_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None):
277 peer_si = self.get_peer_serviceinstance_of_type(sitype, o)
278 return self.get_mac_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter)
279
280 def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter=None):
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500281 try:
Woojoong Kimf002aec2017-10-25 14:43:37 -0700282 net_id = self.get_network_id(network_name)
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500283 ins_id = peer_si.leaf_model.instance_id
Sapan Bhatia968f28f2017-11-22 12:00:01 -0500284 ip_address = Port.objects.get(
285 network_id=net_id, instance_id=ins_id).ip
Woojoong Kimf002aec2017-10-25 14:43:37 -0700286 except Exception:
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500287 self.log.error("Failed to fetch parameter",
288 parameter=parameter,
289 network_name=network_name)
290 self.defer_sync(o, "Waiting for parameters to become available")
Woojoong Kimf002aec2017-10-25 14:43:37 -0700291
292 return ip_address
293
Sapan Bhatia15721932017-12-08 15:36:33 -0500294 def get_mac_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter):
Woojoong Kim04d12162017-11-27 10:59:08 -0800295 try:
296 net_id = self.get_network_id(network_name)
Sapan Bhatia15721932017-12-08 15:36:33 -0500297 ins_id = peer_si.leaf_model.instance_id
298 mac_address = Port.objects.get(
299 network_id=net_id, instance_id=ins_id).mac
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500300
Woojoong Kim04d12162017-11-27 10:59:08 -0800301 except Exception:
Sapan Bhatia15721932017-12-08 15:36:33 -0500302 self.log.error("Failed to fetch parameter to get MAC",
303 parameter=parameter, network_name=network_name)
Sapan Bhatia2f27dbe2017-11-27 21:17:32 -0500304 self.defer_sync(o, "Waiting for parameters to become available")
Woojoong Kim04d12162017-11-27 10:59:08 -0800305
306 return mac_address
307
Woojoong Kimf002aec2017-10-25 14:43:37 -0700308 # To get each network id
309 def get_network_id(self, network_name):
310 return Network.objects.get(name=network_name).id