Module: XClarityClient::Services::PowerActionSenderMixin

Included in:
ChassiManagement, NodeManagement, XClarityClient::SwitchManagement
Defined in:
lib/xclarity_client/services/mixins/power_action_sender_mixin.rb

Overview

A Power Action Sender is capable to send power operation request for its managed endpoint.

An XclarityEndpoint that supports power or LED operations must configure the supported operations through ‘POWER_ACTIONS` and `LED_STATES` constants.

Instance Method Summary collapse

Instance Method Details

#send_led_state_request(uri, requested_state = nil, led_name = 'Identify') ⇒ Object

Do a change LED state request for an endpoint

Parameters:

  • uri (String)
    • The URI that must receive the request.

  • requested_state (String) (defaults to: nil)
    • The new LED state.

  • led_name (String) (defaults to: 'Identify')
    • name of the LED that must have it state changed.

Returns:

  • the LXCA response.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/xclarity_client/services/mixins/power_action_sender_mixin.rb', line 87

def send_led_state_request(uri,
                           requested_state = nil,
                           led_name = 'Identify')
  request = JSON.generate(
    :leds => [{ :name => led_name, :state => requested_state }]
  )
  response = @connection.do_put(uri, request)
  msg = "LED state request has been sent with request #{request}"

  $lxca_log.info("#{self.class.name} send_led_state_request", msg)
  response
end

#send_power_request(uri, requested_state = nil) ⇒ Object

Do a change power state request for an endpoint

Parameters:

  • uri (String)
    • the URI of the endpoint that must have its power state changed.

  • requested_state (symbol) (defaults to: nil)
    • the new power state.

Returns:

  • the LXCA response.



66
67
68
69
70
71
72
73
# File 'lib/xclarity_client/services/mixins/power_action_sender_mixin.rb', line 66

def send_power_request(uri, requested_state = nil)
  power_request = JSON.generate(:powerState => requested_state)
  response = @connection.do_put(uri, power_request)
  msg = "Power state action has been sent with request #{power_request}"

  $lxca_log.info("#{self.class.name} send_power_request", msg)
  response
end

#set_loc_led_state(uuid, state, name = 'Identify') ⇒ Object

Changes the state of a LED of some resource.

Parameters:

  • uuid (String)
    • resource identifier

  • state (String)
    • the new LED state

    it must be listed on ‘managed_resource::LED_STATES`

  • name (String) (defaults to: 'Identify')
    • name of the LED that must have it state changed

Returns:

  • the LXCA response



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/xclarity_client/services/mixins/power_action_sender_mixin.rb', line 44

def set_loc_led_state(uuid, state, name = 'Identify')
  unless valid_arguments?(uuid, state, managed_resource::LED_STATES)
    error = 'Invalid target or power state requested'
    source = "#{self.class.name} set_loc_led_state"
    $lxca_log.info(source, error)
    raise ArgumentError, error
  end

  send_led_state_request(
    "#{managed_resource::BASE_URI}/#{uuid}", state, name
  )
end

#set_power_state(uuid, state) ⇒ Object

Changes the power state for some resource.

Parameters:

  • uuid (String)
    • resource identifier

  • state (symbol)
    • the new power state

    it must be listed on ‘managed_resource::POWER_ACTIONS`

Returns:

  • the LXCA response.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xclarity_client/services/mixins/power_action_sender_mixin.rb', line 21

def set_power_state(uuid, state)
  unless valid_arguments?(uuid, state, managed_resource::POWER_ACTIONS)
    error = 'Invalid target or power state requested'
    source = "#{self.class.name} set_power_state"
    $lxca_log.info(source, error)
    raise ArgumentError, error
  end

  send_power_request(
    "#{managed_resource::BASE_URI}/#{uuid}", state
  )
end