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

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

Methods inherited from Resource

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

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



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 64

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



89
90
91
92
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 89

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:



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

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

#update(attributes = {}, header = { 'If-Match' => '*' }) ⇒ OneviewSDK::Rack

Updates a rack

Parameters:

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

    attributes to be updated

Returns:

  • (OneviewSDK::Rack)

    self



57
58
59
# File 'lib/oneview-sdk/resource/api200/rack.rb', line 57

def update(attributes = {}, header = { 'If-Match' => '*' })
  super(attributes, header)
end