class Archipel::Api::VmApi

Public Class Methods

new(login: nil, password: nil, server: nil, hypervisor: nil) click to toggle source
Calls superclass method Archipel::Api::Internal::Api::new
# File lib/archipel/api/vm_api.rb, line 7
def initialize login: nil, password: nil, server: nil, hypervisor: nil
  @api = Archipel::Api::Internal::VmXmlMessages.new
  super({login: login,
      password: password,
      server: server})
end

Public Instance Methods

autostart(jid, new_state = nil) click to toggle source

Set autostart to new_state; read autostart state when new_state is not given

# File lib/archipel/api/vm_api.rb, line 41
def autostart jid, new_state = nil
  if new_state.nil?
    info(jid).autostart
  else
    method_missing :autostart, jid, new_state
  end
end
info(jid) click to toggle source
# File lib/archipel/api/vm_api.rb, line 32
def info jid
  out = method_missing :info, jid
  resp = out['query'][0]['info'][0]
  VmInfo.new resp['state'], resp['autostart'],
      resp['memory'], resp['maxMem'],
      resp['cpuPrct'], resp['nrVirtCpu']
end
list_disks(jid) click to toggle source
# File lib/archipel/api/vm_api.rb, line 22
def list_disks jid
  out = method_missing :list_disks, jid
  out['query'][0]['disk'] || []
end
method_missing(symbol, *args) click to toggle source
# File lib/archipel/api/vm_api.rb, line 49
def method_missing symbol, *args
  to = args[0]
  xml = @api.send symbol, *args
  call xml, to
end
remove_disk(jid, name, format) click to toggle source
# File lib/archipel/api/vm_api.rb, line 14
def remove_disk jid, name, format
  disks = list_disks jid
  found_disk = disks.find do |disk|
    disk['name'] == name && disk['format'] == format
  end
  method_missing :remove_disk, jid, found_disk['path']
end
xml(jid) click to toggle source
# File lib/archipel/api/vm_api.rb, line 27
def xml jid
  out = method_missing :xml, jid
  out['query'][0]['domain'][0]
end