atom feed20 messages in com.redhat.et-mgmt-toolsRe: [et-mgmt-tools] [patch] virt-conv...
FromSent OnAttachments
Joey BoggsSep 26, 2008 1:00 pm.patch
Bryan KearneySep 30, 2008 10:50 am 
Cole RobinsonSep 30, 2008 10:50 am 
Joey BoggsSep 30, 2008 11:24 am 
Cole RobinsonSep 30, 2008 11:33 am 
Joey BoggsSep 30, 2008 2:39 pm 
Cole RobinsonSep 30, 2008 2:43 pm 
Joey BoggsSep 30, 2008 2:46 pm 
Daniel P. BerrangeOct 1, 2008 2:54 am 
Cole RobinsonOct 1, 2008 6:43 am 
Joey BoggsOct 1, 2008 7:37 am.patch
Daniel P. BerrangeOct 1, 2008 7:42 am 
Daniel P. BerrangeOct 1, 2008 7:43 am 
Joey BoggsOct 1, 2008 9:27 am 
Daniel P. BerrangeOct 1, 2008 9:41 am 
Joey BoggsOct 1, 2008 9:46 am 
Joey BoggsOct 1, 2008 2:15 pm.patch
Cole RobinsonOct 3, 2008 8:15 am 
Joey BoggsOct 3, 2008 8:32 am 
Cole RobinsonOct 3, 2008 8:39 am 
Subject:Re: [et-mgmt-tools] [patch] virt-convert add disk signature into virt-image format export
From:Joey Boggs (jbo@redhat.com)
Date:Oct 1, 2008 2:15:17 pm
List:com.redhat.et-mgmt-tools
Attachments:

Here's what I've got, moved the hexdigest() out of the loop, cleanup and more testing to verify each scenario outputs the right xml configuration data.

Hope this is the final revision :)

Joey Boggs wrote:

That's one thing I forgot to move out of the loop before I sent it. I was still working on the handling of m2 missing prior to that and put it inside the loop for testing. Once moved should that be good to go?

Daniel P. Berrange wrote:

On Wed, Oct 01, 2008 at 12:27:46PM -0400, Joey Boggs wrote:

Here's an update, will this work best or any other suggestions?

try: import hashlib m1 = hashlib.md5(path) m2 = hashlib.sha256(path) except: import md5 m1 = md5.new(path) m2 = None

f = open(path,"r") while 1: chunk = f.read(65536) if not chunk: break m1.update(chunk) md5checksum = m1.hexdigest()

if m2: m2.update(chunk) shachecksum = m2.hexdigest()

hexdigest() should only be called at end, outside the loop. As it stands you're computing a checksum for each chunk & resetting it

diff -r 58a909b4f71c virt-convert --- a/virt-convert Mon Sep 22 11:32:11 2008 -0400 +++ b/virt-convert Wed Oct 01 17:12:45 2008 -0400 @@ -64,6 +64,8 @@ opts.add_option("", "--os-variant", type="string", dest="os_variant", action="callback", callback=cli.check_before_store, help=("The OS variant for fully virtualized guests, e.g.
'fedora6', 'rhel5', 'solaris10', 'win2k', 'vista'")) + opts.add_option("", "--checksum", action="store_true", dest="checksum", + help=("Generate a checksum for a virt-image guest")) opts.add_option("", "--noapic", action="store_true", dest="noapic", help=("Disables APIC for fully virtualized guest (overrides value in
os-type/os-variant db)"), default=False) opts.add_option("", "--noacpi", action="store_true", dest="noacpi", @@ -184,6 +186,9 @@

unixname = vmdef.name.replace(" ", "-")

+ if options.checksum: + vmdef.checksum = "yes" + if not options.output_dir: options.output_dir = unixname try: diff -r 58a909b4f71c virtconv/parsers/virtimage.py --- a/virtconv/parsers/virtimage.py Mon Sep 22 11:32:11 2008 -0400 +++ b/virtconv/parsers/virtimage.py Wed Oct 01 17:12:45 2008 -0400 @@ -171,9 +171,41 @@ type = "raw" if disk.type == diskcfg.DISK_TYPE_ISO: type = "iso" - storage.append( - """<disk file="%s" use="system" format="%s"/>\n""" % - (path, type)) + + if vm.checksum == "yes": + md5checksum = None + shachecksum = None + + storage.append("""<disk file="%s" use="system" format="%s">\n""" %
(path, type)) + + try: + import hashlib + m1 = hashlib.md5(path) + m2 = hashlib.sha256(path) + except: + import md5 + m1 = md5.new(path) + m2 = None + + f = open(path,"r") + while 1: + chunk = f.read(65536) + if not chunk: + break + m1.update(chunk) + + if m2: + m2.update(chunk) + + md5checksum = m1.hexdigest() + storage.append(""" <checksum type="md5">%s</checksum>\n""" %
md5checksum) + + if m2: + shachecksum = m2.hexdigest() + storage.append(""" <checksum type="sha256">%s</checksum>\n"""
% shachecksum) + storage.append(""" </disk>\n""") + else: + storage.append("""<disk file="%s" use="system" format="%s"/>\n""" %
(path, type))

return storage, diskout

diff -r 58a909b4f71c virtconv/vmcfg.py --- a/virtconv/vmcfg.py Mon Sep 22 11:32:11 2008 -0400 +++ b/virtconv/vmcfg.py Wed Oct 01 17:12:45 2008 -0400 @@ -59,6 +59,7 @@ self.noapic = None self.os_type = None self.os_variant = None + self.checksum = None

def validate(self): """