@@ -357,10 +357,14 @@ def get_preset_by_key(self, package_keyname, preset_keyname, mask=None):
357
357
if len (presets ) == 0 :
358
358
raise exceptions .SoftLayerError (
359
359
f"Preset { preset_keyname } does not exist in package { package_keyname } " )
360
-
361
360
return presets [0 ]
362
361
363
362
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 :
364
368
"""Converts a list of item keynames to a list of price IDs.
365
369
366
370
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):
370
374
:param str package_keyname: The package associated with the prices
371
375
:param list item_keynames: A list of item keyname strings
372
376
: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
375
378
376
379
"""
377
380
mask = 'id, description, capacity, itemCategory, keyName, prices[categories], ' \
@@ -380,7 +383,8 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
380
383
item_capacity = self .get_item_capacity (items , item_keynames )
381
384
382
385
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 }
384
388
385
389
for item_keyname in item_keynames :
386
390
matching_item = []
@@ -410,15 +414,33 @@ def get_price_id_list(self, package_keyname, item_keynames, core=None):
410
414
# GPU and PCIe items has two generic prices and they are added to the list
411
415
# according to the number of items in the order.
412
416
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
+
414
419
price_id = [p ['id' ] for p in matching_item ['prices' ]
415
420
if not p ['locationGroupId' ]
416
- and p ['categories' ][0 ]['categoryCode' ] == category_code ][0 ]
421
+ and p ['categories' ][0 ]['categoryCode' ] == item_category ][0 ]
417
422
418
- prices .append (price_id )
423
+ prices .append ({
424
+ "id" : price_id ,
425
+ "categories" : [{"categoryCode" : item_category }],
426
+ "item" : {"keyName" : item_keyname }
427
+ })
419
428
420
429
return prices
421
430
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
+
422
444
@staticmethod
423
445
def get_item_price_id (core , prices , term = 0 ):
424
446
"""get item price id
@@ -644,8 +666,9 @@ def generate_order(self, package_keyname, location, item_keynames, complex_type=
644
666
raise exceptions .SoftLayerError ("A complex type must be specified with the order" )
645
667
order ['complexType' ] = complex_type
646
668
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]
649
672
650
673
container ['orderContainers' ] = [order ]
651
674
0 commit comments