Skip to content

Commit 92fb17e

Browse files
committed
Update ObjectFilter usage in Software to accommodate the new object filters
1 parent 0f62dfd commit 92fb17e

1 file changed

Lines changed: 23 additions & 44 deletions

File tree

lib/softlayer/Software.rb

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ def has_user_password?(username)
127127
# If no client can be found the routine will raise an error.
128128
#
129129
# You may filter the list returned by adding options:
130-
# * <b>+:datacenter+</b> (string) - Include software from hardware matching this datacenter
131-
# * <b>+:description+</b> (string) - Include software that matches this description
132-
# * <b>+:domain+</b> (string) - Include software from hardware matching this domain
133-
# * <b>+:hardware_type+</b> (string) - Include software from hardware matching this hardware type
134-
# * <b>+:hostname+</b> (string) - Include software from hardware matching this hostname
135-
# * <b>+:manufacturer+</b> (string) - Include software that matches this manufacturer
136-
# * <b>+:name+</b> (string) - Include software that matches this name
137-
# * <b>+:username+</b> (string) - Include software that has software password matching this username
130+
# * <b>+:datacenter+</b> (string/array) - Include software from hardware matching this datacenter
131+
# * <b>+:description+</b> (string/array) - Include software that matches this description
132+
# * <b>+:domain+</b> (string/array) - Include software from hardware matching this domain
133+
# * <b>+:hardware_type+</b> (symbol) - Include software from hardware matching this hardware type
134+
# * <b>+:hostname+</b> (string/array) - Include software from hardware matching this hostname
135+
# * <b>+:manufacturer+</b> (string/array) - Include software that matches this manufacturer
136+
# * <b>+:name+</b> (string/array) - Include software that matches this name
137+
# * <b>+:username+</b> (string/array) - Include software that has software password matching this username
138138
#
139139
# You may use the following properties to provide hardware or software object filter instances:
140140
# * <b>+:hardware_object_filter+</b> (ObjectFilter) - Include software from hardware that matches the criteria of this object filter
@@ -167,10 +167,12 @@ def self.find_software_on_hardware(options_hash = {})
167167
}
168168

169169
option_to_filter_path = {
170-
:datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join },
171-
:domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join },
172-
:hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join },
173-
:tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join },
170+
:hardware => {
171+
:datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join },
172+
:domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join },
173+
:hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join },
174+
:tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join }
175+
},
174176
:software => {
175177
:description => "softwareComponents.softwareDescription.longDescription",
176178
:manufacturer => "softwareComponents.softwareDescription.manufacturer",
@@ -185,23 +187,12 @@ def self.find_software_on_hardware(options_hash = {})
185187
end
186188
end
187189

188-
[ :datacenter, :domain, :hostname ].each do |option|
190+
option_to_filter_path[:hardware].keys.each do |option|
189191
if options_hash[option]
190-
hardware_object_filter.modify { |filter| filter.accept(option_to_filter_path[option].call(options_hash[:hardware_type] || :hardware)).when_it is(options_hash[option]) }
192+
hardware_object_filter.modify { |filter| filter.accept(option_to_filter_path[:hardware][option].call(options_hash[:hardware_type] || :hardware)).when_it is(options_hash[option]) }
191193
end
192194
end
193195

194-
if options_hash[:tags]
195-
hardware_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(options_hash[:hardware_type] || :hardware),
196-
{
197-
'operation' => 'in',
198-
'options' => [{
199-
'name' => 'data',
200-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
201-
}]
202-
})
203-
end
204-
205196
option_to_filter_path[:software].each do |option, filter_path|
206197
software_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
207198
end
@@ -245,13 +236,13 @@ def self.find_software_on_hardware(options_hash = {})
245236
# If no client can be found the routine will raise an error.
246237
#
247238
# You may filter the list returned by adding options:
248-
# * <b>+:datacenter+</b> (string) - Include software from virtual servers matching this datacenter
249-
# * <b>+:description+</b> (string) - Include software that matches this description
250-
# * <b>+:domain+</b> (string) - Include software from virtual servers matching this domain
251-
# * <b>+:hostname+</b> (string) - Include software from virtual servers matching this hostname
252-
# * <b>+:manufacturer+</b> (string) - Include software that matches this manufacturer
253-
# * <b>+:name+</b> (string) - Include software that matches this name
254-
# * <b>+:username+</b> (string) - Include software that has software password matching this username
239+
# * <b>+:datacenter+</b> (string/array) - Include software from virtual servers matching this datacenter
240+
# * <b>+:description+</b> (string/array) - Include software that matches this description
241+
# * <b>+:domain+</b> (string/array) - Include software from virtual servers matching this domain
242+
# * <b>+:hostname+</b> (string/array) - Include software from virtual servers matching this hostname
243+
# * <b>+:manufacturer+</b> (string/array) - Include software that matches this manufacturer
244+
# * <b>+:name+</b> (string/array) - Include software that matches this name
245+
# * <b>+:username+</b> (string/array) - Include software that has software password matching this username
255246
#
256247
# You may use the following properties to provide virtual server or software object filter instances:
257248
# * <b>+:virtual_server_object_filter+</b> (ObjectFilter) - Include software from virtual servers that matches the criteria of this object filter
@@ -291,19 +282,7 @@ def self.find_software_on_virtual_servers(options_hash = {})
291282
}
292283
}
293284

294-
if options_hash[:tags]
295-
virtual_server_object_filter.set_criteria_for_key_path(option_to_filter_path[:virtual_server][:tags],
296-
{
297-
'operation' => 'in',
298-
'options' => [{
299-
'name' => 'data',
300-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
301-
}]
302-
})
303-
end
304-
305285
option_to_filter_path[:virtual_server].each do |option, filter_path|
306-
next if option == :tags
307286
virtual_server_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
308287
end
309288

0 commit comments

Comments
 (0)