cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [29/50] cloudstack-ec2stack git commit: Continue work on simulated ebs / instance store: undecided of approah
Date Tue, 05 May 2015 13:26:22 GMT
Continue work on simulated ebs / instance store: undecided of approah


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

Branch: refs/heads/master
Commit: 36ba44f670bbe8ba95ee8ded01841e458165b003
Parents: a4965ff
Author: BroganD1993 <darrenbrogan@hotmail.com>
Authored: Fri Aug 15 22:17:17 2014 +0100
Committer: BroganD1993 <darrenbrogan@hotmail.com>
Committed: Fri Aug 15 22:17:17 2014 +0100

----------------------------------------------------------------------
 ec2stack/configure.py                      |  2 +-
 ec2stack/providers/cloudstack/instances.py | 44 +++++++++++++++++++------
 ec2stack/providers/cloudstack/volumes.py   | 29 +++++++++++-----
 tests/volume_tests.py                      | 17 +++++++---
 4 files changed, 69 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/36ba44f6/ec2stack/configure.py
----------------------------------------------------------------------
diff --git a/ec2stack/configure.py b/ec2stack/configure.py
index 25e79d6..a80b70d 100644
--- a/ec2stack/configure.py
+++ b/ec2stack/configure.py
@@ -170,7 +170,7 @@ def _set_optional_attributes_of_profile(config, profile):
     """
 
     configure_instance_type_mapings = raw_input(
-        'Do you wish to input a local custom storage disk? (Yes/No): '
+        'Do you wish to input a local custom storage disk for instances? (Yes/No): '
     )
 
     if configure_instance_type_mapings.lower() in ['yes', 'y']:

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/36ba44f6/ec2stack/providers/cloudstack/instances.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/instances.py b/ec2stack/providers/cloudstack/instances.py
index 68c8c49..b391c51 100644
--- a/ec2stack/providers/cloudstack/instances.py
+++ b/ec2stack/providers/cloudstack/instances.py
@@ -8,7 +8,7 @@ instances.
 from flask import current_app
 
 from ec2stack.providers import cloudstack
-from ec2stack.providers.cloudstack import requester, service_offerings, zones
+from ec2stack.providers.cloudstack import requester, service_offerings, zones, disk_offerings
 from ec2stack import helpers, errors
 
 
@@ -122,7 +122,21 @@ def _run_instance_request():
 
     @return: Response.
     """
+
     args = {}
+    if helpers.contains_parameter('Placement.AvailabilityZone'):
+        zone_id = zones.get_zone(
+            helpers.get('Placement.AvailabilityZone')
+        )
+    else:
+        zone_id = zones.get_zone(
+            current_app.config['CLOUDSTACK_DEFAULT_ZONE']
+        )['id']
+
+    if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None:
+        args = _get_simulated_combination_instance_storage_args(zone_id)
+    else:
+        args['zoneid'] = zone_id
 
     if helpers.get('InstanceType') is None:
         instance_type = 'm1.small'
@@ -139,15 +153,6 @@ def _run_instance_request():
         service_offerings.get_service_offering(instance_type)['id']
     args['templateid'] = helpers.get('ImageId')
 
-    if helpers.contains_parameter('Placement.AvailabilityZone'):
-        args['zoneid'] = zones.get_zone(
-            helpers.get('Placement.AvailabilityZone')
-        )
-    else:
-        args['zoneid'] = zones.get_zone(
-            current_app.config['CLOUDSTACK_DEFAULT_ZONE']
-        )['id']
-
     if helpers.contains_parameter('KeyName'):
         args['keypair'] = helpers.get('KeyName')
 
@@ -178,6 +183,25 @@ def _run_instance_request():
 
     return response
 
+def _get_simulated_combination_instance_storage_args(zone_id):
+    args = {}
+    disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType')
+    if disk_type == 'gp2':
+        if 'CLOUDSTACK_LOCAL_CUSTOM_DISK_OFFERING' in current_app.config:
+            args['diskofferingid'] = disk_offerings.get_disk_offering(
+                current_app.config['CLOUDSTACK_LOCAL_CUSTOM_DISK_OFFERING']
+            )['id']
+        else:
+            errors.invalid_request(
+                str('CLOUDSTACK_LOCAL_CUSTOM_DISK_OFFERING') + " not found in "
+                "configuration, no able to configure gp2 disk, please run ec2stack-configure
and chose to configure "
+                "a local disk")
+
+    if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None:
+        errors.invalid_request("VolumeSize not found in BlockDeviceMapping")
+    else:
+        args['size'] = helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize')
+
 
 def _run_instance_response(response):
     """

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/36ba44f6/ec2stack/providers/cloudstack/volumes.py
----------------------------------------------------------------------
diff --git a/ec2stack/providers/cloudstack/volumes.py b/ec2stack/providers/cloudstack/volumes.py
index 8b0cb4e..c89ed26 100644
--- a/ec2stack/providers/cloudstack/volumes.py
+++ b/ec2stack/providers/cloudstack/volumes.py
@@ -92,26 +92,39 @@ def _create_volume_request():
     """
     args = {}
 
+    zone_name = helpers.get('AvailabilityZone')
+    zone_id = zones.get_zone(zone_name)['id']
+
+    args['zoneid'] = zone_id
+
     if helpers.contains_parameter('SnapshotId'):
         args['snapshotid'] = helpers.get('SnapshotId')
+        args['name'] = uuid.uuid1()
+        args['command'] = 'createVolume'
+        response = requester.make_request_async(args)
 
     else:
         helpers.require_parameters(['Size'])
-        args['size'] = helpers.get('Size')
-        args['diskofferingid'] = disk_offerings.get_disk_offering(
+        size = helpers.get('Size')
+        disk_id = disk_offerings.get_disk_offering(
             current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
         )['id']
+        response = create_cloudstack_volume_from_disk(disk_id, size, args)
 
-    zone_name = helpers.get('AvailabilityZone')
-    zone_id = zones.get_zone(zone_name)['id']
+    return response
 
-    args['zoneid'] = zone_id
+def create_cloudstack_volume_from_disk(disk_id, size, args):
+    """
+    Create a volume from disk offering.
+
+    @return: Response.
+    """
     args['command'] = 'createVolume'
+    args['diskofferingid'] = disk_id
     args['name'] = uuid.uuid1()
+    args['size'] = size
 
-    response = requester.make_request_async(args)
-
-    return response
+    return requester.make_request_async(args)
 
 
 def _create_volume_response(response):

http://git-wip-us.apache.org/repos/asf/cloudstack-ec2stack/blob/36ba44f6/tests/volume_tests.py
----------------------------------------------------------------------
diff --git a/tests/volume_tests.py b/tests/volume_tests.py
index 7d56402..ad593a2 100644
--- a/tests/volume_tests.py
+++ b/tests/volume_tests.py
@@ -240,11 +240,20 @@ class VolumeTestCase(Ec2StackAppTestCase):
         )
         get_request.return_value.status_code = 200
 
+        get_zone = mock.Mock()
+        get_zone.return_value = json.loads(read_file(
+            'tests/data/zones_search.json'
+        ))
+
         with mock.patch('requests.get', get_request):
-            response = self.post(
-                '/',
-                data=data
-            )
+            with mock.patch(
+                'ec2stack.providers.cloudstack.zones.get_zone',
+                get_zone
+            ):
+                response = self.post(
+                    '/',
+                    data=data
+                )
 
         self.assert_bad_request(response)
         assert 'InvalidDiskOffering.NotFound' in response.data


Mime
View raw message