示例#1
0
 def _create_ha_subnet(self, context, network_id, tenant_id):
     args = {'network_id': network_id,
             'tenant_id': '',
             'name': n_const.HA_SUBNET_NAME % tenant_id,
             'ip_version': 4,
             'cidr': cfg.CONF.l3_ha_net_cidr,
             'enable_dhcp': False,
             'gateway_ip': None}
     return p_utils.create_subnet(self._core_plugin, context,
                                  {'subnet': args})
示例#2
0
 def test_create_subnet(self):
     mock_plugin = mock.Mock()
     mock_plugin.create_subnet = lambda c, s: s
     mock_ctx = mock.Mock()
     mock_ctx.project_id = 'p1'
     net_id = uuidutils.generate_uuid()
     snet = utils.create_subnet(
         mock_plugin, mock_ctx,
         {'subnet': {'network_id': net_id, 'ip_version': 4}})
     self.assertEqual('p1', snet['subnet']['tenant_id'])
     self.assertEqual('p1', snet['subnet']['project_id'])
     self.assertEqual(4, snet['subnet']['ip_version'])
     self.assertEqual(net_id, snet['subnet']['network_id'])
示例#3
0
 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': False,
             '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 (n_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)
示例#4
0
文件: db.py 项目: cubeek/neutron
 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': False,
             '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 (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)