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



80
81
82
# File 'lib/xen/host.rb', line 80

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

#create_console(vm) ⇒ Object



71
72
73
# File 'lib/xen/host.rb', line 71

def create_console(vm)
  Console.create(vm, self)
end

#create_vbd(device, vm, vdi) ⇒ Object



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

def create_vbd(device, vm, vdi)
  VBD.create(device, vm, vdi, self)
end

#create_vdi(name, dev) ⇒ Object



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

def create_vdi(name, dev)
  VDI.create(name, dev, self)
end

#create_vif(vm, network, mac) ⇒ Object



63
64
65
# File 'lib/xen/host.rb', line 63

def create_vif(vm, network, mac)
  VIF.create(vm, network, mac, self)
end

#create_vm(name, memory) ⇒ Object



67
68
69
# File 'lib/xen/host.rb', line 67

def create_vm(name, memory)
  VM.create(name, memory, self)
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_local_srObject

gives the local storage resource



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

def get_local_sr
  SR.get_local(self)
end

#get_value(function, *params) ⇒ Object

Call to the API, Returns only the return value.



85
86
87
# File 'lib/xen/host.rb', line 85

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



75
76
77
# File 'lib/xen/host.rb', line 75

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