Class: Archipel::Api::VmApi

Inherits:
Internal::Api show all
Defined in:
lib/archipel/api/vm_api.rb

Instance Method Summary collapse

Methods inherited from Internal::Api

#call, #in_connection, #wait_for_reply

Constructor Details

#initialize(login: nil, password: nil, server: nil, hypervisor: nil) ⇒ VmApi

Returns a new instance of VmApi.



7
8
9
10
11
12
# 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: ,
      password: password,
      server: server})
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



50
51
52
53
54
# File 'lib/archipel/api/vm_api.rb', line 50

def method_missing symbol, *args
  to = args[0]
  xml = @api.send symbol, *args
  call xml, to
end

Instance Method Details

#autostart(jid, new_state = nil) ⇒ Object

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



42
43
44
45
46
47
48
# File 'lib/archipel/api/vm_api.rb', line 42

def autostart jid, new_state = nil
  if new_state.nil?
    info(jid).autostart
  else
    method_missing :autostart, jid, new_state
  end
end

#info(jid) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/archipel/api/vm_api.rb', line 32

def info jid
  out = method_missing :info, jid
  resp = out['query'][0]['info'][0]
  pp resp
  VmInfo.new resp['state'], resp['autostart'],
      resp['memory'], resp['maxMem'],
      resp['cpuPrct'], resp['nrVirtCpu']
end

#list_disks(jid) ⇒ Object



22
23
24
25
# File 'lib/archipel/api/vm_api.rb', line 22

def list_disks jid
  out = method_missing :list_disks, jid
  out['query'][0]['disk'] || []
end

#remove_disk(jid, name, format) ⇒ Object



14
15
16
17
18
19
20
# 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) ⇒ Object



27
28
29
30
# File 'lib/archipel/api/vm_api.rb', line 27

def xml jid
  out = method_missing :xml, jid
  out['query'][0]['domain'][0]
end