Class: OneviewSDK::Enclosure

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

Overview

Enclosure resource implementation

Validates collapse

VALID_LICENSING_INTENTS =
%w(NotApplicable OneView OneViewNoiLO OneViewStandard).freeze
VALID_REFRESH_STATES =
%w(NotRefreshing RefreshFailed RefreshPending Refreshing).freeze

Constant Summary collapse

BASE_URI =
'/rest/enclosures'.freeze

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Validates collapse

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

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

Returns a new instance of Enclosure.



9
10
11
12
13
# File 'lib/oneview-sdk/resource/enclosure.rb', line 9

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

Instance Method Details

#configurationObject

Reapply enclosure configuration



66
67
68
69
70
71
# File 'lib/oneview-sdk/resource/enclosure.rb', line 66

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

#createObject

Claim/configure the enclosure and its components to the appliance



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oneview-sdk/resource/enclosure.rb', line 30

def create
  ensure_client
  required_attributes = %w(enclosureGroupUri hostname username password licensingIntent)
  required_attributes.each { |k| fail "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

#environmental_configurationObject

Get settings that describe the environmental configuration



101
102
103
104
105
# File 'lib/oneview-sdk/resource/enclosure.rb', line 101

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

#scriptString

Get enclosure script content

Returns:

  • (String)

    Script content



94
95
96
97
98
# File 'lib/oneview-sdk/resource/enclosure.rb', line 94

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 one Enclosure Group to the enclosure to be added

Parameters:



148
149
150
151
# File 'lib/oneview-sdk/resource/enclosure.rb', line 148

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

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

Refresh 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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/oneview-sdk/resource/enclosure.rb', line 77

def set_refresh_state(state, options = {})
  ensure_client && ensure_uri
  s = state.to_s rescue state
  validate_refreshState(s) # Validate refreshState
  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 = {}) ⇒ Object

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/oneview-sdk/resource/enclosure.rb', line 48

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']
    temp_data = [{ op: 'replace', path: '/name', value: @data['name'] }]
    response = @client.rest_patch(@data['uri'], { 'body' => temp_data }, @api_version)
    @client.response_handler(response)
  end
  unless cur_state[:rackName] == @data['rackName']
    temp_data = [{ op: 'replace', path: '/rackName', value: @data['rackName'] }]
    response = @client.rest_patch(@data['uri'], { 'body' => temp_data }, @api_version)
    @client.response_handler(response)
  end
  self
end

#update_attribute(operation, path, value) ⇒ Object

Update specific attributes of a given enclosure resource

Parameters:

  • operation (String)

    operation to be performed

  • path (String)

    path

  • value (String)

    value



140
141
142
143
144
# File 'lib/oneview-sdk/resource/enclosure.rb', line 140

def update_attribute(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

#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)


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/oneview-sdk/resource/enclosure.rb', line 112

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

#validate_licensingIntent(value) ⇒ Object



18
19
20
# File 'lib/oneview-sdk/resource/enclosure.rb', line 18

def validate_licensingIntent(value)
  fail 'Invalid licensingIntent' unless VALID_LICENSING_INTENTS.include?(value) || value.nil?
end

#validate_refreshState(value) ⇒ Object



23
24
25
# File 'lib/oneview-sdk/resource/enclosure.rb', line 23

def validate_refreshState(value)
  fail 'Invalid refreshState' unless VALID_REFRESH_STATES.include?(value)
end