Skip to content

Commit 5d2cfc7

Browse files
committed
Renamed softlayer_resource to sofltayer_dynamic_attr. This makes it lie very nicely aside softlayer_attr. Added more attributes to the existing classes and 'played with' documentation to see how we could document those beasts.
1 parent cddfec3 commit 5d2cfc7

24 files changed

Lines changed: 505 additions & 365 deletions

examples/order_virtual_server.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
begin
3030
# This sample walks through the creation of a Virtual Server.
3131
# It explores techniques for discovering what configuration options
32-
# exist, puts together an order, then sends that order to
32+
# exist, puts together an order, then sends that order to
3333
# SoftLayer for verification.
3434

3535
client = SoftLayer::Client.new(
@@ -42,37 +42,37 @@
4242
server_order = SoftLayer::VirtualServerOrder.new(client)
4343
server_order.hostname = "server1"
4444
server_order.domain = "ruby-api-test.org"
45-
45+
4646
# We must tell the system in which datacenter we want our server created
4747
# We can ask the class to give us a list of options:
4848
puts SoftLayer::VirtualServerOrder.datacenter_options(client).inspect
49-
49+
5050
# The list will look something like ["ams01", "dal01", "dal05",...
5151
# Let's put our server in the 'dal05' (Dallas 5) datacenter
5252
server_order.datacenter = 'dal05'
53-
53+
5454
# The order must know how many computing cores we want in our virtual
55-
# server. Again we can ask the class for options. The result will
55+
# server. Again we can ask the class for options. The result will
5656
# be something like [1, 2, 4, 8, 12, 16]
5757
# 2 sounds like a good number of cores for our simple server
5858
puts SoftLayer::VirtualServerOrder.core_options(client).inspect
5959
server_order.cores = 2
60-
60+
6161
# We must indicate how much memory the virtual server should have.
6262
# Again we can query for options and select a good value
6363
puts SoftLayer::VirtualServerOrder.memory_options(client).inspect
6464
server_order.memory = 2 #GB
65-
65+
6666
# Similarly we can choose an operating system for the server:
6767
puts SoftLayer::VirtualServerOrder.os_reference_code_options(client).inspect
6868
server_order.os_reference_code = 'CENTOS_6_64'
69-
70-
# Finally, in spite of the fact that our server is simple, we want it
69+
70+
# Finally, in spite of the fact that our server is simple, we want it
7171
# to have a blazing fast connection speed. Let's look at the options and choose
7272
# the fastest! (it's probably 1 Gbps)
7373
server_order.max_port_speed = SoftLayer::VirtualServerOrder.max_port_speed_options(client).max
74-
75-
# The server order is now complete. This sample will ask it to verify itself with the
74+
75+
# The server order is now complete. This sample will ask it to verify itself with the
7676
# SoftLayer ordering system, but a simple change from verify to place_order! would ask
7777
# the system to provision the server (and charge it to our account)
7878
begin

lib/softlayer/Account.rb

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,68 @@
2222

2323
module SoftLayer
2424
class Account < SoftLayer::ModelBase
25-
include ::SoftLayer::ModelResource
26-
27-
softlayer_attr :companyName
28-
softlayer_attr :firstName
29-
softlayer_attr :lastName
30-
softlayer_attr :address1
31-
softlayer_attr :address2
32-
softlayer_attr :city
33-
softlayer_attr :state
34-
softlayer_attr :country
35-
softlayer_attr :postalCode
36-
softlayer_attr :officePhone
25+
include ::SoftLayer::DynamicAttribute
26+
27+
##
28+
# :attr_reader:
29+
# The company name of the primary contact
30+
sl_attr :companyName
31+
32+
##
33+
# :attr_reader:
34+
# The given name name of the primary contact
35+
sl_attr :firstName
36+
37+
##
38+
# :attr_reader:
39+
# The surname of the primary contact
40+
sl_attr :lastName
41+
42+
##
43+
# :attr_reader:
44+
# The first address line for the primary contact's address
45+
sl_attr :address1
46+
47+
##
48+
# :attr_reader:
49+
# The second address line (if any, may be nil) for the primary contact's address
50+
sl_attr :address2
51+
52+
##
53+
# :attr_reader:
54+
# The city stored as part of the primary contact's address
55+
sl_attr :city
56+
57+
##
58+
# :attr_reader:
59+
# The two character abbreviation for the state, province, or other similar national
60+
# division that is part of the address of the primary contact. For addresses
61+
# outside of the US and Canada, where there may not be an equivalent to a state,
62+
# this may be 'NA' (for not applicable)
63+
sl_attr :state
64+
65+
##
66+
# :attr_reader:
67+
# The country stored as part of the primary contact's address
68+
sl_attr :country
69+
70+
##
71+
# :attr_reader:
72+
# The postal code (in the US, aka. zip code) of the primary contact's address
73+
sl_attr :postalCode
74+
75+
##
76+
# :attr_reader:
77+
# The office phone nubmer listed for the primary contact
78+
sl_attr :officePhone
3779

3880
##
3981
# The Bare Metal Servers (physical hardware) associated with the
4082
# account. Unless you force these to update, they will be refreshed every
4183
# five minutes.
42-
softlayer_resource :bare_metal_servers do |bare_metal|
84+
# :call-seq:
85+
# bare_metal_servers(force_update=false)
86+
sl_dynamic_attr :bare_metal_servers do |bare_metal|
4387
bare_metal.should_update? do
4488
@last_bare_metal_update ||= Time.at(0)
4589
(Time.now - @last_bare_metal_update) > 5 * 60 # update every 5 minutes
@@ -55,7 +99,9 @@ class Account < SoftLayer::ModelBase
5599
# The virtual servers (aka. CCIs or Virtual_Guests) associated with the
56100
# account. Unless you force these to update, they will be refreshed every
57101
# five minutes.
58-
softlayer_resource :virtual_servers do |virtual_servers|
102+
# :call-seq:
103+
# virtual_servers(force_update=false)
104+
sl_dynamic_attr :virtual_servers do |virtual_servers|
59105
virtual_servers.should_update? do
60106
@last_virtual_server_update ||= Time.at(0)
61107
(Time.now - @last_virtual_server_update) > 5 * 60 # update every 5 minutes
@@ -69,8 +115,10 @@ class Account < SoftLayer::ModelBase
69115

70116
##
71117
# The tickets resource consists of all open tickets, and tickets closed
72-
# "recently". These refresh every 5 minutes
73-
softlayer_resource :tickets do |tickets|
118+
# "recently". These refresh every 5 minutes.
119+
# :call-seq:
120+
# tickets(force_update=false)
121+
sl_dynamic_attr :tickets do |tickets|
74122
tickets.should_update? do
75123
@last_ticket_update ||= Time.at(0)
76124
(Time.now - @last_ticket_update) > 5 * 60 #update every 5 minutes

lib/softlayer/BareMetalServer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
module SoftLayer
2424
#
2525
# This class represents a Bare Metal Server, a hardware server in contrast to a virtual machine,
26-
# in the SoftLayer Environment. It corresponds rougly to the +SoftLayer_Hardware+ and
26+
# in the SoftLayer Environment. It corresponds rougly to the +SoftLayer_Hardware+ and
2727
# +SoftLayer_Hardware_Server+ services in the SoftLayer API
2828
#
2929
# http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware
@@ -68,7 +68,7 @@ def cancel!(reason = :unneeded, comment = '')
6868
end
6969

7070
##
71-
# Returns the SoftLayer Service used to work with instances of this class.
71+
# Returns the SoftLayer Service used to work with instances of this class.
7272
# For Bare Metal Servers that is +SoftLayer_Hardware+ though in some special cases
7373
# you may have to use +SoftLayer_Hardware_Server+ as a type or service.
7474
#
@@ -103,7 +103,7 @@ def self.default_object_mask
103103
#
104104
# When cancelling a server with the cancel! method, the first parameter is the reason and
105105
# should be one of the keys in the hash returned by this method. This, in turn
106-
# will be translated into a string which is, for all intents and purposes, a
106+
# will be translated into a string which is, for all intents and purposes, a
107107
# literal string constant with special meaning to the SoftLayer API.
108108
#
109109
def self.cancellation_reasons

lib/softlayer/BareMetalServerOrder.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module SoftLayer
3131
# that go into configuring the server, please see the
3232
# BareMetalServerOrder_Package class.
3333
#
34-
# This class creates the server with the SoftLayer_Hardware::createObject
34+
# This class creates the server with the SoftLayer_Hardware::createObject
3535
# method.
3636
#
3737
# http://sldn.softlayer.com/reference/services/SoftLayer_Hardware/createObject
@@ -188,13 +188,13 @@ def hardware_instance_template
188188
def self.create_object_options(client)
189189
@@create_object_options ||= client["Hardware"].getCreateObjectOptions()
190190
end
191-
191+
192192
##
193193
# Return a list of values that are valid for the :datacenter attribute
194194
def self.datacenter_options(client)
195195
create_object_options(client)["datacenters"].collect { |datacenter_spec| datacenter_spec['template']['datacenter']["name"] }.uniq.sort!
196196
end
197-
197+
198198
def self.core_options(client)
199199
create_object_options(client)["processors"].collect { |processor_spec| processor_spec['template']['processorCoreAmount'] }.uniq.sort!
200200
end
@@ -215,7 +215,7 @@ def self.os_reference_code_options(client)
215215
# Returns a list of the :max_port_speeds
216216
def self.max_port_speed_options(client)
217217
create_object_options(client)["networkComponents"].collect { |component_spec| component_spec['template']['networkComponents'][0]['maxSpeed'] }
218-
end
218+
end
219219

220220
end # class BareMetalServerOrder
221221
end # module SoftLayer

lib/softlayer/BareMetalServerOrder_Package.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module SoftLayer
2424
#
2525
# This class is used to order a hardware server using a product package.
2626
#
27-
# Ordering a server using a product package is a more complex process than
28-
# ordering with simple attributes (as is done by the BareMetalServerOrder class).
29-
# However with that complexity comes the the ability to specify the configuration
27+
# Ordering a server using a product package is a more complex process than
28+
# ordering with simple attributes (as is done by the BareMetalServerOrder class).
29+
# However with that complexity comes the the ability to specify the configuration
3030
# of the server in exacting detail.
3131
#
3232
# To use this class, you first select a product package. The product package
@@ -58,8 +58,8 @@ class BareMetalServerOrder_Package < Server
5858
attr_accessor :domain
5959

6060
# The value of this property should be a hash. The keys of the hash are ProdcutItemCategory
61-
# codes (like 'os' and 'ram') while the values may be Integers or Objects. The Integer values
62-
# should be the +id+ of a +SoftLayer_Product_Item_Price+ representing the configuration option
61+
# codes (like 'os' and 'ram') while the values may be Integers or Objects. The Integer values
62+
# should be the +id+ of a +SoftLayer_Product_Item_Price+ representing the configuration option
6363
# chosen for that category. Objects must respond to the +price_id+ message and return an integer
6464
# that is the +id+ of a +SoftLayer_Product_Item_Price+. Instances of the ProductConfigurationOption
6565
# class behave this way.
@@ -154,7 +154,7 @@ def hardware_order
154154

155155
product_order
156156
end
157-
157+
158158
end # BareMetalServerOrder_Package
159-
159+
160160
end # SoftLayer

0 commit comments

Comments
 (0)