Class: Xen::Host

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 2000, login = 'user', pass = '') ⇒ Host

Creates a new Host object, and initiates an API connection to the given host on the given port, with a login and pass.



8
9
10
11
# File 'lib/xen/host.rb', line 8

def initialize(host, port = 2000,  = 'user', pass = '')
  @host = host
  @connection = Connection.new(host, port, , pass)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/xen/host.rb', line 5

def connection
  @connection
end

Instance Method Details

#call(function_name, *params) ⇒ Object

Call to the API



55
56
57
# File 'lib/xen/host.rb', line 55

def call(function_name, *params)
  @connection.call(function_name, *params)
end

#find_vm(name) ⇒ Object

Find a certain VM by a given domain-name.



26
27
28
# File 'lib/xen/host.rb', line 26

def find_vm name
  vms.detect { |vm| vm.name == name } # || raise Exception
end

#get_value(function, *params) ⇒ Object

Call to the API, Returns only the return value.



60
61
62
# File 'lib/xen/host.rb', line 60

def get_value(function, *params)
  call(function, *params)['Value']
end

#networksObject

Gives the different bridges on your system



31
32
33
34
35
# File 'lib/xen/host.rb', line 31

def networks
  get_value("network.get_all").collect do |network_uid|
    Network.new(network_uid, self)
  end
end

#recordObject



46
47
48
# File 'lib/xen/host.rb', line 46

def record
  get_value("host.get_record")
end

#to_sObject



50
51
52
# File 'lib/xen/host.rb', line 50

def to_s
  uid.to_s
end

#uidObject

Returns the uid of the host.



14
15
16
# File 'lib/xen/host.rb', line 14

def uid # Lazy Loaded
  @uid ||= get_value("session.get_this_host", @connection.session_id)
end

#versionObject

Gives the API version number in the form of major.minor vendor.



38
39
40
41
42
43
44
# File 'lib/xen/host.rb', line 38

def version
  major  = get_value("host.get_API_version_major", uid)
  minor  = get_value("host.get_API_version_minor", uid)
  vendor = get_value("host.get_API_version_vendor", uid)

  "#{major}.#{minor} #{vendor}"
end

#vmsObject

Gives an array of active VM’s on that Host.



19
20
21
22
23
# File 'lib/xen/host.rb', line 19

def vms
  get_value("host.get_resident_VMs", uid).collect do |vm_uid|
    Vm.new(vm_uid, self) # Isn't this expensive?
  end
end