Class: SoftLayer::AccountPassword

Inherits:
ModelBase
  • Object
show all
Includes:
DynamicAttribute
Defined in:
lib/softlayer/AccountPassword.rb

Overview

Each SoftLayer AccountPassword instance provides information about a user's password associated with a SoftLayer Account instance.

This class roughly corresponds to the entity SoftLayer_Account_Password in the API.

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicAttribute

included

Methods inherited from ModelBase

#[], #has_sl_property?, #initialize, #refresh_details, sl_attr, #to_ary

Constructor Details

This class inherits a constructor from SoftLayer::ModelBase

Class Method Details

.find_network_storage_account_passwords(options_hash = {}) ⇒ Object

Retrieve a list of network storage account passwords from all network storage devices.

The options parameter should contain:

:client - The client used to connect to the API

If no client is given, then the routine will try to use Client.default_client If no client can be found the routine will raise an error.

You may filter the list returned by adding options:

  • :datacenter (string) - Include network storage account passwords from servers matching this datacenter

  • :domain (string) - Include network storage account passwords from servers matching this domain

  • :hostname (string) - Include network storage account passwords from servers matching this hostname

  • :network_storage_server_type (string) - Include network storage account passwords attached to this server type

  • :network_storage_type (string) - Include network storage account passwords from devices of this storage type

  • :tags (Array) - Include network storage account passwords from servers matching these tags

  • :username (string) - Include network storage account passwords with this username only


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/softlayer/AccountPassword.rb', line 85

def self.(options_hash = {})
  softlayer_client = options_hash[:client] || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  if(options_hash.has_key? :network_storage_object_filter)
    network_storage_object_filter = options_hash[:network_storage_object_filter]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_object_filter.kind_of?(SoftLayer::ObjectFilter)
  else
    network_storage_object_filter = ObjectFilter.new()
  end

  if(options_hash.has_key? :account_password_object_filter)
     = options_hash[:account_password_object_filter]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless .kind_of?(SoftLayer::ObjectFilter)
  else
     = ObjectFilter.new()
  end

  if options_hash.has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?(options_hash[:network_storage_server_type])
    raise "Expected one of :hardware or :virtual_server for :network_storage_server_type option in #{__method__}"
  end

  filter_label = {
    :evault          => "evaultNetworkStorage",
    :hardware        => "hardware",
    :hub             => "hubNetworkStorage",
    :iscsi           => "iscsiNetworkStorage",
    :lockbox         => "lockboxNetworkStorage",
    :nas             => "nasNetworkStorage",
    :network_storage => "networkStorage",
    :virtual_server  => "virtualGuest"
  }

  option_to_filter_path = {
    :account_password => {
      :username       => "accountPassword.username"
    },
    :datacenter       => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join        },
    :domain           => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join                 },
    :hostname         => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join               },
    :tags             => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join }
  }

  if options_hash[:network_storage_type]
    unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?(options_hash[:network_storage_type])
      raise "Expected :evault, :hub, :iscsi, :lockbox, :nas or :network_storage for option :network_storage_type in #{__method__}"
    end
  end

  if options_hash[:network_storage_server_type]
    network_storage_type = options_hash[:network_storage_type] || :network_storage

    [ :datacenter, :domain, :hostname ].each do |option|
      if options_hash[option]
        network_storage_object_filter.modify do |filter|
          filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
        end
      end
    end

    if options_hash[:tags]
      network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
                                                              {
                                                                'operation' => 'in',
                                                                'options' => [{
                                                                                'name' => 'data',
                                                                                'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
                                                                              }]
                                                              })
    end
  end

  option_to_filter_path[:account_password].each do |option, filter_path|
    .modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
  end

   = softlayer_client[:Account]
   = .object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
   = .object_mask("mask[id]")

  case options_hash[:network_storage_type]
  when :evault
    network_storage_data = .getEvaultNetworkStorage
  when :hub
    network_storage_data = .getHubNetworkStorage
  when :iscsi
    network_storage_data = .getIscsiNetworkStorage
  when :lockbox
    network_storage_data = .getLockboxNetworkStorage
  when :nas
    network_storage_data = .getNasNetworkStorage
  when :network_storage, nil
    network_storage_data = .getNetworkStorage
  end

   = network_storage_data.collect do |network_storage|
    network_storage_service = softlayer_client[:Network_Storage].object_with_id(network_storage['id'])
    network_storage_service = network_storage_service.object_filter() unless .empty?
    network_storage_service = network_storage_service.object_mask(AccountPassword.default_object_mask)
    network_storage_service = network_storage_service.object_mask(options_hash[:account_password_object_mask]) if options_hash[:account_password_object_mask]

     = network_storage_service.getAccountPassword
    AccountPassword.new(softlayer_client, ) unless .empty?
  end

  .compact
end

.find_network_storage_webcc_passwords(options_hash = {}) ⇒ Object

Retrieve a list of network storage webcc passwords from all network storage devices.

The options parameter should contain:

:client - The client used to connect to the API

If no client is given, then the routine will try to use Client.default_client If no client can be found the routine will raise an error.

You may filter the list returned by adding options:

  • :datacenter (string) - Include network storage webcc passwords from servers matching this datacenter

  • :domain (string) - Include network storage webcc passwords from servers matching this domain

  • :hostname (string) - Include network storage webcc passwords from servers matching this hostname

  • :network_storage_server_type (string) - Include network storage webcc passwords attached to this server type

  • :network_storage_type (string) - Include network storage webcc passwords from devices of this storage type

  • :tags (Array) - Include network storage webcc passwords from servers matching these tags

  • :username (string) - Include network storage webcc passwords with this username only


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/softlayer/AccountPassword.rb', line 212

def self.find_network_storage_webcc_passwords(options_hash = {})
  softlayer_client = options_hash[:client] || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  if(options_hash.has_key? :network_storage_object_filter)
    network_storage_object_filter = options_hash[:network_storage_object_filter]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless network_storage_object_filter.kind_of?(SoftLayer::ObjectFilter)
  else
    network_storage_object_filter = ObjectFilter.new()
  end

  if(options_hash.has_key? :webcc_password_object_filter)
    webcc_password_object_filter = options_hash[:webcc_password_object_filter]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless webcc_password_object_filter.kind_of?(SoftLayer::ObjectFilter)
  else
    webcc_password_object_filter = ObjectFilter.new()
  end

  if options_hash.has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?(options_hash[:network_storage_server_type])
    raise "Expected one of :hardware or :virtual_server for :network_storage_server_type option in #{__method__}"
  end

  filter_label = {
    :evault          => "evaultNetworkStorage",
    :hardware        => "hardware",
    :hub             => "hubNetworkStorage",
    :iscsi           => "iscsiNetworkStorage",
    :lockbox         => "lockboxNetworkStorage",
    :nas             => "nasNetworkStorage",
    :network_storage => "networkStorage",
    :virtual_server  => "virtualGuest"
  }

  option_to_filter_path = {
    :datacenter       => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.datacenter.name' ].join        },
    :domain           => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.domain' ].join                 },
    :hostname         => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.hostname' ].join               },
    :tags             => lambda { |storage_type, server_type| return [ filter_label[storage_type], '.', filter_label[server_type], '.tagReferences.tag.name' ].join },
    :webcc_password => {
      :username       => "webccAccount.username"
    }
  }

  if options_hash[:network_storage_type]
    unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?(options_hash[:network_storage_type])
      raise "Expected :evault, :hub, :iscsi, :lockbox, :nas or :network_storage for option :network_storage_type in #{__method__}"
    end
  end

  if options_hash[:network_storage_server_type]
    network_storage_type = options_hash[:network_storage_type] || :network_storage

    [ :datacenter, :domain, :hostname ].each do |option|
      if options_hash[option]
        network_storage_object_filter.modify do |filter|
          filter.accept(option_to_filter_path[option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
        end
      end
    end

    if options_hash[:tags]
      network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, options_hash[:network_storage_server_type]),
                                                              {
                                                                'operation' => 'in',
                                                                'options' => [{
                                                                                'name' => 'data',
                                                                                'value' => options_hash[:tags].collect{ |tag_value| tag_value.to_s }
                                                                              }]
                                                              })
    end
  end

  option_to_filter_path[:webcc_password].each do |option, filter_path|
    webcc_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
  end

   = softlayer_client[:Account]
   = .object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
   = .object_mask("mask[id]")

  case options_hash[:network_storage_type]
  when :evault
    network_storage_data = .getEvaultNetworkStorage
  when :hub
    network_storage_data = .getHubNetworkStorage
  when :iscsi
    network_storage_data = .getIscsiNetworkStorage
  when :lockbox
    network_storage_data = .getLockboxNetworkStorage
  when :nas
    network_storage_data = .getNasNetworkStorage
  when :network_storage, nil
    network_storage_data = .getNetworkStorage
  end

  webcc_passwords = network_storage_data.collect do |network_storage|
    network_storage_service = softlayer_client[:Network_Storage].object_with_id(network_storage['id'])
    network_storage_service = network_storage_service.object_filter(webcc_password_object_filter) unless webcc_password_object_filter.empty?
    network_storage_service = network_storage_service.object_mask(AccountPassword.default_object_mask)
    network_storage_service = network_storage_service.object_mask(options_hash[:webcc_password_object_mask]) if options_hash[:webcc_password_object_mask]

    webcc_password_data = network_storage_service.getWebccAccount
    AccountPassword.new(softlayer_client, webcc_password_data) unless webcc_password_data.empty?
  end

  webcc_passwords.compact
end

Instance Method Details

#descriptionObject

A description of the use for the account username/password combination.


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/softlayer/AccountPassword.rb', line 35

sl_dynamic_attr :description do |resource|
  resource.should_update? do
    #only retrieved once per instance
    @description == nil
  end

  resource.to_update do
    type = self.service.getType
    type['description']
  end
end

#notesObject

:attr_reader: A simple description of a username/password combination.


21
# File 'lib/softlayer/AccountPassword.rb', line 21

sl_attr :notes

#notes=(notes) ⇒ Object

Updates the notes for the current account password.


50
51
52
53
# File 'lib/softlayer/AccountPassword.rb', line 50

def notes=(notes)
  self.service.editObject({ "notes" => notes.to_s })
  self.refresh_details()
end

#passwordObject

:attr_reader: The password portion of a username/password combination.


26
# File 'lib/softlayer/AccountPassword.rb', line 26

sl_attr :password

#password=(password) ⇒ Object

Updates the password for the current account password.

Raises:

  • (ArgumentError)

58
59
60
61
62
63
64
# File 'lib/softlayer/AccountPassword.rb', line 58

def password=(password)
  raise ArgumentError, "The new password cannot be nil"   unless password
  raise ArgumentError, "The new password cannot be empty" if password.empty?

  self.service.editObject({ "password" => password.to_s })
  self.refresh_details()
end

#serviceObject

Returns the service for interacting with this account password through the network API


323
324
325
# File 'lib/softlayer/AccountPassword.rb', line 323

def service
  softlayer_client[:Account_Password].object_with_id(self.id)
end

#softlayer_properties(object_mask = nil) ⇒ Object

Make an API request to SoftLayer and return the latest properties hash for this object.


331
332
333
334
335
336
337
338
339
340
341
# File 'lib/softlayer/AccountPassword.rb', line 331

def softlayer_properties(object_mask = nil)
  my_service = self.service

  if(object_mask)
    my_service = my_service.object_mask(object_mask)
  else
    my_service = my_service.object_mask(self.class.default_object_mask)
  end

  my_service.getObject()
end

#usernameObject

:attr_reader: The username portion of a username/password combination.


31
# File 'lib/softlayer/AccountPassword.rb', line 31

sl_attr :username