Obtain size info defensively for Packet
@@ -419,13 +419,20 @@ def _list_async(driver):
driver=self, extra=extra)
def _to_size(self, data):
+ try:
cpus = data['specs']['cpus'][0].get('count')
+ except KeyError:
+ cpus = None
regions = [region.get('href').strip('/facilities/')
for region in data.get('available_in')]
extra = {'description': data['description'], 'line': data['line'],
'cpus': cpus, 'regions': regions}
-
- ram = data['specs']['memory']['total']
+ try:
+ ram = int(data['specs']['memory']['total'].replace('GB', '')) * 1024
+ except KeyError:
+ ram = None
+ disk = None
+ if data['specs'].get('drives', ''):
disk = 0
for disks in data['specs']['drives']:
disk_size = disks['size'].replace('GB', '')
@@ -435,8 +442,8 @@ def _list_async(driver):
name = "%s - %s RAM" % (data.get('name'), ram)
price = data['pricing'].get('hour')
return NodeSize(id=data['slug'], name=name,
- ram=int(ram.replace('GB', '')) * 1024, disk=disk,
- bandwidth=0, price=price, extra=extra, driver=self)
+ ram=ram, disk=disk, bandwidth=0,
+ price=price, extra=extra, driver=self)
def _to_key_pairs(self, data):
extra = {'label': data['label'],
