Class: OneviewSDK::Rack

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

Overview

Rack resource implementation

Constant Summary collapse

BASE_URI =
'/rest/racks'.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.



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

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:

Raises:



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

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/oneview-sdk/resource/rack.rb', line 53

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:



40
41
42
# File 'lib/oneview-sdk/resource/rack.rb', line 40

def create
  unavailable_method
end

#deleteObject

Method is not available

Raises:



46
47
48
# File 'lib/oneview-sdk/resource/rack.rb', line 46

def delete
  unavailable_method
end

#get_device_topologyHash

Gets topology information for the rack

Returns:

  • (Hash)

    Environmental analysis



78
79
80
81
# File 'lib/oneview-sdk/resource/rack.rb', line 78

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



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

alias remove delete

#remove_rack_resource(resource) ⇒ Object

Remove resources from the rack

Parameters:



72
73
74
# File 'lib/oneview-sdk/resource/rack.rb', line 72

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