1818
1919LOGGER = logging .getLogger (__name__ )
2020
21-
22- # pylint: disable=no-self-use
21+ # pylint: disable=no-self-use,too-many-lines
2322
2423
2524class VSManager (utils .IdentifierMixin , object ):
@@ -664,12 +663,10 @@ def change_port_speed(self, instance_id, public, speed):
664663 A port speed of 0 will disable the interface.
665664 """
666665 if public :
667- return self .client .call ('Virtual_Guest' ,
668- 'setPublicNetworkInterfaceSpeed' ,
666+ return self .client .call ('Virtual_Guest' , 'setPublicNetworkInterfaceSpeed' ,
669667 speed , id = instance_id )
670668 else :
671- return self .client .call ('Virtual_Guest' ,
672- 'setPrivateNetworkInterfaceSpeed' ,
669+ return self .client .call ('Virtual_Guest' , 'setPrivateNetworkInterfaceSpeed' ,
673670 speed , id = instance_id )
674671
675672 def _get_ids_from_hostname (self , hostname ):
@@ -784,10 +781,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
784781 continue
785782
786783 # We never want swap devices
787- type_name = utils .lookup (block_device ,
788- 'diskImage' ,
789- 'type' ,
790- 'keyName' )
784+ type_name = utils .lookup (block_device , 'diskImage' , 'type' , 'keyName' )
791785 if type_name == 'SWAP' :
792786 continue
793787
@@ -804,8 +798,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
804798 return self .guest .createArchiveTransaction (
805799 name , disks_to_capture , notes , id = instance_id )
806800
807- def upgrade (self , instance_id , cpus = None , memory = None ,
808- nic_speed = None , public = True , preset = None ):
801+ def upgrade (self , instance_id , cpus = None , memory = None , nic_speed = None , public = True , preset = None ):
809802 """Upgrades a VS instance.
810803
811804 Example::
@@ -832,17 +825,16 @@ def upgrade(self, instance_id, cpus=None, memory=None,
832825 data = {'nic_speed' : nic_speed }
833826
834827 if cpus is not None and preset is not None :
835- raise exceptions . SoftLayerError ("Do not use cpu, private and memory if you are using flavors" )
828+ raise ValueError ("Do not use cpu, private and memory if you are using flavors" )
836829 data ['cpus' ] = cpus
837830
838831 if memory is not None and preset is not None :
839- raise exceptions . SoftLayerError ("Do not use memory, private or cpu if you are using flavors" )
832+ raise ValueError ("Do not use memory, private or cpu if you are using flavors" )
840833 data ['memory' ] = memory
841834
842835 maintenance_window = datetime .datetime .now (utils .UTC ())
843836 order = {
844- 'complexType' : 'SoftLayer_Container_Product_Order_Virtual_Guest_'
845- 'Upgrade' ,
837+ 'complexType' : 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade' ,
846838 'properties' : [{
847839 'name' : 'MAINTENANCE_WINDOW' ,
848840 'value' : maintenance_window .strftime ("%Y-%m-%d %H:%M:%S%z" )
@@ -874,6 +866,59 @@ def upgrade(self, instance_id, cpus=None, memory=None,
874866 return True
875867 return False
876868
869+ def order_guest (self , guest_object , test = False ):
870+ """Uses Product_Order::placeOrder to create a virtual guest.
871+
872+ Useful when creating a virtual guest with options not supported by Virtual_Guest::createObject
873+ specifically ipv6 support.
874+
875+ :param dictionary guest_object: See SoftLayer.CLI.virt.create._parse_create_args
876+
877+ Example::
878+ new_vsi = {
879+ 'domain': u'test01.labs.sftlyr.ws',
880+ 'hostname': u'minion05',
881+ 'datacenter': u'hkg02',
882+ 'flavor': 'BL1_1X2X100'
883+ 'dedicated': False,
884+ 'private': False,
885+ 'os_code' : u'UBUNTU_LATEST',
886+ 'hourly': True,
887+ 'ssh_keys': [1234],
888+ 'disks': ('100','25'),
889+ 'local_disk': True,
890+ 'tags': 'test, pleaseCancel',
891+ 'public_security_groups': [12, 15],
892+ 'ipv6': True
893+ }
894+
895+ vsi = mgr.order_guest(new_vsi)
896+ # vsi will have the newly created vsi receipt.
897+ # vsi['orderDetails']['virtualGuests'] will be an array of created Guests
898+ print vsi
899+ """
900+ tags = guest_object .pop ('tags' , None )
901+ template = self .verify_create_instance (** guest_object )
902+
903+ if guest_object .get ('ipv6' ):
904+ ipv6_price = self .ordering_manager .get_price_id_list ('PUBLIC_CLOUD_SERVER' , ['1_IPV6_ADDRESS' ])
905+ template ['prices' ].append ({'id' : ipv6_price [0 ]})
906+
907+ # Notice this is `userdata` from the cli, but we send it in as `userData`
908+ if guest_object .get ('userdata' ):
909+ # SL_Virtual_Guest::generateOrderTemplate() doesn't respect userData, so we need to add it ourself
910+ template ['virtualGuests' ][0 ]['userData' ] = [{"value" : guest_object .get ('userdata' )}]
911+
912+ if test :
913+ result = self .client .call ('Product_Order' , 'verifyOrder' , template )
914+ else :
915+ result = self .client .call ('Product_Order' , 'placeOrder' , template )
916+ if tags is not None :
917+ virtual_guests = utils .lookup (result , 'orderDetails' , 'virtualGuests' )
918+ for guest in virtual_guests :
919+ self .set_tags (tags , guest_id = guest ['id' ])
920+ return result
921+
877922 def _get_package_items (self ):
878923 """Following Method gets all the item ids related to VS.
879924
0 commit comments