softlayer_api 3.0.0 → 3.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9978e710e2d6a05a3880081e3cdee3f6bb2d3753
4
- data.tar.gz: dd01519dab1d396a02f4f870385cd60c6b191c57
3
+ metadata.gz: 498eb5e1ea2559ee02a3d3f471515c5233c665ee
4
+ data.tar.gz: 9957ced500d1790af7e1dcc312b2deec1cad2390
5
5
  SHA512:
6
- metadata.gz: 72845603df5f67b24caa19d5fe6fa41a576362f8eed388180b86695c1945941f335ac0837cf549715272340b2481d35d3d9eb93848a2e8c57ec10c72c0df1647
7
- data.tar.gz: 9b03b78a3f56f54d558a495abc14240abd5ef3d1f3e424b432ef6aee8360106a21dcfa3c4a15f394ce26d03f459ac6351c5786fba6053e622e46eccc962046fc
6
+ metadata.gz: 160b9c1883f81422a9d94fbd4a413a89d5d2c8173683d739223897323e2d72f68becd9f1121e8f9f2ae2cfda9447f4b7d22d9c7750f81643b5ff79c831e69ad9
7
+ data.tar.gz: 5dc081303ba4b1e7abbf3177059b20547471bbf986a1afd1ebd2210fbf2f5b93b7dd78664c110c794060b1751b05b183e0827df6d7c4b832e83948c894df49ee
@@ -47,7 +47,7 @@ begin
47
47
 
48
48
  # The list will look something like ["ams01", "dal01", "dal05",...
49
49
  # Let's put our server in the 'dal05' (Dallas 5) datacenter
50
- server_order.datacenter = 'dal05'
50
+ server_order.datacenter = SoftLayer::Datacenter.datacenter_named 'dal05', client
51
51
 
52
52
  # The order must know how many computing cores we want in our virtual
53
53
  # server. Again we can ask the class for options. The result will
@@ -80,23 +80,21 @@ module SoftLayer
80
80
  end
81
81
 
82
82
  ##
83
- # The virtual servers (aka. CCIs or Virtual_Guests) associated with the
84
- # account. Unless you force these to update, they will be refreshed every
85
- # five minutes.
86
- # :call-seq:
87
- # virtual_servers(force_update=false)
88
- sl_dynamic_attr :virtual_servers do |virtual_servers|
89
- virtual_servers.should_update? do
90
- @last_virtual_server_update ||= Time.at(0)
91
- (Time.now - @last_virtual_server_update) > 5 * 60 # update every 5 minutes
83
+ # Retrieve an account's master EVault user. This is only used when an account
84
+ # has an EVault service.
85
+ sl_dynamic_attr :evault_master_users do |evault_users|
86
+ evault_users.should_update? do
87
+ @evault_master_users == nil
92
88
  end
93
89
 
94
- virtual_servers.to_update do
95
- @last_virtual_server_update = Time.now
96
- VirtualServer.find_servers(:client => self.softlayer_client)
90
+ evault_users.to_update do
91
+ evault_user_passwords = self.service.object_mask(AccountPassword.default_object_mask).getEvaultMasterUsers
92
+ evault_user_passwords.collect { |evault_user_password| AccountPassword.new(softlayer_client, evault_user_password) unless evault_user_password.empty? }.compact
97
93
  end
98
94
  end
99
95
 
96
+ ##
97
+ # Retrieve an account's image templates
100
98
  sl_dynamic_attr :image_templates do |image_templates|
101
99
  image_templates.should_update? do
102
100
  @last_image_template_update ||= Time.at(0)
@@ -109,6 +107,34 @@ module SoftLayer
109
107
  end
110
108
  end
111
109
 
110
+ ##
111
+ # Retrieve an account's network message delivery acounts.
112
+ sl_dynamic_attr :network_message_delivery_accounts do |net_msg_deliv_accts|
113
+ net_msg_deliv_accts.should_update? do
114
+ @network_message_delivery_accounts == nil
115
+ end
116
+
117
+ net_msg_deliv_accts.to_update do
118
+ network_message_delivery_accounts = self.service.object_mask(NetworkMessageDelivery.default_object_mask).getNetworkMessageDeliveryAccounts
119
+ network_message_delivery_accounts.collect { |net_msg_deliv_acct| NetworkMessageDelivery.new(softlayer_client, net_msg_deliv_acct) unless net_msg_deliv_acct.empty? }.compact
120
+ end
121
+ end
122
+
123
+ ##
124
+ # Retrieve an account's network storage groups.
125
+ sl_dynamic_attr :network_storage_groups do |net_stor_groups|
126
+ net_stor_groups.should_update? do
127
+ @network_storage_groups == nil
128
+ end
129
+
130
+ net_stor_groups.to_update do
131
+ network_storage_groups = self.service.object_mask(NetworkStorageGroup.default_object_mask).getNetworkStorageGroups
132
+ network_storage_groups.collect { |net_stor_group| NetworkStorageGroup.new(softlayer_client, net_stor_group) unless net_stor_group.empty? }.compact
133
+ end
134
+ end
135
+
136
+ ##
137
+ # Retrieve an account's open tickets
112
138
  sl_dynamic_attr :open_tickets do |open_tickets|
113
139
  open_tickets.should_update? do
114
140
  @last_open_tickets_update ||= Time.at(0)
@@ -122,6 +148,52 @@ module SoftLayer
122
148
  end
123
149
  end
124
150
 
151
+ ##
152
+ # Retrieve an account's portal users.
153
+ sl_dynamic_attr :users do |users|
154
+ users.should_update? do
155
+ @users == nil
156
+ end
157
+
158
+ users.to_update do
159
+ account_users = self.service.object_mask(UserCustomer.default_object_mask).getUsers
160
+ account_users.collect { |account_user| UserCustomer.new(softlayer_client, account_user) unless account_user.empty? }.compact
161
+ end
162
+ end
163
+
164
+ ##
165
+ # Retrieve an account's virtual disk images
166
+ sl_dynamic_attr :virtual_disk_images do |virtual_disk_images|
167
+ virtual_disk_images.should_update? do
168
+ @last_virtual_disk_images_update ||= Time.at(0)
169
+ (Time.now - @last_virtual_disk_images_update) > 5 * 60 # update every 5 minutes
170
+ end
171
+
172
+ virtual_disk_images.to_update do
173
+ @last_virtual_disk_images_update ||= Time.now
174
+ virtual_disk_images_data = self.service.object_mask(SoftLayer::VirtualDiskImage.default_object_mask).getVirtualDiskImages
175
+ virtual_disk_images_data.collect { |virtual_disk_image| SoftLayer::VirtualDiskImage.new(softlayer_client, virtual_disk_image) }
176
+ end
177
+ end
178
+
179
+ ##
180
+ # The virtual servers (aka. CCIs or Virtual_Guests) associated with the
181
+ # account. Unless you force these to update, they will be refreshed every
182
+ # five minutes.
183
+ # :call-seq:
184
+ # virtual_servers(force_update=false)
185
+ sl_dynamic_attr :virtual_servers do |virtual_servers|
186
+ virtual_servers.should_update? do
187
+ @last_virtual_server_update ||= Time.at(0)
188
+ (Time.now - @last_virtual_server_update) > 5 * 60 # update every 5 minutes
189
+ end
190
+
191
+ virtual_servers.to_update do
192
+ @last_virtual_server_update = Time.now
193
+ VirtualServer.find_servers(:client => self.softlayer_client)
194
+ end
195
+ end
196
+
125
197
  def service
126
198
  softlayer_client[:Account].object_with_id(self.id)
127
199
  end
@@ -164,4 +236,4 @@ module SoftLayer
164
236
  return self.bare_metal_servers + self.virtual_servers
165
237
  end
166
238
  end
167
- end
239
+ end
@@ -0,0 +1,356 @@
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
+ # Each SoftLayer AccountPassword instance provides information about
10
+ # a user's password associated with a SoftLayer Account instance.
11
+ #
12
+ # This class roughly corresponds to the entity SoftLayer_Account_Password
13
+ # in the API.
14
+ #
15
+ class AccountPassword < ModelBase
16
+ include ::SoftLayer::DynamicAttribute
17
+
18
+ ##
19
+ # :attr_reader:
20
+ # A simple description of a username/password combination.
21
+ sl_attr :notes
22
+
23
+ ##
24
+ # :attr_reader:
25
+ # The password portion of a username/password combination.
26
+ sl_attr :password
27
+
28
+ ##
29
+ # :attr_reader:
30
+ # The username portion of a username/password combination.
31
+ sl_attr :username
32
+
33
+ ##
34
+ # A description of the use for the account username/password combination.
35
+ sl_dynamic_attr :description do |resource|
36
+ resource.should_update? do
37
+ #only retrieved once per instance
38
+ @description == nil
39
+ end
40
+
41
+ resource.to_update do
42
+ type = self.service.getType
43
+ type['description']
44
+ end
45
+ end
46
+
47
+ ##
48
+ # Updates the notes for the current account password.
49
+ #
50
+ def notes=(notes)
51
+ self.service.editObject({ "notes" => notes.to_s })
52
+ self.refresh_details()
53
+ end
54
+
55
+ ##
56
+ # Updates the password for the current account password.
57
+ #
58
+ def password=(password)
59
+ raise ArgumentError, "The new password cannot be nil" unless password
60
+ raise ArgumentError, "The new password cannot be empty" if password.empty?
61
+
62
+ self.service.editObject({ "password" => password.to_s })
63
+ self.refresh_details()
64
+ end
65
+
66
+ ##
67
+ # Retrieve a list of network storage account passwords from all network storage devices.
68
+ #
69
+ # The options parameter should contain:
70
+ #
71
+ # <b>+:client+</b> - The client used to connect to the API
72
+ #
73
+ # If no client is given, then the routine will try to use Client.default_client
74
+ # If no client can be found the routine will raise an error.
75
+ #
76
+ # You may filter the list returned by adding options:
77
+ # * <b>+:datacenter+</b> (string) - Include network storage account passwords from servers matching this datacenter
78
+ # * <b>+:domain+</b> (string) - Include network storage account passwords from servers matching this domain
79
+ # * <b>+:hostname+</b> (string) - Include network storage account passwords from servers matching this hostname
80
+ # * <b>+:network_storage_server_type+</b> (string) - Include network storage account passwords attached to this server type
81
+ # * <b>+:network_storage_type+</b> (string) - Include network storage account passwords from devices of this storage type
82
+ # * <b>+:tags+</b> (Array) - Include network storage account passwords from servers matching these tags
83
+ # * <b>+:username+</b> (string) - Include network storage account passwords with this username only
84
+ #
85
+ def self.find_network_storage_account_passwords(options_hash = {})
86
+ softlayer_client = options_hash[:client] || Client.default_client
87
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
88
+
89
+ if(options_hash.has_key? :network_storage_object_filter)
90
+ network_storage_object_filter = options_hash[:network_storage_object_filter]
91
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_object_filter.kind_of?(SoftLayer::ObjectFilter)
92
+ else
93
+ network_storage_object_filter = ObjectFilter.new()
94
+ end
95
+
96
+ if(options_hash.has_key? :account_password_object_filter)
97
+ account_password_object_filter = options_hash[:account_password_object_filter]
98
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless account_password_object_filter.kind_of?(SoftLayer::ObjectFilter)
99
+ else
100
+ account_password_object_filter = ObjectFilter.new()
101
+ end
102
+
103
+ if options_hash.has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?(options_hash[:network_storage_server_type])
104
+ raise "Expected one of :hardware or :virtual_server for :network_storage_server_type option in #{__method__}"
105
+ end
106
+
107
+ filter_label = {
108
+ :evault => "evaultNetworkStorage",
109
+ :hardware => "hardware",
110
+ :hub => "hubNetworkStorage",
111
+ :iscsi => "iscsiNetworkStorage",
112
+ :lockbox => "lockboxNetworkStorage",
113
+ :nas => "nasNetworkStorage",
114
+ :network_storage => "networkStorage",
115
+ :virtual_server => "virtualGuest"
116
+ }
117
+
118
+ option_to_filter_path = {
119
+ :account_password => {
120
+ :username => "accountPassword.username"
121
+ },
122
+ :datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
123
+ :domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
124
+ :hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
125
+ :tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join }
126
+ }
127
+
128
+ if options_hash[:network_storage_type]
129
+ unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?(options_hash[:network_storage_type])
130
+ raise "Expected :evault, :hub, :iscsi, :lockbox, :nas or :network_storage for option :network_storage_type in #{__method__}"
131
+ end
132
+ end
133
+
134
+ if options_hash[:network_storage_server_type]
135
+ network_storage_type = options_hash[:network_storage_type] || :network_storage
136
+
137
+ [ :datacenter, :domain, :hostname ].each do |option|
138
+ if options_hash[option]
139
+ network_storage_object_filter.modify do |filter|
140
+ filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
141
+ end
142
+ end
143
+ end
144
+
145
+ if options_hash[:tags]
146
+ network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
147
+ {
148
+ 'operation' => 'in',
149
+ 'options' => [{
150
+ 'name' => 'data',
151
+ 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
152
+ }]
153
+ })
154
+ end
155
+ end
156
+
157
+ option_to_filter_path[:account_password].each do |option, filter_path|
158
+ account_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
159
+ end
160
+
161
+ account_service = softlayer_client[:Account]
162
+ account_service = account_service.object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
163
+ account_service = account_service.object_mask("mask[id]")
164
+
165
+ case options_hash[:network_storage_type]
166
+ when :evault
167
+ network_storage_data = account_service.getEvaultNetworkStorage
168
+ when :hub
169
+ network_storage_data = account_service.getHubNetworkStorage
170
+ when :iscsi
171
+ network_storage_data = account_service.getIscsiNetworkStorage
172
+ when :lockbox
173
+ network_storage_data = account_service.getLockboxNetworkStorage
174
+ when :nas
175
+ network_storage_data = account_service.getNasNetworkStorage
176
+ when :network_storage, nil
177
+ network_storage_data = account_service.getNetworkStorage
178
+ end
179
+
180
+ account_passwords = network_storage_data.collect do |network_storage|
181
+ network_storage_service = softlayer_client[:Network_Storage].object_with_id(network_storage['id'])
182
+ network_storage_service = network_storage_service.object_filter(account_password_object_filter) unless account_password_object_filter.empty?
183
+ network_storage_service = network_storage_service.object_mask(AccountPassword.default_object_mask)
184
+ network_storage_service = network_storage_service.object_mask(options_hash[:account_password_object_mask]) if options_hash[:account_password_object_mask]
185
+
186
+ account_password_data = network_storage_service.getAccountPassword
187
+ AccountPassword.new(softlayer_client, account_password_data) unless account_password_data.empty?
188
+ end
189
+
190
+ account_passwords.compact
191
+ end
192
+
193
+ ##
194
+ # Retrieve a list of network storage webcc passwords from all network storage devices.
195
+ #
196
+ # The options parameter should contain:
197
+ #
198
+ # <b>+:client+</b> - The client used to connect to the API
199
+ #
200
+ # If no client is given, then the routine will try to use Client.default_client
201
+ # If no client can be found the routine will raise an error.
202
+ #
203
+ # You may filter the list returned by adding options:
204
+ # * <b>+:datacenter+</b> (string) - Include network storage webcc passwords from servers matching this datacenter
205
+ # * <b>+:domain+</b> (string) - Include network storage webcc passwords from servers matching this domain
206
+ # * <b>+:hostname+</b> (string) - Include network storage webcc passwords from servers matching this hostname
207
+ # * <b>+:network_storage_server_type+</b> (string) - Include network storage webcc passwords attached to this server type
208
+ # * <b>+:network_storage_type+</b> (string) - Include network storage webcc passwords from devices of this storage type
209
+ # * <b>+:tags+</b> (Array) - Include network storage webcc passwords from servers matching these tags
210
+ # * <b>+:username+</b> (string) - Include network storage webcc passwords with this username only
211
+ #
212
+ def self.find_network_storage_webcc_passwords(options_hash = {})
213
+ softlayer_client = options_hash[:client] || Client.default_client
214
+ raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
215
+
216
+ if(options_hash.has_key? :network_storage_object_filter)
217
+ network_storage_object_filter = options_hash[:network_storage_object_filter]
218
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_object_filter.kind_of?(SoftLayer::ObjectFilter)
219
+ else
220
+ network_storage_object_filter = ObjectFilter.new()
221
+ end
222
+
223
+ if(options_hash.has_key? :webcc_password_object_filter)
224
+ webcc_password_object_filter = options_hash[:webcc_password_object_filter]
225
+ raise "Expected an instance of SoftLayer::ObjectFilter" unless webcc_password_object_filter.kind_of?(SoftLayer::ObjectFilter)
226
+ else
227
+ webcc_password_object_filter = ObjectFilter.new()
228
+ end
229
+
230
+ if options_hash.has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?(options_hash[:network_storage_server_type])
231
+ raise "Expected one of :hardware or :virtual_server for :network_storage_server_type option in #{__method__}"
232
+ end
233
+
234
+ filter_label = {
235
+ :evault => "evaultNetworkStorage",
236
+ :hardware => "hardware",
237
+ :hub => "hubNetworkStorage",
238
+ :iscsi => "iscsiNetworkStorage",
239
+ :lockbox => "lockboxNetworkStorage",
240
+ :nas => "nasNetworkStorage",
241
+ :network_storage => "networkStorage",
242
+ :virtual_server => "virtualGuest"
243
+ }
244
+
245
+ option_to_filter_path = {
246
+ :datacenter => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join },
247
+ :domain => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join },
248
+ :hostname => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join },
249
+ :tags => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join },
250
+ :webcc_password => {
251
+ :username => "webccAccount.username"
252
+ }
253
+ }
254
+
255
+ if options_hash[:network_storage_type]
256
+ unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?(options_hash[:network_storage_type])
257
+ raise "Expected :evault, :hub, :iscsi, :lockbox, :nas or :network_storage for option :network_storage_type in #{__method__}"
258
+ end
259
+ end
260
+
261
+ if options_hash[:network_storage_server_type]
262
+ network_storage_type = options_hash[:network_storage_type] || :network_storage
263
+
264
+ [ :datacenter, :domain, :hostname ].each do |option|
265
+ if options_hash[option]
266
+ network_storage_object_filter.modify do |filter|
267
+ filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
268
+ end
269
+ end
270
+ end
271
+
272
+ if options_hash[:tags]
273
+ network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
274
+ {
275
+ 'operation' => 'in',
276
+ 'options' => [{
277
+ 'name' => 'data',
278
+ 'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
279
+ }]
280
+ })
281
+ end
282
+ end
283
+
284
+ option_to_filter_path[:webcc_password].each do |option, filter_path|
285
+ webcc_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
286
+ end
287
+
288
+ account_service = softlayer_client[:Account]
289
+ account_service = account_service.object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
290
+ account_service = account_service.object_mask("mask[id]")
291
+
292
+ case options_hash[:network_storage_type]
293
+ when :evault
294
+ network_storage_data = account_service.getEvaultNetworkStorage
295
+ when :hub
296
+ network_storage_data = account_service.getHubNetworkStorage
297
+ when :iscsi
298
+ network_storage_data = account_service.getIscsiNetworkStorage
299
+ when :lockbox
300
+ network_storage_data = account_service.getLockboxNetworkStorage
301
+ when :nas
302
+ network_storage_data = account_service.getNasNetworkStorage
303
+ when :network_storage, nil
304
+ network_storage_data = account_service.getNetworkStorage
305
+ end
306
+
307
+ webcc_passwords = network_storage_data.collect do |network_storage|
308
+ network_storage_service = softlayer_client[:Network_Storage].object_with_id(network_storage['id'])
309
+ network_storage_service = network_storage_service.object_filter(webcc_password_object_filter) unless webcc_password_object_filter.empty?
310
+ network_storage_service = network_storage_service.object_mask(AccountPassword.default_object_mask)
311
+ network_storage_service = network_storage_service.object_mask(options_hash[:webcc_password_object_mask]) if options_hash[:webcc_password_object_mask]
312
+
313
+ webcc_password_data = network_storage_service.getWebccAccount
314
+ AccountPassword.new(softlayer_client, webcc_password_data) unless webcc_password_data.empty?
315
+ end
316
+
317
+ webcc_passwords.compact
318
+ end
319
+
320
+ ##
321
+ # Returns the service for interacting with this account password through the network API
322
+ #
323
+ def service
324
+ softlayer_client[:Account_Password].object_with_id(self.id)
325
+ end
326
+
327
+ ##
328
+ # Make an API request to SoftLayer and return the latest properties hash
329
+ # for this object.
330
+ #
331
+ def softlayer_properties(object_mask = nil)
332
+ my_service = self.service
333
+
334
+ if(object_mask)
335
+ my_service = my_service.object_mask(object_mask)
336
+ else
337
+ my_service = my_service.object_mask(self.class.default_object_mask)
338
+ end
339
+
340
+ my_service.getObject()
341
+ end
342
+
343
+ protected
344
+
345
+ def self.default_object_mask
346
+ {
347
+ "mask(SoftLayer_Account_Password)" => [
348
+ 'id',
349
+ 'notes',
350
+ 'password',
351
+ 'username'
352
+ ]
353
+ }.to_sl_object_mask
354
+ end
355
+ end
356
+ end #SoftLayer