From db8a31735077f8ffa06980cb7065602a39d135fe Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 10:46:50 -0400 Subject: [PATCH 01/12] Add is_contained_by, is_not_contained_by, and is_between_dates ObjectFilter helpers --- lib/softlayer/ObjectFilter.rb | 54 +++++++++++++++++++++++++++++++++-- lib/softlayer_api.rb | 1 + 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/softlayer/ObjectFilter.rb b/lib/softlayer/ObjectFilter.rb index 791876a..4b07ddd 100644 --- a/lib/softlayer/ObjectFilter.rb +++ b/lib/softlayer/ObjectFilter.rb @@ -125,14 +125,16 @@ def when_it(criteria) module ObjectFilterDefinitionContext # Matches when the value in the field is exactly equal to the # given value. This is a case-sensitive match + # If value is Enumerable, it is equivalent to calling is_contained_by def self.is(value) - { 'operation' => value } + value.kind_of?(Enumerable) ? is_contained_by(value) : { 'operation' => value } end # Matches is the value in the field does not exactly equal # the value passed in. + # If value is Enumerable, it is equivalent to calling is_not_contained_by def self.is_not(value) - filter_criteria('!=', value) + value.kind_of?(Enumerable) ? is_not_contained_by(value) : filter_criteria('!=', value) end # Matches when the value is found within the field @@ -158,6 +160,54 @@ def self.matches_ignoring_case(value) filter_criteria('_=', value) end + # Matches when the key path value is a date between the start and end dates provided + # Dates should be strings in '%m/%d/%Y %T' format or Date/DateTime instances + def self.is_between_dates(start_date, end_date) + { + 'operation' => 'betweenDate', + 'options' => [ + { + 'name' => 'startDate', + 'value' => [ start_date.kind_of?(Date) ? start_date.strftime('%m/%d/%Y %T') : DateTime.strptime(start_date.to_s, '%m/%d/%Y %T').strftime('%m/%d/%Y %T') ] + }, + { + 'name' => 'endDate', + 'value' => [ end_date.kind_of?(Date) ? end_date.strftime('%m/%d/%Y %T') : DateTime.strptime(end_date.to_s, '%m/%d/%Y %T').strftime('%m/%d/%Y %T') ] + } + ] + } + end + + # Matches when key path value is equal to one of the given values in the Enumarable + def self.is_contained_by(value) + raise "Expected an Enumerable value with a list of acceptable values that can be converted to strings" unless value.kind_of?(Enumerable) + + { + 'operation' => 'in', + 'options' => [ + { + 'name' => 'data', + 'value' => value.collect { |enum_val| enum_val.to_s } + } + ] + } + end + + # Matches when key path value is not equal to one of the given values in the Enumarable + def self.is_not_contained_by(value) + raise "Expected an Enumerable value with a list of acceptable values that can be converted to strings" unless value.kind_of?(Enumerable) + + { + 'operation' => 'not in', + 'options' => [ + { + 'name' => 'data', + 'value' => value.collect { |enum_val| enum_val.to_s } + } + ] + } + end + # Matches when the value in the field is greater than the given value def self.is_greater_than(value) filter_criteria('>', value) diff --git a/lib/softlayer_api.rb b/lib/softlayer_api.rb index 2168e9f..55ed4d9 100755 --- a/lib/softlayer_api.rb +++ b/lib/softlayer_api.rb @@ -5,6 +5,7 @@ #++ # requirements from the core libraries +require 'date' require 'time' # Requirements for the Foundation Layer From 3f81a236730dfef5fb8cac7dada6d46d4d7e6ac5 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:12:13 -0400 Subject: [PATCH 02/12] Update ObjectFilter usage in AccountPassword to accommodate the new object filters --- lib/softlayer/AccountPassword.rb | 80 +++++++++++++------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/lib/softlayer/AccountPassword.rb b/lib/softlayer/AccountPassword.rb index c88ca45..97748af 100644 --- a/lib/softlayer/AccountPassword.rb +++ b/lib/softlayer/AccountPassword.rb @@ -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: - # * +:datacenter+ (string) - Include network storage account passwords from servers matching this datacenter - # * +:domain+ (string) - Include network storage account passwords from servers matching this domain - # * +:hostname+ (string) - Include network storage account passwords from servers matching this hostname - # * +:network_storage_server_type+ (string) - Include network storage account passwords attached to this server type - # * +:network_storage_type+ (string) - Include network storage account passwords from devices of this storage type - # * +:tags+ (Array) - Include network storage account passwords from servers matching these tags - # * +:username+ (string) - Include network storage account passwords with this username only + # * +:datacenter+ (string/array) - Include network storage account passwords from servers matching this datacenter + # * +:domain+ (string/array) - Include network storage account passwords from servers matching this domain + # * +:hostname+ (string/array) - Include network storage account passwords from servers matching this hostname + # * +:network_storage_server_type+ (string) - Include network storage account passwords attached to this server type + # * +:network_storage_type+ (string) - Include network storage account passwords from devices of this storage type + # * +:tags+ (string/array) - Include network storage account passwords from servers matching these tags + # * +:username+ (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 @@ -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] @@ -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| @@ -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: - # * +:datacenter+ (string) - Include network storage webcc passwords from servers matching this datacenter - # * +:domain+ (string) - Include network storage webcc passwords from servers matching this domain - # * +:hostname+ (string) - Include network storage webcc passwords from servers matching this hostname - # * +:network_storage_server_type+ (string) - Include network storage webcc passwords attached to this server type - # * +:network_storage_type+ (string) - Include network storage webcc passwords from devices of this storage type - # * +:tags+ (Array) - Include network storage webcc passwords from servers matching these tags - # * +:username+ (string) - Include network storage webcc passwords with this username only + # * +:datacenter+ (string/array) - Include network storage webcc passwords from servers matching this datacenter + # * +:domain+ (string/array) - Include network storage webcc passwords from servers matching this domain + # * +:hostname+ (string/array) - Include network storage webcc passwords from servers matching this hostname + # * +:network_storage_server_type+ (string) - Include network storage webcc passwords attached to this server type + # * +:network_storage_type+ (string) - Include network storage webcc passwords from devices of this storage type + # * +:tags+ (string/array) - Include network storage webcc passwords from servers matching these tags + # * +:username+ (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 @@ -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" } } @@ -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| From 597d842ffb60493318c8ecc413e06799ae8580ce Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:12:41 -0400 Subject: [PATCH 03/12] Update ObjectFilter usage in BareMetalServer to accommodate the new object filters --- lib/softlayer/BareMetalServer.rb | 44 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/softlayer/BareMetalServer.rb b/lib/softlayer/BareMetalServer.rb index 27b104e..d6b4337 100644 --- a/lib/softlayer/BareMetalServer.rb +++ b/lib/softlayer/BareMetalServer.rb @@ -183,15 +183,15 @@ def self.server_with_id(server_id, options = {}) # # You may filter the list returned by adding options: # - # * +:tags+ (array) - an array of strings representing tags to search for on the instances - # * +:cpus+ (int) - return servers with the given number of (virtual) CPUs - # * +:memory+ (int) - return servers with at least the given amount of memory (in Gigabytes) - # * +:hostname+ (string) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation) - # * +:domain+ (string) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:datacenter+ (string) - find servers whose data center name matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:nic_speed+ (int) - include servers with the given nic speed (in Mbps) - # * +:public_ip+ (string) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:private_ip+ (string) - same as :public_ip, but for private IP addresses + # * +:tags+ (string/array) - an array of strings representing tags to search for on the instances + # * +:cpus+ (int/array) - return servers with the given number of (virtual) CPUs + # * +:memory+ (int/array) - return servers with at least the given amount of memory (in Gigabytes) + # * +:hostname+ (string/array) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation) + # * +:domain+ (string/array) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:datacenter+ (string/array) - find servers whose data center name matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:nic_speed+ (int/array) - include servers with the given nic speed (in Mbps) + # * +:public_ip+ (string/array) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:private_ip+ (string/array) - same as :public_ip, but for private IP addresses # # Additionally you may provide options related to the request itself: # @@ -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 @@ -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) From def2004f17f9eb6f5685941b5b54fda0aabbfe57 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:13:38 -0400 Subject: [PATCH 04/12] Update ObjectFilter usage in ImageTemplate to accommodate the new object filters --- lib/softlayer/ImageTemplate.rb | 40 ++++++++++------------------------ 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/lib/softlayer/ImageTemplate.rb b/lib/softlayer/ImageTemplate.rb index 9846051..02c4312 100644 --- a/lib/softlayer/ImageTemplate.rb +++ b/lib/softlayer/ImageTemplate.rb @@ -209,8 +209,9 @@ def softlayer_properties(object_mask = nil) # If no client can be found the routine will raise an error. # # Additional options that may be provided: - # * +:name+ (string) - Return templates with the given name - # * +:global_id+ (string) - Return templates with the given global identfier + # * +:name+ (string/array) - Return templates with the given name + # * +:global_id+ (string/array) - Return templates with the given global identfier + # * +:tags+ (string/array) - Return templates with the tags def self.find_private_templates(options_hash = {}) softlayer_client = options_hash[:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client @@ -223,8 +224,9 @@ def self.find_private_templates(options_hash = {}) end option_to_filter_path = { - :name => "privateBlockDeviceTemplateGroups.name", + :name => "privateBlockDeviceTemplateGroups.name", :global_id => "privateBlockDeviceTemplateGroups.globalIdentifier", + :tags => "privateBlockDeviceTemplateGroups.tagReferences.tag.name" } # For each of the options in the option_to_filter_path map, if the options hash includes @@ -234,17 +236,6 @@ def self.find_private_templates(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("privateBlockDeviceTemplateGroups.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) @@ -275,8 +266,9 @@ def self.find_private_templates(options_hash = {}) # If no client can be found the routine will raise an error. # # Additional options that may be provided: - # * +:name+ (string) - Return templates with the given name - # * +:global_id+ (string) - Return templates with the given global identfier + # * +:name+ (string/array) - Return templates with the given name + # * +:global_id+ (string/array) - Return templates with the given global identfier + # * +:tags+ (string/array) - Return templates with the tags def self.find_public_templates(options_hash = {}) softlayer_client = options_hash[:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client @@ -289,8 +281,9 @@ def self.find_public_templates(options_hash = {}) end option_to_filter_path = { - :name => "name", + :name => "name", :global_id => "globalIdentifier", + :tags => "tagReferences.tag.name" } # For each of the options in the option_to_filter_path map, if the options hash includes @@ -299,17 +292,6 @@ def self.find_public_templates(options_hash = {}) option_to_filter_path.each do |option, filter_path| 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("tagReferences.tag.name", { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - } ); - end template_service = softlayer_client[:Virtual_Guest_Block_Device_Template_Group] template_service = template_service.object_filter(object_filter) unless object_filter.empty? @@ -391,4 +373,4 @@ def self.default_object_mask return "mask[id,accountId,name,note,globalIdentifier,datacenters,blockDevices,tagReferences,publicFlag,flexImageFlag,transactionId,children.transactionId]" end end -end \ No newline at end of file +end From 777a9711110bb27d78acba5631cd61263d7ac007 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:14:14 -0400 Subject: [PATCH 05/12] Cleanup formatting of NetworkComponent --- lib/softlayer/NetworkComponent.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/softlayer/NetworkComponent.rb b/lib/softlayer/NetworkComponent.rb index 3d2dbc0..527fa4e 100644 --- a/lib/softlayer/NetworkComponent.rb +++ b/lib/softlayer/NetworkComponent.rb @@ -5,10 +5,10 @@ #++ module SoftLayer - class NetworkComponent < SoftLayer::ModelBase + class NetworkComponent < SoftLayer::ModelBase sl_attr :name sl_attr :port sl_attr :speed sl_attr :maxSpeed end -end \ No newline at end of file +end From c1f156350aeadf76ea2a7151aa215b0c99175d6f Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:14:55 -0400 Subject: [PATCH 06/12] Update ObjectFilter usage in NetworkStorageCredential to accommodate the new object filters --- lib/softlayer/NetworkStorageCredential.rb | 47 ++++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/lib/softlayer/NetworkStorageCredential.rb b/lib/softlayer/NetworkStorageCredential.rb index 9810d3f..ba4a741 100644 --- a/lib/softlayer/NetworkStorageCredential.rb +++ b/lib/softlayer/NetworkStorageCredential.rb @@ -61,14 +61,14 @@ def name # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include network storage account passwords associated with servers matching this datacenter - # * +:domain+ (string) - Include network storage account passwords associated with servers matching this domain - # * +:hostname+ (string) - Include network storage account passwords associated with servers matching this hostname - # * +:network_storage_server_type+ (string) - Include network storage account passwords associated with services of this server type - # * +:network_storage_type+ (string) - Include network storage account passwords from devices of this storage type - # * +:service+ (string) - Include network storage account passwords from devices with this service fqdn - # * +:tags+ (Array) - Include network storage account passwords associated with servers matching these tags - # * +:username+ (string) - Include network storage account passwords with this username only + # * +:datacenter+ (string/array) - Include network storage account passwords associated with servers matching this datacenter + # * +:domain+ (string/array) - Include network storage account passwords associated with servers matching this domain + # * +:hostname+ (string/array) - Include network storage account passwords associated with servers matching this hostname + # * +:network_storage_server_type+ (string) - Include network storage account passwords associated with services of this server type + # * +:network_storage_type+ (string) - Include network storage account passwords from devices of this storage type + # * +:service+ (string/array) - Include network storage account passwords from devices with this service fqdn + # * +:tags+ (string/array) - Include network storage account passwords associated with servers matching these tags + # * +:username+ (string/array) - Include network storage account passwords with this username only # def self.find_network_storage_credentials(options_hash = {}) softlayer_client = options_hash[:client] || Client.default_client @@ -104,11 +104,13 @@ def self.find_network_storage_credentials(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 }, - :service => lambda { |storage_type| return [ filter_label[storage_type], '.serviceResource.backendIpAddress' ].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 }, + :service => lambda { |storage_type| return [ filter_label[storage_type], '.serviceResource.backendIpAddress' ].join }, + :tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join } + }, :network_storage_credential => { :username => "credentials.username" } @@ -124,29 +126,20 @@ def self.find_network_storage_credentials(options_hash = {}) if options_hash[:service] network_storage_object_filter.modify do |filter| - filter.accept(option_to_filter_path[:service].call(network_storage_type)).when_it is(options_hash[:service]) + filter.accept(option_to_filter_path[:network_storage][:service].call(network_storage_type)).when_it is(options_hash[:service]) end end if options_hash[:network_storage_server_type] - [ :datacenter, :domain, :hostname ].each do |option| + option_to_filter_path[:network_storage].keys.each do |option| + next if option == :service + 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[:network_storage_credential].each do |option, filter_path| From 0f62dfd448e1c1d42aaad80333aac78c50459b2c Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:15:25 -0400 Subject: [PATCH 07/12] Update ObjectFilter usage in ProductPackage to accommodate the new object filters --- lib/softlayer/ProductPackage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/softlayer/ProductPackage.rb b/lib/softlayer/ProductPackage.rb index ab2ac38..c996ec9 100644 --- a/lib/softlayer/ProductPackage.rb +++ b/lib/softlayer/ProductPackage.rb @@ -155,7 +155,7 @@ def service ## # Requests a list (array) of ProductPackages whose key names match the - # one passed in. + # one passed in. key_name may be a string or array. # def self.packages_with_key_name(key_name, client = nil) softlayer_client = client || Client.default_client From 92fb17efe04c0435a7430df8389be7f2884e59f5 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:15:56 -0400 Subject: [PATCH 08/12] Update ObjectFilter usage in Software to accommodate the new object filters --- lib/softlayer/Software.rb | 67 ++++++++++++++------------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/lib/softlayer/Software.rb b/lib/softlayer/Software.rb index d8b7847..d81f14f 100644 --- a/lib/softlayer/Software.rb +++ b/lib/softlayer/Software.rb @@ -127,14 +127,14 @@ def has_user_password?(username) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software from hardware matching this datacenter - # * +:description+ (string) - Include software that matches this description - # * +:domain+ (string) - Include software from hardware matching this domain - # * +:hardware_type+ (string) - Include software from hardware matching this hardware type - # * +:hostname+ (string) - Include software from hardware matching this hostname - # * +:manufacturer+ (string) - Include software that matches this manufacturer - # * +:name+ (string) - Include software that matches this name - # * +:username+ (string) - Include software that has software password matching this username + # * +:datacenter+ (string/array) - Include software from hardware matching this datacenter + # * +:description+ (string/array) - Include software that matches this description + # * +:domain+ (string/array) - Include software from hardware matching this domain + # * +:hardware_type+ (symbol) - Include software from hardware matching this hardware type + # * +:hostname+ (string/array) - Include software from hardware matching this hostname + # * +:manufacturer+ (string/array) - Include software that matches this manufacturer + # * +:name+ (string/array) - Include software that matches this name + # * +:username+ (string/array) - Include software that has software password matching this username # # You may use the following properties to provide hardware or software object filter instances: # * +:hardware_object_filter+ (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 = {}) } option_to_filter_path = { - :datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join }, - :domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join }, - :hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join }, - :tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join }, + :hardware => { + :datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join }, + :domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join }, + :hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join }, + :tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join } + }, :software => { :description => "softwareComponents.softwareDescription.longDescription", :manufacturer => "softwareComponents.softwareDescription.manufacturer", @@ -185,23 +187,12 @@ def self.find_software_on_hardware(options_hash = {}) end end - [ :datacenter, :domain, :hostname ].each do |option| + option_to_filter_path[:hardware].keys.each do |option| if options_hash[option] - hardware_object_filter.modify { |filter| filter.accept(option_to_filter_path[option].call(options_hash[:hardware_type] || :hardware)).when_it is(options_hash[option]) } + 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]) } end end - if options_hash[:tags] - hardware_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(options_hash[:hardware_type] || :hardware), - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - option_to_filter_path[:software].each do |option, filter_path| software_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end @@ -245,13 +236,13 @@ def self.find_software_on_hardware(options_hash = {}) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software from virtual servers matching this datacenter - # * +:description+ (string) - Include software that matches this description - # * +:domain+ (string) - Include software from virtual servers matching this domain - # * +:hostname+ (string) - Include software from virtual servers matching this hostname - # * +:manufacturer+ (string) - Include software that matches this manufacturer - # * +:name+ (string) - Include software that matches this name - # * +:username+ (string) - Include software that has software password matching this username + # * +:datacenter+ (string/array) - Include software from virtual servers matching this datacenter + # * +:description+ (string/array) - Include software that matches this description + # * +:domain+ (string/array) - Include software from virtual servers matching this domain + # * +:hostname+ (string/array) - Include software from virtual servers matching this hostname + # * +:manufacturer+ (string/array) - Include software that matches this manufacturer + # * +:name+ (string/array) - Include software that matches this name + # * +:username+ (string/array) - Include software that has software password matching this username # # You may use the following properties to provide virtual server or software object filter instances: # * +:virtual_server_object_filter+ (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 = {}) } } - if options_hash[:tags] - virtual_server_object_filter.set_criteria_for_key_path(option_to_filter_path[:virtual_server][:tags], - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - option_to_filter_path[:virtual_server].each do |option, filter_path| - next if option == :tags virtual_server_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end From 3e272e7cdfaefc8d6214da8ac6223ca2cd76708e Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:16:23 -0400 Subject: [PATCH 09/12] Update ObjectFilter usage in SoftwarePassword to accommodate the new object filters --- lib/softlayer/SoftwarePassword.rb | 165 +++++++++++------------------- 1 file changed, 60 insertions(+), 105 deletions(-) diff --git a/lib/softlayer/SoftwarePassword.rb b/lib/softlayer/SoftwarePassword.rb index 56b78fd..0c40004 100644 --- a/lib/softlayer/SoftwarePassword.rb +++ b/lib/softlayer/SoftwarePassword.rb @@ -65,10 +65,10 @@ def password=(password) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software passwords from application delivery controllers matching this datacenter - # * +:name+ (string) - Include software passwords from application delivery controllers that matches this name - # * +:tags+ (Array) - Include software passwords from application delivery controllers that matches these tags - # * +:username+ (string) - Include software passwords that match this username + # * +:datacenter+ (string/array) - Include software passwords from application delivery controllers matching this datacenter + # * +:name+ (string/array) - Include software passwords from application delivery controllers that matches this name + # * +:tags+ (string/array - Include software passwords from application delivery controllers that matches these tags + # * +:username+ (string/array) - Include software passwords that match this username # def self.find_passwords_for_application_delivery_controllers(options_hash = {}) softlayer_client = options_hash[:client] || Client.default_client @@ -89,34 +89,27 @@ def self.find_passwords_for_application_delivery_controllers(options_hash = {}) end option_to_filter_path = { - :advanced_mode => "applicationDeliveryControllers.advancedModeFlag", - :datacenter => "applicationDeliveryControllers.datacenter.name", - :name => "applicationDeliveryControllers.name", - :tags => "applicationDeliveryControllers.tagReferences.tag.name", - :software_password => { + :app_deliv_controller => { + :advanced_mode => "applicationDeliveryControllers.advancedModeFlag", + :datacenter => "applicationDeliveryControllers.datacenter.name", + :name => "applicationDeliveryControllers.name", + :tags => "applicationDeliveryControllers.tagReferences.tag.name" + }, + :software_password => { :username => "password.username" } } - application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[:advanced_mode]).when_it is(true) } + application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[:app_deliv_controller][:advanced_mode]).when_it is(true) } + + option_to_filter_path[:app_deliv_controller].each do |option, filter_path| + next if option == :advanced_mode - [ :datacenter, :name ].each do |option| if options_hash[option] - application_delivery_controller_object_filter.modify { |filter| filter.accept(option_to_filter_path[option]).when_it is(options_hash[option]) } + application_delivery_controller_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } end end - if options_hash[:tags] - application_delivery_controller_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags], - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - option_to_filter_path[:software_password].each do |option, filter_path| software_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end @@ -150,15 +143,15 @@ def self.find_passwords_for_application_delivery_controllers(options_hash = {}) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software passwords from vlan firewalls matching this datacenter - # * +:vlan_name+ (Array) - Include software passwords from vlans that matches these names - # * +:vlan_numbers+ (Array) - Include software passwords from vlans that matches these numbers - # * +:vlan_space+ (symbol) - Include software passwords from vlans that match this space - # * +:vlan_tags+ (Array) - Include software passwords from vlans that matches these tags - # * +:vlan_fw_fqdn+ (string) - Include software passwords from vlan firewalls that match this fqdn - # * +:vlan_fw_tags+ (Array) - Include software passwords from vlan firewalls that matches these tags - # * +:vlan_fw_type+ (string) - Include software passwords from vlan firewalls that match this type - # * +:username+ (string) - Include software passwords that match this username + # * +:datacenter+ (string/array) - Include software passwords from vlan firewalls matching this datacenter + # * +:vlan_names+ (string/array) - Include software passwords from vlans that matches these names + # * +:vlan_numbers+ (string/array) - Include software passwords from vlans that matches these numbers + # * +:vlan_space+ (symbol) - Include software passwords from vlans that match this space + # * +:vlan_tags+ (string/array) - Include software passwords from vlans that matches these tags + # * +:vlan_fw_fqdn+ (string/array) - Include software passwords from vlan firewalls that match this fqdn + # * +:vlan_fw_tags+ (string/array) - Include software passwords from vlan firewalls that matches these tags + # * +:vlan_fw_type+ (string/array) - Include software passwords from vlan firewalls that match this type + # * +:username+ (string/array) - Include software passwords that match this username # def self.find_passwords_for_vlan_firewalls(options_hash = {}) softlayer_client = options_hash[:client] || Client.default_client @@ -195,16 +188,18 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {}) :software_password => { :username => "managementCredentials.username" }, - :vlan_dedicated_fw => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'dedicatedFirewallFlag' ].join }, - :vlan_names => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'name' ].join }, - :vlan_numbers => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'vlanNumber' ].join }, - :vlan_tags => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'tagReferences.tag.name' ].join }, + :vlan => { + :vlan_dedicated_fw => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'dedicatedFirewallFlag' ].join }, + :vlan_names => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'name' ].join }, + :vlan_numbers => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'vlanNumber' ].join }, + :vlan_tags => lambda { |vlan_space| return [ filter_label[vlan_space], '.', 'tagReferences.tag.name' ].join } + }, :vlan_firewall => { :vlan_fw_datacenter => "networkVlanFirewall.datacenter.name", :vlan_fw_fqdn => "networkVlanFirewall.fullyQualifiedDomainName", + :vlan_fw_tags => "networkVlanFirewall.tagReferences.tag.name", :vlan_fw_type => "networkVlanFirewall.firewallType" - }, - :vlan_fw_tags => "networkVlanFirewall.tagReferences.tag.name" + } } if options_hash[:vlan_space] && ! filter_label.keys.include?(options_hash[:vlan_space]) @@ -217,19 +212,11 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {}) vlan_space = options_hash[:vlan_space] || :all - vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan_dedicated_fw].call(vlan_space)).when_it is(1) } - 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] + option_to_filter_path[:vlan].keys.each do |option| + 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 - [ :vlan_names, :vlan_numbers, :vlan_tags ].each do |option| - if options_hash[option] - vlan_object_filter.set_criteria_for_key_path(option_to_filter_path[option].call(vlan_space), - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[option].collect{ |tag_value| tag_value.to_s } - }] - }) + if options_hash[option] && option != :vlan_dedicated_fw + vlan_object_filter.modify { |filter| filter.accept(option_to_filter_path[:vlan][option].call(vlan_space)).when_it is(options_hash[option]) } end end @@ -237,17 +224,6 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {}) vlan_firewall_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end - if options_hash[:vlan_fw_tags] - vlan_firewall_object_filter.set_criteria_for_key_path(option_to_filter_path[:vlan_fw_tags], - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:vlan_fw_tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - account_service = softlayer_client[:Account] account_service = account_service.object_filter(vlan_object_filter) unless vlan_object_filter.empty? account_service = account_service.object_mask("mask[id]") @@ -293,14 +269,14 @@ def self.find_passwords_for_vlan_firewalls(options_hash = {}) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software passwords from software on hardware matching this datacenter - # * +:description+ (string) - Include software passwords from software that matches this description - # * +:domain+ (string) - Include software passwords from software on hardware matching this domain - # * +:hardware_type+ (string) - Include software passwords from software on hardware matching this hardware type - # * +:hostname+ (string) - Include software passwords from software on hardware matching this hostname - # * +:manufacturer+ (string) - Include software passwords from software that matches this manufacturer - # * +:name+ (string) - Include software passwords from software that matches this name - # * +:username+ (string) - Include software passwords for username matching this username + # * +:datacenter+ (string/array) - Include software passwords from software on hardware matching this datacenter + # * +:description+ (string/array) - Include software passwords from software that matches this description + # * +:domain+ (string/array) - Include software passwords from software on hardware matching this domain + # * +:hardware_type+ (symbol) - Include software passwords from software on hardware matching this hardware type + # * +:hostname+ (string/array) - Include software passwords from software on hardware matching this hostname + # * +:manufacturer+ (string/array) - Include software passwords from software that matches this manufacturer + # * +:name+ (string/array) - Include software passwords from software that matches this name + # * +:username+ (string/array) - Include software passwords for username matching this username # # You may use the following properties to provide hardware or software object filter instances: # * +:hardware_object_filter+ (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 = {}) } option_to_filter_path = { - :datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join }, - :domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join }, - :hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join }, - :tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join }, + :hardware => { + :datacenter => lambda { |hardware_type| return [ filter_label[hardware_type], '.datacenter.name' ].join }, + :domain => lambda { |hardware_type| return [ filter_label[hardware_type], '.domain' ].join }, + :hostname => lambda { |hardware_type| return [ filter_label[hardware_type], '.hostname' ].join }, + :tags => lambda { |hardware_type| return [ filter_label[hardware_type], '.tagReferences.tag.name' ].join } + }, :software => { :description => "softwareComponents.softwareDescription.longDescription", :manufacturer => "softwareComponents.softwareDescription.manufacturer", @@ -362,23 +340,12 @@ def self.find_passwords_for_software_on_hardware(options_hash = {}) end end - [ :datacenter, :domain, :hostname ].each do |option| + option_to_filter_path[:hardware].keys.each do |option| if options_hash[option] - hardware_object_filter.modify { |filter| filter.accept(option_to_filter_path[option].call(options_hash[:hardware_type] || :hardware)).when_it is(options_hash[option]) } + 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]) } end end - if options_hash[:tags] - hardware_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(options_hash[:hardware_type] || :hardware), - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - option_to_filter_path[:software].each do |option, filter_path| software_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end @@ -436,13 +403,13 @@ def self.find_passwords_for_software_on_hardware(options_hash = {}) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:datacenter+ (string) - Include software passwords from software on virtual servers matching this datacenter - # * +:description+ (string) - Include software passwords from software that matches this description - # * +:domain+ (string) - Include software passwords from software on virtual servers matching this domain - # * +:hostname+ (string) - Include software passwords from software on virtual servers matching this hostname - # * +:manufacturer+ (string) - Include software passwords from software that matches this manufacturer - # * +:name+ (string) - Include software passwords from software that matches this name - # * +:username+ (string) - Include software passwords for username matching this username + # * +:datacenter+ (string/array) - Include software passwords from software on virtual servers matching this datacenter + # * +:description+ (string/array) - Include software passwords from software that matches this description + # * +:domain+ (string/array) - Include software passwords from software on virtual servers matching this domain + # * +:hostname+ (string/array) - Include software passwords from software on virtual servers matching this hostname + # * +:manufacturer+ (string/array) - Include software passwords from software that matches this manufacturer + # * +:name+ (string/array) - Include software passwords from software that matches this name + # * +:username+ (string/array) - Include software passwords for username matching this username # # You may use the following properties to provide virtual server or software object filter instances: # * +:virtual_server_object_filter+ (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 = {}) } } - if options_hash[:tags] - virtual_server_object_filter.set_criteria_for_key_path(option_to_filter_path[:virtual_server][:tags], - { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - }) - end - option_to_filter_path[:virtual_server].each do |option, filter_path| - next if option == :tags virtual_server_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option] end From 03543ed2163bcd64f496495ea97a1e05acc3161b Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:17:15 -0400 Subject: [PATCH 10/12] Cleanup formatting for Ticket --- lib/softlayer/Ticket.rb | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/softlayer/Ticket.rb b/lib/softlayer/Ticket.rb index 080bef8..14b162b 100644 --- a/lib/softlayer/Ticket.rb +++ b/lib/softlayer/Ticket.rb @@ -5,7 +5,7 @@ #++ module SoftLayer - class Ticket < SoftLayer::ModelBase + class Ticket < SoftLayer::ModelBase ## # :attr_reader: @@ -35,12 +35,12 @@ def server_admin_ticket? self['serverAdministrationFlag'] != 0 end - ## - # Add an update to this ticket. - # - def update(body = nil) - self.service.edit(self.softlayer_hash, body) - end + ## + # Add an update to this ticket. + # + def update(body = nil) + self.service.edit(self.softlayer_hash, body) + end ## # Override of service from ModelBase. Returns the SoftLayer_Ticket service @@ -52,7 +52,7 @@ def service ## # Override from model base. Requests new details about the ticket # from the server. - def softlayer_properties(object_mask = nil) + def softlayer_properties(object_mask = nil) my_service = self.service if(object_mask) @@ -62,12 +62,12 @@ def softlayer_properties(object_mask = nil) end my_service.getObject() - end + end ## # Returns the default object mask,as a hash, that is used when # retrieving ticket information from the SoftLayer server. - def self.default_object_mask + def self.default_object_mask { "mask" => [ 'id', # This is an internal ticket ID, not the one usually seen in the portal @@ -84,23 +84,23 @@ def self.default_object_mask 'serverAdministrationFlag', # This comes in from the server as an integer :-( ] }.to_sl_object_mask - end + end ## # Queries the SoftLayer API to retrieve a list of the valid # ticket subjects. - def self.ticket_subjects(client = nil) - @ticket_subjects ||= nil + def self.ticket_subjects(client = nil) + @ticket_subjects ||= nil - if !@ticket_subjects + if !@ticket_subjects softlayer_client = client || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client - @ticket_subjects = softlayer_client[:Ticket_Subject].getAllObjects(); - end + @ticket_subjects = softlayer_client[:Ticket_Subject].getAllObjects(); + end - @ticket_subjects - end + @ticket_subjects + end ## # Find the ticket with the given ID and return it @@ -112,7 +112,7 @@ def self.ticket_subjects(client = nil) # If a client is not provided then the routine will search Client::default_client # If Client::default_client is also nil the routine will raise an error. # - def self.ticket_with_id(ticket_id, options = {}) + def self.ticket_with_id(ticket_id, options = {}) softlayer_client = options[:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client @@ -167,5 +167,5 @@ def self.create_standard_ticket(options = {}) ticket_data = softlayer_client[:Ticket].createStandardTicket(new_ticket, body) return new(softlayer_client, ticket_data) end - end -end \ No newline at end of file + end +end From b17b18fdc20ca709029a51742d95bb441bdfcba8 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:17:43 -0400 Subject: [PATCH 11/12] Cleanup formatting for VLANFirewall --- lib/softlayer/VLANFirewall.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/softlayer/VLANFirewall.rb b/lib/softlayer/VLANFirewall.rb index 311f37f..b8e050f 100644 --- a/lib/softlayer/VLANFirewall.rb +++ b/lib/softlayer/VLANFirewall.rb @@ -17,7 +17,7 @@ module SoftLayer # As a result, instances of this class correspond to certain instances # in the SoftLayer_Network_Vlan service. # - class VLANFirewall < SoftLayer::ModelBase + class VLANFirewall < SoftLayer::ModelBase include ::SoftLayer::DynamicAttribute ## @@ -219,7 +219,6 @@ def self.find_firewalls(client = nil) vlan_firewalls.collect { |firewall_data| SoftLayer::VLANFirewall.new(softlayer_client, firewall_data)} end - #-- # Methods for the SoftLayer model #++ @@ -277,4 +276,4 @@ def self.default_rules_mask_keys 'version'] end end # class Firewall -end # module SoftLayer \ No newline at end of file +end # module SoftLayer From 2503599f5760fb5f78febf936aa77a94a7065968 Mon Sep 17 00:00:00 2001 From: Julio Lajara Date: Wed, 15 Apr 2015 11:18:05 -0400 Subject: [PATCH 12/12] Update ObjectFilter usage in VirtualServer to accommodate the new object filters --- lib/softlayer/VirtualServer.rb | 50 ++++++++++++++-------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/lib/softlayer/VirtualServer.rb b/lib/softlayer/VirtualServer.rb index 080bd4e..5fccd12 100644 --- a/lib/softlayer/VirtualServer.rb +++ b/lib/softlayer/VirtualServer.rb @@ -187,18 +187,18 @@ def self.server_with_id(server_id, options = {}) # If no client can be found the routine will raise an error. # # You may filter the list returned by adding options: - # * +:hourly+ (boolean) - Include servers billed hourly in the list - # * +:monthly+ (boolean) - Include servers billed monthly in the list - # * +:tags+ (array) - an array of strings representing tags to search for on the instances - # * +:cpus+ (int) - return virtual servers with the given number of (virtual) CPUs - # * +:memory+ (int) - return servers with at least the given amount of memory (in MB. e.g. 4096 = 4GB) - # * +:hostname+ (string) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation) - # * +:domain+ (string) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:local_disk+ (boolean) - include servers that do, or do not, have local disk storage - # * +:datacenter+ (string) - find servers whose short data center name (e.g. dal05, sjc01) matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:nic_speed+ (int) - include servers with the given nic speed (in Mbps, usually 10, 100, or 1000) - # * +:public_ip+ (string) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation) - # * +:private_ip+ (string) - same as :public_ip, but for private IP addresses + # * +:hourly+ (boolean) - Include servers billed hourly in the list + # * +:monthly+ (boolean) - Include servers billed monthly in the list + # * +:tags+ (string/array) - an array of strings representing tags to search for on the instances + # * +:cpus+ (int/array) - return virtual servers with the given number of (virtual) CPUs + # * +:memory+ (int/array) - return servers with at least the given amount of memory (in MB. e.g. 4096 = 4GB) + # * +:hostname+ (string/array) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation) + # * +:domain+ (string/array) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:local_disk+ (boolean) - include servers that do, or do not, have local disk storage + # * +:datacenter+ (string/array) - find servers whose short data center name (e.g. dal05, sjc01) matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:nic_speed+ (int/array) - include servers with the given nic speed (in Mbps, usually 10, 100, or 1000) + # * +:public_ip+ (string/array) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation) + # * +:private_ip+ (string/array) - same as :public_ip, but for private IP addresses # # Additionally you may provide options related to the request itself: # * +:object_mask+ (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 = {}) end option_to_filter_path = { - :cores => "virtualGuests.maxCpu", - :memory => "virtualGuests.maxMemory", - :hostname => "virtualGuests.hostname", - :domain => "virtualGuests.domain", + :cores => "virtualGuests.maxCpu", + :memory => "virtualGuests.maxMemory", + :hostname => "virtualGuests.hostname", + :domain => "virtualGuests.domain", :local_disk => "virtualGuests.localDiskFlag", :datacenter => "virtualGuests.datacenter.name", - :nic_speed => "virtualGuests.networkComponents.maxSpeed", - :public_ip => "virtualGuests.primaryIpAddress", - :private_ip => "virtualGuests.primaryBackendIpAddress" + :nic_speed => "virtualGuests.networkComponents.maxSpeed", + :public_ip => "virtualGuests.primaryIpAddress", + :private_ip => "virtualGuests.primaryBackendIpAddress", + :tags => "virtualGuests.tagReferences.tag.name" } if options_hash.has_key?(:local_disk) then @@ -238,17 +239,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("virtualGuests.tagReferences.tag.name", { - 'operation' => 'in', - 'options' => [{ - 'name' => 'data', - 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s } - }] - } ); - end - required_properties_mask = 'mask.id' account_service = softlayer_client[:Account]