Class: OneviewSDK::API200::StorageSystem

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/resource/api200/storage_system.rb

Overview

Storage system resource implementation

Constant Summary collapse

BASE_URI =
'/rest/storage-systems'.freeze
UNIQUE_IDENTIFIERS =

credentials is supported too

%w(name uri serialNumber wwn).freeze

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create!, #each, #eql?, find_by, from_file, get_all, #refresh, #schema, schema, #set, #set_all, #to_file, #update

Constructor Details

#initialize(client, params = {}, api_ver = nil) ⇒ StorageSystem

Create a resource object, associate it with a client, and set its properties.

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • params (Hash) (defaults to: {})

    The options for this resource (key-value pairs)

  • api_ver (Integer) (defaults to: nil)

    The api version to use when interracting with this resource.



29
30
31
32
33
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 29

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values:
  @data['type'] ||= 'StorageSystemV3'
end

Class Method Details

.get_host_types(client) ⇒ String

Gets the host types for the storage system resource

Parameters:

Returns:

  • (String)

    response body



126
127
128
129
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 126

def self.get_host_types(client)
  response = client.rest_get(BASE_URI + '/host-types')
  response.body
end

Instance Method Details

#addOneviewSDK::StorageSystem

Note:

Calls the refresh method to set additional data

Adds the resource to OneView using the current data

Returns:

  • (OneviewSDK::StorageSystem)

    self



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 50

def add
  ensure_client
  task = @client.rest_post(self.class::BASE_URI, { 'body' => self['credentials'] }, @api_version)
  temp = @data.clone
  task = @client.wait_for(task['uri'] || task['location'])
  @data['uri'] = task['associatedResource']['resourceUri']
  refresh
  temp.delete('credentials')
  update(temp)
  self
end

#createObject

Method is not available

Raises:



37
38
39
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 37

def create(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



43
44
45
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 43

def delete(*)
  unavailable_method
end

#exists?Boolean

Note:

one of the UNIQUE_IDENTIFIERS or credentials must be specified in the resource

Checks if the resource already exists

Returns:

  • (Boolean)

    Whether or not resource exists

Raises:



66
67
68
69
70
71
72
73
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 66

def exists?
  ip_hostname = self['credentials'][:ip_hostname] || self['credentials']['ip_hostname'] rescue nil
  return true if ip_hostname && self.class.find_by(@client, credentials: { ip_hostname: ip_hostname }).size == 1
  super
rescue IncompleteResource => e
  raise e unless ip_hostname
  false
end

#get_managed_ports(port = nil) ⇒ Object

Lists all managed target ports for the specified storage system, or only the one specified

Parameters:

  • port (String) (defaults to: nil)

    Target port



140
141
142
143
144
145
146
147
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 140

def get_managed_ports(port = nil)
  response = if port.nil?
               @client.rest_get("#{@data['uri']}/managedPorts")
             else
               @client.rest_get("#{@data['uri']}/managedPorts/#{port}")
             end
  response.body
end

#get_storage_poolsObject

Lists the storage pools



132
133
134
135
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 132

def get_storage_pools
  response = @client.rest_get(@data['uri'] + '/storage-pools')
  response.body
end

#like?(other) ⇒ Boolean

Note:

Does not check the client, logger, or api_version if another resource is passed in

Note:

Does not check the password in credentials

Check the equality of the data for the other resource with this resource.

Examples:

Compare to hash

myResource.like?(credentials: { ip_hostname: ‘res1’, username: ‘admin’, password: ‘secret’ })

myResource = OneviewSDK::Resource.new(client, { name: 'res1', description: 'example'}, 200)
myResource.like?(description: '') # returns false
myResource.like?(name: 'res1') # returns true

Parameters:

  • other (Hash, Resource)

    resource or hash to compare the key-value pairs with

Returns:

  • (Boolean)

    Whether or not the two objects are alike



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 104

def like?(other)
  if other.is_a? Hash
    other_copy = Marshal.load(Marshal.dump(other))
  else
    other_copy = other.dup
    other_copy.data = Marshal.load(Marshal.dump(other.data))
  end

  if other_copy['credentials']
    other_copy['credentials'].delete('password') rescue nil
    other_copy['credentials'].delete(:password) rescue nil
  elsif other_copy[:credentials]
    other_copy[:credentials].delete('password') rescue nil
    other_copy[:credentials].delete(:password) rescue nil
  end

  super(other_copy)
end

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



23
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 23

alias remove delete

#retrieve!Boolean

Note:

one of the UNIQUE_IDENTIFIERS or credentials must be specified in the resource

Retrieves the resource details based on this resource’s name or URI.

Returns:

  • (Boolean)

    Whether or not retrieve was successful

Raises:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 79

def retrieve!
  ip_hostname = self['credentials'][:ip_hostname] || self['credentials']['ip_hostname'] rescue nil
  if ip_hostname
    results = self.class.find_by(@client, credentials: { ip_hostname: ip_hostname })
    if results.size == 1
      set_all(results[0].data)
      return true
    end
  end
  super
rescue IncompleteResource => e
  raise e unless ip_hostname
  false
end

#set_refresh_state(state) ⇒ Object

Refreshes a storage system

Parameters:

  • state (String)

    NotRefreshing, RefreshFailed, RefreshPending, Refreshing



151
152
153
154
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 151

def set_refresh_state(state)
  @data['refreshState'] = state
  update
end