Skip to content

Commit 2503599

Browse files
committed
Update ObjectFilter usage in VirtualServer to accommodate the new object filters
1 parent b17b18f commit 2503599

1 file changed

Lines changed: 20 additions & 30 deletions

File tree

lib/softlayer/VirtualServer.rb

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,18 @@ def self.server_with_id(server_id, options = {})
187187
# If no client can be found the routine will raise an error.
188188
#
189189
# You may filter the list returned by adding options:
190-
# * <b>+:hourly+</b> (boolean) - Include servers billed hourly in the list
191-
# * <b>+:monthly+</b> (boolean) - Include servers billed monthly in the list
192-
# * <b>+:tags+</b> (array) - an array of strings representing tags to search for on the instances
193-
# * <b>+:cpus+</b> (int) - return virtual servers with the given number of (virtual) CPUs
194-
# * <b>+:memory+</b> (int) - return servers with at least the given amount of memory (in MB. e.g. 4096 = 4GB)
195-
# * <b>+:hostname+</b> (string) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation)
196-
# * <b>+:domain+</b> (string) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation)
197-
# * <b>+:local_disk+</b> (boolean) - include servers that do, or do not, have local disk storage
198-
# * <b>+:datacenter+</b> (string) - find servers whose short data center name (e.g. dal05, sjc01) matches the query string given (see ObjectFilter::query_to_filter_operation)
199-
# * <b>+:nic_speed+</b> (int) - include servers with the given nic speed (in Mbps, usually 10, 100, or 1000)
200-
# * <b>+:public_ip+</b> (string) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation)
201-
# * <b>+:private_ip+</b> (string) - same as :public_ip, but for private IP addresses
190+
# * <b>+:hourly+</b> (boolean) - Include servers billed hourly in the list
191+
# * <b>+:monthly+</b> (boolean) - Include servers billed monthly in the list
192+
# * <b>+:tags+</b> (string/array) - an array of strings representing tags to search for on the instances
193+
# * <b>+:cpus+</b> (int/array) - return virtual servers with the given number of (virtual) CPUs
194+
# * <b>+:memory+</b> (int/array) - return servers with at least the given amount of memory (in MB. e.g. 4096 = 4GB)
195+
# * <b>+:hostname+</b> (string/array) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation)
196+
# * <b>+:domain+</b> (string/array) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation)
197+
# * <b>+:local_disk+</b> (boolean) - include servers that do, or do not, have local disk storage
198+
# * <b>+:datacenter+</b> (string/array) - find servers whose short data center name (e.g. dal05, sjc01) matches the query string given (see ObjectFilter::query_to_filter_operation)
199+
# * <b>+:nic_speed+</b> (int/array) - include servers with the given nic speed (in Mbps, usually 10, 100, or 1000)
200+
# * <b>+:public_ip+</b> (string/array) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation)
201+
# * <b>+:private_ip+</b> (string/array) - same as :public_ip, but for private IP addresses
202202
#
203203
# Additionally you may provide options related to the request itself:
204204
# * <b>+:object_mask+</b> (string) - A object mask of properties, in addition to the default properties, that you wish to retrieve for the servers
@@ -216,15 +216,16 @@ def self.find_servers(options_hash = {})
216216
end
217217

218218
option_to_filter_path = {
219-
:cores => "virtualGuests.maxCpu",
220-
:memory => "virtualGuests.maxMemory",
221-
:hostname => "virtualGuests.hostname",
222-
:domain => "virtualGuests.domain",
219+
:cores => "virtualGuests.maxCpu",
220+
:memory => "virtualGuests.maxMemory",
221+
:hostname => "virtualGuests.hostname",
222+
:domain => "virtualGuests.domain",
223223
:local_disk => "virtualGuests.localDiskFlag",
224224
:datacenter => "virtualGuests.datacenter.name",
225-
:nic_speed => "virtualGuests.networkComponents.maxSpeed",
226-
:public_ip => "virtualGuests.primaryIpAddress",
227-
:private_ip => "virtualGuests.primaryBackendIpAddress"
225+
:nic_speed => "virtualGuests.networkComponents.maxSpeed",
226+
:public_ip => "virtualGuests.primaryIpAddress",
227+
:private_ip => "virtualGuests.primaryBackendIpAddress",
228+
:tags => "virtualGuests.tagReferences.tag.name"
228229
}
229230

230231
if options_hash.has_key?(:local_disk) then
@@ -238,17 +239,6 @@ def self.find_servers(options_hash = {})
238239
object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option])} if options_hash[option]
239240
end
240241

241-
# Tags get a much more complex object filter operation so we handle them separately
242-
if options_hash.has_key?(:tags)
243-
object_filter.set_criteria_for_key_path("virtualGuests.tagReferences.tag.name", {
244-
'operation' => 'in',
245-
'options' => [{
246-
'name' => 'data',
247-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
248-
}]
249-
} );
250-
end
251-
252242
required_properties_mask = 'mask.id'
253243

254244
account_service = softlayer_client[:Account]

0 commit comments

Comments
 (0)