cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [04/50] cloudstack-ec2stack git commit: Begin addition of VPC support
Date Tue, 05 May 2015 13:25:57 GMT
Begin addition of VPC support


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/commit/2260ea07
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/tree/2260ea07
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/diff/2260ea07

Branch: refs/heads/master
Commit: 2260ea07afc5d5c3cacff7c749b47aa2f8b603f0
Parents: 252e43e
Author: BroganD1993 <darrenbrogan@hotmail.com>
Authored: Tue Jul 15 19:43:55 2014 +0100
Committer: BroganD1993 <darrenbrogan@hotmail.com>
Committed: Tue Jul 15 19:43:55 2014 +0100

----------------------------------------------------------------------
 ec2stack/errors.py                        |  12 +++
 ec2stack/providers/cloudstack/keypairs.py |   4 +-
 ec2stack/providers/cloudstack/volumes.py  |   2 +-
 ec2stack/providers/cloudstack/vpc.py      | 129 +++++++++++++++++++++++++
 4 files changed, 144 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/2260ea07/ec2stack/errors.py
----------------------------------------------------------------------
diff --git a/ec2stack/errors.py b/ec2stack/errors.py
index bf5040a..e7841eb 100644
--- a/ec2stack/errors.py
+++ b/ec2stack/errors.py
@@ -162,6 +162,18 @@ def invalid_resource_id():
         'The specified ID for the resource you are trying to tag is not valid.'
     )
 
+def invalid_vpc_range():
+    """
+    Invalid cidr block.
+
+    @raise Ec2stackError: Defining a bad request and message.
+    """
+    raise Ec2stackError(
+        '400',
+        'InvalidVpcRange',
+        'The specified CIDR block range is not valid.'
+    )
+
 
 def duplicate_security_group():
     """

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/2260ea07/ec2stack/providers/cloudstack/keypairs.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/keypairs.py b/ec2stack/providers/cloudstack/keypairs.py
index d552b60..2a9ff7e 100644
--- a/ec2stack/providers/cloudstack/keypairs.py
+++ b/ec2stack/providers/cloudstack/keypairs.py
@@ -6,10 +6,10 @@
 
 from base64 import b64decode
 
-from ec2stack.providers import cloudstack
+from ec2stack import errors
 from ec2stack import helpers
+from ec2stack.providers import cloudstack
 from ec2stack.providers.cloudstack import requester
-from ec2stack import errors
 
 
 @helpers.authentication_required

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/2260ea07/ec2stack/providers/cloudstack/volumes.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/volumes.py b/ec2stack/providers/cloudstack/volumes.py
index 4f823f0..ec594bb 100644
--- a/ec2stack/providers/cloudstack/volumes.py
+++ b/ec2stack/providers/cloudstack/volumes.py
@@ -107,7 +107,7 @@ def _create_volume_request():
 
     args['zoneid'] = zone_id
     args['command'] = 'createVolume'
-    args['name'] = uuid.uuid4()
+    args['name'] = uuid.uuid()
 
     response = requester.make_request_async(args)
 

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/2260ea07/ec2stack/providers/cloudstack/vpc.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/vpc.py b/ec2stack/providers/cloudstack/vpc.py
new file mode 100644
index 0000000..440b875
--- /dev/null
+++ b/ec2stack/providers/cloudstack/vpc.py
@@ -0,0 +1,129 @@
+
+#!/usr/bin/env python
+# encoding: utf-8
+
+"""This module contains functions for handling requests in relation to vpcs.
+"""
+
+import uuid
+
+from ec2stack import errors
+from ec2stack import helpers
+from ec2stack.providers import cloudstack
+from ec2stack.providers.cloudstack import requester
+
+
+@helpers.authentication_required
+def create_vpc():
+    """
+    Create a vpc.
+
+    @return: Response.
+    """
+    response = _create_vpc_request()
+    return _create_vpc_response(response)
+
+
+def _create_vpc_request():
+    """
+    Request to create a vpc.
+
+    @return: Response.
+    """
+    args = {'command': 'createVPC'}
+    name = uuid.uuid()
+    args['name'] = name
+    args['id'] = name
+    args['cidr'] = helpers.get('CidrBlock')
+
+    response = requester.make_request(args)
+
+    response = response['createvpcresponse']
+
+    return response
+
+
+def _create_vpc_response(response):
+    """
+    Generates a response for create vpc request.
+
+    @param response: Response from Cloudstack.
+    @return: Response.
+    """
+    if 'errortext' in response:
+        errors.invalid_vpc_range()
+    else:
+        response = response['vpc']
+        return {
+            'template_name_or_list': 'create_vpc.xml',
+            'response_type': 'CreateVpcResponse',
+            'response': response
+        }
+
+@helpers.authentication_required
+def delete_vpc():
+    """
+    Delete a vpc.
+
+    @return: Response.
+    """
+    helpers.require_parameters(['VpcId'])
+    _delete_vpc_request()
+    return _delete_vpc_response()
+
+
+def _delete_vpc_request():
+    """
+    Request to delete a vpc.
+
+    @return: Response.
+    """
+    args = {'command': 'deleteVPC', 'id': helpers.get('VpcId')}
+
+    response = requester.make_request(args)
+
+    return response
+
+
+def _delete_vpc_response():
+    """
+    Generates a response for delete vpc request.
+
+    @return: Response.
+    """
+    return {
+        'template_name_or_list': 'status.xml',
+        'response_type': 'DeleteVpcResponse',
+        'return': 'true'
+    }
+
+@helpers.authentication_required
+def describe_vpcs():
+    """
+    Describes a specific vpc or all vpcs.
+
+    @return: Response.
+    """
+    args = {'command': 'listVPCs'}
+    response = cloudstack.describe_item(
+        args, 'vpc', {}, 'vpcId'
+    )
+
+    return _describe_vpc_response(
+        response
+    )
+
+
+def _describe_vpc_response(response):
+    """
+    Generates a response for describe vpc request.
+
+    @param response: Response from Cloudstack.
+    @return: Response.
+    """
+    return {
+        'template_name_or_list': 'vpcs.xml',
+        'response_type': 'DescribeVpcsResponse',
+        'response': response
+    }
+


Mime
View raw message