@@ -111,8 +111,9 @@ class BareMetalServerOrder
111111
112112 ##
113113 # Create a new order that works thorugh the given client connection
114- def initialize ( client )
115- @softlayer_client = client
114+ def initialize ( client = nil )
115+ @softlayer_client = client || Client . default_client
116+ raise "#{ __method__ } requires a client but none was given and Client::default_client is not set" if !@softlayer_client
116117 end
117118
118119 ##
@@ -141,7 +142,7 @@ def place_order!()
141142 order_template = yield order_template if block_given?
142143
143144 server_hash = @softlayer_client [ "Hardware" ] . createObject ( order_template )
144- SoftLayer ::BareMetalServer . server_with_id ( @softlayer_client , server_hash [ "id" ] ) if server_hash
145+ SoftLayer ::BareMetalServer . server_with_id ( server_hash [ "id" ] , :client => @softlayer_client ) if server_hash
145146 end
146147
147148 protected
@@ -185,35 +186,40 @@ def hardware_instance_template
185186 ##
186187 # The first time this is called it requests SoftLayer_Hardware::getCreateObjectOptions
187188 # from the API and remembers the result. On subsequent calls it returns the remembered result.
188- def self . create_object_options ( client )
189- @@create_object_options ||= client [ "Hardware" ] . getCreateObjectOptions ( )
189+ def self . create_object_options ( client = nil )
190+ softlayer_client = client || Client . default_client
191+ raise "#{ __method__ } requires a client but none was given and Client::default_client is not set" if !softlayer_client
192+
193+ @@create_object_options ||= nil
194+ @@create_object_options = softlayer_client [ "Hardware" ] . getCreateObjectOptions ( ) if !@@create_object_options
195+ @@create_object_options
190196 end
191197
192198 ##
193199 # Return a list of values that are valid for the :datacenter attribute
194- def self . datacenter_options ( client )
200+ def self . datacenter_options ( client = nil )
195201 create_object_options ( client ) [ "datacenters" ] . collect { |datacenter_spec | datacenter_spec [ 'template' ] [ 'datacenter' ] [ "name" ] } . uniq . sort!
196202 end
197203
198- def self . core_options ( client )
204+ def self . core_options ( client = nil )
199205 create_object_options ( client ) [ "processors" ] . collect { |processor_spec | processor_spec [ 'template' ] [ 'processorCoreAmount' ] } . uniq . sort!
200206 end
201207
202208 ##
203209 # Return a list of values that are valid the array given to the :disks
204- def self . disk_options ( client )
210+ def self . disk_options ( client = nil )
205211 create_object_options ( client ) [ "hardDrives" ] . collect { |disk_spec | disk_spec [ 'template' ] [ 'hardDrives' ] [ 0 ] [ 'capacity' ] . to_i } . uniq . sort!
206212 end
207213
208214 ##
209215 # Returns a list of the valid :os_refrence_codes
210- def self . os_reference_code_options ( client )
216+ def self . os_reference_code_options ( client = nil )
211217 create_object_options ( client ) [ "operatingSystems" ] . collect { |os_spec | os_spec [ 'template' ] [ 'operatingSystemReferenceCode' ] } . uniq . sort!
212218 end
213219
214220 ##
215221 # Returns a list of the :max_port_speeds
216- def self . max_port_speed_options ( client )
222+ def self . max_port_speed_options ( client = nil )
217223 create_object_options ( client ) [ "networkComponents" ] . collect { |component_spec | component_spec [ 'template' ] [ 'networkComponents' ] [ 0 ] [ 'maxSpeed' ] }
218224 end
219225
0 commit comments