Class: ForemanApiClient::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_api_client/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, manager_ref) ⇒ Host

Returns a new instance of Host.



6
7
8
9
# File 'lib/foreman_api_client/host.rb', line 6

def initialize(connection, manager_ref)
  @connection = connection
  @manager_ref = manager_ref
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/foreman_api_client/host.rb', line 4

def connection
  @connection
end

#manager_refObject

Returns the value of attribute manager_ref.



3
4
5
# File 'lib/foreman_api_client/host.rb', line 3

def manager_ref
  @manager_ref
end

Instance Method Details

#attributesObject



40
41
42
# File 'lib/foreman_api_client/host.rb', line 40

def attributes
  connection.fetch(:hosts, :show, "id" => manager_ref).first
end

#building?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/foreman_api_client/host.rb', line 11

def building?
  attributes["build"]
end

#power_state(action = "status") ⇒ Object

valid actions are (on/start), (off/stop), (soft/reboot), (cycle/reset), (state/status)



24
25
26
# File 'lib/foreman_api_client/host.rb', line 24

def power_state(action = "status")
  connection.fetch(:hosts, :power, "id" => manager_ref, "power_action" => action).first["power"]
end

#powered_off?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/foreman_api_client/host.rb', line 28

def powered_off?
  power_state == "off"
end

#powered_on?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/foreman_api_client/host.rb', line 32

def powered_on?
  power_state == "on"
end

#set_boot_mode(mode = "pxe") ⇒ Object



36
37
38
# File 'lib/foreman_api_client/host.rb', line 36

def set_boot_mode(mode = "pxe")
  connection.fetch(:hosts, :boot, "id" => manager_ref, "device" => mode).first["boot"]
end

#startObject



15
16
17
# File 'lib/foreman_api_client/host.rb', line 15

def start
  power_state("on")
end

#stopObject



19
20
21
# File 'lib/foreman_api_client/host.rb', line 19

def stop
  power_state("off")
end

#update(params) ⇒ Object



44
45
46
# File 'lib/foreman_api_client/host.rb', line 44

def update(params)
  connection.fetch(:hosts, :update, "id" => manager_ref, "host" => params)
end