Repository: libcloud Updated Branches: refs/heads/trunk 90b96de2a -> 8f39dbc1b
implement OpenStack_1_1_NodeDriver ex_get_snapshot to list a volume snapshot by ID, similar to `ex_get_volume` Signed-off-by: Rick van de Loo <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/dae09e28 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/dae09e28 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/dae09e28 Branch: refs/heads/trunk Commit: dae09e28b6fcc663958a2a633fea80e6a0e487d8 Parents: 90b96de Author: Rick van de Loo <[email protected]> Authored: Mon Nov 26 12:43:50 2018 +0100 Committer: Rick van de Loo <[email protected]> Committed: Tue Nov 27 08:31:33 2018 +0100 ---------------------------------------------------------------------- libcloud/compute/drivers/openstack.py | 4 ++ .../fixtures/openstack_v1.1/_os_snapshot.json | 11 ++++++ .../openstack_v1.1/_os_snapshot_rackspace.json | 11 ++++++ libcloud/test/compute/test_openstack.py | 41 ++++++++++++++------ 4 files changed, 55 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/dae09e28/libcloud/compute/drivers/openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py index 211c651..75106f1 100644 --- a/libcloud/compute/drivers/openstack.py +++ b/libcloud/compute/drivers/openstack.py @@ -1703,6 +1703,10 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver): return self._to_snapshots( self.connection.request('/os-snapshots').object) + def ex_get_snapshot(self, snapshotId): + return self._to_snapshot( + self.connection.request('/os-snapshots/%s' % snapshotId).object) + def list_volume_snapshots(self, volume): return [snapshot for snapshot in self.ex_list_snapshots() if snapshot.extra['volume_id'] == volume.id] http://git-wip-us.apache.org/repos/asf/libcloud/blob/dae09e28/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot.json b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot.json new file mode 100644 index 0000000..a79927a --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot.json @@ -0,0 +1,11 @@ +{ + "snapshot": { + "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5", + "display_name": "snap-001", + "display_description": "Daily backup", + "volume_id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + "status": "available", + "size": 30, + "created_at": "2012-02-29T03:50:07Z" + } +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/dae09e28/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot_rackspace.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot_rackspace.json b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot_rackspace.json new file mode 100644 index 0000000..abb0b56 --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_snapshot_rackspace.json @@ -0,0 +1,11 @@ +{ + "snapshot": { + "id": "3fbbcccf-d058-4502-8844-6feeffdf4cb5", + "displayName": "snap-001", + "displayDescription": "Daily backup", + "volumeId": "521752a6-acf6-4b2d-bc7a-119f9148cd8c", + "status": "available", + "size": 30, + "createdAt": "2012-02-29T03:50:07Z" + } +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/dae09e28/libcloud/test/compute/test_openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index c9be795..4119749 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -1482,6 +1482,17 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin): # invalid date is parsed as None assert snapshots[2].created is None + def test_ex_get_snapshot(self): + if self.driver_type.type == 'rackspace': + self.conn_class.type = 'RACKSPACE' + + snapshot = self.driver.ex_get_snapshot('3fbbcccf-d058-4502-8844-6feeffdf4cb5') + self.assertEqual(snapshot.created, datetime.datetime(2012, 2, 29, 3, 50, 7, tzinfo=UTC)) + self.assertEqual(snapshot.extra['created'], "2012-02-29T03:50:07Z") + self.assertEqual(snapshot.extra['name'], 'snap-001') + self.assertEqual(snapshot.name, 'snap-001') + self.assertEqual(snapshot.state, VolumeSnapshotState.AVAILABLE) + def test_list_volume_snapshots(self): volume = self.driver.list_volumes()[0] @@ -2242,18 +2253,11 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase): return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) - def _v1_1_slug_os_snapshots_RACKSPACE(self, method, url, body, headers): - if method == 'GET': - body = self.fixtures.load('_os_snapshots_rackspace.json') - elif method == 'POST': - body = self.fixtures.load('_os_snapshots_create_rackspace.json') - else: - raise NotImplementedError() - - return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) - def _v1_1_slug_os_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5(self, method, url, body, headers): - if method == 'DELETE': + if method == 'GET': + body = self.fixtures.load('_os_snapshot.json') + status_code = httplib.OK + elif method == 'DELETE': body = '' status_code = httplib.NO_CONTENT else: @@ -2262,7 +2266,10 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase): return (status_code, body, self.json_content_headers, httplib.responses[httplib.OK]) def _v1_1_slug_os_snapshots_3fbbcccf_d058_4502_8844_6feeffdf4cb5_RACKSPACE(self, method, url, body, headers): - if method == 'DELETE': + if method == 'GET': + body = self.fixtures.load('_os_snapshot_rackspace.json') + status_code = httplib.OK + elif method == 'DELETE': body = '' status_code = httplib.NO_CONTENT else: @@ -2270,6 +2277,16 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase): return (status_code, body, self.json_content_headers, httplib.responses[httplib.OK]) + def _v1_1_slug_os_snapshots_RACKSPACE(self, method, url, body, headers): + if method == 'GET': + body = self.fixtures.load('_os_snapshots_rackspace.json') + elif method == 'POST': + body = self.fixtures.load('_os_snapshots_create_rackspace.json') + else: + raise NotImplementedError() + + return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + def _v2_1337_v2_0_networks(self, method, url, body, headers): if method == 'GET': body = self.fixtures.load('_v2_0__networks.json')
