Skip to content

Commit 88203f6

Browse files
author
Fernando Ojeda
committed
Refactor functionality to order a hw for capacityRestrictionType PROCCESOR.
1 parent fe4a2f6 commit 88203f6

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

SoftLayer/managers/ordering.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,23 @@ def get_item_price_id(core, prices):
393393
price_id = None
394394
for price in prices:
395395
if not price['locationGroupId']:
396-
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
397-
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
398-
# return first match if no restirction, or no core to check
399-
if capacity_min == -1 or core is None or "PROCESSOR" in price.get("capacityRestrictionType"):
400-
price_id = price['id']
401-
# this check is mostly to work nicely with preset configs
402-
elif capacity_min <= int(core) <= capacity_max:
403-
if "STORAGE" in price.get("capacityRestrictionType") or "CORE" in price.get(
404-
"capacityRestrictionType"):
396+
restriction = price.get('capacityRestrictionType', False)
397+
# There is a price restriction. Make sure the price is within the restriction
398+
if restriction and core is not None:
399+
capacity_min = int(price.get('capacityRestrictionMinimum', -1))
400+
capacity_max = int(price.get('capacityRestrictionMaximum', -1))
401+
if "STORAGE" in restriction:
402+
if capacity_min <= int(core) <= capacity_max:
403+
price_id = price['id']
404+
if "CORE" in restriction:
405+
if capacity_min <= int(core) <= capacity_max:
406+
price_id = price['id']
407+
if "PROCESSOR" in restriction:
405408
price_id = price['id']
409+
# No price restrictions
410+
else:
411+
price_id = price['id']
412+
406413
return price_id
407414

408415
def get_item_capacity(self, items, item_keynames):

0 commit comments

Comments
 (0)