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

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER

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, #deep_merge!, #each, #eql?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #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



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

def self.get_host_types(client)
  response = client.rest_get(BASE_URI + '/host-types')
  client.response_handler(response)
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



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 56

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

#create!Object

Method is not available

Raises:



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

def create!(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



49
50
51
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 49

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:



72
73
74
75
76
77
78
79
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 72

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



145
146
147
148
149
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 145

def get_managed_ports(port = nil)
  uri = @data['uri']
  uri += port.nil? ? '/managedPorts' : "/managedPorts/#{port}"
  self.class.find_with_pagination(@client, uri)
end

#get_storage_poolsObject

Lists the storage pools



138
139
140
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 138

def get_storage_pools
  self.class.find_with_pagination(@client, @data['uri'] + '/storage-pools')
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: { 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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 110

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:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/oneview-sdk/resource/api200/storage_system.rb', line 85

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



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

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