Skip to content

Commit

Permalink
Merge pull request softlayer#100 from ju2wheels/feature/case_cleanup
Browse files Browse the repository at this point in the history
Cleanup syntax case across classes to better follow Ruby style guide.
  • Loading branch information
SLsthompson committed Jul 28, 2015
2 parents bdae747 + 1b19697 commit 2aee085
Show file tree
Hide file tree
Showing 24 changed files with 482 additions and 118 deletions.
62 changes: 61 additions & 1 deletion lib/softlayer/Account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,43 @@ module SoftLayer
class Account < SoftLayer::ModelBase
include ::SoftLayer::DynamicAttribute

##
# :attr_reader: company_name
# The company name of the primary contact
sl_attr :company_name, 'companyName'

##
# :attr_reader:
# The company name of the primary contact
#
# DEPRECATION WARNING: This attribute is deprecated in favor of company_name
# and will be removed in the next major release.
sl_attr :companyName

##
# :attr_reader: first_name
# The given name name of the primary contact
sl_attr :first_name, 'firstName'

##
# :attr_reader:
# The given name name of the primary contact
#
# DEPRECATION WARNING: This attribute is deprecated in favor of first_name
# and will be removed in the next major release.
sl_attr :firstName

##
# :attr_reader: last_name
# The surname of the primary contact
sl_attr :last_name, 'lastName'

##
# :attr_reader:
# The surname of the primary contact
#
# DEPRECATION WARNING: This attribute is deprecated in favor of last_name
# and will be removed in the next major release.
sl_attr :lastName

##
Expand Down Expand Up @@ -51,14 +75,30 @@ class Account < SoftLayer::ModelBase
# The country stored as part of the primary contact's address
sl_attr :country

##
# :attr_reader: postal_code
# The postal code (in the US, aka. zip code) of the primary contact's address
sl_attr :postal_code, 'postalCode'

##
# :attr_reader:
# The postal code (in the US, aka. zip code) of the primary contact's address
#
# DEPRECATION WARNING: This attribute is deprecated in favor of postal_code
# and will be removed in the next major release.
sl_attr :postalCode

##
# :attr_reader: office_phone
# The office phone number listed for the primary contact
sl_attr :office_phone, 'officePhone'

##
# :attr_reader:
# The office phone number listed for the primary contact
#
# DEPRECATION WARNING: This attribute is deprecated in favor of office_phone
# and will be removed in the next major release.
sl_attr :officePhone

##
Expand Down Expand Up @@ -224,6 +264,26 @@ def service
# The IDs of the different segments can be helpful for ordering
# firewalls.
#
def find_vlan_with_number(vlan_number)
filter = SoftLayer::ObjectFilter.new() { |filter|
filter.accept('networkVlans.vlanNumber').when_it is vlan_number
}

vlan_data = self.service.object_mask("mask[id,vlanNumber,primaryRouter,networkSpace]").object_filter(filter).getNetworkVlans
return vlan_data
end

##
# Searches the account's list of VLANs for the ones with the given
# vlan number. This may return multiple results because a VLAN can
# span different routers and you will get a separate segment for
# each router.
#
# The IDs of the different segments can be helpful for ordering
# firewalls.
#
# DEPRECATION WARNING: This method is deprecated in favor of find_vlan_with_number
# and will be removed in the next major release.
def find_VLAN_with_number(vlan_number)
filter = SoftLayer::ObjectFilter.new() { |filter|
filter.accept('networkVlans.vlanNumber').when_it is vlan_number
Expand All @@ -243,7 +303,7 @@ def self.account_for_client(client = nil)

account_service = softlayer_client[:Account]
network_hash = account_service.getObject()
new(softlayer_client, network_hash)
Account.new(softlayer_client, network_hash)
end

##
Expand Down
24 changes: 20 additions & 4 deletions lib/softlayer/AccountPassword.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ def password=(password)
# * <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>+:network_storage_server_type+</b> (symbol) - Include network storage account passwords attached to this server type
# * <b>+:network_storage_type+</b> (symbol) - 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
#
# Additionally you may provide options related to the request itself:
# * <b>*:account_password_object_filter*</b> (ObjectFilter) - Include network storage account passwords for account passwords that match the
# criteria of this object filter
# * <b>*:account_password_object_mask*</b> (string) - The object mask of properties you wish to receive for the items returned.
# If not provided, the result will use the default object mask
# * <b>*:network_storage_object_filter*</b> (ObjectFilter) - Include network storage account passwords from network storage that matches the
# criteria of this object filter
#
def self.find_network_storage_account_passwords(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
Expand Down Expand Up @@ -197,11 +205,19 @@ def self.find_network_storage_account_passwords(options_hash = {})
# * <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>+:network_storage_server_type+</b> (symbol) - Include network storage webcc passwords attached to this server type
# * <b>+:network_storage_type+</b> (symbol) - 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
#
# Additionally you may provide options related to the request itself:
# * <b>*:network_storage_object_filter*</b> (ObjectFilter) - Include network storage account passwords from network storage that matches the
# criteria of this object filter
# * <b>*:webcc_password_object_filter*</b> (ObjectFilter) - Include network storage account passwords for webcc passwords that match the
# criteria of this object filter
# * <b>*:webcc_password_object_mask*</b> (string) - The object mask of properties you wish to receive for the items returned.
# If not provided, the result will use the default object mask
#
def self.find_network_storage_webcc_passwords(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
Expand Down
24 changes: 12 additions & 12 deletions lib/softlayer/BareMetalServer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def firewall_port_speed
#
# If no client is given, then the routine will try to use Client.default_client
# If no client can be found the routine will raise an error.
#
# Additionally you may provide options related to the request itself:
# * <b>*:object_mask*</b> (string) - The object mask of properties you wish to receive for the items returned.
# If not provided, the result will use the default object mask
def self.server_with_id(server_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
Expand Down Expand Up @@ -194,9 +198,11 @@ def self.server_with_id(server_id, options = {})
# * <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:
#
# * <b>+:object_mask+</b> (string, hash, or array) - The object mask of properties you wish to receive for the items returned If not provided, the result will use the default object mask
# * <b>+:result_limit+</b> (hash with :limit, and :offset keys) - Limit the scope of results returned.
# * <b>*:object_filter*</b> (ObjectFilter) - Include hardware servers for servers that matche the
# criteria of this object filter
# * <b>+:object_mask+</b> (string, hash, or array) - The object mask of properties you wish to receive for the items returned.
# If not provided, the result will use the default object mask
# * <b>+:result_limit+</b> (hash with :limit, and :offset keys) - Limit the scope of results returned.
#
def self.find_servers(options_hash = {})
softlayer_client = options_hash[:client] || Client.default_client
Expand Down Expand Up @@ -231,16 +237,10 @@ def self.find_servers(options_hash = {})
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)
account_service = account_service.object_mask(options_hash[:object_mask]) if options_hash[:object_mask]

if(options_hash.has_key? :object_mask)
account_service = account_service.object_mask(options_hash[:object_mask])
end

if options_hash.has_key?(:result_limit)
offset = options[:result_limit][:offset]
limit = options[:result_limit][:limit]

account_service = account_service.result_limit(offset, limit)
if options_hash[:result_limit] && options_hash[:result_limit][:offset] && options_hash[:result_limit][:limit]
account_service = account_service.result_limit(options_hash[:result_limit][:offset], options_hash[:result_limit][:limit])
end

bare_metal_data = account_service.getHardware()
Expand Down
21 changes: 15 additions & 6 deletions lib/softlayer/BareMetalServerOrder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class BareMetalServerOrder
# Object responding to to_s and providing a valid URI, The URI of a post provisioning script to run on
# this server once it is created.
# Corresponds to +postInstallScriptUri+ in the +createObject+ documentation
attr_accessor :provision_script_uri

# Object responding to to_s and providing a valid URI, The URI of a post provisioning script to run on
# this server once it is created.
# Corresponds to +postInstallScriptUri+ in the +createObject+ documentation
#
# DEPRECATION WARNING: This attribute is deprecated in favor of provision_script_uri
# and will be removed in the next major release.
attr_accessor :provision_script_URI

# Boolean, If true then the server will only have a private network interface (and no public network interface)
Expand Down Expand Up @@ -149,13 +157,14 @@ def hardware_instance_template

template['privateNetworkOnlyFlag'] = true if @private_network_only

template['datacenter'] = {"name" => @datacenter.name} if @datacenter
template['userData'] = [{'value' => @user_metadata}] if @user_metadata
template['networkComponents'] = [{'maxSpeed'=> @max_port_speed}] if @max_port_speed
template['postInstallScriptUri'] = @provision_script_URI.to_s if @provision_script_URI
template['sshKeys'] = @ssh_key_ids.collect { |ssh_key| {'id'=> ssh_key.to_i } } if @ssh_key_ids
template['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
template['datacenter'] = {"name" => @datacenter.name} if @datacenter
template['userData'] = [{'value' => @user_metadata}] if @user_metadata
template['networkComponents'] = [{'maxSpeed'=> @max_port_speed}] if @max_port_speed
template['postInstallScriptUri'] = @provision_script_URI.to_s if @provision_script_URI
template['postInstallScriptUri'] = @provision_script_uri.to_s if @provision_script_uri
template['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
template['primaryBackendNetworkComponent'] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
template['sshKeys'] = @ssh_key_ids.collect { |ssh_key| {'id'=> ssh_key.to_i } } if @ssh_key_ids

if @disks && !@disks.empty?
template['hardDrives'] = @disks.collect do |disk|
Expand Down
8 changes: 8 additions & 0 deletions lib/softlayer/BareMetalServerOrder_Package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class BareMetalServerOrder_Package < Server

# The URI of a script to execute on the server after it has been provisioned. This may be
# any object which accepts the to_s message. The resulting string will be passed to SoftLayer API.
attr_accessor :provision_script_uri

# The URI of a script to execute on the server after it has been provisioned. This may be
# any object which accepts the to_s message. The resulting string will be passed to SoftLayer API.
#
# DEPRECATION WARNING: This attribute is deprecated in favor of provision_script_uri
# and will be removed in the next major release.
attr_accessor :provision_script_URI

# An array of the ids of SSH keys to install on the server upon provisioning
Expand Down Expand Up @@ -151,6 +158,7 @@ def hardware_order
product_order['imageTemplateGlobalIdentifier'] = @image_template.global_id if @image_template
product_order['location'] = @datacenter.id if @datacenter
product_order['provisionScripts'] = [@provision_script_URI.to_s] if @provision_script_URI
product_order['provisionScripts'] = [@provision_script_uri.to_s] if @provision_script_uri
product_order['sshKeys'] = [{ 'sshKeyIds' => @ssh_key_ids }] if @ssh_key_ids
product_order['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
product_order['primaryBackendNetworkComponent'] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
Expand Down

0 comments on commit 2aee085

Please sign in to comment.