def _get_internal_net_wait_for_creation(self): ctr = 0 net_id = None while net_id is None and ctr < NET_WAIT_INTERVAL: # Another neutron instance may be in the process of creating this # network. If so, we will have a network with a NULL network id. # Therefore, if we have a network entry, we wail for its ID to show # up in the DB entry. If no entry exists, we exit and create the # network. net_list = nsxv_db.get_nsxv_internal_network( self.context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) if net_list: net_id = net_list[0]['network_id'] # Network found - do we have an ID? if net_id: return net_id else: # No network creation in progress - exit. return self.context.session.expire_all() ctr += NET_CHECK_INTERVAL time.sleep(NET_CHECK_INTERVAL) error = _('Network creation on other neutron instance timed out') raise nsxv_exc.NsxPluginException(err_msg=error)
def _get_internal_network_and_subnet(self): internal_net = None internal_subnet = None # Try to find internal net, internal subnet. If not found, create new net_list = nsxv_db.get_nsxv_internal_network( self.context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) if net_list: internal_net = net_list[0]['network_id'] if internal_net: internal_subnet = self.nsxv_plugin.get_subnets( self.context, fields=['id'], filters={'network_id': [internal_net]})[0]['id'] if internal_net is None or internal_subnet is None: if cfg.CONF.nsxv.metadata_initializer: # Couldn't find net, subnet - create new try: internal_net, internal_subnet = ( self._create_metadata_internal_network( INTERNAL_SUBNET)) except Exception as e: nsxv_db.delete_nsxv_internal_network( self.context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) # if network is created, clean up if internal_net: self.nsxv_plugin.delete_network(self.context, internal_net) LOG.exception(_LE("Exception %s while creating internal " "network for metadata service"), e) return # Update the new network_id in DB nsxv_db.create_nsxv_internal_network( self.context.session, nsxv_constants.INTER_EDGE_PURPOSE, internal_net) else: error = _('Metadata initialization is incomplete on ' 'initializer node') raise nsxv_exc.NsxPluginException(err_msg=error) return internal_net, internal_subnet
def _get_internal_network_and_subnet(self): internal_net = None internal_subnet = None # Try to find internal net, internal subnet. If not found, create new net_list = nsxv_db.get_nsxv_internal_network( self.context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) if net_list: internal_net = net_list[0]['network_id'] if internal_net: internal_subnet = self.nsxv_plugin.get_subnets( self.context, fields=['id'], filters={'network_id': [internal_net]})[0]['id'] if internal_net is None or internal_subnet is None: # Couldn't find net, subnet - create new try: internal_net, internal_subnet = ( self._create_metadata_internal_network(INTERNAL_SUBNET)) except Exception as e: with excutils.save_and_reraise_exception(): nsxv_db.delete_nsxv_internal_network( self.context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) # if network is created, clean up if internal_net: self.nsxv_plugin.delete_network(self.context, internal_net) LOG.exception(_LE("Exception %s while creating internal " "network for metadata service"), e) # Update the new network_id in DB nsxv_db.create_nsxv_internal_network( self.context.session, nsxv_constants.INTER_EDGE_PURPOSE, internal_net) return internal_net, internal_subnet
def _get_optional_and_conflict_router_ids_by_gw(self, context, router_id): """Collect conflict routers and optional routers based on GW port. Collect conflict router if it has different external network, else, collect optional router if it is not distributed and exclusive Returns: optional_router_ids: routers we can use its edge for the shared router. conflict_router_ids: conflict routers which has different gateway """ ext_net_id = self._get_external_network_id_by_router(context, router_id) routers = context.session.query(l3_db.Router).all() optional_router_ids = [] conflict_router_ids = [] if ext_net_id: ports_qry = context.session.query(models_v2.Port) all_gw_ports = ports_qry.filter_by( device_owner=l3_db.DEVICE_OWNER_ROUTER_GW).all() metadata_nets = nsxv_db.get_nsxv_internal_network( context.session, vcns_const.InternalEdgePurposes.INTER_EDGE_PURPOSE) metadata_net_ids = [metadata_net['network_id'] for metadata_net in metadata_nets] # filter out metadata gw_ports all_gw_ports = [gw_port for gw_port in all_gw_ports if gw_port['network_id'] not in metadata_net_ids] for gw_port in all_gw_ports: if gw_port and gw_port['network_id'] != ext_net_id: conflict_router_ids.append(gw_port['device_id']) for router in routers: router_res = {} self.plugin._extend_nsx_router_dict(router_res, router) if (router['id'] not in conflict_router_ids and router_res.get('router_type') == 'shared'): optional_router_ids.append(router['id']) return optional_router_ids, conflict_router_ids