JianHao | 4a9550f | 2017-10-19 11:05:14 +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 |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 17 | import time |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 18 | from django.db.models import Q, F |
| 19 | from synchronizers.new_base.modelaccessor import * |
| 20 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 21 | |
| 22 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 23 | sys.path.insert(0, parentdir) |
| 24 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 25 | |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 26 | class SyncVSPGWCTenant(SyncInstanceUsingAnsible): |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 27 | observes = VSPGWCTenant |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 28 | template_name = "vspgwctenant_playbook.yaml" |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 29 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 30 | |
| 31 | def __init__(self, *args, **kwargs): |
| 32 | super(SyncVSPGWCTenant, self).__init__(*args, **kwargs) |
| 33 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 34 | def get_extra_attributes(self, o): |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 35 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 36 | scenario = self.get_scenario(o) |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 37 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 38 | if scenario == 'normal_scenario': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 39 | return self.get_values_for_normal_scenario(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 40 | elif scenario == 'normal_scenario_without_sdncontroller': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 41 | return self.get_values_for_normal_scenario_wo_sdncontroller(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 42 | elif scenario == 'emulator_scenario': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 43 | return self.get_values_for_emulator_scenario(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 44 | elif scenario == 'emulator_scenario_without_sdncontroller': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 45 | return self.get_values_for_emulator_scenario_wo_sdncontroller(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 46 | else: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 47 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 48 | |
| 49 | # fields for manual case |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 50 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 51 | fields = {} |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 52 | fields['scenario'] = self.get_scenario(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 53 | # for interface.cfg file |
| 54 | fields['zmq_sub_ip'] = "manual" |
| 55 | fields['zmq_pub_ip'] = "manual" |
| 56 | fields['dp_comm_ip'] = "manual" |
| 57 | fields['cp_comm_ip'] = "manual" |
| 58 | fields['fpc_ip'] = "manual" |
| 59 | fields['cp_nb_server_ip'] = "manual" |
| 60 | |
| 61 | # for cp_config.cfg file |
| 62 | fields['s11_sgw_ip'] = "manual" |
| 63 | fields['s11_mme_ip'] = "manual" |
| 64 | fields['s1u_sgw_ip'] = "manual" |
| 65 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 66 | # for rules setup in ONOS |
| 67 | fields['sgi_as_ip'] = "manual" |
| 68 | fields['sgi_spgwu_ip'] = "manual" |
| 69 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 70 | return fields |
| 71 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 72 | def get_values_for_normal_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 73 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 74 | fields['scenario'] = "normal_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 75 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -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( |
| 81 | 'sbi_network', "VSPGWUTenant", 'dp_comm_ip') |
| 82 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 83 | 'nbi_network', o, '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_instance( |
| 87 | 'nbi_network', o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 88 | |
| 89 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 90 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 91 | 's11_network', o, 's11_sgw_ip') |
| 92 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 93 | 's1u_network', "VSPGWUTenant", 's1u_sgw_ip') |
| 94 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 95 | 's11_network', "VMMETenant", 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 96 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 97 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 98 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
| 99 | 'sgi_network', "VENBServiceInstance", 'sgi_as_ip') |
| 100 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 101 | 'sgi_network', "VSPGWUTenant", 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 102 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 103 | return fields |
| 104 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 105 | def get_values_for_normal_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 106 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 107 | fields['scenario'] = "normal_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 108 | # for interface.cfg file |
| 109 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 110 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 111 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 112 | 'spgw_network', "VSPGWUTenant", 'dp_comm_ip') |
| 113 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 114 | 'spgw_network', o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 115 | fields['fpc_ip'] = "127.0.0.1" |
| 116 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 117 | |
| 118 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 119 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 120 | 's11_network', o, 's11_sgw_ip') |
| 121 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 122 | 's1u_network', "VSPGWUTenant", 's1u_sgw_ip') |
| 123 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 124 | 's11_network', "VMMETenant", 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 125 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 126 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 127 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
| 128 | 'sgi_network', "VENBServiceInstance", 'sgi_as_ip') |
| 129 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 130 | 'sgi_network', "VSPGWUTenant", 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 131 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 132 | return fields |
| 133 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 134 | def get_values_for_emulator_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 135 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 136 | fields['scenario'] = "emulator_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 137 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 138 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 139 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_sub_ip') |
| 140 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 141 | 'sbi_network', "SDNControllerServiceInstance", 'zmq_pub_ip') |
| 142 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 143 | 'sbi_network', "VSPGWUTenant", 'dp_comm_ip') |
| 144 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 145 | 'nbi_network', o, 'cp_comm_ip') |
| 146 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
| 147 | 'nbi_network', "SDNControllerServiceInstance", 'fpc_ip') |
| 148 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 149 | 'nbi_network', o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 150 | |
| 151 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 152 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 153 | 's11_network', o, 's11_sgw_ip') |
| 154 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 155 | 's1u_network', "VSPGWUTenant", 's1u_sgw_ip') |
| 156 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 157 | 's11_network', "VENBServiceInstance", 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 158 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 159 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 160 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
| 161 | 'sgi_network', "VENBServiceInstance", 'sgi_as_ip') |
| 162 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 163 | 'sgi_network', "VSPGWUTenant", 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 164 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 165 | return fields |
| 166 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 167 | def get_values_for_emulator_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 168 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 169 | fields['scenario'] = "emulator_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 170 | # for interface.cfg file |
| 171 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 172 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 173 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 174 | 'spgw_network', "VSPGWUTenant", 'dp_comm_ip') |
| 175 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 176 | 'spgw_network', o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 177 | fields['fpc_ip'] = "127.0.0.1" |
| 178 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 179 | |
| 180 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 181 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 182 | 's11_network', o, 's11_sgw_ip') |
| 183 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 184 | 's1u_network', "VSPGWUTenant", 's1u_sgw_ip') |
| 185 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 186 | 's11_network', "VENBServiceInstance", 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 187 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 188 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 189 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
| 190 | 'sgi_network', "VENBServiceInstance", 'sgi_as_ip') |
| 191 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 192 | 'sgi_network', "VSPGWUTenant", 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 193 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 194 | return fields |
| 195 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 196 | def get_scenario(self, o): |
| 197 | venb_flag = self.has_instance("VENBServiceInstance", o) |
| 198 | vmme_flag = self.has_instance("VMMETenant", o) |
| 199 | sdncontroller_flag = self.has_instance( |
| 200 | "SDNControllerServiceInstance", o) |
| 201 | vspgwu_flag = self.has_instance("VSPGWUTenant", o) |
| 202 | internetemulator_flag = self.has_instance( |
| 203 | "SDNControllerServiceInstance", o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 204 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 205 | if vmme_flag and venb_flag and sdncontroller_flag and vspgwu_flag and internetemulator_flag: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 206 | return 'ng4t_with_sdncontroller' |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 207 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 208 | if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwu_flag and internetemulator_flag: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 209 | return 'ng4t_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 210 | |
| 211 | if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag): |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 212 | return 'spirent_with_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 213 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 214 | if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwu_flag and ( |
| 215 | not internetemulator_flag): |
| 216 | return 'spirent_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 217 | |
| 218 | return 'manual' |
| 219 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 220 | def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 221 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
| 222 | return self.get_ip_address_for_peer_service_instance_instance(network_name, peer_si, parameter) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 223 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 224 | def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, parameter=None): |
| 225 | try: |
| 226 | net_id = self.get_network_id(network_name) |
| 227 | ins_id = peer_si.instance_id |
| 228 | ip_address = Port.objects.get( |
| 229 | network_id=net_id, instance_id=ins_id).ip |
| 230 | except Exception: |
| 231 | self.log.error("Failed to fetch parameter", |
| 232 | parameter=parameter, |
| 233 | network_name=network_name) |
| 234 | self.defer_sync("Waiting for parameters to become available") |
| 235 | |
| 236 | return ip_address |
| 237 | |
| 238 | def get_peer_serviceinstance_of_type(self, sitype, o): |
| 239 | prov_link_set = ServiceInstanceLink.objects.filter( |
| 240 | subscriber_service_instance_id=o.id) |
| 241 | |
| 242 | try: |
| 243 | peer_service = next( |
| 244 | p for p in prov_link_set if p.leaf_model_name == sitype) |
| 245 | except StopIteration: |
| 246 | sub_link_set = ServiceInstanceLink.objects.filter( |
| 247 | provider_service_instance_id=o.id) |
| 248 | try: |
| 249 | peer_service = next( |
| 250 | s for s in sub_link_set if s.leaf_model_name == sitype) |
| 251 | except StopIteration: |
| 252 | self.log.error( |
| 253 | 'Could not find service type in service graph', service_type=sitype, object=o) |
| 254 | raise Exception( |
| 255 | "Synchronization failed due to incomplete service graph") |
| 256 | |
| 257 | return peer_service |
| 258 | |
| 259 | # To get IP address |
| 260 | def get_ip_address_from_peer_service_instance(self, network_name, service_instance, parameter): |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 261 | condition = False |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 262 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 263 | while (not condition): |
| 264 | try: |
| 265 | net_id = self.get_network_id(network_name) |
| 266 | ins_id = self.get_instance_id(service_instance) |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 267 | ip_address = Port.objects.get( |
| 268 | network_id=net_id, instance_id=ins_id).ip |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 269 | condition = True |
| 270 | except Exception: |
| 271 | ip_address = "error" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 272 | self.log.error('Could not fetch parameter', |
| 273 | parameter=parameter, network_name=network_name) |
Sapan Bhatia | 4e1a4a7 | 2017-11-22 10:09:40 -0500 | [diff] [blame] | 274 | self.defer_sync("Waiting for parameters to become available") |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 275 | |
| 276 | return ip_address |
| 277 | |
| 278 | # To get each network id |
| 279 | def get_network_id(self, network_name): |
| 280 | return Network.objects.get(name=network_name).id |
| 281 | |
| 282 | # To get service_instance (assumption: there is a single instance for each service) |
| 283 | def get_instance_id(self, serviceinstance): |
| 284 | instances = serviceinstance.objects.all() |
| 285 | instance_id = instances[0].instance_id |
| 286 | return instance_id |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame^] | 287 | |
| 288 | def has_instance(self, sitype, o): |
| 289 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 290 | if not i: |
| 291 | self.log.info("Missing in ServiceInstance graph", |
| 292 | serviceinstance=sitype) |
| 293 | return False |
| 294 | |
| 295 | return i.instance_id |