class SoftLayer::AccountPassword

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.

Attributes

notes[R]

A simple description of a username/password combination.

password[R]

The password portion of a username/password combination.

username[R]

The username portion of a username/password combination.

Public Class Methods

find_network_storage_account_passwords(options_hash = {}) click to toggle source

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 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 account passwords from servers matching this datacenter

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

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

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

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

  • :tags (string/array) - Include network storage account passwords from servers matching these tags

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

Additionally you may provide options related to the request itself:

  • :account_password_object_filter (ObjectFilter) - Include network storage account passwords for account passwords that match the

    criteria of this object filter
    
  • :account_password_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 account passwords from network storage that matches the

    criteria of this object filter
    
# File lib/softlayer/AccountPassword.rb, line 95
def self.find_network_storage_account_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? :account_password_object_filter)
    account_password_object_filter = options_hash[:account_password_object_filter]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless account_password_object_filter.kind_of?(SoftLayer::ObjectFilter)
  else
    account_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 = {
    :account_password => {
      :username       => "accountPassword.username"
    },
    :network_storage  => {
      :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

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

  option_to_filter_path[:account_password].each do |option, filter_path|
    account_password_object_filter.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option]) } if options_hash[option]
  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("mask[id]")

  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

  account_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(account_password_object_filter) unless account_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[:account_password_object_mask]) if options_hash[:account_password_object_mask]

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

  account_passwords.compact
end
find_network_storage_webcc_passwords(options_hash = {}) click to toggle source

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 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 webcc passwords from servers matching this datacenter

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

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

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

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

  • :tags (string/array) - Include network storage webcc passwords from servers matching these tags

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

Additionally you may provide options related to the request itself:

  • :network_storage_object_filter (ObjectFilter) - Include network storage account passwords from network storage that matches the

    criteria of this object filter
    
  • :webcc_password_object_filter (ObjectFilter) - Include network storage account passwords for webcc passwords that match the

    criteria of this object filter
    
  • :webcc_password_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
# File lib/softlayer/AccountPassword.rb, line 221
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 = {
    :network_storage => {
      :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

    option_to_filter_path[:network_storage].keys.each do |option|
      if options_hash[option]
        network_storage_object_filter.modify do |filter|
          filter.accept(option_to_filter_path[:network_storage][option].call(network_storage_type, options_hash[:network_storage_server_type])).when_it is(options_hash[option])
        end
      end
    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

  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("mask[id]")

  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

  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

Protected Class Methods

default_object_mask() click to toggle source
# File lib/softlayer/AccountPassword.rb, line 345
def self.default_object_mask
  {
    "mask(SoftLayer_Account_Password)" => [
                                           'id',
                                           'notes',
                                           'password',
                                           'username'
                                          ]
  }.to_sl_object_mask
end

Public Instance Methods

description(force_update=false) click to toggle source

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

# File lib/softlayer/AccountPassword.rb, line 37
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
notes=(notes) click to toggle source

Updates the notes for the current account password.

# File lib/softlayer/AccountPassword.rb, line 52
def notes=(notes)
  self.service.editObject({ "notes" => notes.to_s })
  self.refresh_details()
end
password=(password) click to toggle source

Updates the password for the current account password.

# File lib/softlayer/AccountPassword.rb, line 60
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
service() click to toggle source

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

# File lib/softlayer/AccountPassword.rb, line 323
def service
  softlayer_client[:Account_Password].object_with_id(self.id)
end
softlayer_properties(object_mask = nil) click to toggle source

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

# 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