Class: OneviewSDK::API200::Enclosure

Inherits:
Resource show all
Includes:
ResourceHelper::ConfigurationOperation
Defined in:
lib/oneview-sdk/resource/api200/enclosure.rb

Overview

Enclosure resource implementation

Direct Known Subclasses

OneviewSDK::API300::C7000::Enclosure

Constant Summary collapse

BASE_URI =
'/rest/enclosures'.freeze
UNIQUE_IDENTIFIERS =
%w[name uri serialNumber activeOaPreferredIP standbyOaPreferredIP].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 included from ResourceHelper::ConfigurationOperation

#configuration

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) ⇒ Enclosure

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.



34
35
36
37
38
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 34

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

Instance Method Details

#addOneviewSDK::Enclosure

Note:

Calls the refresh method to set additional data

Claim/configure the enclosure and its components to the appliance

Returns:

  • (OneviewSDK::Enclosure)

    self



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

def add
  ensure_client
  required_attributes = %w[enclosureGroupUri hostname username password licensingIntent]
  required_attributes.each { |k| raise IncompleteResource, "Missing required attribute: '#{k}'" unless @data.key?(k) }

  optional_attrs = %w[enclosureUri firmwareBaselineUri force forceInstallFirmware state unmanagedEnclosure updateFirmwareOn]
  temp_data = @data.select { |k, _v| required_attributes.include?(k) || optional_attrs.include?(k) }
  response = @client.rest_post(self.class::BASE_URI, { 'body' => temp_data }, @api_version)
  new_data = @client.response_handler(response)
  old_name = @data.select { |k, _v| %w[name rackName].include?(k) } # Save name (if given)
  %w[username password hostname].each { |k| @data.delete(k) } # These are no longer needed
  set_all(new_data)
  set_all(old_name)
  update
  self
end

#createObject

Method is not available

Raises:



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

def create(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



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

def delete(*)
  unavailable_method
end

#environmental_configurationHash

Gets the enclosure settings that describe the environmental configuration

Returns:

  • (Hash)

    The enclosure envirnomental configuration



115
116
117
118
119
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 115

def environmental_configuration
  ensure_client && ensure_uri
  response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', {}, @api_version)
  @client.response_handler(response)
end

#patch(operation, path, value) ⇒ Object

Updates specific attributes of a given enclosure resource

Parameters:

  • operation (String)

    operation to be performed

  • path (String)

    path

  • value (String)

    value



162
163
164
165
166
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 162

def patch(operation, path, value)
  ensure_client && ensure_uri
  response = @client.rest_patch(@data['uri'], { 'body' => [{ op: operation, path: path, value: value }] }, @api_version)
  @client.response_handler(response)
end

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



28
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 28

alias remove delete

#scriptString

Gets the enclosure script content

Returns:

  • (String)

    Script content



107
108
109
110
111
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 107

def script
  ensure_client && ensure_uri
  response = @client.rest_get(@data['uri'] + '/script', {}, @api_version)
  @client.response_handler(response)
end

#set_enclosure_group(eg) ⇒ Object

Associates an enclosure group to the enclosure

Parameters:



170
171
172
173
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 170

def set_enclosure_group(eg)
  eg.retrieve! unless eg['uri']
  @data['enclosureGroupUri'] = eg['uri']
end

#set_environmental_configuration(power) ⇒ Object

Sets the calibrated max power of an unmanaged or unsupported enclosure

Parameters:

  • power (String)

    The calibrated maximum power of the resource



123
124
125
126
127
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 123

def set_environmental_configuration(power)
  ensure_client && ensure_uri
  response = @client.rest_put(@data['uri'] + '/environmentalConfiguration', 'body' => { calibratedMaxPower: power })
  @client.response_handler(response)
end

#set_refresh_state(state, options = {}) ⇒ Object

Refreshes the enclosure along with all of its components

Parameters:

  • state (String)

    NotRefreshing, RefreshFailed, RefreshPending, Refreshing

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

    Optional force fields for refreshing the enclosure



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 91

def set_refresh_state(state, options = {})
  ensure_client && ensure_uri
  s = state.to_s rescue state
  requestBody = {
    'body' => {
      refreshState: s,
      refreshForceOptions: options
    }
  }
  response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version)
  new_data = @client.response_handler(response)
  set_all(new_data)
end

#update(attributes = {}) ⇒ OneviewSDK::Enclosure

Overrides the update operation because only the name and rackName can be updated (and it uses PATCH).

Parameters:

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

    attributes to be updated

Returns:

  • (OneviewSDK::Enclosure)

    self



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

def update(attributes = {})
  set_all(attributes)
  ensure_client && ensure_uri
  cur_state = self.class.find_by(@client, uri: @data['uri']).first
  unless cur_state[:name] == @data['name']
    patch('replace', '/name', @data['name'])
  end
  unless cur_state[:rackName] == @data['rackName']
    patch('replace', '/rackName', @data['rackName'])
  end
  self
end

#utilization(queryParameters = {}) ⇒ Object

Retrieves historical utilization

Parameters:

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

    query parameters (ie :startDate, :endDate, :fields, :view, etc.)

Options Hash (queryParameters):

  • :fields (Array)
  • :startDate (Time, Date, String)
  • :endDate (Time, Date, String)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 134

def utilization(queryParameters = {})
  ensure_client && ensure_uri
  uri = "#{@data['uri']}/utilization?"

  queryParameters[:endDate]   = convert_time(queryParameters[:endDate])
  queryParameters[:startDate] = convert_time(queryParameters[:startDate])

  queryParameters.each do |key, value|
    next if value.nil?
    uri += case key.to_sym
           when :fields
             "fields=#{value.join(',')}"
           when :startDate, :endDate
             "filter=#{key}=#{value}"
           else
             "#{key}=#{value}"
           end
    uri += '&'
  end
  uri.chop! # Get rid of trailing '&' or '?'
  response = @client.rest_get(uri, {}, @api_version)
  @client.response_handler(response)
end