Class: NetVbox::VmSet

Inherits:
Object
  • Object
show all
Defined in:
lib/netvbox/vm_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(vm_set_config) ⇒ VmSet

Returns a new instance of VmSet.



6
7
8
# File 'lib/netvbox/vm_set.rb', line 6

def initialize(vm_set_config)
  @vm_set_config = vm_set_config
end

Instance Method Details

#add_vm(hostname, username, password, vm_name, snapshot_name) ⇒ Object



30
31
32
33
# File 'lib/netvbox/vm_set.rb', line 30

def add_vm(hostname, username, password, vm_name, snapshot_name)
  vm_info = VmInfo.new(SshConnectionInfo.new(hostname, username, password), vm_name, snapshot_name)
  @vm_set_config.add_vm(vm_info)
end

#all_ipsObject

return Hash of VmInfo to (vm ip or :ip_unavailable)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/netvbox/vm_set.rb', line 51

def all_ips
  ip_map = {}
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) do |vm|
      begin
        ip_map[vm.vm_info] = vm.vm_ip
      rescue
        ip_map[vm.vm_info] = :ip_unavailable
      end
    end
  end
  threads.each(&:join)
  ip_map
end

#all_statusObject

return Hash of VmInfo to status



40
41
42
43
44
45
46
47
48
# File 'lib/netvbox/vm_set.rb', line 40

def all_status
  status_map = {}
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) {|vm| status_map[vm.vm_info] = vm.status}
  end
  threads.each(&:join)
  status_map
end

#configObject



10
11
12
# File 'lib/netvbox/vm_set.rb', line 10

def config
  @vm_set_config
end

#load_snapshotsObject



14
15
16
17
18
19
20
# File 'lib/netvbox/vm_set.rb', line 14

def load_snapshots
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) {|vm| vm.load_snapshot}
  end
  threads.each(&:join)
end

#poweroff_allObject



22
23
24
25
26
27
28
# File 'lib/netvbox/vm_set.rb', line 22

def poweroff_all
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) {|vm| vm.poweroff}
  end
  threads.each(&:join)
end

#remove_vm(hostname, username, vm_name) ⇒ Object



35
36
37
# File 'lib/netvbox/vm_set.rb', line 35

def remove_vm(hostname, username, vm_name)
  @vm_set_config.remove_vm(hostname, username, vm_name)
end

#ssh_guests(username, pw, command) ⇒ Object

return Hash of VmInfo to output of command



79
80
81
82
83
84
85
86
87
# File 'lib/netvbox/vm_set.rb', line 79

def ssh_guests(username, pw, command)
  output_map = {}
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) {|vm| output_map[vm.vm_info] = vm.ssh_guest(username, pw, command)}
  end
  threads.each(&:join)
  output_map
end

#ssh_hosts(command) ⇒ Object

return Hash of VmInfo to output of command



68
69
70
71
72
73
74
75
76
# File 'lib/netvbox/vm_set.rb', line 68

def ssh_hosts(command)
  output_map = {}
  threads = []
  get_vms.each do |vm|
    threads << Thread.new(vm) {|vm| output_map[vm.vm_info] = vm.ssh_host(command)}
  end
  threads.each(&:join)
  output_map
end