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 | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 24 | |
Sapan Bhatia | fc9f6b3 | 2017-11-28 14:13:31 -0500 | [diff] [blame] | 25 | class ServiceGraphException(Exception): |
| 26 | pass |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 27 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -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 | |
| 34 | def __init__(self, *args, **kwargs): |
| 35 | super(SyncVSPGWUTenant, self).__init__(*args, **kwargs) |
| 36 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 37 | def get_extra_attributes(self, o): |
| 38 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 39 | scenario = self.get_scenario(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 40 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 41 | 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 Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 49 | else: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 50 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 51 | |
| 52 | # fields for manual case |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 53 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 54 | fields = {} |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 55 | fields['scenario'] = self.get_scenario(o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 56 | # 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 68 | # 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 Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 74 | return fields |
| 75 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 76 | def get_values_for_normal_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 77 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 78 | fields['scenario'] = "normal_scenario" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 79 | # for interface.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 80 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 81 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 82 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 83 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 84 | 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] | 85 | 'sbi_network', o, o, 'dp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 86 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 87 | 'nbi_network', "VSPGWCTenant", o, 'cp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 88 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 89 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 90 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 91 | 'nbi_network', "VSPGWCTenant", o, 'cp_nb_server_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 92 | |
| 93 | # for dp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 94 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 95 | 's1u_network', o, o, 's1u_ip') |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 96 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 97 | 'sgi_network', o, o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 98 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 99 | # for static_arp.cfg file |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 100 | 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 108 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 109 | return fields |
| 110 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 111 | def get_values_for_normal_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 112 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 113 | fields['scenario'] = "normal_scenario_without_sdncontroller" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 114 | # for interface.cfg file |
| 115 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 116 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 117 | 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] | 118 | 'spgw_network', o, o, 'dp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 119 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 120 | 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 121 | 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 Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 125 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 126 | 's1u_network', o, o, 's1u_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 127 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 128 | 'sgi_network', o, o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 129 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 130 | # for static_arp.cfg file |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 131 | 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 139 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 140 | return fields |
| 141 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 142 | def get_values_for_emulator_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 143 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 144 | fields['scenario'] = "emulator_scenario" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 145 | # for interface.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 146 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 147 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 148 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 149 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 150 | 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] | 151 | 'sbi_network', o, o, 'dp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 152 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 153 | 'nbi_network', "VSPGWCTenant", o, 'cp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 154 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 155 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 156 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 157 | 'nbi_network', "VSPGWCTenant", o, 'cp_nb_server_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 158 | |
| 159 | # for dp_config.cfg file |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 160 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 161 | 's1u_network', o, o, 's1u_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 162 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 163 | 'sgi_network', o, o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 164 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 165 | # for static_arp.cfg file |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 166 | 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 174 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 175 | return fields |
| 176 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 177 | def get_values_for_emulator_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 178 | fields = {} |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 179 | fields['scenario'] = "emulator_scenario_without_sdncontroller" |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 180 | # for interface.cfg file |
| 181 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 182 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 183 | 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] | 184 | 'spgw_network', o, o, 'dp_comm_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 185 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 186 | 'spgw_network', "VSPGWCTenant", o, 'cp_comm_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 187 | 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 Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 191 | fields['s1u_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 192 | 's1u_network', o, o, 's1u_ip') |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 193 | fields['sgi_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 194 | 'sgi_network', o, o, 'sgi_ip') |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 195 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 196 | # for static_arp.cfg file |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 197 | 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 205 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 206 | return fields |
| 207 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 208 | def has_instance(self, sitype, o): |
Sapan Bhatia | fc9f6b3 | 2017-11-28 14:13:31 -0500 | [diff] [blame] | 209 | try: |
| 210 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 211 | except ServiceGraphException: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 212 | self.log.info("Missing in ServiceInstance graph", |
| 213 | serviceinstance=sitype) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 214 | return False |
| 215 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 216 | return i.leaf_model.instance_id |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 217 | |
| 218 | # Which scenario does it use among Spirent or NG4T? |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 219 | def get_scenario(self, o): |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 220 | # try get vENB instance: one of both Spirent and NG4T |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 221 | 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 Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 225 | vspgwc_flag = self.has_instance("VSPGWCTenant", o) |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 226 | internetemulator_flag = self.has_instance( |
| 227 | "SDNControllerServiceInstance", o) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 228 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 229 | # 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 Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 232 | |
| 233 | if (not venb_flag): |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 234 | self.defer_sync(o, "Waiting for vENB to come up") |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 235 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 236 | if vmme_flag and venb_flag and sdncontroller_flag and vspgwc_flag and internetemulator_flag: |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 237 | return 'normal_scenario' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 238 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 239 | if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwc_flag and internetemulator_flag: |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 240 | return 'normal_scenario_without_sdncontroller' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 241 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 242 | if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwc_flag and (not internetemulator_flag): |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 243 | return 'emulator_scenario' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 244 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 245 | if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwc_flag and (not internetemulator_flag): |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 246 | return 'emulator_scenario_without_sdncontroller' |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 247 | |
| 248 | return 'manual' |
| 249 | |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 250 | def get_peer_serviceinstance_of_type(self, sitype, o): |
| 251 | prov_link_set = ServiceInstanceLink.objects.filter( |
| 252 | subscriber_service_instance_id=o.id) |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 253 | |
| 254 | try: |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 255 | peer_service = next( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 256 | p.provider_service_instance for p in prov_link_set if p.provider_service_instance.leaf_model_name == sitype) |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 257 | except StopIteration: |
| 258 | sub_link_set = ServiceInstanceLink.objects.filter( |
| 259 | provider_service_instance_id=o.id) |
| 260 | try: |
| 261 | peer_service = next( |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 262 | s.subscriber_service_instance for s in sub_link_set if s.subscriber_service_instance.leaf_model_name == sitype) |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 263 | except StopIteration: |
| 264 | self.log.error( |
| 265 | 'Could not find service type in service graph', service_type=sitype, object=o) |
Sapan Bhatia | fc9f6b3 | 2017-11-28 14:13:31 -0500 | [diff] [blame] | 266 | raise ServiceGraphException( |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 267 | "Synchronization failed due to incomplete service graph") |
| 268 | |
| 269 | return peer_service |
| 270 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 271 | # 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] | 272 | 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 Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 274 | 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] | 275 | |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 276 | 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 Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 281 | try: |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 282 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 283 | ins_id = peer_si.leaf_model.instance_id |
Sapan Bhatia | 968f28f | 2017-11-22 12:00:01 -0500 | [diff] [blame] | 284 | ip_address = Port.objects.get( |
| 285 | network_id=net_id, instance_id=ins_id).ip |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 286 | except Exception: |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 287 | 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 Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 291 | |
| 292 | return ip_address |
| 293 | |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 294 | 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] | 295 | try: |
| 296 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 297 | 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 Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 300 | |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 301 | except Exception: |
Sapan Bhatia | 1572193 | 2017-12-08 15:36:33 -0500 | [diff] [blame^] | 302 | self.log.error("Failed to fetch parameter to get MAC", |
| 303 | parameter=parameter, network_name=network_name) |
Sapan Bhatia | 2f27dbe | 2017-11-27 21:17:32 -0500 | [diff] [blame] | 304 | self.defer_sync(o, "Waiting for parameters to become available") |
Woojoong Kim | 04d1216 | 2017-11-27 10:59:08 -0800 | [diff] [blame] | 305 | |
| 306 | return mac_address |
| 307 | |
Woojoong Kim | f002aec | 2017-10-25 14:43:37 -0700 | [diff] [blame] | 308 | # To get each network id |
| 309 | def get_network_id(self, network_name): |
| 310 | return Network.objects.get(name=network_name).id |