Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 1 | # 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 | |
| 15 | import os |
| 16 | import sys |
| 17 | from django.db.models import Q, F |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 18 | from synchronizers.new_base.modelaccessor import * |
| 19 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 20 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 21 | from collections import defaultdict |
| 22 | |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 23 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 24 | sys.path.insert(0, parentdir) |
| 25 | |
Sapan Bhatia | fc9f6b3 | 2017-11-28 14:13:31 -0500 | [diff] [blame] | 26 | class ServiceGraphException(Exception): |
| 27 | pass |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 28 | |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 29 | class SyncVSPGWUTenant(SyncInstanceUsingAnsible): |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 30 | observes = VSPGWUTenant |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 31 | template_name = "vspgwutenant_playbook.yaml" |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 32 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 33 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 34 | """ Convert ServiceInstance graph into an adjacency set""" |
| 35 | def adj_set_of_service_graph(self, o, visited = None, adj_set = None): |
| 36 | def key(o): |
| 37 | return o.leaf_model_name |
| 38 | |
| 39 | if not adj_set: |
| 40 | adj_set = defaultdict(set) |
| 41 | |
| 42 | if not o: |
| 43 | return adj_set |
| 44 | else: |
| 45 | if not visited: |
| 46 | visited = set() |
| 47 | |
| 48 | ko = key(o) |
| 49 | visited.add(ko) |
| 50 | |
| 51 | provider_links = ServiceInstanceLink.objects.filter(subscriber_service_instance_id = o.id) |
| 52 | for l in provider_links: |
| 53 | n = l.provider_service_instance |
| 54 | kn = key(n) |
| 55 | adj_set[ko].add(kn) |
| 56 | adj_set[kn].update([]) |
| 57 | if kn not in visited: |
| 58 | adj_set = self.adj_set_of_service_graph(n, visited, adj_set) |
| 59 | |
| 60 | subscriber_links = ServiceInstanceLink.objects.filter(provider_service_instance_id = o.id) |
| 61 | for l in subscriber_links: |
| 62 | n = l.subscriber_service_instance |
| 63 | sn = key(n) |
| 64 | adj_set[sn].add(ko) |
| 65 | adj_set[ko].update([]) |
| 66 | if sn not in visited: |
| 67 | adj_set = self.adj_set_of_service_graph(n, visited, adj_set) |
| 68 | |
| 69 | return adj_set |
| 70 | |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 71 | def __init__(self, *args, **kwargs): |
| 72 | super(SyncVSPGWUTenant, self).__init__(*args, **kwargs) |
| 73 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 74 | def get_extra_attributes(self, o): |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 75 | blueprint = self.get_blueprint_and_check_dependencies(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 76 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 77 | if blueprint == 'cord_4_1_blueprint': |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 78 | return self.get_values_for_CORD_4_1(o) |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 79 | elif blueprint == 'cord_5_0_blueprint': |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 80 | return self.get_values_for_CORD_5_0(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 81 | else: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 82 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 83 | |
| 84 | # fields for manual case |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 85 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 86 | fields = {} |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 87 | fields['blueprint'] = "manual" |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 88 | fields['cord_version'] = "manual" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 89 | # for interface.cfg file |
| 90 | fields['zmq_sub_ip'] = "manual" |
| 91 | fields['zmq_pub_ip'] = "manual" |
| 92 | fields['dp_comm_ip'] = "manual" |
| 93 | fields['cp_comm_ip'] = "manual" |
| 94 | fields['fpc_ip'] = "manual" |
| 95 | fields['cp_nb_server_ip'] = "manual" |
| 96 | |
| 97 | # for dp_config.cfg file |
| 98 | fields['s1u_ip'] = "manual" |
| 99 | fields['sgi_ip'] = "manual" |
| 100 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 101 | # for static_arp.cfg file |
| 102 | fields['as_sgi_ip'] = "manual" |
| 103 | fields['as_sgi_mac'] = "manual" |
| 104 | fields['enb_s1u_ip'] = "manual" |
| 105 | fields['enb_s1u_mac'] = "manual" |
| 106 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 107 | return fields |
| 108 | |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 109 | def get_values_for_CORD_4_1(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 110 | fields = {} |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 111 | fields['cord_version'] = "4.1" |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 112 | fields['blueprint'] = "cord_4_1_blueprint" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 113 | # for interface.cfg file |
| 114 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 115 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 116 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 117 | 'spgw_network', o, o, 'dp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 118 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 119 | 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 120 | fields['fpc_ip'] = "127.0.0.1" |
| 121 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 122 | |
| 123 | # for cp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 124 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 125 | 's1u_network', o, o, 's1u_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 126 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 127 | 'sgi_network', o, o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 128 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 129 | # for static_arp.cfg file |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame] | 130 | fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance( |
| 131 | 'sgi_network', "VENBServiceInstance", o, 'as_sgi_ip') |
| 132 | fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance( |
| 133 | 'sgi_network', "VENBServiceInstance", o, 'as_sgi_mac') |
| 134 | fields['enb_s1u_ip'] = self.get_ip_address_from_peer_service_instance( |
| 135 | 's1u_network', "VENBServiceInstance", o, 'enb_s1u_ip') |
| 136 | fields['enb_s1u_mac'] = self.get_mac_address_from_peer_service_instance( |
| 137 | 's1u_network', "VENBServiceInstance", o, 'enb_s1u_mac') |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 138 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 139 | return fields |
| 140 | |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 141 | def get_values_for_CORD_5_0(self, o): |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 142 | fields = {} |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 143 | fields['cord_version'] = "5.0" |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 144 | fields['blueprint'] = "cord_5_0_blueprint" |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 145 | |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 146 | # for interface.cfg file |
| 147 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 148 | fields['zmq_pub_ip'] = "127.0.0.1" |
| 149 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 150 | 'spgw_network', o, o, 'dp_comm_ip') |
| 151 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 152 | 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip') |
| 153 | fields['fpc_ip'] = "127.0.0.1" |
| 154 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 155 | |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 156 | # for cp_config.cfg file |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 157 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Woojoong Kim | 4f3ea43 | 2018-01-22 17:35:52 -0800 | [diff] [blame] | 158 | 'flat_network_s1u', o, o, 's1u_ip') |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 159 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 160 | 'sgi_network', o, o, 'sgi_ip') |
| 161 | |
| 162 | # for static_arp.cfg file |
Woojoong Kim | 2f03e44 | 2018-01-18 20:02:22 -0800 | [diff] [blame] | 163 | internetemulator_flag = self.has_instance("InternetEmulatorServiceInstance", o) |
| 164 | if (internetemulator_flag): |
| 165 | fields['as_sgi_ip'] = self.get_ip_address_from_peer_service_instance('sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_ip') |
| 166 | fields['as_sgi_mac'] = self.get_mac_address_from_peer_service_instance('sgi_network', "InternetEmulatorServiceInstance", o, 'as_sgi_mac') |
| 167 | else: |
| 168 | fields['as_sgi_ip'] = o.appserver_ip_addr |
| 169 | fields['as_sgi_mac'] = o.appserver_mac_addr |
| 170 | fields['enb_s1u_ip'] = o.enodeb_ip_addr # write down eNB IP address manually (S1U) |
| 171 | fields['enb_s1u_mac'] = o.enodeb_mac_addr # write down eNB MAC address manually (S1U) |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 172 | |
| 173 | return fields |
| 174 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 175 | def has_instance(self, sitype, o): |
Sapan Bhatia | fc9f6b3 | 2017-11-28 14:13:31 -0500 | [diff] [blame] | 176 | try: |
| 177 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 178 | except ServiceGraphException: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 179 | self.log.info("Missing in ServiceInstance graph", |
| 180 | serviceinstance=sitype) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 181 | return False |
| 182 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 183 | return i.leaf_model.instance_id |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 184 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 185 | def find_first_blueprint_subgraph(self, blueprints, adj_set): |
| 186 | found_blueprint = None |
| 187 | for blueprint in blueprints: |
| 188 | found = True |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 189 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 190 | for node in blueprint['graph']: |
| 191 | if node['name'] not in adj_set: |
| 192 | found = False |
| 193 | break |
| 194 | try: |
| 195 | links = node['links'] |
| 196 | except KeyError: |
| 197 | links = [] |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 198 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 199 | for link in links: |
| 200 | if link['name'] not in adj_set[node['name']]: |
| 201 | found = False |
| 202 | break |
| 203 | if not found: |
| 204 | break |
Woojoong Kim | 4a15d41 | 2017-12-18 17:17:40 -0800 | [diff] [blame] | 205 | |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 206 | if found: |
| 207 | found_blueprint = blueprint['name'] |
| 208 | break |
| 209 | |
| 210 | return found_blueprint |
| 211 | |
| 212 | def check_instance_dependencies(self, blueprints, blueprint_name, o): |
| 213 | blueprint = next( |
| 214 | b for b in blueprints if b['name'] == blueprint_name) |
| 215 | node = next(n for n in blueprint['graph'] if n['name'] == o.leaf_model_name) |
| 216 | for link in node['links']: |
| 217 | flag = self.has_instance(link['name'], o) |
| 218 | if not flag: |
| 219 | self.defer_sync('%s does not have an instance. Deferring synchronization.'%link['name']) |
| 220 | |
| 221 | def get_blueprint_and_check_dependencies(self, o): |
| 222 | blueprints = Config().get('blueprints') |
| 223 | |
| 224 | adj_set = self.adj_set_of_service_graph(o) |
| 225 | blueprint_name = self.find_first_blueprint_subgraph(blueprints, adj_set) |
| 226 | if blueprint_name: |
| 227 | self.check_instance_dependencies(blueprints, blueprint_name, o) |
| 228 | |
| 229 | ret_blueprint = 'manual' if not blueprint_name else blueprint_name |
| 230 | return ret_blueprint |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 231 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 232 | def get_peer_serviceinstance_of_type(self, sitype, o): |
Woojoong Kim | 4f3ea43 | 2018-01-22 17:35:52 -0800 | [diff] [blame] | 233 | |
| 234 | global_list = self.get_all_instances_in_graph(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 235 | |
| 236 | try: |
Woojoong Kim | 4f3ea43 | 2018-01-22 17:35:52 -0800 | [diff] [blame] | 237 | peer_service = next(p for p in global_list if p.leaf_model_name == sitype) |
| 238 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 239 | except StopIteration: |
Woojoong Kim | 4f3ea43 | 2018-01-22 17:35:52 -0800 | [diff] [blame] | 240 | self.log.error( |
| 241 | 'Could not find service type in service graph', service_type=sitype, object=o) |
| 242 | raise ServiceGraphException( |
| 243 | "Synchronization failed due to incomplete service graph") |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 244 | |
| 245 | return peer_service |
| 246 | |
Woojoong Kim | 4f3ea43 | 2018-01-22 17:35:52 -0800 | [diff] [blame] | 247 | def has_instance_in_list(self, list, o): |
| 248 | for instance in list: |
| 249 | if instance.leaf_model_name == o.leaf_model_name: |
| 250 | return True |
| 251 | |
| 252 | return False |
| 253 | |
| 254 | def get_all_instances_in_graph(self, o): |
| 255 | |
| 256 | to_search_list = self.get_one_hop_instances_in_graph(o) |
| 257 | result_list = [] |
| 258 | |
| 259 | while len(to_search_list) > 0: |
| 260 | tmp_obj = to_search_list[0] |
| 261 | to_search_list.remove(tmp_obj) |
| 262 | tmp_list = self.get_one_hop_instances_in_graph(tmp_obj) |
| 263 | |
| 264 | for index_obj in tmp_list: |
| 265 | if (not self.has_instance_in_list(to_search_list, index_obj)) and (not self.has_instance_in_list(result_list, index_obj)): |
| 266 | to_search_list.append(index_obj) |
| 267 | |
| 268 | result_list.append(tmp_obj) |
| 269 | return result_list |
| 270 | |
| 271 | def get_one_hop_instances_in_graph(self, o): |
| 272 | instance_list = [] |
| 273 | |
| 274 | # 1 hop forward and backward |
| 275 | prov_links = ServiceInstanceLink.objects.filter(subscriber_service_instance_id=o.id) |
| 276 | subs_links = ServiceInstanceLink.objects.filter(provider_service_instance_id=o.id) |
| 277 | |
| 278 | # add instances located in 1 hop into instance_list |
| 279 | for tmp_link1 in prov_links: |
| 280 | if not self.has_instance_in_list(instance_list, tmp_link1.provider_service_instance): |
| 281 | instance_list.append(tmp_link1.provider_service_instance) |
| 282 | |
| 283 | for tmp_link1 in subs_links: |
| 284 | if not self.has_instance_in_list(instance_list, tmp_link1.subscriber_service_instance): |
| 285 | instance_list.append(tmp_link1.subscriber_service_instance) |
| 286 | |
| 287 | return instance_list |
| 288 | |
| 289 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 290 | # Maybe merge the two pairs of functions into one, with an address type "mac" or "ip" - SB |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 291 | def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 292 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 293 | return self.get_ip_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter) |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 294 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 295 | def get_mac_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 296 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
| 297 | return self.get_mac_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter) |
| 298 | |
| 299 | def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter=None): |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 300 | try: |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 301 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 302 | ins_id = peer_si.leaf_model.instance_id |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 303 | ip_address = Port.objects.get( |
| 304 | network_id=net_id, instance_id=ins_id).ip |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 305 | except Exception: |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 306 | self.log.error("Failed to fetch parameter", |
| 307 | parameter=parameter, |
| 308 | network_name=network_name) |
| 309 | self.defer_sync(o, "Waiting for parameters to become available") |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 310 | |
| 311 | return ip_address |
| 312 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame] | 313 | def get_mac_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter): |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 314 | try: |
| 315 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame] | 316 | ins_id = peer_si.leaf_model.instance_id |
| 317 | mac_address = Port.objects.get( |
| 318 | network_id=net_id, instance_id=ins_id).mac |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 319 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 320 | except Exception: |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame] | 321 | self.log.error("Failed to fetch parameter to get MAC", |
| 322 | parameter=parameter, network_name=network_name) |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 323 | self.defer_sync(o, "Waiting for parameters to become available") |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 324 | |
| 325 | return mac_address |
| 326 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 327 | # To get each network id |
| 328 | def get_network_id(self, network_name): |
| 329 | return Network.objects.get(name=network_name).id |
Sapan Bhatia | ae30965 | 2018-01-23 23:40:40 -0500 | [diff] [blame^] | 330 | |