Class: SoftLayer::NetworkStorage

Inherits:
ModelBase show all
Includes:
DynamicAttribute
Defined in:
lib/softlayer/NetworkStorage.rb

Overview

Each SoftLayer NetworkStorage instance provides information about a storage product and access credentials.

This class roughly corresponds to the entity SoftLayer_Network_Storage 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(options_hash = {}) ⇒ Object

Retrieve a list of network storage services.

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/array) - Include network storage associated with servers matching this datacenter

  • :domain (string/array) - Include network storage associated with servers matching this domain

  • :hostname (string/array) - Include network storage associated with servers matching this hostname

  • :network_storage_server_type (symbol) - Include network storage associated with this server type

  • :network_storage_type (symbol) - Include network storage from devices of this storage type

  • :service (string/array) - Include network storage from devices with this service fqdn

  • :tags (string/array) - Include network storage associated with servers matching these tags

Additionally you may provide options related to the request itself:

  • :network_storage_object_mask (string) - The object mask of properties you wish to receive for the items returned.

    If not provided, the result will use the default object mask
    
  • :network_storage_object_filter (ObjectFilter) - Include network storage credentials from network storage that matches the

    criteria of this object filter
    
  • :result_limit (hash with :limit, and :offset keys) - Limit the scope of results returned.



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
# File 'lib/softlayer/NetworkStorage.rb', line 214

def self.find_network_storage(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?(: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                         },
    :service    => lambda { |storage_type|              return [ filter_label[storage_type],                                 '.serviceResource.backendIpAddress' ].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

  network_storage_type = options_hash[:network_storage_type] || :network_storage

  if options_hash[:service]
    network_storage_object_filter.modify do |filter|
      filter.accept(option_to_filter_path[:service].call(network_storage_type)).when_it is(options_hash[:service])
    end
  end
  
  if options_hash[:network_storage_server_type]
    [ :datacenter, :domain, :hostname, :tags ].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
  end

   = softlayer_client[:Account]
   = .object_filter(network_storage_object_filter) unless network_storage_object_filter.empty?
   = .object_mask(NetworkStorage.default_object_mask)
   = .object_mask(options_hash[:network_storage_object_mask]) if options_hash[:network_storage_object_mask]

  if options_hash[:result_limit] && options_hash[:result_limit][:offset] && options_hash[:result_limit][:limit]
     = .result_limit(options_hash[:result_limit][:offset], options_hash[:result_limit][:limit])
  end

  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 { |network_storage| NetworkStorage.new(softlayer_client, network_storage) unless network_storage.empty? }.compact
end

Instance Method Details

#account_passwordObject

Retrieve other usernames and passwords associated with a Storage volume. :call-seq:

(force_update=false)


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/softlayer/NetworkStorage.rb', line 68

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

  resource.to_update do
     = self.service.object_mask(AccountPassword.default_object_mask).getAccountPassword
    AccountPassword.new(softlayer_client, ) unless .empty?
  end
end

#add_credential(credential_type) ⇒ Object

Add a username/password credential to the network storage instance

Raises:

  • (ArgumentError)


127
128
129
130
131
132
133
134
135
136
# File 'lib/softlayer/NetworkStorage.rb', line 127

def add_credential(credential_type)
  raise ArgumentError, "The new credential type cannot be nil"   unless credential_type
  raise ArgumentError, "The new credential type cannot be empty" if credential_type.empty?

  new_credential = self.service.object_mask(NetworkStorageCredential.default_object_mask).assignNewCredential(credential_type.to_s)
  
  @credentials = nil

  NetworkStorageCredential.new(softlayer_client, new_credential) unless new_credential.empty?
end

#assign_credential(username) ⇒ Object

Assign an existing network storage credential specified by the username to the network storage instance

Raises:

  • (ArgumentError)


141
142
143
144
145
146
147
148
# File 'lib/softlayer/NetworkStorage.rb', line 141

def assign_credential(username)
  raise ArgumentError, "The username cannot be nil"   unless username
  raise ArgumentError, "The username cannot be empty" if username.empty?

  self.service.assignCredential(username.to_s)
  
  @credentials = nil
end

#capacityObject

:attr_reader: capacity A Storage account’s capacity, measured in gigabytes.



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

sl_attr :capacity,   'capacityGb'

#createdObject

:attr_reader: created The date a network storage volume was created. DEPRECATION WARNING: This attribute is deprecated in favor of created_at and will be removed in the next major release.



33
# File 'lib/softlayer/NetworkStorage.rb', line 33

sl_attr :created,    'createDate'

#created_atObject

:attr_reader: created_at The date a network storage volume was created.



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

sl_attr :created_at, 'createDate'

#credentialsObject

A Storage volume’s access credentials. :call-seq:

credentials(force_update=false)


84
85
86
87
88
89
90
91
92
93
# File 'lib/softlayer/NetworkStorage.rb', line 84

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

  resource.to_update do
    self.service.object_mask(NetworkStorageCredential.default_object_mask).getCredentials.collect{|cred| NetworkStorageCredential.new(softlayer_client, cred) }
  end
end

#has_user_credential?(username) ⇒ Boolean

Determines if one of the credentials pertains to the specified username.

Returns:

  • (Boolean)


153
154
155
# File 'lib/softlayer/NetworkStorage.rb', line 153

def has_user_credential?(username)
  self.credentials.map { |credential| credential.username }.include?(username)
end

#notesObject

:attr_reader: Public notes related to a Storage volume.



38
# File 'lib/softlayer/NetworkStorage.rb', line 38

sl_attr :notes

#notes=(notes) ⇒ Object

Updates the notes for the network storage instance.



160
161
162
163
# File 'lib/softlayer/NetworkStorage.rb', line 160

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

#passwordObject

:attr_reader: The password used to access a non-EVault Storage volume. This password is used to register the EVault server agent with the vault backup system.



45
# File 'lib/softlayer/NetworkStorage.rb', line 45

sl_attr :password

#password=(password) ⇒ Object

Updates the password for the network storage instance.

Raises:

  • (ArgumentError)


168
169
170
171
172
173
174
# File 'lib/softlayer/NetworkStorage.rb', line 168

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

#remove_credential(username) ⇒ Object

Remove an existing network storage credential specified by the username from the network storage instance

Raises:

  • (ArgumentError)


179
180
181
182
183
184
185
186
# File 'lib/softlayer/NetworkStorage.rb', line 179

def remove_credential(username)
  raise ArgumentError, "The username cannot be nil"   unless username
  raise ArgumentError, "The username cannot be empty" if username.empty?

  self.service.removeCredential(username.to_s)
  
  @credentials = nil
end

#serviceObject

Returns the service for interacting with this network storage through the network API



302
303
304
# File 'lib/softlayer/NetworkStorage.rb', line 302

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

#service_resourceObject

The network resource a Storage service is connected to. :call-seq:

service_resource(force_update=false)


99
100
101
102
103
104
105
106
107
108
# File 'lib/softlayer/NetworkStorage.rb', line 99

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

  resource.to_update do
    NetworkService.new(softlayer_client, self.service.object_mask(NetworkService.default_object_mask).getServiceResource)
  end
end

#softlayer_properties(object_mask = nil) ⇒ Object

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



310
311
312
313
314
315
316
317
318
319
320
# File 'lib/softlayer/NetworkStorage.rb', line 310

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

#typeObject

:attr_reader: type A Storage account’s type.



50
# File 'lib/softlayer/NetworkStorage.rb', line 50

sl_attr :type,       'nasType'

#update_credential_password(username, password) ⇒ Object

Updates the password for the network storage credential of the username specified.

Raises:

  • (ArgumentError)


325
326
327
328
329
330
331
332
333
334
# File 'lib/softlayer/NetworkStorage.rb', line 325

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

  self.service.editCredential(username.to_s, password.to_s)

  @credentials = nil
end

#upgradableObject

:attr_reader: upgradable This flag indicates whether this storage type is upgradable or not.



55
# File 'lib/softlayer/NetworkStorage.rb', line 55

sl_attr :upgradable, 'upgradableFlag'

#usernameObject

:attr_reader: The username used to access a non-EVault Storage volume. This username is used to register the EVault server agent with the vault backup system.



62
# File 'lib/softlayer/NetworkStorage.rb', line 62

sl_attr :username

#webcc_accountObject

The account username and password for the EVault webCC interface.



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/softlayer/NetworkStorage.rb', line 112

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

  resource.to_update do
     = self.service.object_mask(AccountPassword.default_object_mask).getWebccAccount
    AccountPassword.new(softlayer_client, ) unless .empty?
  end
end