Class: ForemanAP::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_vm/cluster.rb

Overview

A cluster of hypervisors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(members, user, password) ⇒ Cluster

Create an object.

members

A list of names of hypervisors to be members.

user

The libvirtd username.

password

The libvirtd password.



72
73
74
75
76
77
78
79
80
81
# File 'lib/foreman_vm/cluster.rb', line 72

def initialize(members, user, password)
  @members = members
  @hv = {}
  @user = user
  @password = password
  @members.each do |fqdn|
    uri = 'qemu+tcp://' + fqdn + '/system'
    @hv[fqdn] = Hypervisor.new(uri, @user, @password)
  end
end

Instance Attribute Details

#membersObject (readonly)

A list of the names of all members of the cluster.



28
29
30
# File 'lib/foreman_vm/cluster.rb', line 28

def members
  @members
end

#passwordObject

DEPRECATED - avoid using these



25
26
27
# File 'lib/foreman_vm/cluster.rb', line 25

def password
  @password
end

#userObject

DEPRECATED - avoid using these



25
26
27
# File 'lib/foreman_vm/cluster.rb', line 25

def user
  @user
end

Instance Method Details

#best_fit(name, memory) ⇒ Object

Return name of best hypervisor

name

The name of the guest to be added

memory

The total size of the guest in Bytes



15
16
17
18
19
20
21
22
# File 'lib/foreman_vm/cluster.rb', line 15

def best_fit(name, memory)
  alloc = ForemanAP::Allocator.new
  @members.each do |hostname|
    host = member(hostname)
    alloc.add_host(host.hostname, host.free_memory, host.domains)   
  end
  alloc.add_guest(name, memory)
end

#find(vm) ⇒ Object

The name of the hypervisor that contains a given virtual machine.

vm

The name of the virtual machine.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/foreman_vm/cluster.rb', line 38

def find(vm)
  @members.each do |host|
    #puts host
    #puts @hv[host].free_memory
    #puts @hv[host].domains.join("\n")
    if @hv[host].domains.include? vm
      return host
    end
  end
  return nil
end

#guest(fqdn) ⇒ Object

Return a handle to the guest domain

fqdn

the FQDN of the guest



7
8
9
10
# File 'lib/foreman_vm/cluster.rb', line 7

def guest(fqdn)
  host = member(find(fqdn)) or raise 'Guest not found'
  host.guest(fqdn)
end

#member(name) ⇒ Object

A handle to the ForemanAP::Hypervisor object for a member of the cluster.

name

The name of the hypervisor.



52
53
54
55
56
57
# File 'lib/foreman_vm/cluster.rb', line 52

def member(name)
 unless @hv.include? name
   raise ArgumentError, "hypervisor #{name} is not defined"
 end 
 @hv[name]
end

#members2Object

Return a list of all Hypervisor objects in the cluster TODO: replace #members with this function



32
33
34
# File 'lib/foreman_vm/cluster.rb', line 32

def members2
  @hv.values
end

#migrate(guest, destination) ⇒ Object

Migrate a virtual machine from one host to another (FIXME - UNIMPLEMENTED)

guest

The name of the guest

destination

The target hypervisor



62
63
64
65
66
# File 'lib/foreman_vm/cluster.rb', line 62

def migrate(guest, destination)
  # TODO: the equivalent of this:
  # virsh migrate $vm qemu+ssh://${target}-san.brontolabs.local/system --verbose --persistent --undefinesource --live --timeout 60
  raise 'STUB'
end