Class VirtP2V::Converter
In: lib/virt-p2v/converter.rb
lib/virt-p2v/converter.rb
Parent: Object

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

Methods

Included Modules

GetText GetText

Attributes

arch  [RW] 
arch  [RW] 
connection  [R] 
connection  [R] 
cpus  [RW] 
cpus  [RW] 
disks  [R] 
disks  [R] 
features  [R] 
features  [R] 
memory  [RW] 
memory  [RW] 
name  [RW] 
name  [RW] 
nics  [R] 
nics  [R] 
profile  [RW] 
profile  [RW] 
removables  [R] 
removables  [R] 

Public Class methods

[Source]

     # File lib/virt-p2v/converter.rb, line 88
 88:     def initialize()
 89:         @profile = nil
 90:         @connection = nil
 91:         @connection_listeners = []
 92: 
 93:         # Initialize basic system information
 94:         @name = '' # There's no reasonable default for this
 95: 
 96:         # Get total memory from /proc/meminfo
 97:         File.open('/proc/meminfo', 'r') do |fd|
 98:             fd.each { |line|
 99:                 next unless line =~ /^MemTotal:\s+(\d+)\b/
100: 
101:                 @memory = Integer($~[1]) * 1024
102:                 break
103:             }
104:         end
105: 
106:         # Get the total number of cpu threads from hwloc-info
107:         hwloc = Document.new `hwloc-info --of xml`
108:         @cpus = XPath.match(hwloc, "//object[@type='PU']").length
109: 
110:         # Get cpu architecture and features from the first flags entry in
111:         # /proc/cpuinfo
112:         File.open('/proc/cpuinfo', 'r') do |fd|
113:             fd.each { |line|
114:                 next unless line =~ /^flags\s*:\s(.*)$/
115: 
116:                 flags = $~[1]
117: 
118:                 # x86_64 if flags contains lm (long mode), i686 otherwise. We
119:                 # don't support anything else.
120:                 @arch = flags =~ /\blm\b/ ? 'x86_64' : 'i686'
121: 
122:                 # Pull some select features from cpu flags
123:                 @features = []
124:                 [ 'apic', 'acpi', 'pae' ].each { |f|
125:                     @features << f if flags =~ /\b#{f}\b/
126:                 }
127:                 break
128:             }
129:         end
130: 
131:         # Initialise empty lists for optional devices. These will be added
132:         # according to the user's selection
133:         @disks = []
134:         @removables = []
135:         @nics = []
136:     end

[Source]

     # File lib/virt-p2v/converter.rb, line 88
 88:     def initialize()
 89:         @profile = nil
 90:         @connection = nil
 91:         @connection_listeners = []
 92: 
 93:         # Initialize basic system information
 94:         @name = '' # There's no reasonable default for this
 95: 
 96:         # Get total memory from /proc/meminfo
 97:         File.open('/proc/meminfo', 'r') do |fd|
 98:             fd.each { |line|
 99:                 next unless line =~ /^MemTotal:\s+(\d+)\b/
100: 
101:                 @memory = Integer($~[1]) * 1024
102:                 break
103:             }
104:         end
105: 
106:         # Get the total number of cpu threads from hwloc-info
107:         hwloc = Document.new `hwloc-info --of xml`
108:         @cpus = XPath.match(hwloc, "//object[@type='PU']").length
109: 
110:         # Get cpu architecture and features from the first flags entry in
111:         # /proc/cpuinfo
112:         File.open('/proc/cpuinfo', 'r') do |fd|
113:             fd.each { |line|
114:                 next unless line =~ /^flags\s*:\s(.*)$/
115: 
116:                 flags = $~[1]
117: 
118:                 # x86_64 if flags contains lm (long mode), i686 otherwise. We
119:                 # don't support anything else.
120:                 @arch = flags =~ /\blm\b/ ? 'x86_64' : 'i686'
121: 
122:                 # Pull some select features from cpu flags
123:                 @features = []
124:                 [ 'apic', 'acpi', 'pae' ].each { |f|
125:                     @features << f if flags =~ /\b#{f}\b/
126:                 }
127:                 break
128:             }
129:         end
130: 
131:         # Initialise empty lists for optional devices. These will be added
132:         # according to the user's selection
133:         @disks = []
134:         @removables = []
135:         @nics = []
136:     end

Public Instance methods

[Source]

    # File lib/virt-p2v/converter.rb, line 61
61:     def connection=(connection)
62:         @connection = connection
63:         @connection_listeners.each { |cb|
64:             cb.call(connection)
65:         }
66:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 61
61:     def connection=(connection)
62:         @connection = connection
63:         @connection_listeners.each { |cb|
64:             cb.call(connection)
65:         }
66:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 68
68:     def convert(status, progress, &completion)
69:         iterate([
70:             lambda { |cb| @connection.set_profile(@profile, &cb) },
71:             lambda { |cb| @connection.metadata(meta, &cb) },
72:             lambda { |cb|
73:                 iterate(@disks.map { |dev|
74:                     lambda { |cb2|
75:                         disk(dev, status, progress, cb2)
76:                     }
77:                 }, cb)
78:             },
79:             lambda { |cb|
80:                 status.call(_('Converting'))
81:                 @connection.convert(&cb)
82:             }
83:         ], completion)
84:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 68
68:     def convert(status, progress, &completion)
69:         iterate([
70:             lambda { |cb| @connection.set_profile(@profile, &cb) },
71:             lambda { |cb| @connection.metadata(meta, &cb) },
72:             lambda { |cb|
73:                 iterate(@disks.map { |dev|
74:                     lambda { |cb2|
75:                         disk(dev, status, progress, cb2)
76:                     }
77:                 }, cb)
78:             },
79:             lambda { |cb|
80:                 status.call(_('Converting'))
81:                 @connection.convert(&cb)
82:             }
83:         ], completion)
84:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 57
57:     def on_connection(&cb)
58:         @connection_listeners << cb
59:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 57
57:     def on_connection(&cb)
58:         @connection_listeners << cb
59:     end

[Validate]