Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 31 additions & 49 deletions lib/softlayer/AccountPassword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def password=(password)
# If no client can be found the routine will raise an error.
#
# You may filter the list returned by adding options:
# * <b>+:datacenter+</b> (string) - Include network storage account passwords from servers matching this datacenter
# * <b>+:domain+</b> (string) - Include network storage account passwords from servers matching this domain
# * <b>+:hostname+</b> (string) - Include network storage account passwords from servers matching this hostname
# * <b>+:network_storage_server_type+</b> (string) - Include network storage account passwords attached to this server type
# * <b>+:network_storage_type+</b> (string) - Include network storage account passwords from devices of this storage type
# * <b>+:tags+</b> (Array) - Include network storage account passwords from servers matching these tags
# * <b>+:username+</b> (string) - Include network storage account passwords with this username only
# * <b>+:datacenter+</b> (string/array) - Include network storage account passwords from servers matching this datacenter
# * <b>+:domain+</b> (string/array) - Include network storage account passwords from servers matching this domain
# * <b>+:hostname+</b> (string/array) - Include network storage account passwords from servers matching this hostname
# * <b>+:network_storage_server_type+</b> (string) - Include network storage account passwords attached to this server type
# * <b>+:network_storage_type+</b> (string) - Include network storage account passwords from devices of this storage type
# * <b>+:tags+</b> (string/array) - Include network storage account passwords from servers matching these tags
# * <b>+:username+</b> (string/array) - Include network storage account passwords with this username only
#
def self.find_network_storage_account_passwords(options_hash = {})
softlayer_client = options_hash[:client] || Client.default_client
Expand Down Expand Up @@ -119,10 +119,12 @@ def self.find_network_storage_account_passwords(options_hash = {})
:account_password => {
:username => "accountPassword.username"
},
:datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
:domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
:hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
:tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join }
:network_storage => {
:datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
:domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
:hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
:tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join }
}
}

if options_hash[:network_storage_type]
Expand All @@ -134,24 +136,13 @@ def self.find_network_storage_account_passwords(options_hash = {})
if options_hash[:network_storage_server_type]
network_storage_type = options_hash[:network_storage_type] || :network_storage

[ :datacenter, :domain, :hostname ].each do |option|
option_to_filter_path[:network_storage].keys.each do |option|
if options_hash[option]
network_storage_object_filter.modify do |filter|
filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
filter.accept(option_to_filter_path[:network_storage][option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
end
end
end

if options_hash[:tags]
network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
{
'operation' => 'in',
'options' => [{
'name' => 'data',
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
}]
})
end
end

option_to_filter_path[:account_password].each do |option, filter_path|
Expand Down Expand Up @@ -201,13 +192,13 @@ def self.find_network_storage_account_passwords(options_hash = {})
# If no client can be found the routine will raise an error.
#
# You may filter the list returned by adding options:
# * <b>+:datacenter+</b> (string) - Include network storage webcc passwords from servers matching this datacenter
# * <b>+:domain+</b> (string) - Include network storage webcc passwords from servers matching this domain
# * <b>+:hostname+</b> (string) - Include network storage webcc passwords from servers matching this hostname
# * <b>+:network_storage_server_type+</b> (string) - Include network storage webcc passwords attached to this server type
# * <b>+:network_storage_type+</b> (string) - Include network storage webcc passwords from devices of this storage type
# * <b>+:tags+</b> (Array) - Include network storage webcc passwords from servers matching these tags
# * <b>+:username+</b> (string) - Include network storage webcc passwords with this username only
# * <b>+:datacenter+</b> (string/array) - Include network storage webcc passwords from servers matching this datacenter
# * <b>+:domain+</b> (string/array) - Include network storage webcc passwords from servers matching this domain
# * <b>+:hostname+</b> (string/array) - Include network storage webcc passwords from servers matching this hostname
# * <b>+:network_storage_server_type+</b> (string) - Include network storage webcc passwords attached to this server type
# * <b>+:network_storage_type+</b> (string) - Include network storage webcc passwords from devices of this storage type
# * <b>+:tags+</b> (string/array) - Include network storage webcc passwords from servers matching these tags
# * <b>+:username+</b> (string/array) - Include network storage webcc passwords with this username only
#
def self.find_network_storage_webcc_passwords(options_hash = {})
softlayer_client = options_hash[:client] || Client.default_client
Expand Down Expand Up @@ -243,11 +234,13 @@ def self.find_network_storage_webcc_passwords(options_hash = {})
}

option_to_filter_path = {
:datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
:domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
:hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
:tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join },
:webcc_password => {
:network_storage => {
:datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
:domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
:hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
:tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join }
},
:webcc_password => {
:username => "webccAccount.username"
}
}
Expand All @@ -261,24 +254,13 @@ def self.find_network_storage_webcc_passwords(options_hash = {})
if options_hash[:network_storage_server_type]
network_storage_type = options_hash[:network_storage_type] || :network_storage

[ :datacenter, :domain, :hostname ].each do |option|
option_to_filter_path[:network_storage].keys.each do |option|
if options_hash[option]
network_storage_object_filter.modify do |filter|
filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
filter.accept(option_to_filter_path[:network_storage][option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
end
end
end

if options_hash[:tags]
network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
{
'operation' => 'in',
'options' => [{
'name' => 'data',
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
}]
})
end
end

option_to_filter_path[:webcc_password].each do |option, filter_path|
Expand Down
44 changes: 17 additions & 27 deletions lib/softlayer/BareMetalServer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ def self.server_with_id(server_id, options = {})
#
# You may filter the list returned by adding options:
#
# * <b>+:tags+</b> (array) - an array of strings representing tags to search for on the instances
# * <b>+:cpus+</b> (int) - return servers with the given number of (virtual) CPUs
# * <b>+:memory+</b> (int) - return servers with at least the given amount of memory (in Gigabytes)
# * <b>+:hostname+</b> (string) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:domain+</b> (string) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:datacenter+</b> (string) - find servers whose data center name matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:nic_speed+</b> (int) - include servers with the given nic speed (in Mbps)
# * <b>+:public_ip+</b> (string) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:private_ip+</b> (string) - same as :public_ip, but for private IP addresses
# * <b>+:tags+</b> (string/array) - an array of strings representing tags to search for on the instances
# * <b>+:cpus+</b> (int/array) - return servers with the given number of (virtual) CPUs
# * <b>+:memory+</b> (int/array) - return servers with at least the given amount of memory (in Gigabytes)
# * <b>+:hostname+</b> (string/array) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:domain+</b> (string/array) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:datacenter+</b> (string/array) - find servers whose data center name matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:nic_speed+</b> (int/array) - include servers with the given nic speed (in Mbps)
# * <b>+:public_ip+</b> (string/array) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation)
# * <b>+:private_ip+</b> (string/array) - same as :public_ip, but for private IP addresses
#
# Additionally you may provide options related to the request itself:
#
Expand All @@ -210,14 +210,15 @@ def self.find_servers(options_hash = {})
end

option_to_filter_path = {
:cpus => "hardware.processorPhysicalCoreAmount",
:memory => "hardware.memoryCapacity",
:hostname => "hardware.hostname",
:domain => "hardware.domain",
:cpus => "hardware.processorPhysicalCoreAmount",
:memory => "hardware.memoryCapacity",
:hostname => "hardware.hostname",
:domain => "hardware.domain",
:datacenter => "hardware.datacenter.name",
:nic_speed => "hardware.networkComponents.maxSpeed",
:public_ip => "hardware.primaryIpAddress",
:private_ip => "hardware.primaryBackendIpAddress"
:nic_speed => "hardware.networkComponents.maxSpeed",
:public_ip => "hardware.primaryIpAddress",
:private_ip => "hardware.primaryBackendIpAddress",
:tags => "hardware.tagReferences.tag.name"
}

# For each of the options in the option_to_filter_path map, if the options hash includes
Expand All @@ -227,17 +228,6 @@ def self.find_servers(options_hash = {})
object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option])} if options_hash[option]
end

# Tags get a much more complex object filter operation so we handle them separately
if options_hash.has_key?(:tags)
object_filter.set_criteria_for_key_path("hardware.tagReferences.tag.name", {
'operation' => 'in',
'options' => [{
'name' => 'data',
'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
}]
} );
end

account_service = softlayer_client[:Account]
account_service = account_service.object_filter(object_filter) unless object_filter.empty?
account_service = account_service.object_mask(default_object_mask.to_sl_object_mask)
Expand Down
Loading