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 | |
| 21 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 22 | sys.path.insert(0, parentdir) |
| 23 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 24 | |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 25 | class SyncVSPGWUTenant(SyncInstanceUsingAnsible): |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 26 | observes = VSPGWUTenant |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 27 | template_name = "vspgwutenant_playbook.yaml" |
Wei-Yu Chen | ba04359 | 2017-10-18 17:08:51 +0800 | [diff] [blame] | 28 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 29 | |
| 30 | def __init__(self, *args, **kwargs): |
| 31 | super(SyncVSPGWUTenant, self).__init__(*args, **kwargs) |
| 32 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 33 | def get_extra_attributes(self, o): |
| 34 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 35 | scenario = self.get_scenario(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 36 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 37 | if scenario == 'normal_scenario': |
| 38 | return self.get_values_for_normal_scenario(o) |
| 39 | elif scenario == 'normal_scenario_without_sdncontroller': |
| 40 | return self.get_values_for_normal_scenario_wo_sdncontroller(o) |
| 41 | elif scenario == 'emulator_scenario': |
| 42 | return self.get_values_for_emulator_scenario(o) |
| 43 | elif scenario == 'emulator_scenario_without_sdncontroller': |
| 44 | return self.get_values_for_emulator_scenario_wo_sdncontroller(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 45 | else: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 46 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 47 | |
| 48 | # fields for manual case |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 49 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 50 | fields = {} |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 51 | fields['scenario'] = self.get_scenario(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 52 | # for interface.cfg file |
| 53 | fields['zmq_sub_ip'] = "manual" |
| 54 | fields['zmq_pub_ip'] = "manual" |
| 55 | fields['dp_comm_ip'] = "manual" |
| 56 | fields['cp_comm_ip'] = "manual" |
| 57 | fields['fpc_ip'] = "manual" |
| 58 | fields['cp_nb_server_ip'] = "manual" |
| 59 | |
| 60 | # for dp_config.cfg file |
| 61 | fields['s1u_ip'] = "manual" |
| 62 | fields['sgi_ip'] = "manual" |
| 63 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 64 | # for static_arp.cfg file |
| 65 | fields['as_sgi_ip'] = "manual" |
| 66 | fields['as_sgi_mac'] = "manual" |
| 67 | fields['enb_s1u_ip'] = "manual" |
| 68 | fields['enb_s1u_mac'] = "manual" |
| 69 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 70 | return fields |
| 71 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 72 | def get_values_for_normal_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 73 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 74 | fields['scenario'] = "normal_scenario" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 75 | # for interface.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 76 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 77 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_sub_ip') |
| 78 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 79 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_pub_ip') |
| 80 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 81 | 'sbi_network', o, 'dp_comm_ip') |
| 82 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 83 | 'nbi_network', "VSPGWCTenant", 'cp_comm_ip') |
| 84 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
| 85 | 'nbi_network', "SDNControllerServiceInstance", 'fpc_ip') |
| 86 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance( |
| 87 | 'nbi_network', "VSPGWCTenant", 'cp_nb_server_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 88 | |
| 89 | # for dp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 90 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 91 | 's1u_network', o, 's1u_ip') |
| 92 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance( |
| 93 | 'sgi_network', "VSPGWUTenant", 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 94 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 95 | # for static_arp.cfg file |
| 96 | fields['as_sgi_ip'] = self.get_ip_address('sgi_network', InternetEmulatorServiceInstance, 'as_sgi_ip') |
| 97 | fields['as_sgi_mac'] = self.get_mac_address('sgi_network', InternetEmulatorServiceInstance, 'as_sgi_mac') |
| 98 | fields['enb_s1u_ip'] = self.get_ip_address('s1u_network', VENBServiceInstance, 'enb_s1u_ip') |
| 99 | fields['enb_s1u_mac'] = self.get_mac_address('s1u_network', VENBServiceInstance, 'enb_s1u_mac') |
| 100 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 101 | return fields |
| 102 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 103 | def get_values_for_normal_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 104 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 105 | fields['scenario'] = "normal_scenario_without_sdncontroller" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 106 | # for interface.cfg file |
| 107 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 108 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 109 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 110 | 'spgw_network', o, 'dp_comm_ip') |
| 111 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 112 | 'spgw_network', "VSPGWCTenant", 'cp_comm_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 113 | fields['fpc_ip'] = "127.0.0.1" |
| 114 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 115 | |
| 116 | # for cp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 117 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 118 | 's1u_network', o, 's1u_ip') |
| 119 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 120 | 'sgi_network', o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 121 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 122 | # for static_arp.cfg file |
| 123 | fields['as_sgi_ip'] = self.get_ip_address('sgi_network', InternetEmulatorServiceInstance, 'as_sgi_ip') |
| 124 | fields['as_sgi_mac'] = self.get_mac_address('sgi_network', InternetEmulatorServiceInstance, 'as_sgi_mac') |
| 125 | fields['enb_s1u_ip'] = self.get_ip_address('s1u_network', VENBServiceInstance, 'enb_s1u_ip') |
| 126 | fields['enb_s1u_mac'] = self.get_mac_address('s1u_network', VENBServiceInstance, 'enb_s1u_mac') |
| 127 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 128 | return fields |
| 129 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 130 | def get_values_for_emulator_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 131 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 132 | fields['scenario'] = "emulator_scenario" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 133 | # for interface.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 134 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 135 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_sub_ip') |
| 136 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 137 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_pub_ip') |
| 138 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 139 | 'sbi_network', o, 'dp_comm_ip') |
| 140 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 141 | 'nbi_network', "VSPGWCTenant", 'cp_comm_ip') |
| 142 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
| 143 | 'nbi_network', "SDNControllerServiceInstance", 'fpc_ip') |
| 144 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance( |
| 145 | 'nbi_network', "VSPGWCTenant", 'cp_nb_server_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 146 | |
| 147 | # for dp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 148 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 149 | 's1u_network', o, 's1u_ip') |
| 150 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 151 | 'sgi_network', o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 152 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 153 | # for static_arp.cfg file |
| 154 | fields['as_sgi_ip'] = self.get_ip_address('sgi_network', VENBServiceInstance, 'as_sgi_ip') |
| 155 | fields['as_sgi_mac'] = self.get_mac_address('sgi_network', VENBServiceInstance, 'as_sgi_mac') |
| 156 | fields['enb_s1u_ip'] = self.get_ip_address('s1u_network', VENBServiceInstance, 'enb_s1u_ip') |
| 157 | fields['enb_s1u_mac'] = self.get_mac_address('s1u_network', VENBServiceInstance, 'enb_s1u_mac') |
| 158 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 159 | return fields |
| 160 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 161 | def get_values_for_emulator_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 162 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 163 | fields['scenario'] = "emulator_scenario_without_sdncontroller" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 164 | # for interface.cfg file |
| 165 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 166 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 167 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 168 | 'spgw_network', o, 'dp_comm_ip') |
| 169 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 170 | 'spgw_network', "VSPGWCTenant", 'cp_comm_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 171 | fields['fpc_ip'] = "127.0.0.1" |
| 172 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 173 | |
| 174 | # for cp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 175 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 176 | 's1u_network', o, 's1u_ip') |
| 177 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 178 | 'sgi_network', o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 179 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 180 | # for static_arp.cfg file |
| 181 | fields['as_sgi_ip'] = self.get_ip_address('sgi_network', VENBServiceInstance, 'as_sgi_ip') |
| 182 | fields['as_sgi_mac'] = self.get_mac_address('sgi_network', VENBServiceInstance, 'as_sgi_mac') |
| 183 | fields['enb_s1u_ip'] = self.get_ip_address('s1u_network', VENBServiceInstance, 'enb_s1u_ip') |
| 184 | fields['enb_s1u_mac'] = self.get_mac_address('s1u_network', VENBServiceInstance, 'enb_s1u_mac') |
| 185 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 186 | return fields |
| 187 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 188 | def has_instance(self, sitype, o): |
| 189 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 190 | if not i: |
| 191 | self.log.info("Missing in ServiceInstance graph", |
| 192 | serviceinstance=sitype) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 193 | return False |
| 194 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 195 | return i.instance_id |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 196 | |
| 197 | # Which scenario does it use among Spirent or NG4T? |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 198 | def get_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 199 | # try get vENB instance: one of both Spirent and NG4T |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 200 | venb_flag = self.has_instance("VENBServiceInstance", o) |
| 201 | vmme_flag = self.has_instance("VMMETenant", o) |
| 202 | sdncontroller_flag = self.has_instance( |
| 203 | "SDNControllerServiceInstance", o) |
| 204 | vspgwu_flag = self.has_instance("VSPGWUTenant", o) |
| 205 | internetemulator_flag = self.has_instance( |
| 206 | "SDNControllerServiceInstance", o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 207 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 208 | # wait until vspgwu and env are comming up |
| 209 | if (not vspgwu_flag): |
| 210 | self.defer_sync("Waiting for vSPGWU to come up") |
| 211 | |
| 212 | if (not venb_flag): |
| 213 | self.defer_sync("Waiting for vENB to come up") |
| 214 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 215 | if vmme_flag and venb_flag and sdncontroller_flag and vspgwu_flag and internetemulator_flag: |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 216 | return 'normal_scenario' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 217 | |
| 218 | if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwu_flag and internetemulator_flag: |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 219 | return 'normal_scenario_without_sdncontroller' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 220 | |
| 221 | if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag): |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 222 | return 'emulator_scenario' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 223 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 224 | if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwu_flag and (not internetemulator_flag): |
| 225 | return 'emulator_scenario_without_sdncontroller' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 226 | |
| 227 | return 'manual' |
| 228 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 229 | def get_peer_serviceinstance_of_type(self, sitype, o): |
| 230 | prov_link_set = ServiceInstanceLink.objects.filter( |
| 231 | subscriber_service_instance_id=o.id) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 232 | |
| 233 | try: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 234 | peer_service = next( |
| 235 | p for p in prov_link_set if p.leaf_model_name == sitype) |
| 236 | except StopIteration: |
| 237 | sub_link_set = ServiceInstanceLink.objects.filter( |
| 238 | provider_service_instance_id=o.id) |
| 239 | try: |
| 240 | peer_service = next( |
| 241 | s for s in sub_link_set if s.leaf_model_name == sitype) |
| 242 | except StopIteration: |
| 243 | self.log.error( |
| 244 | 'Could not find service type in service graph', service_type=sitype, object=o) |
| 245 | raise Exception( |
| 246 | "Synchronization failed due to incomplete service graph") |
| 247 | |
| 248 | return peer_service |
| 249 | |
| 250 | def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 251 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
| 252 | return self.get_ip_address_for_peer_service_instance_instance(network_name, peer_si, parameter) |
| 253 | |
| 254 | def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, parameter=None): |
| 255 | try: |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 256 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 257 | ins_id = peer_si.instance_id |
| 258 | ip_address = Port.objects.get( |
| 259 | network_id=net_id, instance_id=ins_id).ip |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 260 | except Exception: |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 261 | ip_address = "error" |
| 262 | self.log.error("Failed to fetch parameter to get IP", parameter = parameter, network_name = network_name) |
Sapan Bhatia | a71f221 | 2017-11-22 10:12:18 -0500 | [diff] [blame] | 263 | self.defer_sync("Waiting for parameters to become available") |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 264 | |
| 265 | return ip_address |
| 266 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 267 | def get_mac_address(self, network_name, service_instance, parameter): |
| 268 | |
| 269 | try: |
| 270 | net_id = self.get_network_id(network_name) |
| 271 | ins_id = self.get_instance_id(service_instance) |
| 272 | mac_address = Port.objects.get(network_id=net_id, instance_id=ins_id).ip |
| 273 | |
| 274 | except Exception: |
| 275 | mac_address = "error" |
| 276 | self.log.error("Failed to fetch parameter to get MAC", parameter = parameter, network_name = network_name) |
| 277 | self.defer_sync("Waiting for parameters to become available") |
| 278 | |
| 279 | return mac_address |
| 280 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 281 | # To get each network id |
| 282 | def get_network_id(self, network_name): |
| 283 | return Network.objects.get(name=network_name).id |