You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2015/05/05 15:26:00 UTC
[07/50] cloudstack-ec2stack git commit: Complete create/list/delete
vpc actions.
Complete create/list/delete vpc actions.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/commit/174c7981
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/tree/174c7981
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/diff/174c7981
Branch: refs/heads/master
Commit: 174c7981a552c0206794de862613eaca4521af73
Parents: 9515095
Author: BroganD1993 <da...@hotmail.com>
Authored: Thu Jul 17 19:54:26 2014 +0100
Committer: BroganD1993 <da...@hotmail.com>
Committed: Thu Jul 17 19:54:26 2014 +0100
----------------------------------------------------------------------
ec2stack/controllers/default.py | 2 ++
ec2stack/errors.py | 12 ++++++++++++
ec2stack/providers/cloudstack/vpcs.py | 16 ++++++++++------
ec2stack/templates/create_vpc.xml | 6 +++---
4 files changed, 27 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/174c7981/ec2stack/controllers/default.py
----------------------------------------------------------------------
diff --git a/ec2stack/controllers/default.py b/ec2stack/controllers/default.py
index 14503d8..d0b05bd 100644
--- a/ec2stack/controllers/default.py
+++ b/ec2stack/controllers/default.py
@@ -52,6 +52,7 @@ def _get_action(action):
'DeleteSecurityGroup': security_groups.delete_security_group,
'DeleteTags': tags.delete_tags,
'DeleteVolume': volumes.delete_volume,
+ 'DeleteVpc': vpcs.delete_vpc,
'DescribeAvailabilityZones': zones.describe_zones,
'DescribeImageAttribute': images.describe_image_attribute,
'DescribeImages': images.describe_images,
@@ -61,6 +62,7 @@ def _get_action(action):
'DescribeSecurityGroups': security_groups.describe_security_groups,
'DescribeTags': tags.describe_tags,
'DescribeVolumes': volumes.describe_volumes,
+ 'DescribeVpcs': vpcs.describe_vpcs,
'DetachVolume': volumes.detach_volume,
'GetPasswordData': passwords.get_password_data,
'ImportKeyPair': keypairs.import_keypair,
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/174c7981/ec2stack/errors.py
----------------------------------------------------------------------
diff --git a/ec2stack/errors.py b/ec2stack/errors.py
index e7841eb..ba170bf 100644
--- a/ec2stack/errors.py
+++ b/ec2stack/errors.py
@@ -174,6 +174,18 @@ def invalid_vpc_range():
'The specified CIDR block range is not valid.'
)
+def invalid_vpc_id():
+ """
+ VPC with this ID does not exist.
+
+ @raise Ec2stackError: Defining a bad request and message.
+ """
+ raise Ec2stackError(
+ '400',
+ 'InvalidVpcID.NotFound',
+ 'The specified VPC does not exist.'
+ )
+
def duplicate_security_group():
"""
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/174c7981/ec2stack/providers/cloudstack/vpcs.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/vpcs.py b/ec2stack/providers/cloudstack/vpcs.py
index 5f877e2..56b2e40 100644
--- a/ec2stack/providers/cloudstack/vpcs.py
+++ b/ec2stack/providers/cloudstack/vpcs.py
@@ -7,10 +7,12 @@
import uuid
+from flask import current_app
+
from ec2stack import errors
from ec2stack import helpers
from ec2stack.providers import cloudstack
-from ec2stack.providers.cloudstack import requester
+from ec2stack.providers.cloudstack import requester, zones
@helpers.authentication_required
@@ -35,11 +37,12 @@ def _create_vpc_request():
args['name'] = id
args['id'] = id
args['displaytext'] = id
+ args['zoneid'] = zones.get_zone(
+ current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id']
+ args['vpcofferingid'] = current_app.config['VPC_OFFERING_ID']
args['cidr'] = helpers.get('CidrBlock')
- response = requester.make_request(args)
-
- response = response['createvpcresponse']
+ response = requester.make_request_async(args)
return response
@@ -61,6 +64,7 @@ def _create_vpc_response(response):
'response': response
}
+
@helpers.authentication_required
def delete_vpc():
"""
@@ -81,7 +85,7 @@ def _delete_vpc_request():
"""
args = {'command': 'deleteVPC', 'id': helpers.get('VpcId')}
- response = requester.make_request(args)
+ response = requester.make_request_async(args)
return response
@@ -107,7 +111,7 @@ def describe_vpcs():
"""
args = {'command': 'listVPCs'}
response = cloudstack.describe_item(
- args, 'vpc', {}, 'vpcId'
+ args, 'vpc', errors.invalid_vpc_id, 'VpcId'
)
return _describe_vpc_response(
http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/174c7981/ec2stack/templates/create_vpc.xml
----------------------------------------------------------------------
diff --git a/ec2stack/templates/create_vpc.xml b/ec2stack/templates/create_vpc.xml
index a708e72..5c7c804 100644
--- a/ec2stack/templates/create_vpc.xml
+++ b/ec2stack/templates/create_vpc.xml
@@ -1,9 +1,9 @@
{% extends "response.xml" %}
{% block response_content %}
<vpc>
- <vpcId>{{ vpc.id }}</vpcId>
- <state>{{ vpc.state }}</state>
- <cidrBlock>{{ vpc.cidr }}</cidrBlock>
+ <vpcId>{{ response.id }}</vpcId>
+ <state>{{ response.state }}</state>
+ <cidrBlock>{{ response.cidr }}</cidrBlock>
<tagSet/>
</vpc>
{% endblock %}
\ No newline at end of file