Skip to content

Commit 5a7a606

Browse files
committed
A large number of cosmetic changes. Clients are now passed symbols representing the SoftLayer services. This is because they are in essece fixed, well known constants and symbols more properly capture that nature. Also cases were we dereference properties now use single quotes instead of double quotes to capture the fact that they too are largely constants and not 'composeable' arbitrary strings. Finally this change includes the latest round of killing off trailing whitespace
1 parent 405b667 commit 5a7a606

29 files changed

Lines changed: 220 additions & 207 deletions

lib/softlayer/Account.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Account < SoftLayer::ModelBase
123123
end
124124

125125
def service
126-
softlayer_client["Account"].object_with_id(self.id)
126+
softlayer_client[:Account].object_with_id(self.id)
127127
end
128128

129129
##
@@ -134,7 +134,7 @@ def self.account_for_client(client = nil)
134134
softlayer_client = client || Client.default_client
135135
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
136136

137-
account_service = softlayer_client['Account']
137+
account_service = softlayer_client[:Account]
138138
network_hash = account_service.getObject()
139139
new(softlayer_client, network_hash)
140140
end

lib/softlayer/BareMetalServer.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BareMetalServer < Server
2727
#
2828
def bare_metal_instance?
2929
if has_sl_property?(:bareMetalInstanceFlag)
30-
self["bareMetalInstanceFlag"] != 0
30+
self['bareMetalInstanceFlag'] != 0
3131
else
3232
false
3333
end
@@ -47,10 +47,10 @@ def cancel!(reason = :unneeded, comment = '')
4747
if !bare_metal_instance? then
4848
cancellation_reasons = self.class.cancellation_reasons()
4949
cancel_reason = cancellation_reasons[reason] || cancellation_reasons[:unneeded]
50-
softlayer_client["Ticket"].createCancelServerTicket(self.id, cancel_reason, comment, true, 'HARDWARE')
50+
softlayer_client[:Ticket].createCancelServerTicket(self.id, cancel_reason, comment, true, 'HARDWARE')
5151
else
5252
# Note that reason and comment are ignored in this case, unfortunately
53-
softlayer_client['Billing_Item'].object_with_id(self.billingItem['id'].to_i).cancelService()
53+
softlayer_client[:Billing_Item].object_with_id(self.billingItem['id'].to_i).cancelService()
5454
end
5555
end
5656

@@ -59,7 +59,7 @@ def cancel!(reason = :unneeded, comment = '')
5959
# For Bare Metal Servers that is +SoftLayer_Hardware+ though in some special cases
6060
# you may have to use +SoftLayer_Hardware_Server+ as a type or service.
6161
def service
62-
return softlayer_client["Hardware"].object_with_id(self.id)
62+
return softlayer_client[:Hardware].object_with_id(self.id)
6363
end
6464

6565
##
@@ -120,7 +120,7 @@ def self.server_with_id(server_id, options = {})
120120
softlayer_client = options[:client] || Client.default_client
121121
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
122122

123-
hardware_service = softlayer_client["Hardware"]
123+
hardware_service = softlayer_client[:Hardware]
124124
hardware_service = hardware_service.object_mask(default_object_mask.to_sl_object_mask)
125125

126126
if options.has_key?(:object_mask)
@@ -199,7 +199,7 @@ def self.find_servers(options_hash = {})
199199
} );
200200
end
201201

202-
account_service = softlayer_client['Account']
202+
account_service = softlayer_client[:Account]
203203
account_service = account_service.object_filter(object_filter) unless object_filter.empty?
204204
account_service = account_service.object_mask(default_object_mask.to_sl_object_mask)
205205

lib/softlayer/BareMetalServerOrder.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def verify()
111111
order_template = hardware_instance_template
112112
order_template = yield order_template if block_given?
113113

114-
@softlayer_client["Hardware"].generateOrderTemplate(order_template)
114+
@softlayer_client[:Hardware].generateOrderTemplate(order_template)
115115
end
116116

117117
##
@@ -124,8 +124,8 @@ def place_order!()
124124
order_template = hardware_instance_template
125125
order_template = yield order_template if block_given?
126126

127-
server_hash = @softlayer_client["Hardware"].createObject(order_template)
128-
SoftLayer::BareMetalServer.server_with_id(server_hash["id"], :client => @softlayer_client) if server_hash
127+
server_hash = @softlayer_client[:Hardware].createObject(order_template)
128+
SoftLayer::BareMetalServer.server_with_id(server_hash['id'], :client => @softlayer_client) if server_hash
129129
end
130130

131131
protected
@@ -147,15 +147,15 @@ def hardware_instance_template
147147
"hourlyBillingFlag" => !!@hourly
148148
}
149149

150-
template["privateNetworkOnlyFlag"] = true if @private_network_only
150+
template['privateNetworkOnlyFlag'] = true if @private_network_only
151151

152-
template["datacenter"] = {"name" => @datacenter.name} if @datacenter
152+
template['datacenter'] = {"name" => @datacenter.name} if @datacenter
153153
template['userData'] = [{'value' => @user_metadata}] if @user_metadata
154154
template['networkComponents'] = [{'maxSpeed'=> @max_port_speed}] if @max_port_speed
155155
template['postInstallScriptUri'] = @provision_script_URI.to_s if @provision_script_URI
156156
template['sshKeys'] = @ssh_key_ids.collect { |ssh_key| {'id'=> ssh_key.to_i } } if @ssh_key_ids
157157
template['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
158-
template["primaryBackendNetworkComponent"] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
158+
template['primaryBackendNetworkComponent'] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
159159

160160
if @disks && !@disks.empty?
161161
template['hardDrives'] = @disks.collect do |disk|
@@ -174,36 +174,36 @@ def self.create_object_options(client = nil)
174174
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
175175

176176
@@create_object_options ||= nil
177-
@@create_object_options = softlayer_client["Hardware"].getCreateObjectOptions() if !@@create_object_options
177+
@@create_object_options = softlayer_client[:Hardware].getCreateObjectOptions() if !@@create_object_options
178178
@@create_object_options
179179
end
180180

181181
##
182182
# Return a list of values that are valid for the :datacenter attribute
183183
def self.datacenter_options(client = nil)
184-
create_object_options(client)["datacenters"].collect { |datacenter_spec| Datacenter.datacenter_named(datacenter_spec['template']['datacenter']['name'], client) }.uniq
184+
create_object_options(client)['datacenters'].collect { |datacenter_spec| Datacenter.datacenter_named(datacenter_spec['template']['datacenter']['name'], client) }.uniq
185185
end
186186

187187
def self.core_options(client = nil)
188-
create_object_options(client)["processors"].collect { |processor_spec| processor_spec['template']['processorCoreAmount'] }.uniq.sort!
188+
create_object_options(client)['processors'].collect { |processor_spec| processor_spec['template']['processorCoreAmount'] }.uniq.sort!
189189
end
190190

191191
##
192192
# Return a list of values that are valid the array given to the :disks
193193
def self.disk_options(client = nil)
194-
create_object_options(client)["hardDrives"].collect { |disk_spec| disk_spec['template']['hardDrives'][0]['capacity'].to_i}.uniq.sort!
194+
create_object_options(client)['hardDrives'].collect { |disk_spec| disk_spec['template']['hardDrives'][0]['capacity'].to_i}.uniq.sort!
195195
end
196196

197197
##
198198
# Returns a list of the valid :os_refrence_codes
199199
def self.os_reference_code_options(client = nil)
200-
create_object_options(client)["operatingSystems"].collect { |os_spec| os_spec['template']['operatingSystemReferenceCode'] }.uniq.sort!
200+
create_object_options(client)['operatingSystems'].collect { |os_spec| os_spec['template']['operatingSystemReferenceCode'] }.uniq.sort!
201201
end
202202

203203
##
204204
# Returns a list of the :max_port_speeds
205205
def self.max_port_speed_options(client = nil)
206-
create_object_options(client)["networkComponents"].collect { |component_spec| component_spec['template']['networkComponents'][0]['maxSpeed'] }
206+
create_object_options(client)['networkComponents'].collect { |component_spec| component_spec['template']['networkComponents'][0]['maxSpeed'] }
207207
end
208208

209209
end # class BareMetalServerOrder

lib/softlayer/BareMetalServerOrder_Package.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BareMetalServerOrder_Package < Server
5858

5959
# An array of the ids of SSH keys to install on the server upon provisioning
6060
# To obtain a list of existing SSH keys, call getSshKeys on the SoftLayer_Account service:
61-
# client['Account'].getSshKeys()
61+
# client[:Account].getSshKeys()
6262
attr_accessor :ssh_key_ids
6363

6464
# The URI of a script to execute on the server after it has been provisioned. This may be
@@ -88,7 +88,7 @@ def initialize(package, client = nil)
8888
def verify
8989
product_order = hardware_order
9090
product_order = yield product_order if block_given?
91-
softlayer_client["Product_Order"].verifyOrder(product_order)
91+
softlayer_client[:Product_Order].verifyOrder(product_order)
9292
end
9393

9494
##
@@ -106,7 +106,7 @@ def verify
106106
def place_order!
107107
product_order = hardware_order
108108
product_order = yield product_order if block_given?
109-
softlayer_client["Product_Order"].placeOrder(product_order)
109+
softlayer_client[:Product_Order].placeOrder(product_order)
110110
end
111111

112112
protected

lib/softlayer/Config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def Config.file_settings(*additional_files)
8989
search_path.each do |file_path|
9090
if File.readable? file_path
9191
config = ConfigParser.new file_path
92-
softlayer_section = config["softlayer"]
92+
softlayer_section = config['softlayer']
9393

9494
if softlayer_section
9595
result[:username] = softlayer_section['username'] if softlayer_section['username']

lib/softlayer/ImageTemplate.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ def rename!(new_name)
4141
# true if the image template is a flex image
4242
# Note that the publicFlag property comes back as an integer (0 or 1)
4343
def public?
44-
self["publicFlag"] != 0
44+
self['publicFlag'] != 0
4545
end
4646

4747
##
4848
# true if the image template is a flex image
4949
# Note that the flexImageFlag property comes back as a boolean
5050
def flex_image?
51-
!!self["flexImageFlag"]
51+
!!self['flexImageFlag']
5252
end
5353

5454
##
@@ -63,7 +63,7 @@ def notes=(new_notes)
6363
##
6464
# Returns an array of the tags set on the image
6565
def tags
66-
return self["tagReferences"].collect{ |tag_reference| tag_reference["tag"]["name"] }
66+
return self['tagReferences'].collect{ |tag_reference| tag_reference['tag']['name'] }
6767
end
6868

6969
##
@@ -78,7 +78,7 @@ def tags=(tags_array)
7878
##
7979
# Returns the an array containing the datacenters where this image is available.
8080
def datacenters
81-
self["datacenters"].collect{ |datacenter_data| SoftLayer::Datacenter.datacenter_named(datacenter_data["name"])}
81+
self['datacenters'].collect{ |datacenter_data| SoftLayer::Datacenter.datacenter_named(datacenter_data['name'])}
8282
end
8383

8484
##
@@ -107,7 +107,7 @@ def datacenters=(datacenters_array)
107107
#
108108
def available_datacenters
109109
datacenters_data = self.service.getStorageLocations()
110-
datacenters_data.collect { |datacenter_data| SoftLayer::Datacenter.datacenter_named(datacenter_data["name"]) }
110+
datacenters_data.collect { |datacenter_data| SoftLayer::Datacenter.datacenter_named(datacenter_data['name']) }
111111
end
112112

113113

@@ -116,7 +116,7 @@ def available_datacenters
116116
# that this image is shared with
117117
def shared_with_accounts
118118
accounts_data = self.service.getAccountReferences
119-
accounts_data.collect { |account_data| account_data["accountId"] }
119+
accounts_data.collect { |account_data| account_data['accountId'] }
120120
end
121121

122122
##
@@ -177,7 +177,7 @@ def wait_until_ready(max_trials, seconds_between_tries = 2)
177177
self.refresh_details()
178178

179179
parent_ready = !(has_sl_property? :transactionId) || (self[:transactionId] == "")
180-
children_ready = (nil == self["children"].find { |child| child["transactionId"] != "" })
180+
children_ready = (nil == self['children'].find { |child| child['transactionId'] != "" })
181181

182182
ready = parent_ready && children_ready
183183
yield ready if block_given?
@@ -191,7 +191,7 @@ def wait_until_ready(max_trials, seconds_between_tries = 2)
191191

192192
# ModelBase protocol methods
193193
def service
194-
softlayer_client['Virtual_Guest_Block_Device_Template_Group'].object_with_id(self.id)
194+
softlayer_client[:Virtual_Guest_Block_Device_Template_Group].object_with_id(self.id)
195195
end
196196

197197
def softlayer_properties(object_mask = nil)
@@ -245,7 +245,7 @@ def self.find_private_templates(options_hash = {})
245245
} );
246246
end
247247

248-
account_service = softlayer_client['Account']
248+
account_service = softlayer_client[:Account]
249249
account_service = account_service.object_filter(object_filter) unless object_filter.empty?
250250
account_service = account_service.object_mask(default_object_mask)
251251

@@ -311,7 +311,7 @@ def self.find_public_templates(options_hash = {})
311311
} );
312312
end
313313

314-
template_service = softlayer_client['Virtual_Guest_Block_Device_Template_Group']
314+
template_service = softlayer_client[:Virtual_Guest_Block_Device_Template_Group]
315315
template_service = template_service.object_filter(object_filter) unless object_filter.empty?
316316
template_service = template_service.object_mask(default_object_mask)
317317

@@ -347,7 +347,7 @@ def self.template_with_id(id, options_hash = {})
347347
softlayer_client = options_hash[:client] || Client.default_client
348348
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
349349

350-
service = softlayer_client['Virtual_Guest_Block_Device_Template_Group'].object_with_id(id)
350+
service = softlayer_client[:Virtual_Guest_Block_Device_Template_Group].object_with_id(id)
351351
service.object_mask(default_object_mask)
352352

353353
if options_hash.has_key? :object_mask

lib/softlayer/ModelBase.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def initialize(softlayer_client, network_hash)
4747
# a particular entity in the SoftLayer_Ticket service. The particular
4848
# entity is identified by its id so the Ticket class would return
4949
#
50-
# softlayer_client["Ticket"].object_with_id
50+
# softlayer_client[:Ticket].object_with_id
5151
#
5252
# which is a service which would allow calls to the ticket service
5353
# through that particular object.

lib/softlayer/ProductItemCategory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ProductItemCategory < ModelBase
8484
end
8585

8686
def service
87-
softlayer_client["SoftLayer_Product_Item_Category"].object_with_id(self.id)
87+
softlayer_client[:SoftLayer_Product_Item_Category].object_with_id(self.id)
8888
end
8989

9090
##

lib/softlayer/ProductPackage.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ProductPackage < ModelBase
6565
# filtering mechanism on the server side to give us a list of the categories, groups, and prices that are valid for the current
6666
# account at the current time. We construct the ProductItemCategory objects from the results we get back.
6767
#
68-
configuration_data = softlayer_client['Product_Package'].object_with_id(self.id).object_mask("mask[isRequired,itemCategory.categoryCode]").getConfiguration()
68+
configuration_data = softlayer_client[:Product_Package].object_with_id(self.id).object_mask("mask[isRequired,itemCategory.categoryCode]").getConfiguration()
6969

7070
# We sort of invert the information and create a map from category codes to a boolean representing
7171
# whether or not they are required.
@@ -75,7 +75,7 @@ class ProductPackage < ModelBase
7575
end
7676

7777
# This call to getCategories is the one that does lots of fancy back-end filtering for us
78-
categories_data = softlayer_client['Product_Package'].object_with_id(self.id).getCategories()
78+
categories_data = softlayer_client[:Product_Package].object_with_id(self.id).getCategories()
7979

8080
# Run though the categories and for each one that's in our config, create a SoftLayer::ProductItemCategory object.
8181
# Conveniently the +keys+ of the required_by_category_code gives us a list of the category codes in the configuration
@@ -129,7 +129,7 @@ def category(category_code)
129129
##
130130
# Returns a list of the datacenters that this package is available in
131131
def datacenter_options
132-
available_locations.collect { |location_data| Datacenter::datacenter_named(location_data["location"]["name"], self.softlayer_client) }.compact
132+
available_locations.collect { |location_data| Datacenter::datacenter_named(location_data['location']['name'], self.softlayer_client) }.compact
133133
end
134134

135135
##
@@ -150,7 +150,7 @@ def items_with_description(expected_description)
150150
# Returns the service for interacting with this package through the network API
151151
#
152152
def service
153-
softlayer_client['Product_Package'].object_with_id(self.id)
153+
softlayer_client[:Product_Package].object_with_id(self.id)
154154
end
155155

156156
##
@@ -165,7 +165,7 @@ def self.packages_with_key_name(key_name, client = nil)
165165
filter.accept('type.keyName').when_it is(key_name)
166166
end
167167

168-
filtered_service = softlayer_client['Product_Package'].object_filter(filter).object_mask(self.default_object_mask('mask'))
168+
filtered_service = softlayer_client[:Product_Package].object_filter(filter).object_mask(self.default_object_mask('mask'))
169169
packages_data = filtered_service.getAllObjects
170170
packages_data.collect { |package_data| ProductPackage.new(softlayer_client, package_data) }
171171
end
@@ -178,7 +178,7 @@ def self.package_with_id(package_id, client = nil)
178178
softlayer_client = client || Client.default_client
179179
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
180180

181-
package_data = softlayer_client['Product_Package'].object_with_id(package_id).object_mask(self.default_object_mask('mask')).getObject
181+
package_data = softlayer_client[:Product_Package].object_with_id(package_id).object_mask(self.default_object_mask('mask')).getObject
182182
ProductPackage.new(softlayer_client, package_data)
183183
end
184184

0 commit comments

Comments
 (0)