Class: SoftLayer::NetworkStorage
- 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
Class Method Summary collapse
-
.find_network_storage(options_hash = {}) ⇒ Object
Retrieve a list of network storage services.
Instance Method Summary collapse
-
#account_password ⇒ Object
Other usernames and passwords associated with a Storage volume.
-
#add_credential(credential_type) ⇒ Object
Add a username/password credential to the network storage instance.
-
#assign_credential(username) ⇒ Object
Assign an existing network storage credential specified by the username to the network storage instance.
-
#capacity ⇒ Object
:attr_reader: A Storage account’s capacity, measured in gigabytes.
-
#created ⇒ Object
:attr_reader: The date a network storage volume was created.
-
#credentials ⇒ Object
A Storage volume’s access credentials.
-
#has_user_credential?(username) ⇒ Boolean
Determines if one of the credentials pertains to the specified username.
-
#notes ⇒ Object
:attr_reader: Public notes related to a Storage volume.
-
#notes=(notes) ⇒ Object
Updates the notes for the network storage instance.
-
#password ⇒ Object
:attr_reader: The password used to access a non-EVault Storage volume.
-
#password=(password) ⇒ Object
Updates the password for the network storage instance.
-
#remove_credential(username) ⇒ Object
Remove an existing network storage credential specified by the username from the network storage instance.
-
#service ⇒ Object
Returns the service for interacting with this network storage through the network API.
-
#service_resource ⇒ Object
The network resource a Storage service is connected to.
-
#softlayer_properties(object_mask = nil) ⇒ Object
Make an API request to SoftLayer and return the latest properties hash for this object.
-
#type ⇒ Object
:attr_reader: A Storage account’s type.
-
#update_credential_password(username, password) ⇒ Object
Updates the password for the network storage credential of the username specified.
-
#upgradable ⇒ Object
:attr_reader: This flag indicates whether this storage type is upgradable or not.
-
#username ⇒ Object
:attr_reader: The username used to access a non-EVault Storage volume.
-
#webcc_account ⇒ Object
The account username and password for the EVault webCC interface.
Methods included from DynamicAttribute
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) - Include network storage associated with servers matching this datacenter -
:domain(string) - Include network storage associated with servers matching this domain -
:hostname(string) - Include network storage associated with servers matching this hostname -
:network_storage_server_type(string) - Include network storage associated with this server type -
:network_storage_type(string) - Include network storage from devices of this storage type -
:service(string) - Include network storage from devices with this service fqdn -
:tags(Array) - Include network storage associated with servers matching these tags
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 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 |
# File 'lib/softlayer/NetworkStorage.rb', line 194 def self.find_network_storage( = {}) softlayer_client = [:client] || Client.default_client raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client if(.has_key? :network_storage_object_filter) network_storage_object_filter = [: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 .has_key?(:network_storage_server_type) && ! [ :hardware, :virtual_server ].include?([: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 [:network_storage_type] unless filter_label.select{|label,filter| filter.end_with?("Storage")}.keys.include?([: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 = [:network_storage_type] || :network_storage if [:service] network_storage_object_filter.modify do |filter| filter.accept(option_to_filter_path[:service].call(network_storage_type)).when_it is([:service]) end end if [:network_storage_server_type] [ :datacenter, :domain, :hostname ].each do |option| if [option] network_storage_object_filter.modify do |filter| filter.accept(option_to_filter_path[option].call(network_storage_type, [:network_storage_server_type])).when_it is([option]) end end end if [:tags] network_storage_object_filter.set_criteria_for_key_path(option_to_filter_path[:tags].call(network_storage_type, [:network_storage_server_type]), { 'operation' => 'in', 'options' => [{ 'name' => 'data', 'value' => [:tags].collect{ |tag_value| tag_value.to_s } }] }) 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([:network_storage_object_mask]) if [:network_storage_object_mask] case [: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 |
Instance Method Details
#account_password ⇒ Object
Other usernames and passwords associated with a Storage volume.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/softlayer/NetworkStorage.rb', line 59 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_credential(credential_type) ⇒ Object
Add a username/password credential to the network storage instance
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/softlayer/NetworkStorage.rb', line 114 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
128 129 130 131 132 133 134 135 |
# File 'lib/softlayer/NetworkStorage.rb', line 128 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 |
#capacity ⇒ Object
:attr_reader: A Storage account’s capacity, measured in gigabytes.
21 |
# File 'lib/softlayer/NetworkStorage.rb', line 21 sl_attr :capacity, 'capacityGb' |
#created ⇒ Object
:attr_reader: The date a network storage volume was created.
26 |
# File 'lib/softlayer/NetworkStorage.rb', line 26 sl_attr :created, 'createDate' |
#credentials ⇒ Object
A Storage volume’s access credentials.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/softlayer/NetworkStorage.rb', line 73 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.
140 141 142 |
# File 'lib/softlayer/NetworkStorage.rb', line 140 def has_user_credential?(username) self.credentials.map { |credential| credential.username }.include?(username) end |
#notes ⇒ Object
:attr_reader: Public notes related to a Storage volume.
31 |
# File 'lib/softlayer/NetworkStorage.rb', line 31 sl_attr :notes |
#notes=(notes) ⇒ Object
Updates the notes for the network storage instance.
147 148 149 150 |
# File 'lib/softlayer/NetworkStorage.rb', line 147 def notes=(notes) self.service.editObject({ "notes" => notes.to_s }) self.refresh_details() end |
#password ⇒ Object
: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.
38 |
# File 'lib/softlayer/NetworkStorage.rb', line 38 sl_attr :password |
#password=(password) ⇒ Object
Updates the password for the network storage instance.
155 156 157 158 159 160 161 |
# File 'lib/softlayer/NetworkStorage.rb', line 155 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
166 167 168 169 170 171 172 173 |
# File 'lib/softlayer/NetworkStorage.rb', line 166 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 |
#service ⇒ Object
Returns the service for interacting with this network storage through the network API
289 290 291 |
# File 'lib/softlayer/NetworkStorage.rb', line 289 def service softlayer_client[:Network_Storage].object_with_id(self.id) end |
#service_resource ⇒ Object
The network resource a Storage service is connected to.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/softlayer/NetworkStorage.rb', line 86 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.
297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/softlayer/NetworkStorage.rb', line 297 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 |
#type ⇒ Object
:attr_reader: A Storage account’s type.
43 |
# File 'lib/softlayer/NetworkStorage.rb', line 43 sl_attr :type, 'nasType' |
#update_credential_password(username, password) ⇒ Object
Updates the password for the network storage credential of the username specified.
312 313 314 315 316 317 318 319 320 321 |
# File 'lib/softlayer/NetworkStorage.rb', line 312 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 |
#upgradable ⇒ Object
:attr_reader: This flag indicates whether this storage type is upgradable or not.
48 |
# File 'lib/softlayer/NetworkStorage.rb', line 48 sl_attr :upgradable, 'upgradableFlag' |
#username ⇒ Object
: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.
55 |
# File 'lib/softlayer/NetworkStorage.rb', line 55 sl_attr :username |
#webcc_account ⇒ Object
The account username and password for the EVault webCC interface.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/softlayer/NetworkStorage.rb', line 99 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 |