cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [06/50] cloudstack-ec2stack git commit: Modify configuration, add 'advanced' network option
Date Tue, 05 May 2015 13:25:59 GMT
Modify configuration, add 'advanced' network option


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

Branch: refs/heads/master
Commit: 951509538ec13807dcd4d20c09a7df3207e2b49b
Parents: bd27404
Author: BroganD1993 <darrenbrogan@hotmail.com>
Authored: Wed Jul 16 21:47:03 2014 +0100
Committer: BroganD1993 <darrenbrogan@hotmail.com>
Committed: Wed Jul 16 21:47:03 2014 +0100

----------------------------------------------------------------------
 ec2stack/__init__.py                       |   1 +
 ec2stack/configure.py                      |  45 +++++++-
 ec2stack/controllers/default.py            |   3 +-
 ec2stack/providers/cloudstack/requester.py |  21 ++--
 ec2stack/providers/cloudstack/volumes.py   |   2 +-
 ec2stack/providers/cloudstack/vpc.py       | 129 -----------------------
 ec2stack/providers/cloudstack/vpcs.py      | 130 ++++++++++++++++++++++++
 ec2stack/templates/create_vpc.xml          |   2 +-
 ec2stack/templates/vpcs.xml                |   2 +-
 9 files changed, 188 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/__init__.py
----------------------------------------------------------------------
diff --git a/ec2stack/__init__.py b/ec2stack/__init__.py
index 91ca81d..1c75571 100644
--- a/ec2stack/__init__.py
+++ b/ec2stack/__init__.py
@@ -31,6 +31,7 @@ def create_app(settings=None):
         args = _generate_args()
         profile = args.pop('profile')
         app.config['DEBUG'] = args.pop('debug')
+        app.config['DEBUG'] = True
         config_file = _load_config_file()
         database_uri = _load_database()
         _config_from_config_profile(config_file, profile, app)

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/configure.py
----------------------------------------------------------------------
diff --git a/ec2stack/configure.py b/ec2stack/configure.py
index 93b4649..3fa337d 100644
--- a/ec2stack/configure.py
+++ b/ec2stack/configure.py
@@ -43,8 +43,9 @@ def _create_config_file(config_folder):
     """
     args = _generate_args()
     profile = args.pop('profile')
+    advanced_network_enabled = args.pop('advanced')
     config_file_path = config_folder + '/ec2stack.conf'
-    config = _modify_config_profile(config_file_path, profile)
+    config = _modify_config_profile(config_file_path, profile, advanced_network_enabled)
     config_file = open(config_file_path, 'w+')
     config.write(config_file)
 
@@ -67,12 +68,20 @@ def _generate_args():
         default='initial'
     )
 
+    parser.add_argument(
+        '-a',
+        '--advanced',
+        required=False,
+        help='Turn advanced network config on for application',
+        default=False
+    )
+
     args = parser.parse_args()
 
     return vars(args)
 
 
-def _modify_config_profile(config_file, profile):
+def _modify_config_profile(config_file, profile, advanced_network_enabled):
     """
     Modify configuration profile.
 
@@ -86,6 +95,23 @@ def _modify_config_profile(config_file, profile):
     if not config.has_section(profile):
         config.add_section(profile)
 
+    config = _set_mandatory_attributes_of_profile(config, profile)
+
+    if advanced_network_enabled:
+        config = _set_advanced_network_attributes_of_profile(config, profile)
+
+    config = _set_optional_attributes_of_profile(config, profile)
+
+    return config
+
+def _set_mandatory_attributes_of_profile(config, profile):
+    """
+    Modify mandatory attributes of profile.
+
+    @param config: current configparser configuration.
+    @param profile: the profile to set the attribute in.
+    @return: configparser configuration.
+    """
     config = _set_attribute_of_profile(
         config, profile, 'ec2stack_bind_address', 'EC2Stack bind address', 'localhost'
     )
@@ -115,7 +141,20 @@ def _modify_config_profile(config_file, profile):
         if config.get(profile, 'cloudstack_default_zone') is not '':
             break
 
-    config = _set_optional_attributes_of_profile(config, profile)
+    return config
+
+
+def _set_advanced_network_attributes_of_profile(config, profile):
+    """
+    Modify advanced network attributes of profile.
+
+    @param config: current configparser configuration.
+    @param profile: the profile to set the attribute in.
+    @return: configparser configuration.
+    """
+    config = _set_attribute_of_profile(
+        config, profile, 'vpc_offering_id', 'VPC offering id', ''
+    )
 
     return config
 

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/controllers/default.py
----------------------------------------------------------------------
diff --git a/ec2stack/controllers/default.py b/ec2stack/controllers/default.py
index 97293dd..14503d8 100644
--- a/ec2stack/controllers/default.py
+++ b/ec2stack/controllers/default.py
@@ -8,7 +8,7 @@ from ec2stack.helpers import get, error_response, \
 from ec2stack.core import Ec2stackError
 from ec2stack.services import USERS
 from ec2stack.providers.cloudstack import images, instances, keypairs, \
-    passwords, security_groups, zones, volumes, tags
+    passwords, security_groups, zones, volumes, tags, vpcs
 
 
 DEFAULT = Blueprint('default', __name__)
@@ -47,6 +47,7 @@ def _get_action(action):
         'CreateSecurityGroup': security_groups.create_security_group,
         'CreateTags': tags.create_tags,
         'CreateVolume': volumes.create_volume,
+        'CreateVpc': vpcs.create_vpc,
         'DeleteKeyPair': keypairs.delete_keypair,
         'DeleteSecurityGroup': security_groups.delete_security_group,
         'DeleteTags': tags.delete_tags,

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/providers/cloudstack/requester.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/requester.py b/ec2stack/providers/cloudstack/requester.py
index 147b958..401a617 100644
--- a/ec2stack/providers/cloudstack/requester.py
+++ b/ec2stack/providers/cloudstack/requester.py
@@ -34,20 +34,19 @@ def make_request(args):
 
     response = requests.get(request_url)
 
+    response_data = json.loads(
+        response.text,
+        object_hook=helpers.normalize_dict_keys
+    )
+    current_app.logger.debug(
+        'request url:' + str(request_url) +
+        'status code: ' + str(response.status_code) +
+        json.dumps(response_data, indent=4, separators=(',', ': '))
+    )
+
     if response.status_code in [401, 432]:
         abort(400)
     else:
-        response_data = json.loads(
-            response.text,
-            object_hook=helpers.normalize_dict_keys
-        )
-
-        current_app.logger.debug(
-            'request url:' + str(request_url) +
-            'status code: ' + str(response.status_code) +
-            json.dumps(response_data, indent=4, separators=(',', ': '))
-        )
-
         return response_data
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/providers/cloudstack/volumes.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/volumes.py b/ec2stack/providers/cloudstack/volumes.py
index ec594bb..8b0cb4e 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.uuid()
+    args['name'] = uuid.uuid1()
 
     response = requester.make_request_async(args)
 

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/providers/cloudstack/vpc.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/vpc.py b/ec2stack/providers/cloudstack/vpc.py
deleted file mode 100644
index 440b875..0000000
--- a/ec2stack/providers/cloudstack/vpc.py
+++ /dev/null
@@ -1,129 +0,0 @@
-
-#!/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
-    }
-

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/providers/cloudstack/vpcs.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/vpcs.py b/ec2stack/providers/cloudstack/vpcs.py
new file mode 100644
index 0000000..5f877e2
--- /dev/null
+++ b/ec2stack/providers/cloudstack/vpcs.py
@@ -0,0 +1,130 @@
+
+#!/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'}
+    id = uuid.uuid1()
+    args['name'] = id
+    args['id'] = id
+    args['displaytext'] = id
+    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
+    }
+

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/templates/create_vpc.xml
----------------------------------------------------------------------
diff --git a/ec2stack/templates/create_vpc.xml b/ec2stack/templates/create_vpc.xml
index 99f8624..a708e72 100644
--- a/ec2stack/templates/create_vpc.xml
+++ b/ec2stack/templates/create_vpc.xml
@@ -2,7 +2,7 @@
 {% block response_content %}
    <vpc>
       <vpcId>{{ vpc.id }}</vpcId>
-      <state>{{ vpc.state}}</state>
+      <state>{{ vpc.state }}</state>
       <cidrBlock>{{ vpc.cidr }}</cidrBlock>
       <tagSet/>
    </vpc>

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/95150953/ec2stack/templates/vpcs.xml
----------------------------------------------------------------------
diff --git a/ec2stack/templates/vpcs.xml b/ec2stack/templates/vpcs.xml
index 036e1bb..5eb9269 100644
--- a/ec2stack/templates/vpcs.xml
+++ b/ec2stack/templates/vpcs.xml
@@ -4,7 +4,7 @@
         {% for vpc in response.vpc %}
         <item>
             <vpcId>{{ vpc.id }}</vpcId>
-            <state>{{ vpc.state}}</state>
+            <state>{{ vpc.state }}</state>
             <cidrBlock>{{ vpc.cidr }}</cidrBlock>
             <tagSet/>
         </item>


Mime
View raw message