Class: Moxprox::Machine

Inherits:
Struct
  • Object
show all
Defined in:
lib/moxprox/machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/moxprox/machine.rb', line 2

def id
  @id
end

#nodeObject

Returns the value of attribute node

Returns:

  • (Object)

    the current value of node



2
3
4
# File 'lib/moxprox/machine.rb', line 2

def node
  @node
end

Instance Method Details

#configObject



19
20
21
# File 'lib/moxprox/machine.rb', line 19

def config
  request("config")
end

#request(path, method = "get", query = {}) ⇒ Object



29
30
31
# File 'lib/moxprox/machine.rb', line 29

def request(path, method = "get", query = {})
  node.request("qemu/#{id}/#{path}", method, query)
end

#shutdown(&block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/moxprox/machine.rb', line 11

def shutdown(&block)
  logger.info "shutting down machine #{id} on #{node.name}"
  upid = request("status/shutdown", "post")
  if block_given?
    node.wait_for_task(upid, &block)
  end
end

#start(&block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/moxprox/machine.rb', line 3

def start(&block)
  logger.info "starting machine #{id} on #{node.name}"
  upid = request("status/start", "post")
  if block_given?
    node.wait_for_task(upid, &block)
  end
end

#statusObject



23
24
25
26
27
# File 'lib/moxprox/machine.rb', line 23

def status
  res = request("status/current")
  logger.debug "status of machine #{id} on #{node.name}: #{res["status"]}"
  res["status"].to_sym
end