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

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

[Source]

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

Public Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

    # File lib/virt-p2v/converter.rb, line 54
54:     def on_connection(&cb)
55:         @connection_listeners << cb
56:     end

[Source]

    # File lib/virt-p2v/converter.rb, line 54
54:     def on_connection(&cb)
55:         @connection_listeners << cb
56:     end

[Validate]