Repository: libcloud Updated Branches: refs/heads/trunk c0f0de72b -> 43cec4eb3
Improve MachineType (size) coverage of GCE API Signed-off-by: Sebastien Goasguen <[email protected]> This closes #396 Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2aa6f34b Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2aa6f34b Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2aa6f34b Branch: refs/heads/trunk Commit: 2aa6f34bd40a7e5d6bbe8b06ed042bbee42899a9 Parents: c0f0de7 Author: Eric Johnson <[email protected]> Authored: Thu Nov 20 21:50:02 2014 +0000 Committer: Sebastien Goasguen <[email protected]> Committed: Sat Nov 22 16:15:52 2014 -0500 ---------------------------------------------------------------------- CHANGES.rst | 4 ++++ libcloud/compute/drivers/gce.py | 22 ++++++++++++++--- ...s-central1-a_machineTypes_n1-standard-1.json | 25 ++++++++++---------- libcloud/test/compute/test_gce.py | 5 +++- 4 files changed, 39 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/2aa6f34b/CHANGES.rst ---------------------------------------------------------------------- diff --git a/CHANGES.rst b/CHANGES.rst index bf1ea1a..5c23dc6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -45,6 +45,10 @@ Compute (GITHUB-397) [Eric Johnson] +- GCE: Improve MachineType (size) coverage of GCE API + (GITHUB-396) + [Eric Johnson] + Changes with Apache Libcloud 0.16.0 ----------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/2aa6f34b/libcloud/compute/drivers/gce.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py index ce7bfef..6b42ce6 100644 --- a/libcloud/compute/drivers/gce.py +++ b/libcloud/compute/drivers/gce.py @@ -3512,11 +3512,27 @@ class GCENodeDriver(NodeDriver): :rtype: :class:`GCENodeSize` """ extra = {} + disk_size = 10 extra['selfLink'] = machine_type.get('selfLink') + extra['creationTimestamp'] = machine_type.get('creationTimestamp') extra['zone'] = self.ex_get_zone(machine_type['zone']) extra['description'] = machine_type.get('description') extra['guestCpus'] = machine_type.get('guestCpus') - extra['creationTimestamp'] = machine_type.get('creationTimestamp') + extra['memoryMb'] = machine_type.get('memoryMb') + extra['maximumPersistentDisks'] = \ + machine_type.get('maximumPersistentDisks') + if 'imageSpaceGb' in machine_type: + extra['imageSpaceGb'] = machine_type.get('imageSpaceGb') + disk_size = extra['imageSpaceGb'] + if 'maximumPersistentDisksSizeGb' in machine_type: + extra['maximumPersistentDisksSizeGb'] = \ + int(machine_type.get('maximumPersistentDisksSizeGb')) + disk_size = extra['maximumPersistentDisksSizeGb'] + if 'deprecated' in machine_type: + extra['deprecated'] = machine_type.get('deprecated') + if 'scratchDisks' in machine_type: + extra['scratchDisks'] = machine_type.get('scratchDisks') + try: price = self._get_size_price(size_id=machine_type['name']) except KeyError: @@ -3524,8 +3540,8 @@ class GCENodeDriver(NodeDriver): return GCENodeSize(id=machine_type['id'], name=machine_type['name'], ram=machine_type.get('memoryMb'), - disk=machine_type.get('imageSpaceGb'), - bandwidth=0, price=price, driver=self, extra=extra) + disk=disk_size, bandwidth=0, price=price, + driver=self, extra=extra) def _to_project(self, project): """ http://git-wip-us.apache.org/repos/asf/libcloud/blob/2aa6f34b/libcloud/test/compute/fixtures/gce/zones_us-central1-a_machineTypes_n1-standard-1.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/gce/zones_us-central1-a_machineTypes_n1-standard-1.json b/libcloud/test/compute/fixtures/gce/zones_us-central1-a_machineTypes_n1-standard-1.json index d1b3d74..98608d5 100644 --- a/libcloud/test/compute/fixtures/gce/zones_us-central1-a_machineTypes_n1-standard-1.json +++ b/libcloud/test/compute/fixtures/gce/zones_us-central1-a_machineTypes_n1-standard-1.json @@ -1,14 +1,13 @@ { - "creationTimestamp": "2012-06-07T13:48:14.670-07:00", - "description": "1 vCPU, 3.75 GB RAM", - "guestCpus": 1, - "id": "11077240422128681563", - "imageSpaceGb": 10, - "kind": "compute#machineType", - "maximumPersistentDisks": 16, - "maximumPersistentDisksSizeGb": "10240", - "memoryMb": 3840, - "name": "n1-standard-1", - "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/machineTypes/n1-standard-1", - "zone": "us-central1-a" -} \ No newline at end of file + "kind": "compute#machineType", + "id": "12907738072351752276", + "creationTimestamp": "2012-06-07T13:48:14.670-07:00", + "name": "n1-standard-1", + "description": "1 vCPU, 3.75 GB RAM", + "guestCpus": 1, + "memoryMb": 3840, + "maximumPersistentDisks": 16, + "maximumPersistentDisksSizeGb": "10240", + "zone": "us-central1-a", + "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/machineTypes/n1-standard-1" +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/2aa6f34b/libcloud/test/compute/test_gce.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py index ae21eff..2e3d6a6 100644 --- a/libcloud/test/compute/test_gce.py +++ b/libcloud/test/compute/test_gce.py @@ -676,9 +676,12 @@ class GCENodeDriverTest(LibcloudTestCase, TestCaseMixin): size = self.driver.ex_get_size(size_name) self.assertEqual(size.name, size_name) self.assertEqual(size.extra['zone'].name, 'us-central1-a') - self.assertEqual(size.disk, 10) + self.assertEqual(size.disk, 10240) self.assertEqual(size.ram, 3840) self.assertEqual(size.extra['guestCpus'], 1) + self.assertEqual(size.extra['memoryMb'], 3840) + self.assertEqual(size.extra['maximumPersistentDisks'], 16) + self.assertEqual(size.extra['maximumPersistentDisksSizeGb'], 10240) def test_ex_get_targetpool(self): targetpool_name = 'lctargetpool'
