@@ -821,14 +821,15 @@ def authorize_storage(self, hardware_id, username_storage):
821821
822822 def upgrade (self , instance_id , memory = None ,
823823 nic_speed = None , drive_controller = None ,
824- public_bandwidth = None , test = False ):
824+ public_bandwidth = None , disk = None , test = False ):
825825 """Upgrades a hardware server instance.
826826
827827 :param int instance_id: Instance id of the hardware server to be upgraded.
828828 :param int memory: Memory size.
829829 :param string nic_speed: Network Port Speed data.
830830 :param string drive_controller: Drive Controller data.
831831 :param int public_bandwidth: Public keyName data.
832+ :param list disk: List of disks to add or upgrade Hardware Server.
832833 :param bool test: Test option to verify the request.
833834
834835 :returns: bool
@@ -860,6 +861,10 @@ def upgrade(self, instance_id, memory=None,
860861 'packageId' : package_id
861862 }
862863
864+ if disk :
865+ prices = self ._get_disk_price_list (instance_id , disk )
866+ order ['prices' ] = prices
867+
863868 for option , value in data .items ():
864869 price_id = self ._get_prices_for_upgrade_option (upgrade_prices , option , value )
865870 if not price_id :
@@ -888,13 +893,13 @@ def get_instance(self, instance_id):
888893 the specified instance.
889894 """
890895 mask = [
891- 'billingItem[id,package[id,keyName]]'
896+ 'billingItem[id,package[id,keyName],nextInvoiceChildren ]'
892897 ]
893898 mask = "mask[%s]" % ',' .join (mask )
894899
895900 return self .hardware .getObject (id = instance_id , mask = mask )
896901
897- def _get_upgrade_prices (self , instance_id , include_downgrade_options = True ):
902+ def _get_upgrade_prices (self , instance_id ):
898903 """Following Method gets all the price ids related to upgrading a Hardware Server.
899904
900905 :param int instance_id: Instance id of the Hardware Server to be upgraded.
@@ -908,7 +913,7 @@ def _get_upgrade_prices(self, instance_id, include_downgrade_options=True):
908913 'item[keyName,description,capacity,units]'
909914 ]
910915 mask = "mask[%s]" % ',' .join (mask )
911- return self .hardware .getUpgradeItemPrices (include_downgrade_options , id = instance_id , mask = mask )
916+ return self .hardware .getUpgradeItemPrices (id = instance_id , mask = mask )
912917
913918 @staticmethod
914919 def _get_prices_for_upgrade_option (upgrade_prices , option , value ):
@@ -927,7 +932,10 @@ def _get_prices_for_upgrade_option(upgrade_prices, option, value):
927932 'disk_controller' : 'disk_controller' ,
928933 'bandwidth' : 'bandwidth'
929934 }
930- category_code = option_category .get (option )
935+ if 'disk' in option :
936+ category_code = option
937+ else :
938+ category_code = option_category .get (option )
931939
932940 for price in upgrade_prices :
933941 if price .get ('categories' ) is None or price .get ('item' ) is None :
@@ -953,12 +961,75 @@ def _get_prices_for_upgrade_option(upgrade_prices, option, value):
953961 elif option == 'bandwidth' :
954962 if str (product .get ('capacity' )) == str (value ):
955963 price_id = price .get ('id' )
964+ elif 'disk' in option :
965+ if str (product .get ('capacity' )) == str (value ):
966+ price_id = price
956967 else :
957968 if str (product .get ('capacity' )) == str (value ):
958969 price_id = price .get ('id' )
959970
960971 return price_id
961972
973+ def _get_disk_price_list (self , instance_id , disk ):
974+ """Get the disks prices to be added or upgraded.
975+
976+ :param int instance_id: Hardware Server instance id.
977+ :param list disk: List of disks to be added o upgraded to the HW.
978+
979+ :return list.
980+ """
981+ prices = []
982+ disk_exist = False
983+ upgrade_prices = self ._get_upgrade_prices (instance_id )
984+ server_response = self .get_instance (instance_id )
985+ for disk_data in disk :
986+ disk_channel = 'disk' + str (disk_data .get ('number' ))
987+ for item in utils .lookup (server_response , 'billingItem' , 'nextInvoiceChildren' ):
988+ if disk_channel == item ['categoryCode' ]:
989+ disk_exist = True
990+ break
991+ if disk_exist :
992+ disk_price_detail = self ._get_disk_price_detail (disk_data , upgrade_prices , disk_channel , 'add_disk' )
993+ prices .append (disk_price_detail )
994+ else :
995+ disk_price_detail = self ._get_disk_price_detail (disk_data , upgrade_prices , disk_channel , 'resize_disk' )
996+ prices .append (disk_price_detail )
997+
998+ return prices
999+
1000+ def _get_disk_price_detail (self , disk_data , upgrade_prices , disk_channel , disk_type ):
1001+ """Get the disk price detail.
1002+
1003+ :param disk_data: List of disks to be added or upgraded.
1004+ :param list upgrade_prices: List of item prices.
1005+ :param String disk_channel: Disk position.
1006+ :param String disk_type: Disk type.
1007+
1008+ """
1009+ if disk_data .get ('description' ) == disk_type :
1010+ if "add" in disk_type :
1011+ raise SoftLayerError ("Unable to add the disk because this already exists." )
1012+ if "resize" in disk_type :
1013+ raise SoftLayerError ("Unable to resize the disk because this does not exists." )
1014+ else :
1015+ price_id = self ._get_prices_for_upgrade_option (upgrade_prices , disk_channel ,
1016+ disk_data .get ('capacity' ))
1017+ if not price_id :
1018+ raise SoftLayerError ("The item price was not found for %s with 'capacity:' %i" %
1019+ (disk_channel , disk_data .get ('capacity' )))
1020+
1021+ disk_price = {
1022+ "id" : price_id .get ('id' ),
1023+ "categories" : [
1024+ {
1025+ "categoryCode" : price_id ['categories' ][0 ]['categoryCode' ],
1026+ "id" : price_id ['categories' ][0 ]['id' ]
1027+ }
1028+ ]
1029+ }
1030+
1031+ return disk_price
1032+
9621033
9631034def _get_bandwidth_key (items , hourly = True , no_public = False , location = None ):
9641035 """Picks a valid Bandwidth Item, returns the KeyName"""
0 commit comments