Class: ProxyAPI::BMC

Inherits:
Resource show all
Defined in:
lib/proxy_api/bmc.rb

Instance Attribute Summary

Attributes inherited from Resource

#url

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ BMC


4
5
6
7
8
# File 'lib/proxy_api/bmc.rb', line 4

def initialize args
  @target = args[:host_ip] || '127.0.0.1'
  @url = args[:url] + "/bmc"
  super args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/proxy_api/bmc.rb', line 93

def method_missing(method, *args, &block)
  begin
    super(method, *args, &block)
  rescue NoMethodError
    margs = args.first
    farg  = method.to_s.split('_')
    # method must contain 2 parts, ie: power_on, boot_disk
    raise NoMethodError unless farg.length == 2

    case farg.first
    when "power"
      margs[:action] = farg.last
      power(margs)
    when "boot"
      margs[:function] = "bootdevice"
      margs[:device]   = farg.last
      boot(margs)
    when "identify"
      margs[:action] = farg.last
      identify(margs)
    when "lan"
      margs[:action] = farg.last
      lan(margs)
    else
      raise NoMethodError
    end
  end
end

Instance Method Details

#boot(args) ⇒ Object

Perform a boot operation on the bmc device


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/proxy_api/bmc.rb', line 21

def boot args
  valid_boot_devices = %w[disk cdrom pxe bios]
  # valid additional arguments args[:reboot] = true|false, args[:persistent] = true|false
  #  put "/bmc/:host/chassis/config/?:function?/?:action?" do
  case args[:function]
  when "bootdevice"
    if valid_boot_devices.include?(args[:device])
      parse put(args, bmc_url_for('config',"#{args[:function]}/#{args[:device]}"))
    else
      raise NoMethodError
    end
  else
    raise NoMethodError
  end
end

#identify(args) ⇒ Object

perform an identify operation on the bmc device


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/proxy_api/bmc.rb', line 56

def identify args
  # get "/bmc/:host/chassis/identify/:action"
  # put "/bmc/:host/chassis/identify/:action"
  case args[:action]
  when "status"
    parse get(bmc_url_for('identify',args[:action]), args)
  when "on", "off"
    parse put(args, bmc_url_for('identify',args[:action]))
  else
    raise NoMethodError
  end

end

#lan(args) ⇒ Object

perform a lan get operation on the bmc device


71
72
73
74
75
76
77
78
79
80
# File 'lib/proxy_api/bmc.rb', line 71

def lan args
  # get "/bmc/:host/lan/:action"
  case args[:action]
  when "ip", "netmask", "mac", "gateway"
    response = parse(get(bmc_url_for('lan',args[:action]), args))
    response.is_a?(Hash) ?  response['result'] : response
  else
    raise NoMethodError
  end
end

#power(args) ⇒ Object

Perform a power operation on the bmc device


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/proxy_api/bmc.rb', line 38

def power args
  # get "/bmc/:host/chassis/power/:action"
  # put "/bmc/:host/chassis/power/:action"
  case args[:action]
  when "on?", "off?", "status"
    args[:action].chop! if args[:action].include?('?')
    response = parse(get(bmc_url_for('power',args[:action]), args))
    response.is_a?(Hash) ?  response['result'] : response
  when "on", "off", "cycle", "soft"
    res = parse put(args, bmc_url_for('power',args[:action]))
    # This is a simple action, just return the result of the action
    res && res['result'] == true
  else
    raise NoMethodError
  end
end

#providersObject

gets a list of supported providers


11
12
13
# File 'lib/proxy_api/bmc.rb', line 11

def providers
  parse get("providers")
end

#providers_installedObject

gets a list of supported providers installed on the proxy


16
17
18
# File 'lib/proxy_api/bmc.rb', line 16

def providers_installed
  parse get("providers/installed")
end