Skip to content

Commit 46c6716

Browse files
Merge pull request #2226 from softlayer/nvme
Support for NVMe Dual Raid card ordering.
2 parents 39ee130 + 54775a7 commit 46c6716

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-02-14T20:05:29Z",
6+
"generated_at": "2025-06-11T21:28:32Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -700,7 +700,7 @@
700700
"hashed_secret": "8af1f8146d96a3cd862281442d0d6c5cb6f8f9e5",
701701
"is_secret": false,
702702
"is_verified": false,
703-
"line_number": 181,
703+
"line_number": 187,
704704
"type": "Hex High Entropy String",
705705
"verified_result": null
706706
}

SoftLayer/managers/ordering.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,14 @@ def get_preset_by_key(self, package_keyname, preset_keyname, mask=None):
357357
if len(presets) == 0:
358358
raise exceptions.SoftLayerError(
359359
f"Preset {preset_keyname} does not exist in package {package_keyname}")
360-
361360
return presets[0]
362361

363362
def get_price_id_list(self, package_keyname, item_keynames, core=None):
363+
"""Returns just a list of price IDs for backwards compatability"""
364+
prices = self.get_ordering_prices(package_keyname, item_keynames, core)
365+
return [price.get('id') for price in prices]
366+
367+
def get_ordering_prices(self, package_keyname: str, item_keynames: list, core=None) -> list:
364368
"""Converts a list of item keynames to a list of price IDs.
365369
366370
This function is used to convert a list of item keynames into
@@ -370,8 +374,7 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
370374
:param str package_keyname: The package associated with the prices
371375
:param list item_keynames: A list of item keyname strings
372376
:param str core: preset guest core capacity.
373-
:returns: A list of price IDs associated with the given item
374-
keynames in the given package
377+
:returns: A list of price IDs associated with the given item keynames in the given package
375378
376379
"""
377380
mask = 'id, description, capacity, itemCategory, keyName, prices[categories], ' \
@@ -380,7 +383,8 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
380383
item_capacity = self.get_item_capacity(items, item_keynames)
381384

382385
prices = []
383-
category_dict = {"gpu0": -1, "pcie_slot0": -1}
386+
# start at -1 so we can increment before we use it. 0 is a valid value here
387+
category_dict = {"gpu0": -1, "pcie_slot0": -1, "disk_controller": -1}
384388

385389
for item_keyname in item_keynames:
386390
matching_item = []
@@ -410,15 +414,33 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
410414
# GPU and PCIe items has two generic prices and they are added to the list
411415
# according to the number of items in the order.
412416
category_dict[item_category] += 1
413-
category_code = item_category[:-1] + str(category_dict[item_category])
417+
item_category = self.get_special_category(category_dict[item_category], item_category)
418+
414419
price_id = [p['id'] for p in matching_item['prices']
415420
if not p['locationGroupId']
416-
and p['categories'][0]['categoryCode'] == category_code][0]
421+
and p['categories'][0]['categoryCode'] == item_category][0]
417422

418-
prices.append(price_id)
423+
prices.append({
424+
"id": price_id,
425+
"categories": [{"categoryCode": item_category}],
426+
"item": {"keyName": item_keyname}
427+
})
419428

420429
return prices
421430

431+
@staticmethod
432+
def get_special_category(index: int, base: str) -> str:
433+
"""Handles cases where we need to find price on a special category price id"""
434+
# disk_controller and disk_controller1
435+
if base == "disk_controller":
436+
if index == 0:
437+
return base
438+
else:
439+
return f"{base}1"
440+
441+
# gpu0 and gpu1, pcie_slot0 and pcie_slot1
442+
return base[:-1] + str(index)
443+
422444
@staticmethod
423445
def get_item_price_id(core, prices, term=0):
424446
"""get item price id
@@ -644,8 +666,9 @@ def generate_order(self, package_keyname, location, item_keynames, complex_type=
644666
raise exceptions.SoftLayerError("A complex type must be specified with the order")
645667
order['complexType'] = complex_type
646668

647-
price_ids = self.get_price_id_list(package_keyname, item_keynames, preset_core)
648-
order['prices'] = [{'id': price_id} for price_id in price_ids]
669+
order['prices'] = self.get_ordering_prices(package_keyname, item_keynames, preset_core)
670+
# price_ids = self.get_price_id_list(package_keyname, item_keynames, preset_core)
671+
# order['prices'] = [{'id': price_id} for price_id in price_ids]
649672

650673
container['orderContainers'] = [order]
651674

tests/managers/ordering_tests.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ def test_generate_order(self):
435435
pkg = 'PACKAGE_KEYNAME'
436436
items = ['ITEM1', 'ITEM2']
437437
complex_type = 'My_Type'
438-
expected_order = {'orderContainers': [
439-
{'complexType': 'My_Type',
440-
'location': 1854895,
441-
'packageId': 1234,
442-
'prices': [{'id': 1111}, {'id': 2222}],
443-
'quantity': 1,
444-
'useHourlyPricing': True}
438+
expected_order = {'orderContainers': [{
439+
'complexType': 'My_Type',
440+
'location': 1854895,
441+
'packageId': 1234,
442+
'prices': [{'id': 1111}, {'id': 2222}],
443+
'quantity': 1,
444+
'useHourlyPricing': True}
445445
]}
446446

447447
mock_pkg, mock_preset, mock_get_ids = self._patch_for_generate()
@@ -568,7 +568,7 @@ def _patch_for_generate(self):
568568
# with patchers
569569
mock_pkg = mock.patch.object(self.ordering, 'get_package_by_key')
570570
mock_preset = mock.patch.object(self.ordering, 'get_preset_by_key')
571-
mock_get_ids = mock.patch.object(self.ordering, 'get_price_id_list')
571+
mock_get_ids = mock.patch.object(self.ordering, 'get_ordering_prices')
572572

573573
# start each patcher, and set a cleanup to stop each patcher as well
574574
to_return = []
@@ -579,7 +579,7 @@ def _patch_for_generate(self):
579579
# set the return values on each of the mocks
580580
to_return[0].return_value = {'id': 1234}
581581
to_return[1].return_value = {'id': 5678}
582-
to_return[2].return_value = [1111, 2222]
582+
to_return[2].return_value = [{'id': 1111}, {'id': 2222}]
583583
return to_return
584584

585585
def test_get_location_id_short(self):

tests/managers/vs/vs_capacity_tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ def test_create(self):
7777
'quantity': 5,
7878
'useHourlyPricing': True,
7979
'complexType': 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity',
80-
'prices': [{'id': 217561}
81-
]
80+
'prices': [{
81+
'id': 217561,
82+
'categories': [{'categoryCode': 'reserved_capacity'}],
83+
'item': {'keyName': 'B1_1X2_1_YEAR_TERM'}
84+
}]
8285
}
8386
]
8487
}
@@ -103,8 +106,11 @@ def test_create_test(self):
103106
'quantity': 5,
104107
'useHourlyPricing': True,
105108
'complexType': 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity',
106-
'prices': [{'id': 217561}],
107-
109+
'prices': [{
110+
'id': 217561,
111+
'categories': [{'categoryCode': 'reserved_capacity'}],
112+
'item': {'keyName': 'B1_1X2_1_YEAR_TERM'}
113+
}]
108114
}
109115
]
110116
}

0 commit comments

Comments
 (0)