Class: OneviewSDK::StorageSystem

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

Overview

Storage system resource implementation

Constant Summary collapse

BASE_URI =
'/rest/storage-systems'.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, #like?, #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.



25
26
27
28
29
# File 'lib/oneview-sdk/resource/storage_system.rb', line 25

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



90
91
92
93
# File 'lib/oneview-sdk/resource/storage_system.rb', line 90

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:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oneview-sdk/resource/storage_system.rb', line 46

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:



33
34
35
# File 'lib/oneview-sdk/resource/storage_system.rb', line 33

def create
  unavailable_method
end

#deleteObject

Method is not available

Raises:



39
40
41
# File 'lib/oneview-sdk/resource/storage_system.rb', line 39

def delete
  unavailable_method
end

#exists?Boolean

Note:

name,uri or ip_hostname must be specified inside resource

Checks if the resource already exists

Returns:

  • (Boolean)

    Whether or not resource exists



61
62
63
64
65
66
67
68
69
70
# File 'lib/oneview-sdk/resource/storage_system.rb', line 61

def exists?
  ip_hostname = self['credentials'][:ip_hostname] || self['credentials']['ip_hostname'] if self['credentials']
  return true if @data['name'] && self.class.find_by(@client, name: @data['name']).size == 1
  return true if @data['uri']  && self.class.find_by(@client, uri:  @data['uri']).size == 1
  return true if ip_hostname && self.class.find_by(@client, credentials: { ip_hostname: ip_hostname }).size == 1
  unless @data['name'] || @data['uri'] || ip_hostname
    fail IncompleteResource, 'Must set resource name, uri or ip_hostname before trying to retrieve!'
  end
  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



104
105
106
107
108
109
110
111
# File 'lib/oneview-sdk/resource/storage_system.rb', line 104

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



96
97
98
99
# File 'lib/oneview-sdk/resource/storage_system.rb', line 96

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

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



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

alias remove delete

#retrieve!Boolean

Note:

Name,URI or ip_hostname must be specified inside resource

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

Returns:

  • (Boolean)

    Whether or not retrieve was successful

Raises:



76
77
78
79
80
81
82
83
84
85
# File 'lib/oneview-sdk/resource/storage_system.rb', line 76

def retrieve!
  ip_hostname = self['credentials'][:ip_hostname] || self['credentials']['ip_hostname'] if self['credentials']
  return super if @data['name'] || @data['uri']

  fail IncompleteResource, 'Must set resource name, uri or ip_hostname before trying to retrieve!' unless ip_hostname
  results = self.class.find_by(@client, credentials: { ip_hostname: ip_hostname })
  return false unless results.size == 1
  set_all(results[0].data)
  true
end