FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 06-26-2008, 02:32 PM
Joey Boggs
 
Default convert vmware machines to virt-image xml format

Forgot to merge back changes into the tree before running the latest
patch, updated patch file


Joey Boggs wrote:
These patches provide the virt-unpack command which converts vmware
format machines into virt-image xml format hvm/paravirt runnable
instances. Next revision will contain libvirt format as well. As also
with the virt-pack command all required vmware/xen/hvm kernel modules
must be in place prior to conversion to boot machine.

------------------------------------------------------------------------

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-26-2008, 03:10 PM
Cole Robinson
 
Default convert vmware machines to virt-image xml format

Joey Boggs wrote:

>> These patches provide the virt-unpack command which converts vmware
>> format machines into virt-image xml format hvm/paravirt runnable
>> instances. Next revision will contain libvirt format as well. As also
>> with the virt-pack command all required vmware/xen/hvm kernel modules
>> must be in place prior to conversion to boot machine.
>> ------------------------------------------------------------------------
>>


Comments inline:

> diff -Naur virtinst--devel.orig/virt-unpack virtinst--devel/virt-unpack
> --- virtinst--devel.orig/virt-unpack 1969-12-31 19:00:00.000000000 -0500
> +++ virtinst--devel/virt-unpack 2008-06-26 10:30:45.000000000 -0400
> @@ -0,0 +1,231 @@
> +#!/usr/bin/python
> +#
> +# Convert a VMware(tm) virtual machine into an XML image description
> +#
> +# Copyright 2008 Red Hat, Inc.
> +# Joey Boggs <jboggs@redhat.com>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301 USA.
> +
> +import sys
> +from string import ascii_letters
> +import virtinst.cli as cli
> +import os
> +import random
> +import pdb
> +import shutil
> +import logging
> +from optparse import OptionParser, OptionValueError
> +
> +def parse_args():
> + parser = OptionParser()
> + parser.set_usage("%prog [options] image.vmx")
> + parser.add_option("-a", "--arch", type="string", dest="arch",
> + help=("Machine Architecture Type (i686/x86_64/ppc)"))
> + parser.add_option("-t", "--type", type="string", dest="type",
> + help=("Output virtualization type (hvm, paravirt"))

For type I would use the convention that virt-install uses: add seperate
options for --paravirt and --hvm (optionally -p or -v). Also I'd recommend
just defaulting to --hvm since that is the most common case at this point.

> + parser.add_option("-d", "--debug", action="store_true", dest="debug",
> + help=("Print debugging information"))
> + parser.add_option("-o", "--outputdir", type="string", dest="outputdir",
> + help=("Output directory in which files will be created"))
> + (options,args) = parser.parse_args()
> +
> + if len(args) < 1:
> + parser.error(("You need to provide an image XML descriptor"))
> + options.file = args[0]
> +
> + if (options.arch is None) or (options.type is None):
> + parser.error(("You need to provide all input options"
> + "

Architecture: " + str(options.arch) +
> + "
Output Virt Type: " + str(options.type)))
> + sys.exit(1)

Won't need sys.exit here since parser.error will handle this for you.

> + return options
> +
> +# Begin creation of xml template from parsed vmx config file
> +def create_xml_template(disks_list,record,options,dirn ame):

Kind of a nit, but create_xml_template isn't really descriptive.
convert_to_image? vmx_to_image?

> + pv_disk_list = []
> + fv_disk_list = []
> + storage_disk_list = []
> +
> + name = record["displayName"]
> + memory = record["memsize"]
> + memory = int(memory) * 1024
> +
> + # can't guarantee annotation or vcpus are set in vmware config, requires evaluation
> + if record.has_key("annotation"):
> + annotation = record["annotation"]
> + else:
> + annotation = ""
> +
> + if record.has_key("numvcpus"):
> + vcpus = record["numvcpus"]
> + else:
> + vcpus = "1"
> +
> +# create disk filename lists for xml template
> + for (number, file) in enumerate(disks_list):
> + file = str(file.replace(".vmdk","")).strip()
> + pv_disk_list.append("""<drive disk="%s.img" target="xvd%s"/>""" %
> + (file, ascii_letters[number % 26]))
> + fv_disk_list.append("""<drive disk="%s.img" target="hd%s"/>""" %
> + (file, ascii_letters[number % 26]))
> + storage_disk_list.append("""<disk file="%s.img" use="system" format="raw"/>""" % (file))
> +# determine virtualization type for image.boot section
> + if options.type == "paravirt":
> + virt_boot_template = """<boot type="xen">
> + <guest>
> + <arch>%(vm_arch)s</arch>
> + <features>
> + <pae/>
> + </features>
> + </guest>
> + <os>
> + <loader>pygrub</loader>
> + </os>
> + %(vm_pv_disks)s
> + </boot>"""
> + elif options.type == "fullvirt":
> +
> + virt_boot_template = """<boot type="hvm">
> + <guest>
> + <arch>%(vm_arch)s</arch>
> + </guest>
> + <os>
> + <loader dev="hd"/>
> + </os>
> + %(vm_fv_disks)s
> + </boot>"""
> + else:
> + print "Invalid virtualization type specified"
> + sys.exit(1)

If you use the above --paravirt/--hvm option change, you won't need
this check.

> +
> +
> +# xml replacements dictionaries
> + virt_boot_xml_dict = {
> + "vm_pv_disks" : "".join(pv_disk_list),
> + "vm_fv_disks" : "".join(fv_disk_list),
> + "vm_arch" : options.arch,
> + }

If you do the above --paravirt/--hvm change, you can then just pass
options.arch directly to the function rather than the whole options
list.

> + virt_boot_template = virt_boot_template % virt_boot_xml_dict
> +
> + virt_image_xml_dict = {
> + "virt_boot_template" : virt_boot_template,
> + "vm_displayName": name.replace(" ","_"),
> + "vm_annotation" : annotation,
> + "vm_vcpus" : vcpus,
> + "vm_mem" : memory,
> + "vm_storage" : "".join(storage_disk_list),
> + }
> +
> + virt_image_xml_template = """<image>
> + <name>%(vm_displayName)s</name>
> + <label>%(vm_displayName)s</label>
> + <description>
> + %(vm_annotation)s
> + </description>
> + <domain>
> + %(virt_boot_template)s
> + <devices>
> + <vcpu>%(vm_vcpus)s</vcpu>
> + <memory>%(vm_mem)s</memory>
> + <interface/>
> + <graphics/>
> + </devices>
> + </domain>
> + <storage>
> + %(vm_storage)s
> + </storage>
> +</image>"""
> +
> + virt_image_xml_template = virt_image_xml_template % virt_image_xml_dict
> + virt_image_xml_config_file = open(dirname + "/" + name + ".virtimage.xml","w")
> + virt_image_xml_config_file.writelines(virt_image_x ml_template)
> + virt_image_xml_config_file.close()

I'd recommend moving this end piece to the main function. If keeps the
conversion function doing only the conversion. If we ever wanted to reuse
this code in another app which won't be writing an output file, this would
be a necessary change.

> + return
> +
> +# parse input vmware configuration
> +def parse_vmware_config(options):
> + if not os.access(options.file,os.R_OK):
> + raise ValueError, "Could not read file: %s" % options.file
> + input = open(options.file,"r")
> + contents = input.readlines()
> + input.close()
> + record = {}
> + vm_config = []
> + disks_list = []
> +
> +# strip out comment and blank lines for easy splitting of values
> + for line in contents:
> + if not line.strip() or line.startswith("#"):
> + continue
> + else:
> + vm_config.append(line)
> +
> + for line in vm_config:
> + beforeEq, afterEq = line.split("=", 1)
> + key = beforeEq.replace(" ","")
> + value = afterEq.replace('"',"")
> + record[key] = value.strip()
> + logging.debug("Key: %s Value: %s" % (key,value))
> + if value.endswith("vmdk
"): # separate disks from config
> + disks_list.append(value)
> + return vm_config,record,disks_list,options

Shouldn't need to return vm_config or options here: options hasn't changed,
vm_config isn't used anywhere else.

> +
> +
> +def convert_disks(disks_list,name,dirname):

Name isn't used here anymore.

> + for disk in disks_list:
> + file = disk.replace(".vmdk","").strip()
> + convert_cmd="qemu-img convert %s -O raw %s/%s.img" % (disk.strip(),dirname,file)
> + logging.debug("Converting %s" % disk.strip())
> + print "
Converting %s to %s/%s.img" % (disk.strip(),dirname,file)
> + os.system(convert_cmd)
> +
> +
> +
> +def main():
> + options = parse_args()
> + cli.setupLogging("virt-unpack", options.debug)
> + vm_config = parse_vmware_config(options)
> + config, record, disks_list, options = vm_config
> + name = record["displayName"].replace(" ","-")

Just thinking, there are a lot of checks here directly into the record. If
we are passed a vmx file that is missing one of these options, either
through a bad config or some change in the format, we are going to throw
an undescriptive error like "Key error: displayName". Maybe create a small
wrapper function like record_lookup that you pass the record and the key
to, and will throw a more clear error to the user like "key 'blah' was
not parsed from the vmx config"

> + dirname = options.outputdir
> + if not dirname:
> + dirname = name
> + try:
> + logging.debug ("Creating directory %s" % dirname)
> + os.mkdir(dirname)
> + except OSError,e:
> + if e.errno == 17:
> + logging.error("Could not create directory %s or directory already exists", dirname)
> + sys.exit(1)

You'll want to exit here regardless of the errno. I'd recommend just losing
the errno check, and use something general like:
logging.error("Could not create directory '%s': %s" % (dirname, str(e))
sys.exit(1)

Also, if you move the file creation aspect out of the create_xml_template,
you can move the dir creation after the create_xml_template call. That
way we move the dir creation as late as possible so that if there is
an exception earlier in the process we don't need to clean up/delete
the unpopulated directory.
> +
> + create_xml_template(disks_list,record,options,dirn ame)
> + convert_disks(disks_list,name,dirname)
> +
> + print "

Conversion completed and placed in: %s" % dirname
> +
> +
> +if __name__ == "__main__":
> + try:
> + main()
> + except SystemExit, e:
> + sys.exit(e.code)
> + except KeyboardInterrupt, e:
> + print >> sys.stderr, _("Aborted at user request")
> + except Exception, e:
> + logging.exception(e)
> + sys.exit(1)
> +

Thanks,
Cole

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-26-2008, 03:19 PM
"Daniel P. Berrange"
 
Default convert vmware machines to virt-image xml format

On Thu, Jun 26, 2008 at 11:10:29AM -0400, Cole Robinson wrote:
> > +def parse_args():
> > + parser = OptionParser()
> > + parser.set_usage("%prog [options] image.vmx")
> > + parser.add_option("-a", "--arch", type="string", dest="arch",
> > + help=("Machine Architecture Type (i686/x86_64/ppc)"))
> > + parser.add_option("-t", "--type", type="string", dest="type",
> > + help=("Output virtualization type (hvm, paravirt"))
>
> For type I would use the convention that virt-install uses: add seperate
> options for --paravirt and --hvm (optionally -p or -v). Also I'd recommend
> just defaulting to --hvm since that is the most common case at this point.

Yes, keeping consistent naming of CLI args across all the virt-XXX tools
is very important - even if some of our existing naming is a little odd :-)

Regards,
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-26-2008, 08:42 PM
Joey Boggs
 
Default convert vmware machines to virt-image xml format

I integrated the common cli options and all the other modifications, but
wasn't sure the best way to approach the para/full virt check removal
from the comments


"If you use the above --paravirt/--hvm option change, you won't need
this check." Both before and after code snips below.

I changed the if/else to evaluate the options for True on either
para/full, if there's something else you'd want to see please let me know



-------------------------------------------------------------------------------
parser.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
help=("This guest should be a fully virtualized
guest"))
parser.add_option("-p", "--paravirt", action="store_true",
dest="paravirt",

help=("This guest should be a paravirtualized guest"))




if options.paravirt is True:
virt_boot_template = """<boot type="xen">
<guest>
<arch>%(vm_arch)s</arch>
<features>
<pae/>
</features>
</guest>
<os>
<loader>pygrub</loader>
</os>
%(vm_pv_disks)s
</boot>"""
elif options.fullvirt is True:

virt_boot_template = """<boot type="hvm">
<guest>
<arch>%(vm_arch)s</arch>
</guest>
<os>
<loader dev="hd"/>
</os>
%(vm_fv_disks)s
</boot>"""
else:
print "Invalid virtualization type specified"
sys.exit(1)
-------------------------------------------------------------------------------


> > + if options.type == "paravirt":
> > + virt_boot_template = """<boot type="xen">
> > + <guest>
> > + <arch>%(vm_arch)s</arch>
> > + <features>
> > + <pae/>
> > + </features>
> > + </guest>
> > + <os>
> > + <loader>pygrub</loader>
> > + </os>
> > + %(vm_pv_disks)s
> > + </boot>"""
> > + elif options.type == "fullvirt":
> > +
> > + virt_boot_template = """<boot type="hvm">
> > + <guest>
> > + <arch>%(vm_arch)s</arch>
> > + </guest>
> > + <os>
> > + <loader dev="hd"/>
> > + </os>
> > + %(vm_fv_disks)s
> > + </boot>"""
> > + else:
> > + print "Invalid virtualization type specified"
> > + sys.exit(1)

If you use the above --paravirt/--hvm option change, you won't need
this check.


Regards,
Joey









Cole Robinson wrote:

Joey Boggs wrote:


These patches provide the virt-unpack command which converts vmware
format machines into virt-image xml format hvm/paravirt runnable
instances. Next revision will contain libvirt format as well. As also
with the virt-pack command all required vmware/xen/hvm kernel modules
must be in place prior to conversion to boot machine.

------------------------------------------------------------------------





Comments inline:



diff -Naur virtinst--devel.orig/virt-unpack virtinst--devel/virt-unpack
--- virtinst--devel.orig/virt-unpack 1969-12-31 19:00:00.000000000 -0500
+++ virtinst--devel/virt-unpack 2008-06-26 10:30:45.000000000 -0400
@@ -0,0 +1,231 @@
+#!/usr/bin/python
+#

+# Convert a VMware(tm) virtual machine into an XML image description
+#
+# Copyright 2008 Red Hat, Inc.
+# Joey Boggs <jboggs@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301 USA.
+
+import sys
+from string import ascii_letters
+import virtinst.cli as cli
+import os
+import random
+import pdb
+import shutil
+import logging
+from optparse import OptionParser, OptionValueError
+
+def parse_args():
+ parser = OptionParser()
+ parser.set_usage("%prog [options] image.vmx")
+ parser.add_option("-a", "--arch", type="string", dest="arch",
+ help=("Machine Architecture Type (i686/x86_64/ppc)"))
+ parser.add_option("-t", "--type", type="string", dest="type",
+ help=("Output virtualization type (hvm, paravirt"))



For type I would use the convention that virt-install uses: add seperate
options for --paravirt and --hvm (optionally -p or -v). Also I'd recommend
just defaulting to --hvm since that is the most common case at this point.



+ parser.add_option("-d", "--debug", action="store_true", dest="debug",
+ help=("Print debugging information"))
+ parser.add_option("-o", "--outputdir", type="string", dest="outputdir",
+ help=("Output directory in which files will be created"))
+ (options,args) = parser.parse_args()
+
+ if len(args) < 1:

+ parser.error(("You need to provide an image XML descriptor"))
+ options.file = args[0]
+
+ if (options.arch is None) or (options.type is None):

+ parser.error(("You need to provide all input options"
+ "

Architecture: " + str(options.arch) +
+ "
Output Virt Type: " + str(options.type)))

+ sys.exit(1)



Won't need sys.exit here since parser.error will handle this for you.



+ return options
+
+# Begin creation of xml template from parsed vmx config file
+def create_xml_template(disks_list,record,options,dirn ame):



Kind of a nit, but create_xml_template isn't really descriptive.
convert_to_image? vmx_to_image?



+ pv_disk_list = []
+ fv_disk_list = []
+ storage_disk_list = []
+
+ name = record["displayName"]
+ memory = record["memsize"]
+ memory = int(memory) * 1024
+
+ # can't guarantee annotation or vcpus are set in vmware config, requires evaluation
+ if record.has_key("annotation"):
+ annotation = record["annotation"]
+ else:
+ annotation = ""
+
+ if record.has_key("numvcpus"):
+ vcpus = record["numvcpus"]
+ else:
+ vcpus = "1"
+
+# create disk filename lists for xml template

+ for (number, file) in enumerate(disks_list):
+ file = str(file.replace(".vmdk","")).strip()
+ pv_disk_list.append("""<drive disk="%s.img" target="xvd%s"/>""" %
+ (file, ascii_letters[number % 26]))
+ fv_disk_list.append("""<drive disk="%s.img" target="hd%s"/>""" %
+ (file, ascii_letters[number % 26]))
+ storage_disk_list.append("""<disk file="%s.img" use="system" format="raw"/>""" % (file))
+# determine virtualization type for image.boot section
+ if options.type == "paravirt":
+ virt_boot_template = """<boot type="xen">
+ <guest>
+ <arch>%(vm_arch)s</arch>
+ <features>
+ <pae/>
+ </features>
+ </guest>
+ <os>
+ <loader>pygrub</loader>
+ </os>
+ %(vm_pv_disks)s
+ </boot>"""
+ elif options.type == "fullvirt":
+
+ virt_boot_template = """<boot type="hvm">
+ <guest>
+ <arch>%(vm_arch)s</arch>
+ </guest>
+ <os>
+ <loader dev="hd"/>
+ </os>
+ %(vm_fv_disks)s
+ </boot>"""
+ else:
+ print "Invalid virtualization type specified"
+ sys.exit(1)



If you use the above --paravirt/--hvm option change, you won't need
this check.



+
+
+# xml replacements dictionaries
+ virt_boot_xml_dict = {
+ "vm_pv_disks" : "".join(pv_disk_list),
+ "vm_fv_disks" : "".join(fv_disk_list),
+ "vm_arch" : options.arch,
+ }



If you do the above --paravirt/--hvm change, you can then just pass
options.arch directly to the function rather than the whole options
list.



+ virt_boot_template = virt_boot_template % virt_boot_xml_dict
+
+ virt_image_xml_dict = {
+ "virt_boot_template" : virt_boot_template,
+ "vm_displayName": name.replace(" ","_"),
+ "vm_annotation" : annotation,
+ "vm_vcpus" : vcpus,
+ "vm_mem" : memory,
+ "vm_storage" : "".join(storage_disk_list),
+ }
+
+ virt_image_xml_template = """<image>

+ <name>%(vm_displayName)s</name>
+ <label>%(vm_displayName)s</label>
+ <description>
+ %(vm_annotation)s
+ </description>
+ <domain>
+ %(virt_boot_template)s
+ <devices>
+ <vcpu>%(vm_vcpus)s</vcpu>
+ <memory>%(vm_mem)s</memory>
+ <interface/>
+ <graphics/>
+ </devices>
+ </domain>
+ <storage>
+ %(vm_storage)s
+ </storage>
+</image>"""
+
+ virt_image_xml_template = virt_image_xml_template % virt_image_xml_dict

+ virt_image_xml_config_file = open(dirname + "/" + name + ".virtimage.xml","w")
+ virt_image_xml_config_file.writelines(virt_image_x ml_template)
+ virt_image_xml_config_file.close()



I'd recommend moving this end piece to the main function. If keeps the
conversion function doing only the conversion. If we ever wanted to reuse
this code in another app which won't be writing an output file, this would
be a necessary change.



+ return
+
+# parse input vmware configuration
+def parse_vmware_config(options):
+ if not os.access(options.file,os.R_OK):
+ raise ValueError, "Could not read file: %s" % options.file
+ input = open(options.file,"r")
+ contents = input.readlines()
+ input.close()
+ record = {}
+ vm_config = []
+ disks_list = []
+
+# strip out comment and blank lines for easy splitting of values
+ for line in contents:
+ if not line.strip() or line.startswith("#"):
+ continue
+ else:
+ vm_config.append(line)
+
+ for line in vm_config:

+ beforeEq, afterEq = line.split("=", 1)
+ key = beforeEq.replace(" ","")
+ value = afterEq.replace('"',"")
+ record[key] = value.strip()
+ logging.debug("Key: %s Value: %s" % (key,value))
+ if value.endswith("vmdk
"): # separate disks from config
+ disks_list.append(value)
+ return vm_config,record,disks_list,options



Shouldn't need to return vm_config or options here: options hasn't changed,
vm_config isn't used anywhere else.



+
+
+def convert_disks(disks_list,name,dirname):



Name isn't used here anymore.



+ for disk in disks_list:
+ file = disk.replace(".vmdk","").strip()
+ convert_cmd="qemu-img convert %s -O raw %s/%s.img" % (disk.strip(),dirname,file)
+ logging.debug("Converting %s" % disk.strip())
+ print "
Converting %s to %s/%s.img" % (disk.strip(),dirname,file)
+ os.system(convert_cmd)
+
+

+
+def main():
+ options = parse_args()
+ cli.setupLogging("virt-unpack", options.debug)
+ vm_config = parse_vmware_config(options)
+ config, record, disks_list, options = vm_config
+ name = record["displayName"].replace(" ","-")



Just thinking, there are a lot of checks here directly into the record. If
we are passed a vmx file that is missing one of these options, either
through a bad config or some change in the format, we are going to throw
an undescriptive error like "Key error: displayName". Maybe create a small
wrapper function like record_lookup that you pass the record and the key
to, and will throw a more clear error to the user like "key 'blah' was
not parsed from the vmx config"



+ dirname = options.outputdir
+ if not dirname:
+ dirname = name
+ try:
+ logging.debug ("Creating directory %s" % dirname)
+ os.mkdir(dirname)
+ except OSError,e:
+ if e.errno == 17:
+ logging.error("Could not create directory %s or directory already exists", dirname)
+ sys.exit(1)



You'll want to exit here regardless of the errno. I'd recommend just losing
the errno check, and use something general like:
logging.error("Could not create directory '%s': %s" % (dirname, str(e))
sys.exit(1)

Also, if you move the file creation aspect out of the create_xml_template,
you can move the dir creation after the create_xml_template call. That
way we move the dir creation as late as possible so that if there is
an exception earlier in the process we don't need to clean up/delete
the unpopulated directory.


+
+ create_xml_template(disks_list,record,options,dirn ame)
+ convert_disks(disks_list,name,dirname)
+
+ print "

Conversion completed and placed in: %s" % dirname
+
+
+if __name__ == "__main__":

+ try:
+ main()
+ except SystemExit, e:
+ sys.exit(e.code)
+ except KeyboardInterrupt, e:
+ print >> sys.stderr, _("Aborted at user request")
+ except Exception, e:
+ logging.exception(e)
+ sys.exit(1)
+



Thanks,
Cole




_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-26-2008, 09:29 PM
Cole Robinson
 
Default convert vmware machines to virt-image xml format

Joey Boggs wrote:
> I integrated the common cli options and all the other modifications, but
> wasn't sure the best way to approach the para/full virt check removal
> from the comments
>
> "If you use the above --paravirt/--hvm option change, you won't need
> this check." Both before and after code snips below.
>
> I changed the if/else to evaluate the options for True on either
> para/full, if there's something else you'd want to see please let me know
>
>
> -------------------------------------------------------------------------------
> parser.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
> help=("This guest should be a fully virtualized
> guest"))
> parser.add_option("-p", "--paravirt", action="store_true",
> dest="paravirt",
> help=("This guest should be a paravirtualized guest"))
>
>
>
>
> if options.paravirt is True:
> virt_boot_template = """<boot type="xen">
> <guest>
> <arch>%(vm_arch)s</arch>
> <features>
> <pae/>
> </features>
> </guest>
> <os>
> <loader>pygrub</loader>
> </os>
> %(vm_pv_disks)s
> </boot>"""
> elif options.fullvirt is True:
>
> virt_boot_template = """<boot type="hvm">
> <guest>
> <arch>%(vm_arch)s</arch>
> </guest>
> <os>
> <loader dev="hd"/>
> </os>
> %(vm_fv_disks)s
> </boot>"""
> else:
> print "Invalid virtualization type specified"
> sys.exit(1)

Sorry, I wasn't very clear. The unnecessary check I was talking about
was the last sanity check, the "Invalid virtualization type". Since this
is basically a boolean option (hvm or not), i'd do something like

if options.paravirt:
hvm = False
else:
hvm = True

In main() and pass hvm explictly to the above function.

- Cole

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-27-2008, 06:09 PM
Joey Boggs
 
Default convert vmware machines to virt-image xml format

Updated version based on comments.

Cole, check the record validation section to see if that's fine. I just
integrated it with the 2 checks that were already in place rather than
creating another function.



Cole Robinson wrote:

Joey Boggs wrote:

I integrated the common cli options and all the other modifications, but
wasn't sure the best way to approach the para/full virt check removal
from the comments


"If you use the above --paravirt/--hvm option change, you won't need
this check." Both before and after code snips below.

I changed the if/else to evaluate the options for True on either
para/full, if there's something else you'd want to see please let me know



-------------------------------------------------------------------------------
parser.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
help=("This guest should be a fully virtualized
guest"))
parser.add_option("-p", "--paravirt", action="store_true",
dest="paravirt",

help=("This guest should be a paravirtualized guest"))




if options.paravirt is True:
virt_boot_template = """<boot type="xen">
<guest>
<arch>%(vm_arch)s</arch>
<features>
<pae/>
</features>
</guest>
<os>
<loader>pygrub</loader>
</os>
%(vm_pv_disks)s
</boot>"""
elif options.fullvirt is True:

virt_boot_template = """<boot type="hvm">
<guest>
<arch>%(vm_arch)s</arch>
</guest>
<os>
<loader dev="hd"/>
</os>
%(vm_fv_disks)s
</boot>"""
else:
print "Invalid virtualization type specified"
sys.exit(1)



Sorry, I wasn't very clear. The unnecessary check I was talking about
was the last sanity check, the "Invalid virtualization type". Since this
is basically a boolean option (hvm or not), i'd do something like

if options.paravirt:
hvm = False
else:
hvm = True

In main() and pass hvm explictly to the above function.

- Cole



_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 06-30-2008, 05:48 PM
Cole Robinson
 
Default convert vmware machines to virt-image xml format

Joey Boggs wrote:
> Updated version based on comments.
>
> Cole, check the record validation section to see if that's fine. I just
> integrated it with the 2 checks that were already in place rather than
> creating another function.
>
>

Alright, I think this looks good. I'll probably commit sometime
today or tomorrow.

Thanks,
Cole

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 07-01-2008, 02:32 AM
John Levon
 
Default convert vmware machines to virt-image xml format

On Thu, Jun 26, 2008 at 10:32:11AM -0400, Joey Boggs wrote:

> --- virtinst--devel.orig/virt-unpack 1969-12-31 19:00:00.000000000 -0500
> +++ virtinst--devel/virt-unpack 2008-06-26 10:30:45.000000000 -0400

Why isn't this called virt-convert? I don't see any actually "unpacking"
going on here.

More generally, I'd like to see this be a lot more general, instead of
hard-coding for vmx. Ideally 'virt-convert' would be a simple shell that
would call out to .../virtinst/formats/vmx.py (or whatever) to handle
the details. There's already Unware code there, shouldn't we re-use
details wherever possible?

regards
john

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 07-01-2008, 03:14 AM
David Lutterkort
 
Default convert vmware machines to virt-image xml format

On Tue, 2008-07-01 at 03:32 +0100, John Levon wrote:
> On Thu, Jun 26, 2008 at 10:32:11AM -0400, Joey Boggs wrote:
>
> > --- virtinst--devel.orig/virt-unpack 1969-12-31 19:00:00.000000000 -0500
> > +++ virtinst--devel/virt-unpack 2008-06-26 10:30:45.000000000 -0400
>
> Why isn't this called virt-convert? I don't see any actually "unpacking"
> going on here.

Calling it virt-pack is more a historical accident. I think renaming it
to virt-convert makes sense. It'll require some small changes in the
command line switches though, so you cna say from what format and to
what format you want to convert.

David


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 07-01-2008, 03:38 AM
Joey Boggs
 
Default convert vmware machines to virt-image xml format

Yep it was heading that way, and it's name was historical based on the
original virt-pack work. Either way is fine with me, I figured getting a
couple formats out there first and then rebasing the master conversion
program to virt-convert might be easier once the few types of
conversions had been used a bit to beat out any potential bugs.


David Lutterkort wrote:

On Tue, 2008-07-01 at 03:32 +0100, John Levon wrote:


On Thu, Jun 26, 2008 at 10:32:11AM -0400, Joey Boggs wrote:



--- virtinst--devel.orig/virt-unpack 1969-12-31 19:00:00.000000000 -0500
+++ virtinst--devel/virt-unpack 2008-06-26 10:30:45.000000000 -0400


Why isn't this called virt-convert? I don't see any actually "unpacking"
going on here.


Calling it virt-pack is more a historical accident. I think renaming it

to virt-convert makes sense. It'll require some small changes in the
command line switches though, so you cna say from what format and to
what format you want to convert.

David


_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools



_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 12:08 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org