From 9fa614a89c2568e37f9679a9e5ff255b3564c2fa Mon Sep 17 00:00:00 2001 From: Allard Hoeve Date: Thu, 12 Feb 2015 14:49:15 +0100 Subject: [PATCH] Make EC2 conform to interface --- libcloud/common/linode.py | 4 ++-- libcloud/common/types.py | 20 ++++++++-------- libcloud/compute/drivers/ec2.py | 5 ++-- libcloud/compute/drivers/rimuhosting.py | 4 ++-- libcloud/compute/drivers/vcloud.py | 6 ++--- libcloud/storage/drivers/s3.py | 2 +- libcloud/test/compute/__init__.py | 5 ++-- .../fixtures/ec2/describe_snapshots.xml | 24 ++++++++++++++++++- libcloud/test/compute/test_ec2.py | 10 +++++++- libcloud/utils/dist.py | 3 +-- 10 files changed, 57 insertions(+), 26 deletions(-) diff --git a/libcloud/common/linode.py b/libcloud/common/linode.py index fb6ea2bd3a..aba75f005d 100644 --- a/libcloud/common/linode.py +++ b/libcloud/common/linode.py @@ -127,8 +127,8 @@ def parse_body(self): ret = [] errs = [] for obj in js: - if ("DATA" not in obj or "ERRORARRAY" not in obj - or "ACTION" not in obj): + if ("DATA" not in obj or "ERRORARRAY" not in obj or + "ACTION" not in obj): ret.append(None) errs.append(self.invalid) continue diff --git a/libcloud/common/types.py b/libcloud/common/types.py index 6020440a2d..b5ff512fb8 100644 --- a/libcloud/common/types.py +++ b/libcloud/common/types.py @@ -37,10 +37,10 @@ def __str__(self): return self.__repr__() def __repr__(self): - return ("") + return ("") class MalformedResponseError(LibcloudError): @@ -57,12 +57,12 @@ def __str__(self): return self.__repr__() def __repr__(self): - return (": " - + repr(self.body)) + return (": " + + repr(self.body)) class ProviderError(LibcloudError): diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index df71eb674a..fd7c98c8cd 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -2407,8 +2407,9 @@ def create_volume_snapshot(self, volume, name=None): return snapshot - def list_volume_snapshots(self, snapshot): - return self.list_snapshots(snapshot) + def list_volume_snapshots(self, volume): + return [snapshot for snapshot in self.list_snapshots(owner='self') + if snapshot.extra["volume_id"] == volume.id] def list_snapshots(self, snapshot=None, owner=None): """ diff --git a/libcloud/compute/drivers/rimuhosting.py b/libcloud/compute/drivers/rimuhosting.py index acde574336..f7cfdd7e12 100644 --- a/libcloud/compute/drivers/rimuhosting.py +++ b/libcloud/compute/drivers/rimuhosting.py @@ -151,8 +151,8 @@ def _to_node(self, order): name=order['domain_name'], state=NodeState.RUNNING, public_ips=( - [order['allocated_ips']['primary_ip']] - + order['allocated_ips']['secondary_ips']), + [order['allocated_ips']['primary_ip']] + + order['allocated_ips']['secondary_ips']), private_ips=[], driver=self.connection.driver, extra={ diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py index d18d390d4a..0ce10b3fd8 100644 --- a/libcloud/compute/drivers/vcloud.py +++ b/libcloud/compute/drivers/vcloud.py @@ -581,9 +581,9 @@ def ex_list_nodes(self, vdcs=None): ) vapps = [ (i.get('name'), i.get('href')) - for i in elms - if i.get('type') == 'application/vnd.vmware.vcloud.vApp+xml' - and i.get('name') + for i in elms if + i.get('type') == 'application/vnd.vmware.vcloud.vApp+xml' and + i.get('name') ] for vapp_name, vapp_href in vapps: diff --git a/libcloud/storage/drivers/s3.py b/libcloud/storage/drivers/s3.py index 60e55624c2..eca2910609 100644 --- a/libcloud/storage/drivers/s3.py +++ b/libcloud/storage/drivers/s3.py @@ -729,7 +729,7 @@ def finder(node, text): if response.status != httplib.OK: raise LibcloudError('Error fetching multipart uploads. ' - 'Got code: %s' % (response.status), + 'Got code: %s' % response.status, driver=self) body = response.parse_body() diff --git a/libcloud/test/compute/__init__.py b/libcloud/test/compute/__init__.py index 42e478c349..1db7b2d115 100644 --- a/libcloud/test/compute/__init__.py +++ b/libcloud/test/compute/__init__.py @@ -38,8 +38,9 @@ def test_list_sizes_response(self): self.assertTrue(size.bandwidth is None or isinstance(size.bandwidth, int)) # Check that price values are ints, floats, or None. - self.assertTrue(size.price is None or isinstance(size.price, float) - or isinstance(size.price, int)) + self.assertTrue(size.price is None or + isinstance(size.price, float) or + isinstance(size.price, int)) def test_list_images_response(self): images = self.driver.list_images() diff --git a/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml b/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml index b884c79c4e..2faf38ff6e 100644 --- a/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml +++ b/libcloud/test/compute/fixtures/ec2/describe_snapshots.xml @@ -40,4 +40,26 @@ - \ No newline at end of file + + + snap-18349160 + vol-10ae5e2b + pending + 2014-09-15T16:00:30.000Z + 30% + 1938218231 + 15 + Weekly backup + + + Name + DB Backup 1 + + + Key2 + db_backup + + + + + diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index e1565656ac..1b79781a4d 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -828,7 +828,7 @@ def test_create_volume_snapshot(self): def test_list_snapshots(self): snaps = self.driver.list_snapshots() - self.assertEqual(len(snaps), 2) + self.assertEqual(len(snaps), 3) self.assertEqual('snap-428abd35', snaps[0].id) self.assertEqual('vol-e020df80', snaps[0].extra['volume_id']) @@ -841,6 +841,14 @@ def test_list_snapshots(self): self.assertEqual('Weekly backup', snaps[1].extra['description']) self.assertEqual('DB Backup 1', snaps[1].extra['name']) + def test_list_volume_snapshots(self): + volume = self.driver.list_volumes()[0] + assert volume.id == 'vol-10ae5e2b' + + snapshots = self.driver.list_volume_snapshots(volume) + self.assertEqual(len(snapshots), 1) + self.assertEqual(snapshots[0].id, 'snap-18349160') + def test_destroy_snapshot(self): snap = VolumeSnapshot(id='snap-428abd35', size=10, driver=self.driver) resp = snap.destroy() diff --git a/libcloud/utils/dist.py b/libcloud/utils/dist.py index 4477e2ae2d..01e523e026 100644 --- a/libcloud/utils/dist.py +++ b/libcloud/utils/dist.py @@ -36,8 +36,7 @@ def _filter_names(names): # copy (likely a checkout) rather than a pristine export: for pattern in EXCLUDE_PATTERNS: names = [n for n in names - if (not fnmatch.fnmatch(n, pattern)) - and (not n.endswith('.py'))] + if not fnmatch.fnmatch(n, pattern) and not n.endswith('.py')] return names