name User entry memory Editable cpus Editable arch Detected: cpuflags contains lm (long mode) features Detected: apic, acpi, pae disks Editable, default to all
device Detected path Detected is_block 1 format raw
removables Editable, default to all
device Detected type Detected
nics Editable, default to all connected
mac Detected, option to generate new vnet Set to nic name vnet_type bridge
# File lib/virt-p2v/converter.rb, line 85 def initialize() @profile = nil @connection = nil @connection_listeners = [] # Initialize basic system information @name = '' # There's no reasonable default for this # Get total memory from /proc/meminfo File.open('/proc/meminfo', 'r') do |fd| fd.each { |line| next unless line =~ %r^MemTotal:\s+(\d+)\b/ @memory = Integer($~[1]) * 1024 break } end # Get the total number of cpu threads from hwloc-info hwloc = Document.new %xhwloc-info --of xml` @cpus = XPath.match(hwloc, "//object[@type='PU']").length # Get cpu architecture and features from the first flags entry in # /proc/cpuinfo File.open('/proc/cpuinfo', 'r') do |fd| fd.each { |line| next unless line =~ %r^flags\s*:\s(.*)$/ flags = $~[1] # x86_64 if flags contains lm (long mode), i686 otherwise. We # don't support anything else. @arch = flags =~ %r\blm\b/ ? 'x86_64' : 'i686' # Pull some select features from cpu flags @features = [] [ 'apic', 'acpi', 'pae' ].each { |f| @features << f if flags =~ %r\b#{f}\b/ } break } end # Initialise empty lists for optional devices. These will be added # according to the user's selection @disks = [] @removables = [] @nics = [] end
# File lib/virt-p2v/converter.rb, line 58 def connection=(connection) @connection = connection @connection_listeners.each { |cb| cb.call(connection) } end
# File lib/virt-p2v/converter.rb, line 65 def convert(status, progress, &completion) iterate([ lambda { |cb| @connection.set_profile(@profile, &cb) }, lambda { |cb| @connection.metadata(meta, &cb) }, lambda { |cb| iterate(@disks.map { |dev| lambda { |cb2| disk(dev, status, progress, cb2) } }, cb) }, lambda { |cb| status.call('Converting') @connection.convert(&cb) } ], completion) end
# File lib/virt-p2v/converter.rb, line 54 def on_connection(&cb) @connection_listeners << cb end