You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/03/04 23:37:04 UTC
[2/5] libcloud git commit: Implement creating volumes from OpenStack
snapshots
Implement creating volumes from OpenStack snapshots
LIBCLOUD-673 #close
Signed-off-by: Tomaz Muraus <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/1628fc49
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/1628fc49
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/1628fc49
Branch: refs/heads/trunk
Commit: 1628fc49bb39ebfa43f26618aaa7edd6ee80b039
Parents: ceccf30
Author: Allard Hoeve <al...@byte.nl>
Authored: Tue Feb 24 13:50:42 2015 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Mar 4 23:30:12 2015 +0100
----------------------------------------------------------------------
libcloud/compute/drivers/openstack.py | 48 +++++++++++++++++++++---------
1 file changed, 34 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/1628fc49/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index da8c05b..313abab 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -149,23 +149,43 @@ class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
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,
+ }
+ }
+
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):