softlayer_api 3.0.2 → 3.1.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.textile +3 -0
  3. data/lib/softlayer/Account.rb +85 -8
  4. data/lib/softlayer/AccountPassword.rb +49 -49
  5. data/lib/softlayer/BareMetalServer.rb +33 -43
  6. data/lib/softlayer/BareMetalServerOrder.rb +17 -8
  7. data/lib/softlayer/BareMetalServerOrder_Package.rb +25 -7
  8. data/lib/softlayer/Client.rb +7 -7
  9. data/lib/softlayer/Config.rb +105 -49
  10. data/lib/softlayer/Datacenter.rb +10 -2
  11. data/lib/softlayer/DynamicAttribute.rb +1 -1
  12. data/lib/softlayer/ImageTemplate.rb +44 -61
  13. data/lib/softlayer/ModelBase.rb +2 -2
  14. data/lib/softlayer/NetworkComponent.rb +25 -3
  15. data/lib/softlayer/NetworkMessageDelivery.rb +25 -5
  16. data/lib/softlayer/NetworkMonitor.rb +333 -0
  17. data/lib/softlayer/NetworkService.rb +6 -4
  18. data/lib/softlayer/NetworkStorage.rb +42 -29
  19. data/lib/softlayer/NetworkStorageAllowedHost.rb +9 -3
  20. data/lib/softlayer/NetworkStorageCredential.rb +44 -29
  21. data/lib/softlayer/NetworkStorageGroup.rb +42 -10
  22. data/lib/softlayer/ObjectFilter.rb +54 -4
  23. data/lib/softlayer/ObjectMaskParser.rb +1 -1
  24. data/lib/softlayer/ProductItemCategory.rb +34 -5
  25. data/lib/softlayer/ProductPackage.rb +11 -7
  26. data/lib/softlayer/Server.rb +77 -5
  27. data/lib/softlayer/ServerFirewall.rb +12 -11
  28. data/lib/softlayer/Service.rb +1 -1
  29. data/lib/softlayer/Software.rb +35 -50
  30. data/lib/softlayer/SoftwarePassword.rb +92 -107
  31. data/lib/softlayer/Ticket.rb +37 -28
  32. data/lib/softlayer/UserCustomer.rb +56 -13
  33. data/lib/softlayer/UserCustomerExternalBinding.rb +18 -5
  34. data/lib/softlayer/VLANFirewall.rb +40 -9
  35. data/lib/softlayer/VLANFirewallOrder.rb +1 -1
  36. data/lib/softlayer/VirtualDiskImage.rb +38 -10
  37. data/lib/softlayer/VirtualServer.rb +75 -48
  38. data/lib/softlayer/VirtualServerOrder.rb +15 -8
  39. data/lib/softlayer/VirtualServerOrder_Package.rb +25 -7
  40. data/lib/softlayer/VirtualServerUpgradeOrder.rb +1 -1
  41. data/lib/softlayer/base.rb +1 -1
  42. data/lib/softlayer/object_mask_helpers.rb +1 -1
  43. data/lib/softlayer_api.rb +2 -0
  44. metadata +4 -3
@@ -69,7 +69,7 @@ module SoftLayer
69
69
  ##
70
70
  # Returns the value of of the given property as stored in the
71
71
  # softlayer_hash. This gives you access to the low-level, raw
72
- # properties that underly this model object. The need for this
72
+ # properties that underlie this model object. The need for this
73
73
  # is not uncommon, but using this method should still be done
74
74
  # with deliberation.
75
75
  def [](softlayer_property)
@@ -107,7 +107,7 @@ module SoftLayer
107
107
 
108
108
  ##
109
109
  # Subclasses should implement this method as part of enabling the
110
- # refresh_details fuctionality The implementation should make a request
110
+ # refresh_details functionality The implementation should make a request
111
111
  # to the SoftLayer API and retrieve an up-to-date SoftLayer hash
112
112
  # representation of this object. That hash should be the return value
113
113
  # of this routine.
@@ -5,10 +5,32 @@
5
5
  #++
6
6
 
7
7
  module SoftLayer
8
- class NetworkComponent < SoftLayer::ModelBase
8
+ class NetworkComponent < SoftLayer::ModelBase
9
+ ##
10
+ # :attr_reader: max_speed
11
+ # A network component's maximum allowed speed,
12
+ sl_attr :max_speed, 'maxSpeed'
13
+
14
+ ##
15
+ # :attr_reader:
16
+ # A network component's maximum allowed speed,
17
+ #
18
+ # DEPRECATION WARNING: This attribute is deprecated in favor of max_speed
19
+ # and will be removed in the next major release.
20
+ sl_attr :maxSpeed
21
+
22
+ ##
23
+ # :attr_reader:
24
+ # A network component's short name.
9
25
  sl_attr :name
26
+
27
+ # :attr_reader:
28
+ # A network component's port number.
10
29
  sl_attr :port
30
+
31
+ ##
32
+ # :attr_reader:
33
+ # A network component's speed, measured in Mbit per second.
11
34
  sl_attr :speed
12
- sl_attr :maxSpeed
13
35
  end
14
- end
36
+ end
@@ -17,13 +17,27 @@ module SoftLayer
17
17
  include ::SoftLayer::DynamicAttribute
18
18
 
19
19
  ##
20
- # :attr_reader:
20
+ # :attr_reader: created_at
21
+ # The date this username/password pair was created.
22
+ sl_attr :created_at, 'createDate'
23
+
24
+ ##
25
+ # :attr_reader: created
21
26
  # The date this username/password pair was created.
27
+ # DEPRECATION WARNING: This attribute is deprecated in favor of created_at
28
+ # and will be removed in the next major release.
22
29
  sl_attr :created, 'createDate'
23
30
 
24
31
  ##
25
- # :attr_reader:
32
+ # :attr_reader: modified_at
33
+ # The date of the last modification to this username/password pair.
34
+ sl_attr :modified_at, 'modifyDate'
35
+
36
+ ##
37
+ # :attr_reader: modified
26
38
  # The date of the last modification to this username/password pair.
39
+ # DEPRECATION WARNING: This attribute is deprecated in favor of modified_at
40
+ # and will be removed in the next major release.
27
41
  sl_attr :modified, 'modifyDate'
28
42
 
29
43
  ##
@@ -37,7 +51,9 @@ module SoftLayer
37
51
  sl_attr :username
38
52
 
39
53
  ##
40
- # The message delivery type description of a network message delivery account.
54
+ # Retrieve the message delivery type description of a network message delivery account.
55
+ # :call-seq:
56
+ # description(force_update=false)
41
57
  sl_dynamic_attr :description do |resource|
42
58
  resource.should_update? do
43
59
  #only retrieved once per instance
@@ -51,7 +67,9 @@ module SoftLayer
51
67
  end
52
68
 
53
69
  ##
54
- # The message delivery type name of a network message delivery account.
70
+ # Retrieve the message delivery type name of a network message delivery account.
71
+ # :call-seq:
72
+ # name(force_update=false)
55
73
  sl_dynamic_attr :name do |resource|
56
74
  resource.should_update? do
57
75
  #only retrieved once per instance
@@ -65,7 +83,9 @@ module SoftLayer
65
83
  end
66
84
 
67
85
  ##
68
- # The vendor name for a network message delivery account.
86
+ # Retrieve the vendor name for a network message delivery account.
87
+ # :call-seq:
88
+ # vendor(force_update=false)
69
89
  sl_dynamic_attr :vendor do |resource|
70
90
  resource.should_update? do
71
91
  #only retrieved once per instance
@@ -0,0 +1,333 @@
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 struct represents the network monitor levels of a server.
10
+ # It is roughly equivalent to SoftLayer data type
11
+ # SoftLayer_Network_Monitor_Version1_Query_Host_Stratum
12
+ class NetworkMonitorLevels < Struct.new(:monitor_level, :response_level)
13
+ def initialize(monitor_levels_data)
14
+ self.monitor_level = monitor_levels_data['monitorLevel']
15
+ self.response_level = monitor_levels_data['responseLevel']
16
+ end
17
+ end
18
+
19
+ ##
20
+ # This struct represents a network monitor query result that shows the last
21
+ # state of the network monitor
22
+ class NetworkMonitorQueryResult < Struct.new(:finished_at, :responded_in, :response_status)
23
+ ##
24
+ # This constant is a mapping of network monitor query result statuses to descriptions
25
+ STATUS_DESCRIPTIONS = {
26
+ 0 => "Down/Critical: Server is down and/or has passed the critical response threshold (extremely long ping response, abnormal behavior, etc.).",
27
+ 1 => "Warning - Server may be recovering from a previous down state, or may have taken too long to respond.",
28
+ 2 => "Up",
29
+ 3 => "Not used",
30
+ 4 => "Unknown - An unknown error has occurred. If the problem persists, contact support.",
31
+ 5 => "Unknown - An unknown error has occurred. If the problem persists, contact support."
32
+ }
33
+
34
+ def initialize(query_result_data)
35
+ self.finished_at = query_result_data['finishTime']
36
+ self.responded_in = query_result_data['responseTime']
37
+ self.response_status = query_result_data['responseStatus']
38
+ end
39
+ end
40
+
41
+ ##
42
+ # This struct represents a network monitor query type used for creating
43
+ # new network monitors.
44
+ class NetworkMonitorQueryType < Struct.new(:argument_description, :description, :id, :monitor_level, :name)
45
+ def initialize(query_type_data)
46
+ self.argument_description = query_type_data['arugmentDescription']
47
+ self.description = query_type_data['description']
48
+ self.id = query_type_data['monitorLevel']
49
+ self.name = query_type_data['name']
50
+ end
51
+ end
52
+
53
+ ##
54
+ # This struct represents a network monitor response type used for configuring
55
+ # network monitor responses when created.
56
+ class NetworkMonitorResponseType < Struct.new(:action_description, :id, :level)
57
+ def initialize(response_type_data)
58
+ self.action_description = response_type_data['actionDescription']
59
+ self.id = response_type_data['id']
60
+ self.level = response_type_data['level']
61
+ end
62
+ end
63
+
64
+ ##
65
+ # Each SoftLayer NetworkMonitor instance provides information about network
66
+ # monitors configured to check host ping or host ports of servers.
67
+ #
68
+ # This class roughly corresponds to the entity SofyLayer_Network_Monitor_Version1_Query_Host
69
+ # in the API.
70
+ #
71
+ class NetworkMonitor < ModelBase
72
+ include ::SoftLayer::DynamicAttribute
73
+
74
+ @@available_query_types = nil
75
+ @@available_response_types = nil
76
+
77
+ ##
78
+ # :attr_reader: argument_value
79
+ # The argument to be used for this monitor, if necessary. The lowest monitoring levels (like ping)
80
+ # ignore this setting, but higher levels like HTTP custom use it.
81
+ sl_attr :argument_value, 'arg1Value'
82
+
83
+ ##
84
+ # :attr_reader: ip_address
85
+ # The IP address to be monitored. Must be attached to the server on this object.
86
+ sl_attr :ip_address, 'ipAddress'
87
+
88
+ ##
89
+ # :attr_reader:
90
+ # The status of this monitoring instance. Anything other than "ON" means that the monitor has been disabled.
91
+ sl_attr :status
92
+
93
+ ##
94
+ # :attr_reader: wait_cycles
95
+ # The number of 5-minute cycles to wait before the "responseAction" is taken. If set to 0, the response
96
+ # action will be taken immediately.
97
+ sl_attr :wait_cycles, 'waitCycles'
98
+
99
+ ##
100
+ # The most recent result for this particular monitoring instance.
101
+ # :call-seq:
102
+ # last_query_result(force_update=false)
103
+ sl_dynamic_attr :last_query_result do |resource|
104
+ resource.should_update? do
105
+ #only retrieved once per instance
106
+ @last_query_result == nil
107
+ end
108
+
109
+ resource.to_update do
110
+ NetworkMonitorQueryResult.new(self.service.object_mask("mask[finishTime,responseStatus,responseTime]").getLastResult)
111
+ end
112
+ end
113
+
114
+ ##
115
+ # The type of monitoring query that is executed when this server is monitored.
116
+ # :call-seq:
117
+ # query_type(force_update=false)
118
+ sl_dynamic_attr :query_type do |resource|
119
+ resource.should_update? do
120
+ #only retrieved once per instance
121
+ @query_type == nil
122
+ end
123
+
124
+ resource.to_update do
125
+ NetworkMonitorQueryType.new(self.service.getQueryType)
126
+ end
127
+ end
128
+
129
+ ##
130
+ # The response action taken when a monitor fails.
131
+ # :call-seq:
132
+ # response_type(force_update=false)
133
+ sl_dynamic_attr :response_type do |resource|
134
+ resource.should_update? do
135
+ #only retrieved once per instance
136
+ @response_type == nil
137
+ end
138
+
139
+ resource.to_update do
140
+ NetworkMonitorResponseType.new(self.service.getResponseAction)
141
+ end
142
+ end
143
+
144
+ ##
145
+ # Add a network monitor for a host ping or port check to a server.
146
+ #
147
+ def self.add_network_monitor(server, ip_address, query_type, response_type, wait_cycles = 0, argument_value = nil, options = {})
148
+ softlayer_client = options[:client] || Client.default_client
149
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
150
+ raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server)
151
+ raise "#{__method__} requires an IP address to monitor but none was given" if !ip_address || ip_address.empty?
152
+ raise "#{__method__} requires a query type for the monitor but none was given" if !query_type || !query_type.kind_of?(NetworkMonitorQueryType)
153
+ raise "#{__method__} requires a response type for the monitor but none was given" if !response_type || !response_type.kind_of?(NetworkMonitorResponseType)
154
+
155
+ if available_query_types(:client => softlayer_client, :query_level => server.network_monitor_levels.monitor_level).select{ |query| query.id == query_type.id }.empty?
156
+ raise "#{__method__} requested monitor query level is not supported for this server"
157
+ end
158
+
159
+ if available_response_types(:client => softlayer_client, :response_level => server.network_monitor_levels.response_level).select{ |response| response.id == response_type.id }.empty?
160
+ raise "#{__method__} requested monitor response level is not supported for this server"
161
+ end
162
+
163
+ network_monitor_object_filter = ObjectFilter.new()
164
+ server_id_label = server.kind_of?(VirtualServer) ? 'guestId' : 'hardwareId'
165
+
166
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.arg1Value').when_it is(argument_value.to_s) }
167
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.' + server_id_label).when_it is(server.id) }
168
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.ipAddress').when_it is(ip_address.to_s) }
169
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.queryTypeId').when_it is(query_type.id) }
170
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.responseActionId').when_it is(response_type.id) }
171
+ network_monitor_object_filter.modify { |filter| filter.accept('networkMonitors.waitCycles').when_it is(wait_cycles) }
172
+
173
+ if server.service.object_filter(network_monitor_object_filter).getNetworkMonitors.empty?
174
+ network_monitor = softlayer_client[:Network_Monitor_Version1_Query_Host].createObject({
175
+ 'arg1Value' => argument_value.to_s,
176
+ server_id_label => server.id,
177
+ 'ipAddress' => ip_address.to_s,
178
+ 'queryTypeId' => query_type.id,
179
+ 'responseActionId' => response_type.id,
180
+ 'waitCycles' => wait_cycles
181
+ })
182
+
183
+ NetworkMonitor.new(softlayer_client, network_monitor)
184
+ end
185
+ end
186
+
187
+ ##
188
+ # Add user customers to the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer
189
+ # instances or user customer usernames.
190
+ #
191
+ def self.add_network_monitor_notification_users(server, user_customers, options = {})
192
+ softlayer_client = options[:client] || Client.default_client
193
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
194
+ raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server)
195
+ raise "#{__method__} requires a list user customers but none was given" if !user_customers || user_customers.empty?
196
+
197
+ user_customers_data = user_customers.map do |user_customer|
198
+ raise "#{__method__} requires a user customer but none was given" if !user_customer || (!user_customer.class.method_defined?(:username) && user_customer.empty?)
199
+
200
+ user_customer_data = user_customer.class.method_defined?(:username) ? user_customer : UserCustomer.user_customer_with_username(user_customer, softlayer_client)
201
+
202
+ raise "#{__method__} user customer with username #{user_customer.inspect} not found" unless user_customer_data
203
+
204
+ user_customer_data
205
+ end
206
+
207
+ current_user_customers = server.notified_network_monitor_users.map { |notified_network_monitor_user| notified_network_monitor_user['id'] }
208
+
209
+ user_customers_data.delete_if { |user_customer| current_user_customers.include?(user_customer['id']) }
210
+
211
+ unless user_customers_data.empty?
212
+ notification_monitor_user_service = server.kind_of?(VirtualServer) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware
213
+ server_id_label = server.kind_of?(VirtualServer) ? 'guestId' : 'hardwareId'
214
+
215
+ user_customer_notifications = user_customers_data.map { |user_customer| { server_id_label => server.id, 'userId' => user_customer['id'] } }
216
+
217
+ softlayer_client[notification_monitor_user_service].createObjects(user_customer_notifications)
218
+ end
219
+ end
220
+
221
+ ##
222
+ # Return the list of available query types (optionally limited to a max query level)
223
+ #
224
+ def self.available_query_types(options = {})
225
+ softlayer_client = options[:client] || Client.default_client
226
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
227
+
228
+ unless @@available_query_types
229
+ available_query_types_data = softlayer_client[:Network_Monitor_Version1_Query_Host_Stratum].getAllQueryTypes
230
+ @@available_query_types = available_query_types_data.map{ |query_type| NetworkMonitorQueryType.new(query_type) }
231
+ end
232
+
233
+ if options[:query_level]
234
+ @@available_query_types.select { |query_type| query_type.monitor_level.to_i <= options[:query_level].to_i }
235
+ else
236
+ @@available_query_types
237
+ end
238
+ end
239
+
240
+ ##
241
+ # Return the list of available response types (optionally limited to a max response level)
242
+ #
243
+ def self.available_response_types(options = {})
244
+ softlayer_client = options[:client] || Client.default_client
245
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
246
+
247
+ unless @@available_response_types
248
+ available_response_types_data = softlayer_client[:Network_Monitor_Version1_Query_Host_Stratum].getAllResponseTypes
249
+ @@available_response_types = available_response_types_data.map { |response_type| NetworkMonitorResponseType.new(response_type) }
250
+ end
251
+
252
+ if options[:response_level]
253
+ @@available_response_types.select { |response_type| response_type.level.to_i <= options[:response_level].to_i }
254
+ else
255
+ @@available_response_types
256
+ end
257
+ end
258
+
259
+ ##
260
+ # Rmove user customers from the list of users notified on monitor failure for the specified server. Accepts a list of UserCustomer
261
+ # instances or user customer usernames.
262
+ #
263
+ def self.remove_network_monitor_notification_users(server, user_customers, options = {})
264
+ softlayer_client = options[:client] || Client.default_client
265
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
266
+ raise "#{__method__} requires a server to monitor but none was given" if !server || !server.kind_of?(Server)
267
+ raise "#{__method__} requires a list user customers but none was given" if !user_customers || user_customers.empty?
268
+
269
+ user_customers_data = user_customers.map do |user_customer|
270
+ raise "#{__method__} requires a user customer but none was given" if !user_customer || (!user_customer.kind_of?(UserCustomer) && user_customer.empty?)
271
+
272
+ user_customer_data = user_customer.kind_of?(UserCustomer) ? user_customer : UserCustomer.user_customer_with_username(user_customer, softlayer_client)
273
+
274
+ raise "#{__method__} user customer with username #{user_customer.inspect} not found" unless user_customer_data
275
+
276
+ user_customer_data
277
+ end
278
+
279
+ current_user_customers = user_customers_data.map { |user_customer| user_customer['id'] }
280
+ monitor_user_notification_object_filter = ObjectFilter.new()
281
+
282
+ monitor_user_notification_object_filter.modify { |filter| filter.accept('monitoringUserNotification.userId').when_it is(current_user_customers) }
283
+
284
+ monitor_user_notification_data = server.service.object_filter(monitor_user_notification_object_filter).object_mask("mask[id]").getMonitoringUserNotification
285
+
286
+ unless monitor_user_notification_data.empty?
287
+ notification_monitor_user_service = server.kind_of?(VirtualServer) ? :User_Customer_Notification_Virtual_Guest : :User_Customer_Notification_Hardware
288
+
289
+ softlayer_client[notification_monitor_user_service].deleteObjects(monitor_user_notification_data)
290
+ end
291
+ end
292
+
293
+ ##
294
+ # Removes the list of network monitors from their associated servers. Accpets a list of NetworkMonitor instances or id's.
295
+ #
296
+ def self.remove_network_monitors(network_monitors, options = {})
297
+ softlayer_client = options[:client] || Client.default_client
298
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
299
+
300
+ network_monitors_data = network_monitors.map do |network_monitor|
301
+ raise "#{__method__} requires a network monitor instance or id but non provided" if !network_monitor || (!network_monitor.kind_of?(NetworkMonitor) && network_monitor.empty?)
302
+
303
+ network_monitor.kind_of?(NetworkMonitor) ? { 'id' => network_monitor['id'] } : { 'id' => network_monitor }
304
+ end
305
+
306
+ softlayer_client[:Network_Monitor_Version1_Query_Host].deleteObjects(network_monitors_data)
307
+ end
308
+
309
+ ##
310
+ # Returns the service for interacting with this network monitor component through the network API
311
+ #
312
+ def service
313
+ softlayer_client[:Network_Monitor_Version1_Query_Host].object_with_id(self.id)
314
+ end
315
+
316
+ protected
317
+
318
+ def self.default_object_mask
319
+ {
320
+ "mask(SoftLayer_Network_Monitor_Version1_Query_Host)" => [
321
+ 'arg1Value',
322
+ 'guestId',
323
+ 'hardwareId',
324
+ 'hostId',
325
+ 'id',
326
+ 'ipAddress',
327
+ 'status',
328
+ 'waitCycles'
329
+ ]
330
+ }.to_sl_object_mask
331
+ end
332
+ end
333
+ end #SoftLayer