@@ -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
0 commit comments