softlayer_api 2.2.2 → 3.0.b1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,8 @@
1
- #
1
+ #--
2
2
  # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
3
  #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
22
6
 
23
7
  module SoftLayer
24
8
  #
@@ -38,9 +22,7 @@ module SoftLayer
38
22
  # a virtual server
39
23
  #++
40
24
 
41
- # String, short name of the data center that will house the new virtual server (e.g. "dal05" or "sea01")
42
- # Corresponds to +datacenter.name+ in the documentation for createObject. If not provided, the server will
43
- # be provisioned in the first available data center.
25
+ # An instance of SoftLayer::Datacenter. The server will be provisioned in that Datacenter.
44
26
  attr_accessor :datacenter
45
27
 
46
28
  # String, The hostname to assign to the new server
@@ -58,17 +40,18 @@ module SoftLayer
58
40
  attr_accessor :memory
59
41
 
60
42
  #--
61
- # These two options are mutually exclusive, but one or the other must be provided.
62
- # If you provide both, the image_global_id will be added to the order and the os_reference_code will be ignored
43
+ # These two options are mutually exclusive, but one of them must be provided.
44
+ # If you provide both, the image_template will be added to the order and the
45
+ # os_reference_code will be ignored
63
46
  #++
64
47
 
65
48
  # String, An OS reference code for the operating system to install on the virtual server
66
49
  # Corresponds to +operatingSystemReferenceCode+ in the +createObject+ documentation
67
50
  attr_accessor :os_reference_code
68
51
 
69
- # String, The globalIdentifier of a disk image to put on the newly created server
70
- # Corresponds to +blockDeviceTemplateGroup.globalIdentifier+ in the +createObject+ documentation
71
- attr_accessor :image_global_id
52
+ # An instance of the SoftLayer::ImageTemplate class. Represents the image template that should
53
+ # be installed on the server.
54
+ attr_accessor :image_template
72
55
 
73
56
  #--
74
57
  # Optional attributes
@@ -173,7 +156,7 @@ module SoftLayer
173
156
  template["dedicatedAccountHostOnlyFlag"] = true if @dedicated_host_only
174
157
  template["privateNetworkOnlyFlag"] = true if @private_network_only
175
158
 
176
- template["datacenter"] = {"name" => @datacenter} if @datacenter
159
+ template["datacenter"] = {"name" => @datacenter.name} if @datacenter
177
160
  template['userData'] = [{'value' => @user_metadata}] if @user_metadata
178
161
  template['networkComponents'] = [{'maxSpeed'=> @max_port_speed}] if @max_port_speed
179
162
  template['postInstallScriptUri'] = @provision_script_URI.to_s if @provision_script_URI
@@ -181,8 +164,8 @@ module SoftLayer
181
164
  template['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
182
165
  template["primaryBackendNetworkComponent"] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
183
166
 
184
- if @image_global_id
185
- template["blockDeviceTemplateGroup"] = {"globalIdentifier" => @image_global_id}
167
+ if @image_template
168
+ template["blockDeviceTemplateGroup"] = {"globalIdentifier" => @image_template.global_id}
186
169
  elsif @os_reference_code
187
170
  template["operatingSystemReferenceCode"] = @os_reference_code
188
171
  end
@@ -227,7 +210,7 @@ module SoftLayer
227
210
  ##
228
211
  # Return a list of values that are valid for the :datacenter attribute
229
212
  def self.datacenter_options(client = nil)
230
- create_object_options(client)["datacenters"].collect { |datacenter_spec| datacenter_spec['template']['datacenter']["name"] }.uniq.sort!
213
+ create_object_options(client)["datacenters"].collect { |datacenter_spec| Datacenter.datacenter_named(datacenter_spec['template']['datacenter']['name'], client) }.uniq
231
214
  end
232
215
 
233
216
  ##
@@ -0,0 +1,142 @@
1
+ #--
2
+ # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
+ #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
6
+
7
+ module SoftLayer
8
+ # This class is used to order changes to a virtual server. Although
9
+ # the class is named "upgrade" this class can also be used for "downgrades"
10
+ # (i.e. changing attributes to a smaller, or slower, value)
11
+ #
12
+ # The class can also be used to discover what upgrades are available
13
+ # for a given virtual server.
14
+ #
15
+ class VirtualServerUpgradeOrder
16
+ # The virtual server that this order is designed to upgrade.
17
+ attr_reader :virtual_server
18
+
19
+ # The number of cores the server should have after the upgrade.
20
+ # If this is nil, the the number of cores will not change
21
+ attr_accessor :cores
22
+
23
+ # The amount of RAM (in GB) that the server should have after the upgrade
24
+ # If this is nil, the ram will not change
25
+ attr_accessor :ram
26
+
27
+ # The port speed (in Mega bits per second) that the server should have
28
+ # after the upgrade. This is typically a value like 100, or 1000
29
+ # If this is nil, the port speeds will not change
30
+ attr_accessor :max_port_speed
31
+
32
+ # The date and time when you would like the upgrade to be processed.
33
+ # This should simply be a Time object. If nil then the upgrade
34
+ # will be performed immediately
35
+ attr_accessor :upgrade_at
36
+
37
+ ##
38
+ # Create an upgrade order for the virtual server provided.
39
+ #
40
+ def initialize(virtual_server)
41
+ raise "A virtual server must be provided at the time a virtual server order is created" if !virtual_server || !virtual_server.kind_of?(SoftLayer::VirtualServer)
42
+ @virtual_server = virtual_server
43
+ end
44
+
45
+ ##
46
+ # Sends the order represented by this object to SoftLayer for validation.
47
+ #
48
+ # If a block is passed to verify, the code will send the order template
49
+ # being constructed to the block before the order is actually sent for
50
+ # validation.
51
+ #
52
+ def verify()
53
+ if has_order_items?
54
+ order_object = self.order_object
55
+ order_object = yield order_object if block_given?
56
+
57
+ @virtual_server.softlayer_client["Product_Order"].verifyOrder(order_object)
58
+ end
59
+ end
60
+
61
+ ##
62
+ # Places the order represented by this object. This is likely to
63
+ # involve a change to the charges on an account.
64
+ #
65
+ # If a block is passed to this routine, the code will send the order template
66
+ # being constructed to that block before the order is sent
67
+ #
68
+ def place_order!()
69
+ if has_order_items?
70
+ order_object = self.order_object
71
+ order_object = yield order_object if block_given?
72
+
73
+ @virtual_server.softlayer_client["Product_Order"].placeOrder(order_object)
74
+ end
75
+ end
76
+
77
+ ##
78
+ # Return a list of values that are valid for the :cores attribute
79
+ def core_options()
80
+ self._item_prices_in_category("guest_core").map { |item_price| item_price["item"]["capacity"].to_i}.sort.uniq
81
+ end
82
+
83
+ ##
84
+ # Return a list of values that are valid for the :memory attribute
85
+ def memory_options()
86
+ self._item_prices_in_category("ram").map { |item_price| item_price["item"]["capacity"].to_i}.sort.uniq
87
+ end
88
+
89
+ ##
90
+ # Returns a list of valid values for max_port_speed
91
+ def max_port_speed_options(client = nil)
92
+ self._item_prices_in_category("port_speed").map { |item_price| item_price["item"]["capacity"].to_i}.sort.uniq
93
+ end
94
+
95
+ private
96
+
97
+ ##
98
+ # Returns true if this order object has any upgrades specified
99
+ #
100
+ def has_order_items?
101
+ @cores != nil || @ram != nil || @max_port_speed != nil
102
+ end
103
+
104
+ ##
105
+ # Returns a list of the update item prices, in the given category, for the server
106
+ #
107
+ def _item_prices_in_category(which_category)
108
+ @virtual_server.upgrade_options.select { |item_price| item_price["categories"].find { |category| category["categoryCode"] == which_category } }
109
+ end
110
+
111
+ ##
112
+ # Searches through the upgrade items pricess known to this server for the one that is in a particular category
113
+ # and whose capacity matches the value given. Returns the item_price or nil
114
+ #
115
+ def _item_price_with_capacity(which_category, capacity)
116
+ self._item_prices_in_category(which_category).find { |item_price| item_price["item"]["capacity"].to_i == capacity}
117
+ end
118
+
119
+ ##
120
+ # construct an order object
121
+ #
122
+ def order_object
123
+ prices = []
124
+
125
+ cores_price_item = @cores ? _item_price_with_capacity("guest_core", @cores) : nil
126
+ ram_price_item = @ram ? _item_price_with_capacity("ram", @ram) : nil
127
+ max_port_speed_price_item = @max_port_speed ? _item_price_with_capacity("port_speed", @max_port_speed) : nil
128
+
129
+ prices << { "id" => cores_price_item["id"] } if cores_price_item
130
+ prices << { "id" => ram_price_item["id"] } if ram_price_item
131
+ prices << { "id" => max_port_speed_price_item["id"] } if max_port_speed_price_item
132
+
133
+ # put together an order
134
+ upgrade_order = {
135
+ 'complexType' => 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade',
136
+ 'virtualGuests' => [{'id' => @virtual_server.id }],
137
+ 'properties' => [{'name' => 'MAINTENANCE_WINDOW', 'value' => @upgrade_at ? @upgrade_at.iso8601 : Time.now.iso8601}],
138
+ 'prices' => prices
139
+ }
140
+ end
141
+ end # VirtualServerUpgradeOrder
142
+ end # SoftLayer Module
@@ -1,37 +1,18 @@
1
- #
1
+ #--
2
2
  # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
3
  #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
22
6
 
23
7
  require 'rubygems'
24
8
 
25
- # This module is used to provide a namespace for SoftLayer code. It also declares a number of
26
- # global variables:
27
- # - +$SL_API_USERNAME+ - The default username passed by clients to the server for authentication.
28
- # Set this if you want to use the same username for all clients and don't want to have to specify it when the client is created
29
- # - +$SL_API_KEY+ - The default API key passed by clients to the server for authentication.
30
- # Set this if you want to use the same api for all clients and don't want to have to specify it when the client is created
31
- # - +$SL_API_BASE_URL+- The default URL used to access the SoftLayer API. This defaults to the value of +SoftLayer::API_PUBLIC_ENDPOINT+
9
+ ##
10
+ # The SoftLayer module provides a namespace for SoftLayer code.
32
11
  #
33
12
  module SoftLayer
34
- VERSION = "2.2.2" # version history in the CHANGELOG.textile file at the root of the source
13
+ # The version number (including major, minor, and bugfix numbers)
14
+ # This should change in accordance with the concept of Semantic Versioning
15
+ VERSION = "3.0.0" # version history in the CHANGELOG.textile file at the root of the source
35
16
 
36
17
  # The base URL of the SoftLayer API available to the public internet.
37
18
  API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'
@@ -39,9 +20,9 @@ module SoftLayer
39
20
  # The base URL of the SoftLayer API available through SoftLayer's private network
40
21
  API_PRIVATE_ENDPOINT = 'https://api.service.softlayer.com/xmlrpc/v3/'
41
22
 
42
- #
23
+ #--
43
24
  # These globals can be used to simplify client creation
44
- #
25
+ #++
45
26
 
46
27
  # Set this if you want to provide a default username for each client as it is created.
47
28
  # usernames provided to the client initializer will override the global
@@ -59,4 +40,4 @@ end # module SoftLayer
59
40
  #
60
41
  # History:
61
42
  #
62
- # The history has been moved to the CHANGELOG.textile file in the source directory
43
+ # The history can be found in the CHANGELOG.textile file in the project root directory
@@ -1,24 +1,8 @@
1
- #
1
+ #--
2
2
  # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
3
  #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
22
6
 
23
7
  ##
24
8
  # This extension to the Hash class to allows object masks to be constructed
data/lib/softlayer_api.rb CHANGED
@@ -1,45 +1,35 @@
1
- #
1
+ #--
2
2
  # Copyright (c) 2014 SoftLayer Technologies, Inc. All rights reserved.
3
3
  #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
4
+ # For licensing information see the LICENSE.md file in the project root.
5
+ #++
22
6
 
7
+ # requirements from the core libraries
8
+ require 'time'
9
+
10
+ # Requirements for the Foundation Layer
23
11
  require 'softlayer/base'
24
12
  require 'softlayer/object_mask_helpers'
25
13
  require 'softlayer/APIParameterFilter'
26
14
  require 'softlayer/ObjectFilter'
27
15
  require 'softlayer/ObjectMaskParser'
28
16
  require 'softlayer/Config'
29
-
30
17
  require 'softlayer/Client'
31
18
  require 'softlayer/Service'
32
19
 
33
- # model classes
20
+ # Requirements for the Model Layer
34
21
  require 'softlayer/ModelBase'
22
+ require 'softlayer/Datacenter'
35
23
  require 'softlayer/DynamicAttribute'
36
24
  require 'softlayer/Account'
37
- require 'softlayer/Ticket'
38
25
  require 'softlayer/Server'
39
26
  require 'softlayer/BareMetalServer'
40
27
  require 'softlayer/BareMetalServerOrder'
41
28
  require 'softlayer/BareMetalServerOrder_Package'
29
+ require 'softlayer/ImageTemplate'
42
30
  require 'softlayer/ProductPackage'
43
31
  require 'softlayer/ProductItemCategory'
32
+ require 'softlayer/Ticket'
44
33
  require 'softlayer/VirtualServer'
45
34
  require 'softlayer/VirtualServerOrder'
35
+ require 'softlayer/VirtualServerUpgradeOrder'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softlayer_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.0.b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SoftLayer Development Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configparser
@@ -122,7 +122,9 @@ files:
122
122
  - lib/softlayer/BareMetalServerOrder_Package.rb
123
123
  - lib/softlayer/Client.rb
124
124
  - lib/softlayer/Config.rb
125
+ - lib/softlayer/Datacenter.rb
125
126
  - lib/softlayer/DynamicAttribute.rb
127
+ - lib/softlayer/ImageTemplate.rb
126
128
  - lib/softlayer/ModelBase.rb
127
129
  - lib/softlayer/ObjectFilter.rb
128
130
  - lib/softlayer/ObjectMaskParser.rb
@@ -136,6 +138,7 @@ files:
136
138
  - lib/softlayer/Ticket.rb
137
139
  - lib/softlayer/VirtualServer.rb
138
140
  - lib/softlayer/VirtualServerOrder.rb
141
+ - lib/softlayer/VirtualServerUpgradeOrder.rb
139
142
  - lib/softlayer/base.rb
140
143
  - lib/softlayer/object_mask_helpers.rb
141
144
  - lib/softlayer_api.rb
@@ -154,9 +157,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
157
  version: 1.9.2
155
158
  required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  requirements:
157
- - - ">="
160
+ - - ">"
158
161
  - !ruby/object:Gem::Version
159
- version: '0'
162
+ version: 1.3.1
160
163
  requirements: []
161
164
  rubyforge_project:
162
165
  rubygems_version: 2.2.2