Handle and log OS errors for vpc
Change-Id: Ib936187500e91219dfe7acd8b1a6d3c2ff513ce5
This commit is contained in:
@@ -79,6 +79,8 @@ def create_security_group(context, group_name, group_description,
|
|||||||
|
|
||||||
|
|
||||||
def _create_default_security_group(context, vpc):
|
def _create_default_security_group(context, vpc):
|
||||||
|
# NOTE(Alex): OpenStack doesn't allow creation of another group
|
||||||
|
# named 'default' hence 'Default' is used.
|
||||||
return create_security_group(context, 'Default',
|
return create_security_group(context, 'Default',
|
||||||
'Default VPC security group', vpc['id'])
|
'Default VPC security group', vpc['id'])
|
||||||
|
|
||||||
|
@@ -35,6 +35,8 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
"""VPC-object related API implementation
|
"""VPC-object related API implementation
|
||||||
"""
|
"""
|
||||||
|
# TODO(ft): implement DescribeVpcAttribute, ModifyVpcAttribute API methods
|
||||||
|
# TODO(ft): implement 'instanceTenancy' VPC property
|
||||||
|
|
||||||
|
|
||||||
Validator = common.Validator
|
Validator = common.Validator
|
||||||
@@ -42,12 +44,12 @@ Validator = common.Validator
|
|||||||
|
|
||||||
def create_vpc(context, cidr_block, instance_tenancy='default'):
|
def create_vpc(context, cidr_block, instance_tenancy='default'):
|
||||||
neutron = clients.neutron(context)
|
neutron = clients.neutron(context)
|
||||||
# TODO(Alex): Handle errors like overlimit
|
|
||||||
# TODO(ft) dhcp_options_id
|
|
||||||
# TODO(ft): refactor to prevent update created objects
|
|
||||||
with common.OnCrashCleaner() as cleaner:
|
with common.OnCrashCleaner() as cleaner:
|
||||||
os_router_body = {'router': {}}
|
os_router_body = {'router': {}}
|
||||||
|
try:
|
||||||
os_router = neutron.create_router(os_router_body)['router']
|
os_router = neutron.create_router(os_router_body)['router']
|
||||||
|
except neutron_exception.OverQuotaClient:
|
||||||
|
raise exception.VpcLimitExceeded()
|
||||||
cleaner.addCleanup(neutron.delete_router, os_router['id'])
|
cleaner.addCleanup(neutron.delete_router, os_router['id'])
|
||||||
vpc = db_api.add_item(context, 'vpc',
|
vpc = db_api.add_item(context, 'vpc',
|
||||||
{'os_id': os_router['id'],
|
{'os_id': os_router['id'],
|
||||||
@@ -59,22 +61,21 @@ def create_vpc(context, cidr_block, instance_tenancy='default'):
|
|||||||
vpc['route_table_id'] = route_table['id']
|
vpc['route_table_id'] = route_table['id']
|
||||||
db_api.update_item(context, vpc)
|
db_api.update_item(context, vpc)
|
||||||
neutron.update_router(os_router['id'], {'router': {'name': vpc['id']}})
|
neutron.update_router(os_router['id'], {'router': {'name': vpc['id']}})
|
||||||
# NOTE(Alex): OpenStack doesn't allow creation of another group
|
security_group_api._create_default_security_group(context, vpc)
|
||||||
# named 'default' hence 'Default' is used.
|
|
||||||
security_group = security_group_api._create_default_security_group(
|
|
||||||
context, vpc)
|
|
||||||
return {'vpc': _format_vpc(vpc)}
|
return {'vpc': _format_vpc(vpc)}
|
||||||
|
|
||||||
|
|
||||||
def delete_vpc(context, vpc_id):
|
def delete_vpc(context, vpc_id):
|
||||||
vpc = ec2utils.get_db_item(context, 'vpc', vpc_id)
|
vpc = ec2utils.get_db_item(context, 'vpc', vpc_id)
|
||||||
subnets = subnet_api.describe_subnets(context,
|
subnets = subnet_api.describe_subnets(
|
||||||
|
context,
|
||||||
filter=[{'name': 'vpc-id', 'value': [vpc_id]}])['subnetSet']
|
filter=[{'name': 'vpc-id', 'value': [vpc_id]}])['subnetSet']
|
||||||
internet_gateways = internet_gateway_api.describe_internet_gateways(
|
internet_gateways = internet_gateway_api.describe_internet_gateways(
|
||||||
context,
|
context,
|
||||||
filter=[{'name': 'attachment.vpc-id',
|
filter=[{'name': 'attachment.vpc-id',
|
||||||
'value': [vpc['id']]}])['internetGatewaySet']
|
'value': [vpc['id']]}])['internetGatewaySet']
|
||||||
route_tables = route_table_api.describe_route_tables(context,
|
route_tables = route_table_api.describe_route_tables(
|
||||||
|
context,
|
||||||
filter=[{'name': 'vpc-id', 'value': [vpc['id']]}])['routeTableSet']
|
filter=[{'name': 'vpc-id', 'value': [vpc['id']]}])['routeTableSet']
|
||||||
if subnets or internet_gateways or len(route_tables) > 1:
|
if subnets or internet_gateways or len(route_tables) > 1:
|
||||||
msg = _("The vpc '%(vpc_id)s' has dependencies and "
|
msg = _("The vpc '%(vpc_id)s' has dependencies and "
|
||||||
@@ -97,11 +98,13 @@ def delete_vpc(context, vpc_id):
|
|||||||
context, group_id=security_group['groupId'])
|
context, group_id=security_group['groupId'])
|
||||||
try:
|
try:
|
||||||
neutron.delete_router(vpc['os_id'])
|
neutron.delete_router(vpc['os_id'])
|
||||||
except neutron_exception.NeutronClientException as ex:
|
except neutron_exception.Conflict as ex:
|
||||||
# TODO(ft): do log error
|
LOG.warning(_('Failed to delete router %(os_id)s during deleting '
|
||||||
# TODO(ft): adjust catched exception classes to catch:
|
'VPC %(id)s. Reason: %(reason)s'),
|
||||||
# the router doesn't exist
|
{'id': vpc['id'],
|
||||||
# somewhat plugged to the router
|
'os_id': vpc['os_id'],
|
||||||
|
'reason': ex.message})
|
||||||
|
except neutron_exception.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@@ -341,6 +341,10 @@ class RouteAlreadyExists(Invalid):
|
|||||||
'already exists.')
|
'already exists.')
|
||||||
|
|
||||||
|
|
||||||
|
class VpcLimitExceeded(Overlimit):
|
||||||
|
msg_fmt = _("The maximum number of VPCs has been reached.")
|
||||||
|
|
||||||
|
|
||||||
class NetworkInterfaceLimitExceeded(Overlimit):
|
class NetworkInterfaceLimitExceeded(Overlimit):
|
||||||
msg_fmt = _('You have reached the limit of network interfaces for subnet'
|
msg_fmt = _('You have reached the limit of network interfaces for subnet'
|
||||||
'%(subnet_id)s.')
|
'%(subnet_id)s.')
|
||||||
|
@@ -88,9 +88,9 @@ class VpcTestCase(base.ApiTestCase):
|
|||||||
resp = self.execute('CreateVpc', {'CidrBlock': '10.0.0.0/8'})
|
resp = self.execute('CreateVpc', {'CidrBlock': '10.0.0.0/8'})
|
||||||
check_response(resp, 'InvalidVpc.Range')
|
check_response(resp, 'InvalidVpc.Range')
|
||||||
|
|
||||||
@base.skip_not_implemented
|
|
||||||
def test_create_vpc_overlimit(self):
|
def test_create_vpc_overlimit(self):
|
||||||
self.neutron.create_router.side_effect = neutron_exception.Conflict
|
self.neutron.create_router.side_effect = (
|
||||||
|
neutron_exception.OverQuotaClient)
|
||||||
self.db_api.add_item.side_effect = fakes.get_db_api_add_item(
|
self.db_api.add_item.side_effect = fakes.get_db_api_add_item(
|
||||||
fakes.ID_EC2_VPC_1)
|
fakes.ID_EC2_VPC_1)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user