Class: NetVbox::PrintingDelegator
- Inherits:
-
Object
- Object
- NetVbox::PrintingDelegator
- Defined in:
- lib/netvbox/printing_delegator.rb
Instance Method Summary collapse
- #add_vm(hostname, username, password, vm_name, snapshot_name) ⇒ Object
- #create_set(set_name) ⇒ Object
-
#initialize(vm_set_manager, vm_set) ⇒ PrintingDelegator
constructor
A new instance of PrintingDelegator.
- #list_sets ⇒ Object
- #list_vm_ips ⇒ Object
- #list_vms ⇒ Object
- #load_snapshots ⇒ Object
- #poweroff_all ⇒ Object
- #print_current_set ⇒ Object
- #print_status ⇒ Object
- #remove_set(set_name) ⇒ Object
- #remove_vm(hostname, username, vm_name) ⇒ Object
- #ssh_guests(username, password, command) ⇒ Object
- #ssh_hosts(command) ⇒ Object
- #use_default_set ⇒ Object
- #use_set(set_name) ⇒ Object
Constructor Details
#initialize(vm_set_manager, vm_set) ⇒ PrintingDelegator
Returns a new instance of PrintingDelegator.
6 7 8 9 |
# File 'lib/netvbox/printing_delegator.rb', line 6 def initialize(vm_set_manager, vm_set) @vm_set = vm_set @vm_set_manager = vm_set_manager end |
Instance Method Details
#add_vm(hostname, username, password, vm_name, snapshot_name) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/netvbox/printing_delegator.rb', line 11 def add_vm(hostname, username, password, vm_name, snapshot_name) begin @vm_set.add_vm(hostname, username, password, vm_name, snapshot_name) puts "Added (#{vm_name}, #{snapshot_name}) on host, #{hostname}" rescue => e puts "Could not add VM snapshot: #{e.}" end end |
#create_set(set_name) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/netvbox/printing_delegator.rb', line 85 def create_set(set_name) begin @vm_set_manager.create_set set_name puts "Created set: #{set_name}" rescue => e puts "Could not create set: #{e.}" end end |
#list_sets ⇒ Object
98 99 100 |
# File 'lib/netvbox/printing_delegator.rb', line 98 def list_sets @vm_set_manager.vm_set_names.each {|vm_set_name| puts vm_set_name} end |
#list_vm_ips ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/netvbox/printing_delegator.rb', line 29 def list_vm_ips puts 'Retrieving VM IP addresses for VMs with guest additions...' all_ips = @vm_set.all_ips all_ips.each do |vm_info, ip| ip_string = (ip == :ip_unavailable) ? 'unavailable' : ip printf "%-40s %s\n", "#{vm_info.vm_name} on #{vm_info.ssh_connection_info.hostname}", "[#{ip_string}]" end puts 'There are no vms' if all_ips.empty? end |
#list_vms ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/netvbox/printing_delegator.rb', line 20 def list_vms all_vm_info = @vm_set.config.all_vm_info all_vm_info.each do |vm_info| ssh_info = vm_info.ssh_connection_info printf "vm: %-36s host: %s\n", "#{vm_info.vm_name} (#{vm_info.snapshot_name})", "#{ssh_info.username}@#{ssh_info.hostname}" end puts 'No vms' if all_vm_info.empty? end |
#load_snapshots ⇒ Object
39 40 41 42 43 |
# File 'lib/netvbox/printing_delegator.rb', line 39 def load_snapshots puts 'Loading snapshots...' @vm_set.load_snapshots print_status end |
#poweroff_all ⇒ Object
45 46 47 48 49 |
# File 'lib/netvbox/printing_delegator.rb', line 45 def poweroff_all puts 'Powering off VMs...' @vm_set.poweroff_all print_status end |
#print_current_set ⇒ Object
94 95 96 |
# File 'lib/netvbox/printing_delegator.rb', line 94 def print_current_set puts @vm_set_manager.current_set_name end |
#print_status ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/netvbox/printing_delegator.rb', line 76 def print_status puts 'Retrieving status info...' all_status = @vm_set.all_status all_status.each do |vm_info, status| printf "%-40s %s\n", "#{vm_info.vm_name} on #{vm_info.ssh_connection_info.hostname}", "[#{status}]" end puts 'There are no vms' if all_status.empty? end |
#remove_set(set_name) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/netvbox/printing_delegator.rb', line 102 def remove_set(set_name) begin @vm_set_manager.remove_set set_name puts "Removed set: #{set_name}" rescue => e puts "Could not remove set: #{e.}" end end |
#remove_vm(hostname, username, vm_name) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/netvbox/printing_delegator.rb', line 51 def remove_vm(hostname, username, vm_name) begin @vm_set.remove_vm(hostname, username, vm_name) puts "Removed #{vm_name} snapshot on host, #{hostname}" rescue => e puts "Could not remove #{vm_name} snapshot: #{e.}" end end |
#ssh_guests(username, password, command) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/netvbox/printing_delegator.rb', line 68 def ssh_guests(username, password, command) all_output = @vm_set.ssh_guests(username, password, command) all_output.each do |vm_info, output| output.split("\n").each {|line| puts "[#{vm_info.vm_name} on #{vm_info.ssh_connection_info.hostname}] #{line}"} end puts 'There are no vms' if all_output.empty? end |
#ssh_hosts(command) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/netvbox/printing_delegator.rb', line 60 def ssh_hosts(command) all_output = @vm_set.ssh_hosts command all_output.each do |vm_info, output| output.split("\n").each {|line| puts "[#{vm_info.ssh_connection_info.hostname}] #{line}"} end puts 'There are no vms' if all_output.empty? end |
#use_default_set ⇒ Object
111 112 113 114 |
# File 'lib/netvbox/printing_delegator.rb', line 111 def use_default_set @vm_set_manager.use_default_set puts "Now using set: #{@vm_set_manager.current_set_name}" end |
#use_set(set_name) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/netvbox/printing_delegator.rb', line 116 def use_set(set_name) begin @vm_set_manager.use_set set_name rescue => e puts "Could not use set: #{e.}" end puts "Now using set: #{@vm_set_manager.current_set_name}" end |