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_internal_network_and_subnet(self): internal_net = None internal_subnet = None try: nsxv_db.create_nsxv_internal_network( self.context.session, nsxv_constants.INTER_EDGE_PURPOSE, None) except db_exc.DBDuplicateEntry: # We may have a race condition, where another Neutron instance # initialized these elements. Use existing elements return self._get_internal_network() 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.update_nsxv_internal_network( self.context.session, nsxv_constants.INTER_EDGE_PURPOSE, internal_net) return internal_net, internal_subnet