Class: OneviewSDK::API200::Rack

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

Overview

Rack resource implementation

Constant Summary collapse

BASE_URI =
'/rest/racks'.freeze
UNIQUE_IDENTIFIERS =
%w(name uri serialNumber).freeze

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

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

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.



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

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

Instance Method Details

#addOneviewSDK::Rack

Note:

Calls the refresh method to set additional data

Add the resource on OneView using the current data

Returns:

  • (OneviewSDK::Rack)

    self

Raises:



26
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 26

alias add create

#add_rack_resource(resource, options = {}) ⇒ Object

Adds the rack resource with specified options

Parameters:

  • resource (OneviewSDK::Resource)

    Resource to be added

  • options (String) (defaults to: {})

    rack options



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 57

def add_rack_resource(resource, options = {})
  rack_resource_options = {}
  # Write values to hash and transform any symbol to string
  options.each { |key, val| rack_resource_options[key.to_s] = val }

  # Verify if the rack resource exists in the rack, if not init add it
  rack_resource = @data['rackMounts'].find { |resource_from_rack| resource_from_rack['mountUri'] == resource['uri'] }
  if rack_resource
    rack_resource_options.each { |key, val| rack_resource[key] = val }
  else
    # Set default values if not given
    rack_resource_options['mountUri'] = resource['uri']
    rack_resource_options['location'] = 'CenterFront' unless rack_resource_options['location']
    @data['rackMounts'] << rack_resource_options
  end
end

#createObject

Method is not available

Raises:



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

def create(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



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

def delete(*)
  unavailable_method
end

#get_device_topologyHash

Gets topology information for the rack

Returns:

  • (Hash)

    Environmental analysis



82
83
84
85
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 82

def get_device_topology
  response = @client.rest_get(@data['uri'] + '/deviceTopology')
  @client.response_handler(response)
end

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



30
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 30

alias remove delete

#remove_rack_resource(resource) ⇒ Object

Remove resources from the rack

Parameters:



76
77
78
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 76

def remove_rack_resource(resource)
  @data['rackMounts'].reject! { |rack_resource| rack_resource['mountUri'] == resource['uri'] }
end