Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageVolumeSnapshot now has a .name #867

Closed
wants to merge 2 commits into from
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
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Compute
(GITHUB-857)
[Allard Hoeve]

- StorageVolumeSnapshot now has an attribute `name` that has the name of the snapshot
if the provider supports it. This used to be `.extra['name']`, but that is inconsistent
with `Node` and `StorageVolume`. The `extra` dict still holds `name` for backwards
compatibility.
(GITHUB-867)
[Allard Hoeve]

Container
~~~~~~~~~

Expand Down
10 changes: 7 additions & 3 deletions libcloud/compute/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class VolumeSnapshot(object):
A base VolumeSnapshot class to derive from.
"""
def __init__(self, id, driver, size=None, extra=None, created=None,
state=None):
state=None, name=None):
"""
VolumeSnapshot constructor.

Expand All @@ -583,13 +583,17 @@ def __init__(self, id, driver, size=None, extra=None, created=None,
:param state: A string representing the state the snapshot is
in. See `libcloud.compute.types.StorageVolumeState`.
:type state: ``str``

:param name: A string representing the name of the snapshot
:type name: ``str``
"""
self.id = id
self.driver = driver
self.size = size
self.extra = extra or {}
self.created = created
self.state = state
self.name = name

def destroy(self):
"""
Expand All @@ -600,8 +604,8 @@ def destroy(self):
return self.driver.destroy_volume_snapshot(snapshot=self)

def __repr__(self):
return ('<VolumeSnapshot id=%s size=%s driver=%s state=%s>' %
(self.id, self.size, self.driver.name, self.state))
return ('<VolumeSnapshot "%s" id=%s size=%s driver=%s state=%s>' %
(self.name, self.id, self.size, self.driver.name, self.state))


class KeyPair(object):
Expand Down
3 changes: 2 additions & 1 deletion libcloud/compute/drivers/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5601,7 +5601,8 @@ def _to_snapshot(self, element, name=None):
driver=self,
extra=extra,
created=created,
state=state)
state=state,
name=name)

def _to_key_pairs(self, elems):
key_pairs = [self._to_key_pair(elem=elem) for elem in elems]
Expand Down
4 changes: 2 additions & 2 deletions libcloud/compute/drivers/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ def __repr__(self):
class GCESnapshot(VolumeSnapshot):
def __init__(self, id, name, size, status, driver, extra=None,
created=None):
self.name = name
self.status = status
super(GCESnapshot, self).__init__(id, driver, size, extra, created)
super(GCESnapshot, self).__init__(id, driver, size, extra,
created, name=name)


class GCETargetHttpProxy(UuidMixin):
Expand Down
3 changes: 2 additions & 1 deletion libcloud/compute/drivers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,8 @@ def _to_snapshot(self, data):

snapshot = VolumeSnapshot(id=data['id'], driver=self,
size=data['size'], extra=extra,
created=created_dt, state=state)
created=created_dt, state=state,
name=display_name)
return snapshot

def _to_size(self, api_flavor, price=None, bandwidth=None):
Expand Down
3 changes: 2 additions & 1 deletion libcloud/compute/drivers/rackspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def _to_snapshot(self, api_node):
size=api_node['size'],
extra=extra,
created=created_td,
state=state)
state=state,
name=api_node['displayName'])
return snapshot

def _ex_connection_class_kwargs(self):
Expand Down
1 change: 1 addition & 0 deletions libcloud/test/compute/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ def test_list_snapshots(self):
self.assertEqual('Daily Backup', snaps[0].extra['description'])

self.assertEqual('snap-18349159', snaps[1].id)
self.assertEqual('DB Backup 1', snaps[1].name)
self.assertEqual(VolumeSnapshotState.AVAILABLE, snaps[1].state)
self.assertEqual('vol-b5a2c1v9', snaps[1].extra['volume_id'])
self.assertEqual(15, snaps[1].size)
Expand Down
1 change: 1 addition & 0 deletions libcloud/test/compute/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ def test_ex_create_volume_snapshot(self):
snapshot_name = 'lcsnapshot'
volume = self.driver.ex_get_volume('lcdisk')
snapshot = volume.snapshot(snapshot_name)

self.assertEqual(snapshot.name, snapshot_name)
self.assertEqual(snapshot.size, '10')

Expand Down
1 change: 1 addition & 0 deletions libcloud/test/compute/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ def test_ex_list_snapshots(self):
self.assertEqual(snapshots[0].created, datetime.datetime(2012, 2, 29, 3, 50, 7, tzinfo=UTC))
self.assertEqual(snapshots[0].extra['created'], "2012-02-29T03:50:07Z")
self.assertEqual(snapshots[0].extra['name'], 'snap-001')
self.assertEqual(snapshots[0].name, 'snap-001')
self.assertEqual(snapshots[0].state, VolumeSnapshotState.AVAILABLE)

# invalid date is parsed as None
Expand Down