Class: QemuToolkit::Vmadm

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/qemu-toolkit/vmadm.rb

Instance Method Summary collapse

Instance Method Details

#backendObject

Command backend to use during the processing of subcommands.



20
21
22
# File 'lib/qemu-toolkit/vmadm.rb', line 20

def backend
  Config.backend
end

#executeObject

Main execute method - delegates to _execute in the subcommands. This handles transforming Ruby errors into simple shell errors.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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_addressObject



175
176
177
178
179
180
181
182
183
# 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) ⇒ Object



184
185
186
187
188
189
190
191
192
# 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