You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2017/04/21 05:42:52 UTC

[05/16] libcloud git commit: Added support for EC2 Modify Volume API method; fixed volume's extra attribute name

Added support for EC2 Modify Volume API method; fixed volume's extra attribute name


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/27fef81c
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/27fef81c
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/27fef81c

Branch: refs/heads/trunk
Commit: 27fef81c90d09ac0edf0785ffb6105745af0130f
Parents: f2edb15
Author: Hennadii Stas <ut...@gmail.com>
Authored: Tue Mar 28 18:14:55 2017 +0300
Committer: Hennadii Stas <ut...@gmail.com>
Committed: Thu Apr 20 13:03:09 2017 +0300

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py | 133 +++++++++++++++++++++++++++++++++--
 1 file changed, 129 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/27fef81c/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 12e1e1c..f7de3f4 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -79,7 +79,7 @@ __all__ = [
     'IdempotentParamError'
 ]
 
-API_VERSION = '2013-10-15'
+API_VERSION = '2016-11-15'
 NAMESPACE = 'http://ec2.amazonaws.com/doc/%s/' % (API_VERSION)
 
 # Eucalyptus Constants
@@ -2431,7 +2431,7 @@ RESOURCE_EXTRA_ATTRIBUTES_MAP = {
             'xpath': 'attachmentSet/item/deleteOnTermination',
             'transform_func': str
         },
-        'type': {
+        'volume_type': {
             'xpath': 'volumeType',
             'transform_func': str
         }
@@ -2444,8 +2444,60 @@ RESOURCE_EXTRA_ATTRIBUTES_MAP = {
     }
 }
 
+VOLUME_MODIFICATION_ATTRIBUTE_MAP = {
+    'end_time': {
+        'xpath': 'endTime',
+        'transform_func': parse_date
+    },
+    'modification_state': {
+        'xpath': 'modificationState',
+        'transform_func': str
+    },
+    'original_iops': {
+        'xpath': 'originalIops',
+        'transform_func': str
+    },
+    'original_size': {
+        'xpath': 'originalSize',
+        'transform_func': str
+    },
+    'original_volume_type': {
+        'xpath': 'originalVolumeType',
+        'transform_func': str
+    },
+    'progress': {
+        'xpath': 'progress',
+        'transform_func': str
+    },
+    'start_time': {
+        'xpath': 'startTime',
+        'transform_func': parse_date
+    },
+    'status_message': {
+        'xpath': 'statusMessage',
+        'transform_func': str
+    },
+    'target_iops': {
+        'xpath': 'targetIops',
+        'transform_func': str
+    },
+    'target_size': {
+        'xpath': 'targetSize',
+        'transform_func': str
+    },
+    'target_volume_type': {
+        'xpath': 'targetVolumeType',
+        'transform_func': str
+    },
+    'volume_id': {
+        'xpath': 'volumeId',
+        'transform_func': str
+    }
+}
+
 VALID_EC2_REGIONS = REGION_DETAILS.keys()
 VALID_EC2_REGIONS = [r for r in VALID_EC2_REGIONS if r != 'nimbus']
+VALID_VOLUME_TYPES = ['standard', 'io1', 'gp2', 'st1', 'sc1']
 
 
 class EC2NodeLocation(NodeLocation):
@@ -2815,6 +2867,41 @@ class EC2SubnetAssociation(object):
         return (('<EC2SubnetAssociation: id=%s>') % (self.id))
 
 
+class EC2VolumeModification(object):
+    """
+    Describes the modification status of an EBS volume.
+
+    If the volume has never been modified, some element values will be null.
+    """
+
+    def __init__(self,
+            end_time=None,
+            modification_state=None,
+            original_iops=None,
+            original_size=None,
+            original_volume_type=None,
+            progress=None,
+            start_time=None,
+            status_message=None,
+            target_iops=None,
+            target_size=None,
+            target_volume_type=None,
+            volume_id=None,
+            ):
+        self.end_time = end_time
+        self.modification_state = modification_state
+        self.original_iops = original_iops
+        self.original_size = original_size
+        self.original_volume_type = original_volume_type
+        self.progress = progress
+        self.start_time = start_time
+        self.status_message = status_message
+        self.target_iops = target_iops
+        self.target_size = target_size
+        self.target_volume_type = target_volume_type
+        self.volume_id = volume_id
+
+
 class BaseEC2NodeDriver(NodeDriver):
     """
     Base Amazon EC2 node driver.
@@ -3275,13 +3362,12 @@ class BaseEC2NodeDriver(NodeDriver):
         :return: The newly created volume.
         :rtype: :class:`StorageVolume`
         """
-        valid_volume_types = ['standard', 'io1', 'gp2', 'st1', 'sc1']
 
         params = {
             'Action': 'CreateVolume',
             'Size': str(size)}
 
-        if ex_volume_type and ex_volume_type not in valid_volume_types:
+        if ex_volume_type and ex_volume_type not in VALID_VOLUME_TYPES:
             raise ValueError('Invalid volume type specified: %s' %
                              (ex_volume_type))
 
@@ -5534,6 +5620,32 @@ class BaseEC2NodeDriver(NodeDriver):
 
         return self._get_boolean(res)
 
+    def ex_modify_volume(self, volume, parameters):
+        """
+        Modify volume parameters.
+        A list of valid parameters can be found at  https://goo.gl/N0rPEQ
+
+        :param      Volume: Volume instance
+        :type       Volume: :class:`Volume`
+
+        :param      parameters: Dictionary with updated volume parameters
+        :type       parameters: ``dict``
+
+        :return: Volume modification status object
+        :rtype: :class:`VolumeModification
+        """
+        parameters = parameters or {}
+
+        volume_type = parameters.get('VolumeType')
+        if volume_type and volume_type not in VALID_VOLUME_TYPES:
+            raise ValueError('Invalid volume type specified: %s' % volume_type)
+
+        parameters.update({'Action': 'ModifyVolume', 'VolumeId': volume.id})
+
+        response = self.connection.request(self.path,
+                                           params=parameters.copy()).object
+        return self._to_volume_modification(response)
+
     def _ex_connection_class_kwargs(self):
         kwargs = super(BaseEC2NodeDriver, self)._ex_connection_class_kwargs()
         if hasattr(self, 'token') and self.token is not None:
@@ -5662,6 +5774,19 @@ class BaseEC2NodeDriver(NodeDriver):
                              state=state,
                              extra=extra)
 
+    def _to_volume_modification(self, element):
+        """
+        Parse the XML element and return a StorageVolume object.
+
+        :rtype:     :class:`EC2VolumeModification`
+        """
+        params_element = element.find(
+            fixxpath(xpath='volumeModification', namespace=NAMESPACE))
+        params = self._get_extra_dict(params_element,
+                                      VOLUME_MODIFICATION_ATTRIBUTE_MAP)
+
+        return EC2VolumeModification(**params)
+
     def _to_snapshots(self, response):
         return [self._to_snapshot(el) for el in response.findall(
             fixxpath(xpath='snapshotSet/item', namespace=NAMESPACE))