Skip to content

Commit 174c798

Browse files
committed
Complete create/list/delete vpc actions.
1 parent 9515095 commit 174c798

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

ec2stack/controllers/default.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _get_action(action):
5252
'DeleteSecurityGroup': security_groups.delete_security_group,
5353
'DeleteTags': tags.delete_tags,
5454
'DeleteVolume': volumes.delete_volume,
55+
'DeleteVpc': vpcs.delete_vpc,
5556
'DescribeAvailabilityZones': zones.describe_zones,
5657
'DescribeImageAttribute': images.describe_image_attribute,
5758
'DescribeImages': images.describe_images,
@@ -61,6 +62,7 @@ def _get_action(action):
6162
'DescribeSecurityGroups': security_groups.describe_security_groups,
6263
'DescribeTags': tags.describe_tags,
6364
'DescribeVolumes': volumes.describe_volumes,
65+
'DescribeVpcs': vpcs.describe_vpcs,
6466
'DetachVolume': volumes.detach_volume,
6567
'GetPasswordData': passwords.get_password_data,
6668
'ImportKeyPair': keypairs.import_keypair,

ec2stack/errors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ def invalid_vpc_range():
174174
'The specified CIDR block range is not valid.'
175175
)
176176

177+
def invalid_vpc_id():
178+
"""
179+
VPC with this ID does not exist.
180+
181+
@raise Ec2stackError: Defining a bad request and message.
182+
"""
183+
raise Ec2stackError(
184+
'400',
185+
'InvalidVpcID.NotFound',
186+
'The specified VPC does not exist.'
187+
)
188+
177189

178190
def duplicate_security_group():
179191
"""

ec2stack/providers/cloudstack/vpcs.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
import uuid
99

10+
from flask import current_app
11+
1012
from ec2stack import errors
1113
from ec2stack import helpers
1214
from ec2stack.providers import cloudstack
13-
from ec2stack.providers.cloudstack import requester
15+
from ec2stack.providers.cloudstack import requester, zones
1416

1517

1618
@helpers.authentication_required
@@ -35,11 +37,12 @@ def _create_vpc_request():
3537
args['name'] = id
3638
args['id'] = id
3739
args['displaytext'] = id
40+
args['zoneid'] = zones.get_zone(
41+
current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id']
42+
args['vpcofferingid'] = current_app.config['VPC_OFFERING_ID']
3843
args['cidr'] = helpers.get('CidrBlock')
3944

40-
response = requester.make_request(args)
41-
42-
response = response['createvpcresponse']
45+
response = requester.make_request_async(args)
4346

4447
return response
4548

@@ -61,6 +64,7 @@ def _create_vpc_response(response):
6164
'response': response
6265
}
6366

67+
6468
@helpers.authentication_required
6569
def delete_vpc():
6670
"""
@@ -81,7 +85,7 @@ def _delete_vpc_request():
8185
"""
8286
args = {'command': 'deleteVPC', 'id': helpers.get('VpcId')}
8387

84-
response = requester.make_request(args)
88+
response = requester.make_request_async(args)
8589

8690
return response
8791

@@ -107,7 +111,7 @@ def describe_vpcs():
107111
"""
108112
args = {'command': 'listVPCs'}
109113
response = cloudstack.describe_item(
110-
args, 'vpc', {}, 'vpcId'
114+
args, 'vpc', errors.invalid_vpc_id, 'VpcId'
111115
)
112116

113117
return _describe_vpc_response(

ec2stack/templates/create_vpc.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{% extends "response.xml" %}
22
{% block response_content %}
33
<vpc>
4-
<vpcId>{{ vpc.id }}</vpcId>
5-
<state>{{ vpc.state }}</state>
6-
<cidrBlock>{{ vpc.cidr }}</cidrBlock>
4+
<vpcId>{{ response.id }}</vpcId>
5+
<state>{{ response.state }}</state>
6+
<cidrBlock>{{ response.cidr }}</cidrBlock>
77
<tagSet/>
88
</vpc>
99
{% endblock %}

0 commit comments

Comments
 (0)