Skip to content

Commit 3e272e7

Browse files
committed
Update ObjectFilter usage in SoftwarePassword to accommodate the new object filters
1 parent 92fb17e commit 3e272e7

1 file changed

Lines changed: 60 additions & 105 deletions

File tree

lib/softlayer/SoftwarePassword.rb

Lines changed: 60 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def password=(password)
6565
# If no client can be found the routine will raise an error.
6666
#
6767
# You may filter the list returned by adding options:
68-
# * <b>+:datacenter+</b> (string) - Include software passwords from application delivery controllers matching this datacenter
69-
# * <b>+:name+</b> (string) - Include software passwords from application delivery controllers that matches this name
70-
# * <b>+:tags+</b> (Array) - Include software passwords from application delivery controllers that matches these tags
71-
# * <b>+:username+</b> (string) - Include software passwords that match this username
68+
# * <b>+:datacenter+</b> (string/array) - Include software passwords from application delivery controllers matching this datacenter
69+
# * <b>+:name+</b> (string/array) - Include software passwords from application delivery controllers that matches this name
70+
# * <b>+:tags+</b> (string/array - Include software passwords from application delivery controllers that matches these tags
71+
# * <b>+:username+</b> (string/array) - Include software passwords that match this username
7272
#
7373
def self.find_passwords_for_application_delivery_controllers(options_hash = {})
7474
softlayer_client = options_hash[:client] || Client.default_client
@@ -89,34 +89,27 @@ def self.find_passwords_for_application_delivery_controllers(options_hash = {})
8989
end
9090

9191
option_to_filter_path = {
92-
:advanced_mode => "applicationDeliveryControllers.advancedModeFlag",
93-
:datacenter => "applicationDeliveryControllers.datacenter.name",
94-
:name => "applicationDeliveryControllers.name",
95-
:tags => "applicationDeliveryControllers.tagReferences.tag.name",
96-
:software_password => {
92+
:app_deliv_controller => {
93+
:advanced_mode => "applicationDeliveryControllers.advancedModeFlag",
94+
:datacenter => "applicationDeliveryControllers.datacenter.name",
95+
:name => "applicationDeliveryControllers.name",
96+
:tags => "applicationDeliveryControllers.tagReferences.tag.name"
97+
},
98+
:software_password => {
9799
:username => "password.username"
98100
}
99101
}
100102

101-
application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[:advanced_mode]).when_it is(true) }
103+
application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[:app_deliv_controller][:advanced_mode]).when_it is(true) }
104+
105+
option_to_filter_path[:app_deliv_controller].each do |option, filter_path|
106+
next if option == :advanced_mode
102107

103-
[ :datacenter, :name ].each do |option|
104108
if options_hash[option]
105-
application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[option]).when_it is(options_hash[option]) }
109+
application_delivery_controller_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) }
106110
end
107111
end
108112

109-
if options_hash[:tags]
110-
application_delivery_controller_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags],
111-
{
112-
'operation' => 'in',
113-
'options' => [{
114-
'name' => 'data',
115-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
116-
}]
117-
})
118-
end
119-
120113
option_to_filter_path[:software_password].each do |option, filter_path|
121114
software_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
122115
end
@@ -150,15 +143,15 @@ def self.find_passwords_for_application_delivery_controllers(options_hash = {})
150143
# If no client can be found the routine will raise an error.
151144
#
152145
# You may filter the list returned by adding options:
153-
# * <b>+:datacenter+</b> (string) - Include software passwords from vlan firewalls matching this datacenter
154-
# * <b>+:vlan_name+</b> (Array) - Include software passwords from vlans that matches these names
155-
# * <b>+:vlan_numbers+</b> (Array) - Include software passwords from vlans that matches these numbers
156-
# * <b>+:vlan_space+</b> (symbol) - Include software passwords from vlans that match this space
157-
# * <b>+:vlan_tags+</b> (Array) - Include software passwords from vlans that matches these tags
158-
# * <b>+:vlan_fw_fqdn+</b> (string) - Include software passwords from vlan firewalls that match this fqdn
159-
# * <b>+:vlan_fw_tags+</b> (Array) - Include software passwords from vlan firewalls that matches these tags
160-
# * <b>+:vlan_fw_type+</b> (string) - Include software passwords from vlan firewalls that match this type
161-
# * <b>+:username+</b> (string) - Include software passwords that match this username
146+
# * <b>+:datacenter+</b> (string/array) - Include software passwords from vlan firewalls matching this datacenter
147+
# * <b>+:vlan_names+</b> (string/array) - Include software passwords from vlans that matches these names
148+
# * <b>+:vlan_numbers+</b> (string/array) - Include software passwords from vlans that matches these numbers
149+
# * <b>+:vlan_space+</b> (symbol) - Include software passwords from vlans that match this space
150+
# * <b>+:vlan_tags+</b> (string/array) - Include software passwords from vlans that matches these tags
151+
# * <b>+:vlan_fw_fqdn+</b> (string/array) - Include software passwords from vlan firewalls that match this fqdn
152+
# * <b>+:vlan_fw_tags+</b> (string/array) - Include software passwords from vlan firewalls that matches these tags
153+
# * <b>+:vlan_fw_type+</b> (string/array) - Include software passwords from vlan firewalls that match this type
154+
# * <b>+:username+</b> (string/array) - Include software passwords that match this username
162155
#
163156
def self.find_passwords_for_vlan_firewalls(options_hash = {})
164157
softlayer_client = options_hash[:client] || Client.default_client
@@ -195,16 +188,18 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {})
195188
:software_password => {
196189
:username => "managementCredentials.username"
197190
},
198-
:vlan_dedicated_fw => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'dedicatedFirewallFlag' ].join },
199-
:vlan_names => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'name' ].join },
200-
:vlan_numbers => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'vlanNumber' ].join },
201-
:vlan_tags => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'tagReferences.tag.name' ].join },
191+
:vlan => {
192+
:vlan_dedicated_fw => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'dedicatedFirewallFlag' ].join },
193+
:vlan_names => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'name' ].join },
194+
:vlan_numbers => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'vlanNumber' ].join },
195+
:vlan_tags => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'tagReferences.tag.name' ].join }
196+
},
202197
:vlan_firewall => {
203198
:vlan_fw_datacenter => "networkVlanFirewall.datacenter.name",
204199
:vlan_fw_fqdn => "networkVlanFirewall.fullyQualifiedDomainName",
200+
:vlan_fw_tags => "networkVlanFirewall.tagReferences.tag.name",
205201
:vlan_fw_type => "networkVlanFirewall.firewallType"
206-
},
207-
:vlan_fw_tags => "networkVlanFirewall.tagReferences.tag.name"
202+
}
208203
}
209204

210205
if options_hash[:vlan_space] && ! filter_label.keys.include?(options_hash[:vlan_space])
@@ -217,37 +212,18 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {})
217212

218213
vlan_space = options_hash[:vlan_space] || :all
219214

220-
vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan_dedicated_fw].call(vlan_space)).when_it is(1) }
221-
vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan_name].call(vlan_space)).when_it is(options_hash[:vlan_name]) } if options_hash[:vlan_name]
215+
option_to_filter_path[:vlan].keys.each do |option|
216+
vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan][option].call(vlan_space)).when_it is(1) } if option == :vlan_dedicated_fw
222217

223-
[ :vlan_names, :vlan_numbers, :vlan_tags ].each do |option|
224-
if options_hash[option]
225-
vlan_object_filter.set_criteria_for_key_path(option_to_filter_path[option].call(vlan_space),
226-
{
227-
'operation' => 'in',
228-
'options' => [{
229-
'name' => 'data',
230-
'value' => options_hash[option].collect{ |tag_value| tag_value.to_s }
231-
}]
232-
})
218+
if options_hash[option] && option != :vlan_dedicated_fw
219+
vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan][option].call(vlan_space)).when_it is(options_hash[option]) }
233220
end
234221
end
235222

236223
option_to_filter_path[:vlan_firewall].each do |option, filter_path|
237224
vlan_firewall_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
238225
end
239226

240-
if options_hash[:vlan_fw_tags]
241-
vlan_firewall_object_filter.set_criteria_for_key_path(option_to_filter_path[:vlan_fw_tags],
242-
{
243-
'operation' => 'in',
244-
'options' => [{
245-
'name' => 'data',
246-
'value' => options_hash[:vlan_fw_tags].collect{ |tag_value| tag_value.to_s }
247-
}]
248-
})
249-
end
250-
251227
account_service = softlayer_client[:Account]
252228
account_service = account_service.object_filter(vlan_object_filter) unless vlan_object_filter.empty?
253229
account_service = account_service.object_mask("mask[id]")
@@ -293,14 +269,14 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {})
293269
# If no client can be found the routine will raise an error.
294270
#
295271
# You may filter the list returned by adding options:
296-
# * <b>+:datacenter+</b> (string) - Include software passwords from software on hardware matching this datacenter
297-
# * <b>+:description+</b> (string) - Include software passwords from software that matches this description
298-
# * <b>+:domain+</b> (string) - Include software passwords from software on hardware matching this domain
299-
# * <b>+:hardware_type+</b> (string) - Include software passwords from software on hardware matching this hardware type
300-
# * <b>+:hostname+</b> (string) - Include software passwords from software on hardware matching this hostname
301-
# * <b>+:manufacturer+</b> (string) - Include software passwords from software that matches this manufacturer
302-
# * <b>+:name+</b> (string) - Include software passwords from software that matches this name
303-
# * <b>+:username+</b> (string) - Include software passwords for username matching this username
272+
# * <b>+:datacenter+</b> (string/array) - Include software passwords from software on hardware matching this datacenter
273+
# * <b>+:description+</b> (string/array) - Include software passwords from software that matches this description
274+
# * <b>+:domain+</b> (string/array) - Include software passwords from software on hardware matching this domain
275+
# * <b>+:hardware_type+</b> (symbol) - Include software passwords from software on hardware matching this hardware type
276+
# * <b>+:hostname+</b> (string/array) - Include software passwords from software on hardware matching this hostname
277+
# * <b>+:manufacturer+</b> (string/array) - Include software passwords from software that matches this manufacturer
278+
# * <b>+:name+</b> (string/array) - Include software passwords from software that matches this name
279+
# * <b>+:username+</b> (string/array) - Include software passwords for username matching this username
304280
#
305281
# You may use the following properties to provide hardware or software object filter instances:
306282
# * <b>+:hardware_object_filter+</b> (ObjectFilter) - Include software passwords from software on hardware that matches the criteria of this object filter
@@ -341,10 +317,12 @@ def self.find_passwords_for_software_on_hardware(options_hash = {})
341317
}
342318

343319
option_to_filter_path = {
344-
:datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join },
345-
:domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join },
346-
:hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join },
347-
:tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join },
320+
:hardware => {
321+
:datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join },
322+
:domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join },
323+
:hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join },
324+
:tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join }
325+
},
348326
:software => {
349327
:description => "softwareComponents.softwareDescription.longDescription",
350328
:manufacturer => "softwareComponents.softwareDescription.manufacturer",
@@ -362,23 +340,12 @@ def self.find_passwords_for_software_on_hardware(options_hash = {})
362340
end
363341
end
364342

365-
[ :datacenter, :domain, :hostname ].each do |option|
343+
option_to_filter_path[:hardware].keys.each do |option|
366344
if options_hash[option]
367-
hardware_object_filter.modify { |filter| filter.accept(option_to_filter_path[option].call(options_hash[:hardware_type] || :hardware)).when_it is(options_hash[option]) }
345+
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]) }
368346
end
369347
end
370348

371-
if options_hash[:tags]
372-
hardware_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(options_hash[:hardware_type] || :hardware),
373-
{
374-
'operation' => 'in',
375-
'options' => [{
376-
'name' => 'data',
377-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
378-
}]
379-
})
380-
end
381-
382349
option_to_filter_path[:software].each do |option, filter_path|
383350
software_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
384351
end
@@ -436,13 +403,13 @@ def self.find_passwords_for_software_on_hardware(options_hash = {})
436403
# If no client can be found the routine will raise an error.
437404
#
438405
# You may filter the list returned by adding options:
439-
# * <b>+:datacenter+</b> (string) - Include software passwords from software on virtual servers matching this datacenter
440-
# * <b>+:description+</b> (string) - Include software passwords from software that matches this description
441-
# * <b>+:domain+</b> (string) - Include software passwords from software on virtual servers matching this domain
442-
# * <b>+:hostname+</b> (string) - Include software passwords from software on virtual servers matching this hostname
443-
# * <b>+:manufacturer+</b> (string) - Include software passwords from software that matches this manufacturer
444-
# * <b>+:name+</b> (string) - Include software passwords from software that matches this name
445-
# * <b>+:username+</b> (string) - Include software passwords for username matching this username
406+
# * <b>+:datacenter+</b> (string/array) - Include software passwords from software on virtual servers matching this datacenter
407+
# * <b>+:description+</b> (string/array) - Include software passwords from software that matches this description
408+
# * <b>+:domain+</b> (string/array) - Include software passwords from software on virtual servers matching this domain
409+
# * <b>+:hostname+</b> (string/array) - Include software passwords from software on virtual servers matching this hostname
410+
# * <b>+:manufacturer+</b> (string/array) - Include software passwords from software that matches this manufacturer
411+
# * <b>+:name+</b> (string/array) - Include software passwords from software that matches this name
412+
# * <b>+:username+</b> (string/array) - Include software passwords for username matching this username
446413
#
447414
# You may use the following properties to provide virtual server or software object filter instances:
448415
# * <b>+:virtual_server_object_filter+</b> (ObjectFilter) - Include software passwords from software on virtual servers that matches the criteria of this object filter
@@ -493,19 +460,7 @@ def self.find_passwords_for_software_on_virtual_servers(options_hash = {})
493460
}
494461
}
495462

496-
if options_hash[:tags]
497-
virtual_server_object_filter.set_criteria_for_key_path(option_to_filter_path[:virtual_server][:tags],
498-
{
499-
'operation' => 'in',
500-
'options' => [{
501-
'name' => 'data',
502-
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
503-
}]
504-
})
505-
end
506-
507463
option_to_filter_path[:virtual_server].each do |option, filter_path|
508-
next if option == :tags
509464
virtual_server_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
510465
end
511466

0 commit comments

Comments
 (0)