Skip to content

Commit 1435ab7

Browse files
Merge pull request #1290 from FernandoOjeda/fo_order_hw
Add functionality to order a hw for capacityRestrictionType PROCCESOR.
2 parents 0bf2018 + 88203f6 commit 1435ab7

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-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:
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):

tests/managers/ordering_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,16 @@ def test_get_item_price_id_storage_with_capacity_restriction(self):
666666

667667
self.assertEqual(1234, price_id)
668668

669+
def test_get_item_price_id_processor_with_capacity_restriction(self):
670+
category1 = {'categoryCode': 'cat1'}
671+
price1 = [{'id': 1234, 'locationGroupId': '', "capacityRestrictionMaximum": "1",
672+
"capacityRestrictionMinimum": "1", "capacityRestrictionType": "PROCESSOR",
673+
'categories': [category1]}]
674+
675+
price_id = self.ordering.get_item_price_id("8", price1)
676+
677+
self.assertEqual(1234, price_id)
678+
669679
def test_issues1067(self):
670680
# https://github.com/softlayer/softlayer-python/issues/1067
671681
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')

0 commit comments

Comments
 (0)