@@ -51,6 +51,7 @@ def __init__(self, client, ordering_manager=None):
5151 self .client = client
5252 self .account = client ['Account' ]
5353 self .guest = client ['Virtual_Guest' ]
54+ self .package_svc = client ['Product_Package' ]
5455 self .resolvers = [self ._get_ids_from_ip , self ._get_ids_from_hostname ]
5556 if ordering_manager is None :
5657 self .ordering_manager = ordering .OrderingManager (client )
@@ -209,6 +210,7 @@ def get_instance(self, instance_id, **kwargs):
209210 'maxMemory,'
210211 'datacenter,'
211212 'activeTransaction[id, transactionStatus[friendlyName,name]],'
213+ 'lastTransaction[transactionStatus],'
212214 'lastOperatingSystemReload.id,'
213215 'blockDevices,'
214216 'blockDeviceTemplateGroup[id, name, globalIdentifier],'
@@ -225,6 +227,7 @@ def get_instance(self, instance_id, **kwargs):
225227 'hourlyBillingFlag,'
226228 'userData,'
227229 '''billingItem[id,nextInvoiceTotalRecurringAmount,
230+ package[id,keyName],
228231 children[categoryCode,nextInvoiceTotalRecurringAmount],
229232 orderItem[id,
230233 order.userRecord[username],
@@ -803,7 +806,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
803806 name , disks_to_capture , notes , id = instance_id )
804807
805808 def upgrade (self , instance_id , cpus = None , memory = None ,
806- nic_speed = None , public = True ):
809+ nic_speed = None , public = True , preset = None ):
807810 """Upgrades a VS instance.
808811
809812 Example::
@@ -817,6 +820,7 @@ def upgrade(self, instance_id, cpus=None, memory=None,
817820 :param int instance_id: Instance id of the VS to be upgraded
818821 :param int cpus: The number of virtual CPUs to upgrade to
819822 of a VS instance.
823+ :param string preset: preset assigned to the vsi
820824 :param int memory: RAM of the VS to be upgraded to.
821825 :param int nic_speed: The port speed to set
822826 :param bool public: CPU will be in Private/Public Node.
@@ -826,9 +830,28 @@ def upgrade(self, instance_id, cpus=None, memory=None,
826830 upgrade_prices = self ._get_upgrade_prices (instance_id )
827831 prices = []
828832
829- for option , value in {'cpus' : cpus ,
830- 'memory' : memory ,
831- 'nic_speed' : nic_speed }.items ():
833+ data = {'nic_speed' : nic_speed }
834+
835+ if cpus is not None and preset is not None :
836+ raise exceptions .SoftLayerError ("Do not use cpu, private and memory if you are using flavors" )
837+ data ['cpus' ] = cpus
838+
839+ if memory is not None and preset is not None :
840+ raise exceptions .SoftLayerError ("Do not use memory, private or cpu if you are using flavors" )
841+ data ['memory' ] = memory
842+
843+ maintenance_window = datetime .datetime .now (utils .UTC ())
844+ order = {
845+ 'complexType' : 'SoftLayer_Container_Product_Order_Virtual_Guest_'
846+ 'Upgrade' ,
847+ 'properties' : [{
848+ 'name' : 'MAINTENANCE_WINDOW' ,
849+ 'value' : maintenance_window .strftime ("%Y-%m-%d %H:%M:%S%z" )
850+ }],
851+ 'virtualGuests' : [{'id' : int (instance_id )}],
852+ }
853+
854+ for option , value in data .items ():
832855 if not value :
833856 continue
834857 price_id = self ._get_price_id_for_upgrade_option (upgrade_prices ,
@@ -841,19 +864,13 @@ def upgrade(self, instance_id, cpus=None, memory=None,
841864 "Unable to find %s option with value %s" % (option , value ))
842865
843866 prices .append ({'id' : price_id })
867+ order ['prices' ] = prices
844868
845- maintenance_window = datetime .datetime .now (utils .UTC ())
846- order = {
847- 'complexType' : 'SoftLayer_Container_Product_Order_Virtual_Guest_'
848- 'Upgrade' ,
849- 'prices' : prices ,
850- 'properties' : [{
851- 'name' : 'MAINTENANCE_WINDOW' ,
852- 'value' : maintenance_window .strftime ("%Y-%m-%d %H:%M:%S%z" )
853- }],
854- 'virtualGuests' : [{'id' : int (instance_id )}],
855- }
856- if prices :
869+ if preset is not None :
870+ vs_object = self .get_instance (instance_id )['billingItem' ]['package' ]
871+ order ['presetId' ] = self .ordering_manager .get_preset_by_key (vs_object ['keyName' ], preset )['id' ]
872+
873+ if prices or preset :
857874 self .client ['Product_Order' ].placeOrder (order )
858875 return True
859876 return False
0 commit comments