def _provision_external_connectivity( self, context, default_external_network, subnets, tenant_id): """Uplink tenant subnet(s) to external network.""" router_args = { 'name': 'auto_allocated_router', l3.EXTERNAL_GW_INFO: default_external_network, 'tenant_id': tenant_id, 'admin_state_up': True } router = None try: router = self.l3_plugin.create_router( context, {'router': router_args}) attached_subnets = [] for subnet in subnets: self.l3_plugin.add_router_interface( context, router['id'], {'subnet_id': subnet['id']}) attached_subnets.append(subnet) return router except n_exc.BadRequest: LOG.error(_LE("Unable to auto allocate topology for tenant " "%s because of router errors."), tenant_id) if router: self._cleanup(context, network_id=subnets[0]['network_id'], router_id=router['id'], subnets=attached_subnets) raise exceptions.AutoAllocationFailure( reason=_("Unable to provide external connectivity"))
def _get_default_external_network(self, context): """Get the default external network for the deployment. CCloud specific: the default external network depends on current domain scope """ external_networks = net_obj.ExternalNetwork.get_objects(context) if not external_networks: raise exceptions.AutoAllocationFailure( reason=_("Unable to find any external network " "for project, please run the project wizard" "in the dashboard first")) if len(external_networks) > 1: default_external_networks = [ net for net in external_networks if net.get('is_default') ] if not default_external_networks: LOG.warning( "Multiple external networks for project %s" " found, choosing (default) network %s", context.tenant_name, external_networks[0].network_id) default_external_networks = external_networks return default_external_networks[0].network_id
def _provision_tenant_private_network(self, context, tenant_id): """Create a tenant private network/subnets.""" network = None try: network_args = { 'name': 'auto_allocated_network', 'admin_state_up': True, 'tenant_id': tenant_id, 'shared': False } network = p_utils.create_network( self.core_plugin, context, {'network': network_args}) subnets = [] for pool in self._get_supported_subnetpools(context): subnet_args = { 'name': 'auto_allocated_subnet_v%s' % pool['ip_version'], 'network_id': network['id'], 'tenant_id': tenant_id, 'ip_version': pool['ip_version'], 'subnetpool_id': pool['id'], } subnets.append(p_utils.create_subnet( self.core_plugin, context, {'subnet': subnet_args})) return subnets except (ValueError, n_exc.BadRequest, n_exc.NotFound): LOG.error(_LE("Unable to auto allocate topology for tenant " "%s due to missing requirements, e.g. default " "or shared subnetpools"), tenant_id) if network: self._cleanup(context, network['id']) raise exceptions.AutoAllocationFailure( reason=_("Unable to provide tenant private network"))
def _check_requirements(self, context, tenant_id): """Raise if requirements are not met.""" self._get_default_external_network(context) try: self._get_supported_subnetpools(context) except n_exc.NotFound: raise exceptions.AutoAllocationFailure( reason=_("No default subnetpools defined")) return {'id': 'dry-run=pass', 'tenant_id': tenant_id}
def _get_default_external_network(self, context): """Get the default external network for the deployment.""" default_external_networks = net_obj.ExternalNetwork.get_objects( context, is_default=True) if not default_external_networks: LOG.error(_LE("Unable to find default external network " "for deployment, please create/assign one to " "allow auto-allocation to work correctly.")) raise exceptions.AutoAllocationFailure( reason=_("No default router:external network")) if len(default_external_networks) > 1: LOG.error(_LE("Multiple external default networks detected. " "Network %s is true 'default'."), default_external_networks[0]['network_id']) return default_external_networks[0].network_id
def _provision_tenant_private_network(self, context, tenant_id): """Create a tenant private network/subnets. CCloud specific: use specific cidr range instead of default subnetpool """ network = None try: network_args = { 'name': 'auto_allocated_network', 'admin_state_up': False, 'tenant_id': tenant_id, 'shared': False } network = p_utils.create_network(self.core_plugin, context, {'network': network_args}) subnets = [] subnet_args = { 'name': 'auto_allocated_subnet_v4', 'network_id': network['id'], 'tenant_id': tenant_id, 'ip_version': 4, 'cidr': '10.180.0.0/24', } subnets.append( p_utils.create_subnet(self.core_plugin, context, {'subnet': subnet_args})) return subnets except (c_exc.SubnetAllocationError, ValueError, n_exc.BadRequest, n_exc.NotFound) as e: LOG.error( "Unable to auto allocate topology for tenant " "%(tenant_id)s due to missing or unmet " "requirements. Reason: %(reason)s", { 'tenant_id': tenant_id, 'reason': e }) if network: self._cleanup(context, network['id']) raise exceptions.AutoAllocationFailure( reason=_("Unable to provide tenant private network")) except Exception as e: network_id = network['id'] if network else None raise exceptions.UnknownProvisioningError(e, network_id=network_id)
def _provision_external_connectivity(self, context, default_external_network, subnets, tenant_id): """Uplink tenant subnet(s) to external network.""" router_args = { 'name': 'auto_allocated_router', l3_apidef.EXTERNAL_GW_INFO: { 'network_id': default_external_network }, 'tenant_id': tenant_id, 'admin_state_up': True } router = None attached_subnets = [] try: router = self.l3_plugin.create_router(context, {'router': router_args}) for subnet in subnets: self.l3_plugin.add_router_interface( context, router['id'], {'subnet_id': subnet['id']}) attached_subnets.append(subnet) return router except n_exc.BadRequest as e: LOG.error( "Unable to auto allocate topology for tenant " "%(tenant_id)s because of router errors. " "Reason: %(reason)s", { 'tenant_id': tenant_id, 'reason': e }) router_id = router['id'] if router else None self._cleanup(context, network_id=subnets[0]['network_id'], router_id=router_id, subnets=attached_subnets) raise exceptions.AutoAllocationFailure( reason=_("Unable to provide external connectivity")) except Exception as e: router_id = router['id'] if router else None raise exceptions.UnknownProvisioningError( e, network_id=subnets[0]['network_id'], router_id=router_id, subnets=subnets)
def _get_default_external_network(self, context): """Get the default external network for the deployment.""" with context.session.begin(subtransactions=True): default_external_networks = (context.session.query( external_net_db.ExternalNetwork). filter_by(is_default=sql.true()). join(models_v2.Network). join(model_base.StandardAttribute). order_by(model_base.StandardAttribute.id).all()) if not default_external_networks: LOG.error(_LE("Unable to find default external network " "for deployment, please create/assign one to " "allow auto-allocation to work correctly.")) raise exceptions.AutoAllocationFailure( reason=_("No default router:external network")) if len(default_external_networks) > 1: LOG.error(_LE("Multiple external default networks detected. " "Network %s is true 'default'."), default_external_networks[0]['network_id']) return default_external_networks[0]