class SoftLayer::NetworkStorage
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.
Attributes
A Storage account's capacity, measured in gigabytes.
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.
The date a network storage volume was created.
Public notes related to a Storage volume.
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.
A Storage account's type.
This flag indicates whether this storage type is upgradable or not.
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.
Public Class Methods
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 SoftLayer::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.
# 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 account_service = softlayer_client[:Account] account_service = account_service.object_filter(network_storage_object_filter) unless network_storage_object_filter.empty? account_service = account_service.object_mask(NetworkStorage.default_object_mask) account_service = account_service.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] account_service = account_service.result_limit(options_hash[:result_limit][:offset], options_hash[:result_limit][:limit]) end case options_hash[:network_storage_type] when :evault network_storage_data = account_service.getEvaultNetworkStorage when :hub network_storage_data = account_service.getHubNetworkStorage when :iscsi network_storage_data = account_service.getIscsiNetworkStorage when :lockbox network_storage_data = account_service.getLockboxNetworkStorage when :nas network_storage_data = account_service.getNasNetworkStorage when :network_storage, nil network_storage_data = account_service.getNetworkStorage end network_storage_data.collect { |network_storage| NetworkStorage.new(softlayer_client, network_storage) unless network_storage.empty? }.compact end
Protected Class Methods
# File lib/softlayer/NetworkStorage.rb, line 338 def self.default_object_mask { "mask(SoftLayer_Network_Storage)" => [ 'capacityGb', 'createDate', 'id', 'nasType', 'notes', 'password', 'upgradableFlag', 'username' ] }.to_sl_object_mask end
Public Instance Methods
Retrieve other usernames and passwords associated with a Storage volume.
# 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 account_password = self.service.object_mask(AccountPassword.default_object_mask).getAccountPassword AccountPassword.new(softlayer_client, account_password) unless account_password.empty? end end
Add a username/password credential to the network storage instance
# 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 an existing network storage credential specified by the username to the network storage instance
# 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
A Storage volume's access credentials.
# 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
Determines if one of the credentials pertains to the specified username.
# File lib/softlayer/NetworkStorage.rb, line 153 def has_user_credential?(username) self.credentials.map { |credential| credential.username }.include?(username) end
Updates the notes for the network storage instance.
# File lib/softlayer/NetworkStorage.rb, line 160 def notes=(notes) self.service.editObject({ "notes" => notes.to_s }) self.refresh_details() end
Updates the password for the network storage instance.
# 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 an existing network storage credential specified by the username from the network storage instance
# 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
Returns the service for interacting with this network storage through the network API
# File lib/softlayer/NetworkStorage.rb, line 302 def service softlayer_client[:Network_Storage].object_with_id(self.id) end
The network resource a Storage service is connected to.
# 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
Make an API request to SoftLayer and return the latest properties hash for this object.
# 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
Updates the password for the network storage credential of the username specified.
# 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
The account username and password for the EVault webCC interface.
# 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 webcc_account = self.service.object_mask(AccountPassword.default_object_mask).getWebccAccount AccountPassword.new(softlayer_client, webcc_account) unless webcc_account.empty? end end