softlayer_api 3.0.b1 → 3.0.b2

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.
@@ -0,0 +1,93 @@
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
+ #
9
+ # This class allows you to order a Firewall for a VLAN
10
+ #
11
+ class VLANFirewallOrder
12
+ ##
13
+ # The VLAN that you are ordering the firewall for.
14
+ attr_reader :vlan_id
15
+
16
+ ##
17
+ # Set high_availabilty to true if you want redundant
18
+ # firewall devices (defaults to false, no high_availability)
19
+ attr_accessor :high_availability
20
+
21
+ ##
22
+ # Create a new order for the given VLAN
23
+ # Note that the vlan_id is NOT the same as the vlan number.
24
+ def initialize (vlan_id, client = nil)
25
+ @softlayer_client = client || Client.default_client
26
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !@softlayer_client
27
+
28
+ @vlan_id = vlan_id
29
+ @high_availability = false
30
+ end
31
+
32
+ ##
33
+ # Calls the SoftLayer API to verify that the template provided by this order is valid
34
+ # This routine will return the order template generated by the API or will throw an exception
35
+ #
36
+ # This routine will not actually create a Bare Metal Instance and will not affect billing.
37
+ #
38
+ # If you provide a block, it will receive the order template as a parameter and
39
+ # the block may make changes to the template before it is submitted.
40
+ def verify()
41
+ order_template = firewall_order_template
42
+ order_template = yield order_template if block_given?
43
+
44
+ @softlayer_client[:Product_Order].verifyOrder(order_template)
45
+ end
46
+
47
+ ##
48
+ # Calls the SoftLayer API to place an order for a new server based on the template in this
49
+ # order. If this succeeds then you will be billed for the new server.
50
+ #
51
+ # If you provide a block, it will receive the order template as a parameter and
52
+ # the block may make changes to the template before it is submitted.
53
+ def place_order!()
54
+ order_template = firewall_order_template
55
+ order_template = yield order_template if block_given?
56
+
57
+ @softlayer_client[:Product_Order].placeOrder(order_template)
58
+ end
59
+
60
+ protected
61
+
62
+ ##
63
+ # Returns a hash of the creation options formatted to be sent to
64
+ # the SoftLayer API for either verification or completion
65
+ def firewall_order_template
66
+ client = @softlayer_client
67
+ additional_products_package = SoftLayer::ProductPackage.additional_products_package(client)
68
+
69
+ template = {
70
+ 'complexType' => 'SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated',
71
+ 'quantity' => 1,
72
+ 'packageId' => additional_products_package.id,
73
+ 'vlanId' => @vlan_id
74
+ }
75
+
76
+ if @high_availability
77
+ expected_description = "Hardware Firewall (High Availability)"
78
+ else
79
+ expected_description = "Hardware Firewall (Dedicated)"
80
+ end
81
+
82
+ firewall_items = additional_products_package.items_with_description(expected_description)
83
+
84
+ raise "Could not find a price item matching the description '#{expected_description}'" if firewall_items.empty?
85
+
86
+ firewall_item = firewall_items[0]
87
+
88
+ template['prices'] = [{ 'id' => firewall_item.price_id }] if firewall_item.respond_to?(:price_id)
89
+
90
+ template
91
+ end
92
+ end # class VLANFirewallOrder
93
+ end # module SoftLayer
@@ -87,13 +87,16 @@ module SoftLayer
87
87
  # You may use the wait_until_ready routine of SoftLayer::ImageTemplate to
88
88
  # wait on it.
89
89
  #
90
- def capture_image(image_name, include_attached_storage = false, image_notes = nil)
90
+ def capture_image(image_name, include_attached_storage = false, image_notes = '')
91
+ image_notes = '' if !image_notes
92
+ image_name = 'Captured Image' if !image_name
93
+
91
94
  disk_filter = lambda { |disk| disk['device'] == '0' }
92
95
  disk_filter = lambda { |disk| disk['device'] != '1' } if include_attached_storage
93
96
 
94
97
  disks = self.blockDevices.select(&disk_filter)
95
98
 
96
- self.service.createArchiveTransaction(image_name, disks, notes ? notes : "") if disks && !disks.empty?
99
+ self.service.createArchiveTransaction(image_name, disks, image_notes) if disks && !disks.empty?
97
100
 
98
101
  image_templates = SoftLayer::ImageTemplate.find_private_templates(:name => image_name)
99
102
  image_templates[0] if !image_templates.empty?
@@ -161,7 +164,7 @@ module SoftLayer
161
164
  softlayer_client = options[:client] || Client.default_client
162
165
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
163
166
 
164
- vg_service = softlayer_client["Virtual_Guest"]
167
+ vg_service = softlayer_client[:Virtual_Guest]
165
168
  vg_service = vg_service.object_mask(default_object_mask.to_sl_object_mask)
166
169
 
167
170
  if options.has_key?(:object_mask)
@@ -248,7 +251,7 @@ module SoftLayer
248
251
 
249
252
  required_properties_mask = 'mask.id'
250
253
 
251
- account_service = softlayer_client['Account']
254
+ account_service = softlayer_client[:Account]
252
255
  account_service = account_service.object_filter(object_filter) unless object_filter.empty?
253
256
  account_service = account_service.object_mask(default_object_mask.to_sl_object_mask)
254
257
 
@@ -307,7 +310,7 @@ module SoftLayer
307
310
  # For VirtualServers the service is +SoftLayer_Virtual_Guest+ and
308
311
  # addressing this object is done by id.
309
312
  def service
310
- return softlayer_client["Virtual_Guest"].object_with_id(self.id)
313
+ return softlayer_client[:Virtual_Guest].object_with_id(self.id)
311
314
  end
312
315
  end #class VirtualServer
313
316
  end
@@ -119,7 +119,7 @@ module SoftLayer
119
119
  order_template = virtual_guest_template
120
120
  order_template = yield order_template if block_given?
121
121
 
122
- @softlayer_client["Virtual_Guest"].generateOrderTemplate(order_template)
122
+ @softlayer_client[:Virtual_Guest].generateOrderTemplate(order_template)
123
123
  end
124
124
 
125
125
  # Calls the SoftLayer API to place an order for a new virtual server based on the template in this
@@ -132,8 +132,8 @@ module SoftLayer
132
132
  order_template = virtual_guest_template
133
133
  order_template = yield order_template if block_given?
134
134
 
135
- virtual_server_hash = @softlayer_client["Virtual_Guest"].createObject(order_template)
136
- SoftLayer::VirtualServer.server_with_id(virtual_server_hash["id"], :client => @softlayer_client) if virtual_server_hash
135
+ virtual_server_hash = @softlayer_client[:Virtual_Guest].createObject(order_template)
136
+ SoftLayer::VirtualServer.server_with_id(virtual_server_hash['id'], :client => @softlayer_client) if virtual_server_hash
137
137
  end
138
138
 
139
139
  protected
@@ -153,21 +153,21 @@ module SoftLayer
153
153
  "hourlyBillingFlag" => !!@hourly
154
154
  }
155
155
 
156
- template["dedicatedAccountHostOnlyFlag"] = true if @dedicated_host_only
157
- template["privateNetworkOnlyFlag"] = true if @private_network_only
156
+ template['dedicatedAccountHostOnlyFlag'] = true if @dedicated_host_only
157
+ template['privateNetworkOnlyFlag'] = true if @private_network_only
158
158
 
159
- template["datacenter"] = {"name" => @datacenter.name} if @datacenter
159
+ template['datacenter'] = {"name" => @datacenter.name} if @datacenter
160
160
  template['userData'] = [{'value' => @user_metadata}] if @user_metadata
161
161
  template['networkComponents'] = [{'maxSpeed'=> @max_port_speed}] if @max_port_speed
162
162
  template['postInstallScriptUri'] = @provision_script_URI.to_s if @provision_script_URI
163
163
  template['sshKeys'] = @ssh_key_ids.collect { |ssh_key_id| {'id'=> ssh_key_id.to_i } } if @ssh_key_ids
164
164
  template['primaryNetworkComponent'] = { "networkVlan" => { "id" => @public_vlan_id.to_i } } if @public_vlan_id
165
- template["primaryBackendNetworkComponent"] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
165
+ template['primaryBackendNetworkComponent'] = { "networkVlan" => {"id" => @private_vlan_id.to_i } } if @private_vlan_id
166
166
 
167
167
  if @image_template
168
- template["blockDeviceTemplateGroup"] = {"globalIdentifier" => @image_template.global_id}
168
+ template['blockDeviceTemplateGroup'] = {"globalIdentifier" => @image_template.global_id}
169
169
  elsif @os_reference_code
170
- template["operatingSystemReferenceCode"] = @os_reference_code
170
+ template['operatingSystemReferenceCode'] = @os_reference_code
171
171
  end
172
172
 
173
173
  if @disks && !@disks.empty?
@@ -196,7 +196,7 @@ module SoftLayer
196
196
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
197
197
 
198
198
  @@create_object_options ||= nil
199
- @@create_object_options = softlayer_client["Virtual_Guest"].getCreateObjectOptions() if !@@create_object_options
199
+ @@create_object_options = softlayer_client[:Virtual_Guest].getCreateObjectOptions() if !@@create_object_options
200
200
  @@create_object_options
201
201
  end
202
202
 
@@ -210,37 +210,37 @@ module SoftLayer
210
210
  ##
211
211
  # Return a list of values that are valid for the :datacenter attribute
212
212
  def self.datacenter_options(client = nil)
213
- create_object_options(client)["datacenters"].collect { |datacenter_spec| Datacenter.datacenter_named(datacenter_spec['template']['datacenter']['name'], client) }.uniq
213
+ create_object_options(client)['datacenters'].collect { |datacenter_spec| Datacenter.datacenter_named(datacenter_spec['template']['datacenter']['name'], client) }.uniq
214
214
  end
215
215
 
216
216
  ##
217
217
  # Return a list of values that are valid for the :cores attribute
218
218
  def self.core_options(client = nil)
219
- create_object_options(client)["processors"].collect { |processor_spec| processor_spec['template']['startCpus'] }.uniq.sort!
219
+ create_object_options(client)['processors'].collect { |processor_spec| processor_spec['template']['startCpus'] }.uniq.sort!
220
220
  end
221
221
 
222
222
  ##
223
223
  # Return a list of values that are valid for the :memory attribute
224
224
  def self.memory_options(client = nil)
225
- create_object_options(client)["memory"].collect { |memory_spec| memory_spec['template']['maxMemory'].to_i / 1024}.uniq.sort!
225
+ create_object_options(client)['memory'].collect { |memory_spec| memory_spec['template']['maxMemory'].to_i / 1024}.uniq.sort!
226
226
  end
227
227
 
228
228
  ##
229
229
  # Return a list of values that are valid the array given to the :disks
230
230
  def self.disk_options(client = nil)
231
- create_object_options(client)["blockDevices"].collect { |block_device_spec| block_device_spec['template']['blockDevices'][0]['diskImage']['capacity']}.uniq.sort!
231
+ create_object_options(client)['blockDevices'].collect { |block_device_spec| block_device_spec['template']['blockDevices'][0]['diskImage']['capacity']}.uniq.sort!
232
232
  end
233
233
 
234
234
  ##
235
235
  # Returns a list of the valid :os_refrence_codes
236
236
  def self.os_reference_code_options(client = nil)
237
- create_object_options(client)["operatingSystems"].collect { |os_spec| os_spec['template']['operatingSystemReferenceCode'] }.uniq.sort!
237
+ create_object_options(client)['operatingSystems'].collect { |os_spec| os_spec['template']['operatingSystemReferenceCode'] }.uniq.sort!
238
238
  end
239
239
 
240
240
  ##
241
241
  # Returns a list of the :max_port_speeds
242
242
  def self.max_port_speed_options(client = nil)
243
- create_object_options(client)["networkComponents"].collect { |component_spec| component_spec['template']['networkComponents'][0]['maxSpeed'] }
243
+ create_object_options(client)['networkComponents'].collect { |component_spec| component_spec['template']['networkComponents'][0]['maxSpeed'] }
244
244
  end
245
245
  end # class VirtualServerOrder
246
246
  end # module SoftLayer
@@ -15,25 +15,25 @@ module SoftLayer
15
15
  class VirtualServerUpgradeOrder
16
16
  # The virtual server that this order is designed to upgrade.
17
17
  attr_reader :virtual_server
18
-
18
+
19
19
  # The number of cores the server should have after the upgrade.
20
20
  # If this is nil, the the number of cores will not change
21
21
  attr_accessor :cores
22
-
22
+
23
23
  # The amount of RAM (in GB) that the server should have after the upgrade
24
24
  # If this is nil, the ram will not change
25
25
  attr_accessor :ram
26
-
26
+
27
27
  # The port speed (in Mega bits per second) that the server should have
28
28
  # after the upgrade. This is typically a value like 100, or 1000
29
29
  # If this is nil, the port speeds will not change
30
30
  attr_accessor :max_port_speed
31
-
31
+
32
32
  # The date and time when you would like the upgrade to be processed.
33
33
  # This should simply be a Time object. If nil then the upgrade
34
34
  # will be performed immediately
35
35
  attr_accessor :upgrade_at
36
-
36
+
37
37
  ##
38
38
  # Create an upgrade order for the virtual server provided.
39
39
  #
@@ -54,12 +54,12 @@ module SoftLayer
54
54
  order_object = self.order_object
55
55
  order_object = yield order_object if block_given?
56
56
 
57
- @virtual_server.softlayer_client["Product_Order"].verifyOrder(order_object)
57
+ @virtual_server.softlayer_client[:Product_Order].verifyOrder(order_object)
58
58
  end
59
59
  end
60
60
 
61
61
  ##
62
- # Places the order represented by this object. This is likely to
62
+ # Places the order represented by this object. This is likely to
63
63
  # involve a change to the charges on an account.
64
64
  #
65
65
  # If a block is passed to this routine, the code will send the order template
@@ -70,26 +70,26 @@ module SoftLayer
70
70
  order_object = self.order_object
71
71
  order_object = yield order_object if block_given?
72
72
 
73
- @virtual_server.softlayer_client["Product_Order"].placeOrder(order_object)
73
+ @virtual_server.softlayer_client[:Product_Order].placeOrder(order_object)
74
74
  end
75
75
  end
76
76
 
77
77
  ##
78
78
  # Return a list of values that are valid for the :cores attribute
79
79
  def core_options()
80
- self._item_prices_in_category("guest_core").map { |item_price| item_price["item"]["capacity"].to_i}.sort.uniq
80
+ self._item_prices_in_category("guest_core").map { |item_price| item_price['item']['capacity'].to_i}.sort.uniq
81
81
  end
82
82
 
83
83
  ##
84
84
  # Return a list of values that are valid for the :memory attribute
85
85
  def memory_options()
86
- self._item_prices_in_category("ram").map { |item_price| item_price["item"]["capacity"].to_i}.sort.uniq
86
+ self._item_prices_in_category("ram").map { |item_price| item_price['item']['capacity'].to_i}.sort.uniq
87
87
  end
88
88
 
89
89
  ##
90
90
  # Returns a list of valid values for max_port_speed
91
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
92
+ self._item_prices_in_category("port_speed").map { |item_price| item_price['item']['capacity'].to_i}.sort.uniq
93
93
  end
94
94
 
95
95
  private
@@ -105,30 +105,30 @@ module SoftLayer
105
105
  # Returns a list of the update item prices, in the given category, for the server
106
106
  #
107
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 } }
108
+ @virtual_server.upgrade_options.select { |item_price| item_price['categories'].find { |category| category['categoryCode'] == which_category } }
109
109
  end
110
-
110
+
111
111
  ##
112
112
  # Searches through the upgrade items pricess known to this server for the one that is in a particular category
113
113
  # and whose capacity matches the value given. Returns the item_price or nil
114
114
  #
115
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}
116
+ self._item_prices_in_category(which_category).find { |item_price| item_price['item']['capacity'].to_i == capacity}
117
117
  end
118
-
119
- ##
118
+
119
+ ##
120
120
  # construct an order object
121
121
  #
122
122
  def order_object
123
123
  prices = []
124
-
124
+
125
125
  cores_price_item = @cores ? _item_price_with_capacity("guest_core", @cores) : nil
126
126
  ram_price_item = @ram ? _item_price_with_capacity("ram", @ram) : nil
127
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
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
132
 
133
133
  # put together an order
134
134
  upgrade_order = {
@@ -12,7 +12,7 @@ require 'rubygems'
12
12
  module SoftLayer
13
13
  # The version number (including major, minor, and bugfix numbers)
14
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
15
+ VERSION = "3.0.b2" # version history in the CHANGELOG.textile file at the root of the source
16
16
 
17
17
  # The base URL of the SoftLayer API available to the public internet.
18
18
  API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'
data/lib/softlayer_api.rb CHANGED
@@ -27,9 +27,14 @@ require 'softlayer/BareMetalServer'
27
27
  require 'softlayer/BareMetalServerOrder'
28
28
  require 'softlayer/BareMetalServerOrder_Package'
29
29
  require 'softlayer/ImageTemplate'
30
+ require 'softlayer/NetworkComponent'
30
31
  require 'softlayer/ProductPackage'
31
32
  require 'softlayer/ProductItemCategory'
33
+ require 'softlayer/ServerFirewall'
34
+ require 'softlayer/ServerFirewallOrder'
32
35
  require 'softlayer/Ticket'
33
36
  require 'softlayer/VirtualServer'
34
37
  require 'softlayer/VirtualServerOrder'
35
38
  require 'softlayer/VirtualServerUpgradeOrder'
39
+ require 'softlayer/VLANFirewall'
40
+ require 'softlayer/VLANFirewallOrder'
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: 3.0.b1
4
+ version: 3.0.b2
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-15 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configparser
@@ -113,6 +113,7 @@ files:
113
113
  - examples/create_ticket.rb
114
114
  - examples/open_tickets.rb
115
115
  - examples/order_bare_metal_package.rb
116
+ - examples/order_server_firewall.rb
116
117
  - examples/order_virtual_server.rb
117
118
  - examples/ticket_info.rb
118
119
  - lib/softlayer/APIParameterFilter.rb
@@ -126,6 +127,7 @@ files:
126
127
  - lib/softlayer/DynamicAttribute.rb
127
128
  - lib/softlayer/ImageTemplate.rb
128
129
  - lib/softlayer/ModelBase.rb
130
+ - lib/softlayer/NetworkComponent.rb
129
131
  - lib/softlayer/ObjectFilter.rb
130
132
  - lib/softlayer/ObjectMaskParser.rb
131
133
  - lib/softlayer/ObjectMaskProperty.rb
@@ -134,8 +136,12 @@ files:
134
136
  - lib/softlayer/ProductItemCategory.rb
135
137
  - lib/softlayer/ProductPackage.rb
136
138
  - lib/softlayer/Server.rb
139
+ - lib/softlayer/ServerFirewall.rb
140
+ - lib/softlayer/ServerFirewallOrder.rb
137
141
  - lib/softlayer/Service.rb
138
142
  - lib/softlayer/Ticket.rb
143
+ - lib/softlayer/VLANFirewall.rb
144
+ - lib/softlayer/VLANFirewallOrder.rb
139
145
  - lib/softlayer/VirtualServer.rb
140
146
  - lib/softlayer/VirtualServerOrder.rb
141
147
  - lib/softlayer/VirtualServerUpgradeOrder.rb