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