class QemuToolkit::Vmadm
Public Instance Methods
_execute()
click to toggle source
# File lib/qemu-toolkit/vmadm.rb, line 47 def _execute output_fields = (fields || 'name,pid').split(/,/) VM.all(backend).each do |vm| printf "%-20s", vm.name if output_fields.include?('name') printf " %5s", vm.running? ? vm.pid : 'off' if output_fields.include?('pid') puts end end
backend()
click to toggle source
Command backend to use during the processing of subcommands.
# File lib/qemu-toolkit/vmadm.rb, line 20 def backend Config.backend end
execute()
click to toggle source
Main execute method - delegates to _execute in the subcommands. This handles transforming Ruby errors into simple shell errors.
# File lib/qemu-toolkit/vmadm.rb, line 27 def execute backend.verbose = verbose? Config.etc = vmpath Config.var_run = varrun fail NotImplementedError, "Missing subcommand." unless respond_to?(:_execute) _execute rescue => error raise if verbose? || $rspec_executing $stderr.puts error.to_s exit 1 end
random_mac_address()
click to toggle source
# File lib/qemu-toolkit/vmadm.rb, line 175 def random_mac_address # Please see this discussion if improving this: # http://stackoverflow.com/questions/8484877/mac-address-generator-in-python mac = [ 0x00, 0x24, 0x81, rand(0x7f), rand(0xff), rand(0xff) ] mac.map { |e| e.to_s(16) }.join(':') end
vm(name)
click to toggle source
# File lib/qemu-toolkit/vmadm.rb, line 184 def vm(name) vm = VM[name, backend] unless vm puts "No virtual machine by the name '#{name}' found." exit 1 end vm end
vm_template(name)
click to toggle source
# File lib/qemu-toolkit/vmadm.rb, line 82 def vm_template(name) local_disks = StringIO.new disk_sets = LocalDiskSet.for(name, backend) disk_sets.each do |set| local_disks.puts " # Disks for storage at #{set.name}" set.each_disk do |dev_path| local_disks.puts " disk '#{dev_path}'" end local_disks.puts end %Q(virtual_machine "#{name}" do # Block device setup # # Either configure a remote disk (via iSCSI): # iscsi_target 'iqn.2012-01.com.qemu-toolkit:#{name}', "10.40.0.1" # # Or a local disk, like a zvol for example: # disk /dev/zvol/rdsk/pool/#{name}/disk1 #{local_disks.string} # Network configuration # nic 'eth0', # macaddr: '#{random_mac_address}', # via: 'igbX' end ) end