Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Changes with Apache Libcloud in development
Compute
~~~~~~~

- Add support for creating volumes based on snapshots to EC2 and OS drivers.
Also modify signature of base NodeDriver.create_volume to reflect the fact
that all drivers expect a StorageSnapshot object as the snapshot argument.
(GITHUB-467, LIBCLOUD-672)
[Allard Hoeve]

- Improve GCE create_node, make sure ex_get_disktype function
(GITHUB-448)
[Markos Gogoulos]
Expand Down
10 changes: 10 additions & 0 deletions docs/upgrade_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ This page describes how to upgrade from a previous version to a new version
which contains backward incompatible or semi-incompatible changes and how to
preserve the old behavior when this is possible.

Development
-----------

* The base signature of NodeDriver.create_volume has changed. The snapshot
argument is now expected to be a VolumeSnapshot instead of a string.
The older signature was never correct for built-in drivers, but custom
drivers may break. (GCE accepted strings, names or None and still does.
Other drivers did not implement creating volumes from snapshots at all
until now.)

Libcloud 0.16.0
---------------

Expand Down
6 changes: 3 additions & 3 deletions libcloud/compute/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,9 @@ def create_volume(self, size, name, location=None, snapshot=None):
(optional)
:type location: :class:`.NodeLocation`

:param snapshot: Name of snapshot from which to create the new
volume. (optional)
:type snapshot: ``str``
:param snapshot: Snapshot from which to create the new
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change - can you please document it in docs/upgrade_notes.rst?

volume. (optional)
:type snapshot: :class:`.VolumeSnapshot`

:return: The newly created volume.
:rtype: :class:`StorageVolume`
Expand Down
23 changes: 23 additions & 0 deletions libcloud/compute/drivers/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,23 @@ def destroy_node(self, node):
def create_volume(self, size, name, location=None, snapshot=None,
ex_volume_type='standard', ex_iops=None):
"""
Create a new volume.

:param size: Size of volume in gigabytes (required)
:type size: ``int``

:param name: Name of the volume to be created
:type name: ``str``

:param location: Which data center to create a volume in. If
empty, undefined behavior will be selected.
(optional)
:type location: :class:`.NodeLocation`

:param snapshot: Snapshot from which to create the new
volume. (optional)
:type snapshot: :class:`.VolumeSnapshot`

:param location: Datacenter in which to create a volume in.
:type location: :class:`.ExEC2AvailabilityZone`

Expand All @@ -2324,6 +2341,9 @@ def create_volume(self, size, name, location=None, snapshot=None,
that the volume supports. Only used if ex_volume_type
is io1.
:type iops: ``int``

:return: The newly created volume.
:rtype: :class:`StorageVolume`
"""
valid_volume_types = ['standard', 'io1', 'gp2']

Expand All @@ -2335,6 +2355,9 @@ def create_volume(self, size, name, location=None, snapshot=None,
raise ValueError('Invalid volume type specified: %s' %
(ex_volume_type))

if snapshot:
params['SnapshotId'] = snapshot.id

if location is not None:
params['AvailabilityZone'] = location.availability_zone.name

Expand Down
49 changes: 35 additions & 14 deletions libcloud/compute/drivers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,44 @@ def list_nodes(self, ex_all_tenants=False):
self.connection.request('/servers/detail', params=params).object)

def create_volume(self, size, name, location=None, snapshot=None):
"""
Create a new volume.

:param size: Size of volume in gigabytes (required)
:type size: ``int``

:param name: Name of the volume to be created
:type name: ``str``

:param location: Which data center to create a volume in. If
empty, undefined behavior will be selected.
(optional)
:type location: :class:`.NodeLocation`

:param snapshot: Snapshot from which to create the new
volume. (optional)
:type snapshot: :class:`.VolumeSnapshot`

:return: The newly created volume.
:rtype: :class:`StorageVolume`
"""
volume = {
'display_name': name,
'display_description': name,
'size': size,
'volume_type': None,
'metadata': {
'contents': name,
},
'availability_zone': location
}

if snapshot:
raise NotImplementedError(
"create_volume does not yet support create from snapshot")
volume['snapshot_id'] = snapshot.id

resp = self.connection.request('/os-volumes',
method='POST',
data={
'volume': {
'display_name': name,
'display_description': name,
'size': size,
'volume_type': None,
'metadata': {
'contents': name,
},
'availability_zone': location,
}
})
data={'volume': volume})
return self._to_volume(resp.object)

def destroy_volume(self, volume):
Expand Down