Repository: libcloud Updated Branches: refs/heads/trunk 0696e27eb -> 63dbd4284
Allow user to specify volume type and number of IOPS when creating a new volume in the EC2 driver by passing ex_volume_type and ex_iops argument to the create_volume method. Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/63dbd428 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/63dbd428 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/63dbd428 Branch: refs/heads/trunk Commit: 63dbd4284bfedf051bc168acf32876693d1d2c7e Parents: 0696e27 Author: Tomaz Muraus <to...@apache.org> Authored: Wed Jun 18 15:06:52 2014 +0200 Committer: Tomaz Muraus <to...@apache.org> Committed: Wed Jun 18 15:22:19 2014 +0200 ---------------------------------------------------------------------- CHANGES.rst | 5 ++++ docs/compute/drivers/ec2.rst | 12 ++++++++++ .../ec2/create_general_purpose_ssd_volume.py | 8 +++++++ .../ec2/create_provisioned_iops_volume.py | 8 +++++++ libcloud/compute/drivers/ec2.py | 25 ++++++++++++++++++-- 5 files changed, 56 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/63dbd428/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index 46e804b..1897783 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -234,6 +234,11 @@ Compute - Fix ex_list_snapshots for HP Helion OpenStack based driver. [Tomaz Muraus] +- Allow user to specify volume type and number of IOPS when creating a new + volume in the EC2 driver by passing ``ex_volume_type`` and ``ex_iops`` + argument to the ``create_volume`` method. + [Tomaz Muraus] + Storage ~~~~~~~ http://git-wip-us.apache.org/repos/asf/libcloud/blob/63dbd428/docs/compute/drivers/ec2.rst ---------------------------------------------------------------------- diff --git a/docs/compute/drivers/ec2.rst b/docs/compute/drivers/ec2.rst index d7d6f71..b42ca53 100644 --- a/docs/compute/drivers/ec2.rst +++ b/docs/compute/drivers/ec2.rst @@ -49,6 +49,18 @@ Allocate, Associate, Disassociate, and Release an Elastic IP .. literalinclude:: /examples/compute/create_ec2_node_and_associate_elastic_ip.py :language: python +Create a general purpose SSD volume +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: /examples/compute/ec2/create_general_purpose_ssd_volume.py + :language: python + +Create a provisioned IOPS volume +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: /examples/compute/ec2/create_provisioned_iops_volume.py + :language: python + API Docs -------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/63dbd428/docs/examples/compute/ec2/create_general_purpose_ssd_volume.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/ec2/create_general_purpose_ssd_volume.py b/docs/examples/compute/ec2/create_general_purpose_ssd_volume.py new file mode 100644 index 0000000..1389673 --- /dev/null +++ b/docs/examples/compute/ec2/create_general_purpose_ssd_volume.py @@ -0,0 +1,8 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +cls = get_driver(Provider.EC2, region='us-east-i1') +driver = cls('access key', 'secret key') + +volume = driver.create_volume(size=100, name='Test GP volume', + ex_volume_type='g2') http://git-wip-us.apache.org/repos/asf/libcloud/blob/63dbd428/docs/examples/compute/ec2/create_provisioned_iops_volume.py ---------------------------------------------------------------------- diff --git a/docs/examples/compute/ec2/create_provisioned_iops_volume.py b/docs/examples/compute/ec2/create_provisioned_iops_volume.py new file mode 100644 index 0000000..6414790 --- /dev/null +++ b/docs/examples/compute/ec2/create_provisioned_iops_volume.py @@ -0,0 +1,8 @@ +from libcloud.compute.types import Provider +from libcloud.compute.providers import get_driver + +cls = get_driver(Provider.EC2, region='us-east-i1') +driver = cls('access key', 'secret key') + +volume = driver.create_volume(size=100, name='Test IOPS volume', + ex_volume_type='io1', ex_iops=1000) http://git-wip-us.apache.org/repos/asf/libcloud/blob/63dbd428/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 9128c66..22c1a64 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -2151,18 +2151,39 @@ class BaseEC2NodeDriver(NodeDriver): res = self.connection.request(self.path, params=params).object return self._get_terminate_boolean(res) - def create_volume(self, size, name, location=None, snapshot=None): + def create_volume(self, size, name, location=None, snapshot=None, + ex_volume_type='standard', ex_iops=None): """ :param location: Datacenter in which to create a volume in. - :type location: :class:`ExEC2AvailabilityZone` + :type location: :class:`.ExEC2AvailabilityZone` + + :param ex_volume_type: Type of volume to create. + :type ex_volume_type: ``str`` + + :param iops: The number of I/O operations per second (IOPS) + that the volume supports. Only used if ex_volume_type + is io1. + :type iops: ``int`` """ + valid_volume_types = ['standard', 'io1', 'g2'] + params = { 'Action': 'CreateVolume', 'Size': str(size)} + if ex_volume_type and ex_volume_type not in valid_volume_types: + raise ValueError('Invalid volume type specified: %s' % + (ex_volume_type)) + if location is not None: params['AvailabilityZone'] = location.availability_zone.name + if ex_volume_type: + params['VolumeType'] = ex_volume_type + + if ex_volume_type == 'io1' and ex_iops: + params['Iops'] = ex_iops + volume = self._to_volume( self.connection.request(self.path, params=params).object, name=name)