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

[google compute] improve MachineType (size) coverage of GCE API #396

Closed
wants to merge 1 commit 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
22 changes: 19 additions & 3 deletions libcloud/compute/drivers/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3508,20 +3508,36 @@ def _to_node_size(self, machine_type):
:rtype: :class:`GCENodeSize`
"""
extra = {}
disk_size = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erjohnso so we cannot change the disk_size through an argument ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Runseb - no, you can't change parameters on a GCE MachineType. These are analogous to AWS "sizes" like x2.large, c2.medium (or whatever they are). They are static descriptions of the "size" of VM.

Google has made a change to the API since this code was originally contributed and now the most appropriate way to report a MachineType's disk size is to use maximumPersistentDisksSizeGb over the now rarely seen imageSpaceGb attribute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool, I have not used GCE in couple months :)

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:
price = None

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):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
"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"
}
5 changes: 4 additions & 1 deletion libcloud/test/compute/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,12 @@ def test_ex_get_size(self):
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'
Expand Down