Skip to content

Commit daa4ec6

Browse files
committed
cleaning up getting a price id for an option
1 parent 6898e69 commit daa4ec6

1 file changed

Lines changed: 14 additions & 20 deletions

File tree

SoftLayer/managers/vs.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -863,38 +863,32 @@ def _get_price_id_for_upgrade_option(self, upgrade_prices, option, value,
863863
'cpus': 'guest_core',
864864
'nic_speed': 'port_speed'
865865
}
866-
category_code = option_category[option]
866+
category_code = option_category.get(option)
867867
for price in upgrade_prices:
868-
if 'locationGroupId' in price and price['locationGroupId']:
869-
# Skip location based prices
870-
continue
871-
872-
if 'categories' not in price:
873-
continue
874-
875-
if 'item' not in price:
868+
if price.get('categories') is None or price.get('item') is None:
876869
continue
877870

878-
product = price['item']
871+
product = price.get('item')
879872
is_private = (product.get('units') == 'PRIVATE_CORE'
880873
or product.get('units') == 'DEDICATED_CORE')
881874

882-
categories = price['categories']
883-
for category in categories:
884-
if not (category['categoryCode'] == category_code
885-
and str(product['capacity']) == str(value)):
875+
for category in price.get('categories'):
876+
if not (category.get('categoryCode') == category_code
877+
and str(product.get('capacity')) == str(value)):
886878
continue
879+
887880
if option == 'cpus':
881+
# Public upgrade and public guest_core price
888882
if public and not is_private:
889-
return price['id']
883+
return price.get('id')
884+
# Private upgrade and private guest_core price
890885
elif not public and is_private:
891-
return price['id']
886+
return price.get('id')
892887
elif option == 'nic_speed':
893-
if 'Public' in product['description']:
894-
return price['id']
888+
if 'Public' in product.get('description'):
889+
return price.get('id')
895890
else:
896-
return price['id']
897-
891+
return price.get('id')
898892

899893
def _get_price_id_for_upgrade(self, package_items, option, value,
900894
public=True):

0 commit comments

Comments
 (0)