[PATCH 09 of 11] Add OS variant options to virt-convert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1215470455 25200
# Node ID 26beabc283b11e40ed01584be33678fd0840fed2
# Parent  9d9b282172f77f9d77035017bb0bc8e219be18ba
Add OS variant options to virt-convert.

And use them to set ACPI, APIC, clock, and USB tablet.

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/man/en/virt-convert.1 b/man/en/virt-convert.1
--- a/man/en/virt-convert.1
+++ b/man/en/virt-convert.1
@@ -186,6 +186,151 @@ Print debugging information
 .IP "\-q, \-\-quiet" 4
 .IX Item "-q, --quiet"
 Avoid verbose output.
+.IP "\-\-os\-type=OS_TYPE" 4
+.IX Item "--os-type=OS_TYPE"
+Optimize the guest configuration for a type of operating system. This will
+attempt to pick the most suitable \s-1ACPI\s0 & \s-1APIC\s0 settings, optimally supported
+mouse drivers and generally accommodate other operating system quirks. The
+valid operating system types are
+.RS 4
+.IP "linux" 4
+.IX Item "linux"
+Linux 2.x series
+.IP "windows" 4
+.IX Item "windows"
+Microsoft Windows 9x or later
+.IP "unix" 4
+.IX Item "unix"
+Traditional \s-1UNIX\s0 \s-1BSD\s0 or SysV derivatives
+.IP "other" 4
+.IX Item "other"
+Operating systems not in one of the 3 prior groups
+.RE
+.RS 4
+.RE
+.IP "\-\-os\-variant=OS_VARIANT" 4
+.IX Item "--os-variant=OS_VARIANT"
+Further optimize the guest configuration for a specific operating system
+variant. This parameter is optional. The valid variants are
+.RS 4
+.IP "linux" 4
+.IX Item "linux"
+.RS 4
+.PD 0
+.IP "rhel2.1" 4
+.IX Item "rhel2.1"
+.PD
+Red Hat Enterprise Linux 2.1
+.IP "rhel3" 4
+.IX Item "rhel3"
+Red Hat Enterprise Linux 3
+.IP "rhel4" 4
+.IX Item "rhel4"
+Red Hat Enterprise Linux 4
+.IP "rhel5" 4
+.IX Item "rhel5"
+Red Hat Enterprise Linux 5
+.IP "centos5" 4
+.IX Item "centos5"
+Cent \s-1OS\s0 5
+.IP "fedora5" 4
+.IX Item "fedora5"
+Fedora Core 5
+.IP "fedora6" 4
+.IX Item "fedora6"
+Fedora Core 6
+.IP "fedora7" 4
+.IX Item "fedora7"
+Fedora 7
+.IP "sles10" 4
+.IX Item "sles10"
+Suse Linux Enterprise Server 10.x
+.IP "debianEtch" 4
+.IX Item "debianEtch"
+Debian 4.0 (Etch)
+.IP "debianLenny" 4
+.IX Item "debianLenny"
+Debian Lenny
+.IP "generic26" 4
+.IX Item "generic26"
+Generic Linux 2.6.x kernel
+.IP "generic24" 4
+.IX Item "generic24"
+Generic Linux 2.4.x kernel
+.RE
+.RS 4
+.RE
+.IP "windows" 4
+.IX Item "windows"
+.RS 4
+.PD 0
+.IP "winxp" 4
+.IX Item "winxp"
+.PD
+Microsoft Windows \s-1XP\s0
+.IP "win2k" 4
+.IX Item "win2k"
+Microsoft Windows 2000
+.IP "win2k3" 4
+.IX Item "win2k3"
+Microsoft Windows 2003
+.IP "vista" 4
+.IX Item "vista"
+Microsoft Windows Vista
+.RE
+.RS 4
+.RE
+.IP "unix" 4
+.IX Item "unix"
+.RS 4
+.PD 0
+.IP "solaris9" 4
+.IX Item "solaris9"
+.PD
+Sun Solaris 9
+.IP "solaris10" 4
+.IX Item "solaris10"
+Sun Solaris 10
+.IP "freebsd6" 4
+.IX Item "freebsd6"
+Free \s-1BSD\s0 6.x
+.IP "openbsd4" 4
+.IX Item "openbsd4"
+Open \s-1BSD\s0 4.x
+.RE
+.RS 4
+.RE
+.IP "other" 4
+.IX Item "other"
+.RS 4
+.PD 0
+.IP "msdos" 4
+.IX Item "msdos"
+.PD
+Microsoft \s-1DOS\s0
+.IP "netware4" 4
+.IX Item "netware4"
+Novell Netware 4
+.IP "netware5" 4
+.IX Item "netware5"
+Novell Netware 5
+.IP "netware6" 4
+.IX Item "netware6"
+Novell Netware 6
+.RE
+.RS 4
+.RE
+.RE
+.RS 4
+.RE
+.IP "\-\-noapic" 4
+.IX Item "--noapic"
+Override the \s-1OS\s0 type / variant to disables the \s-1APIC\s0 setting for fully 
+virtualized guest.
+.IP "\-\-noacpi" 4
+.IX Item "--noacpi"
+Override the \s-1OS\s0 type / variant to disables the \s-1ACPI\s0 setting for fully 
+virtualized guest. 
 .SH "EXAMPLES"
 .IX Header "EXAMPLES"
 Convert a paravirt guest from \f(CW\*(C`image.vmx\*(C'\fR:
diff --git a/man/en/virt-convert.pod b/man/en/virt-convert.pod
--- a/man/en/virt-convert.pod
+++ b/man/en/virt-convert.pod
@@ -72,6 +72,176 @@ Print debugging information
 
 Avoid verbose output.
 
+=item  --os-type=OS_TYPE
+
+Optimize the guest configuration for a type of operating system. This will
+attempt to pick the most suitable ACPI & APIC settings, optimally supported
+mouse drivers and generally accommodate other operating system quirks. The
+valid operating system types are
+
+=over 4
+
+=item linux
+
+Linux 2.x series
+
+=item windows
+
+Microsoft Windows 9x or later
+
+=item unix
+
+Traditional UNIX BSD or SysV derivatives
+
+=item other
+
+Operating systems not in one of the 3 prior groups
+
+=back
+
+=item --os-variant=OS_VARIANT
+
+Further optimize the guest configuration for a specific operating system
+variant. This parameter is optional. The valid variants are
+
+=over 4
+
+=item linux
+
+=over 4
+
+=item rhel2.1
+
+Red Hat Enterprise Linux 2.1
+
+=item rhel3
+
+Red Hat Enterprise Linux 3
+
+=item rhel4
+
+Red Hat Enterprise Linux 4
+
+=item rhel5
+
+Red Hat Enterprise Linux 5
+
+=item centos5
+
+Cent OS 5
+
+=item fedora5
+
+Fedora Core 5
+
+=item fedora6
+
+Fedora Core 6
+
+=item fedora7
+
+Fedora 7
+
+=item sles10
+
+Suse Linux Enterprise Server 10.x
+
+=item debianEtch
+
+Debian 4.0 (Etch)
+
+=item debianLenny
+
+Debian Lenny
+
+=item generic26
+
+Generic Linux 2.6.x kernel
+
+=item generic24
+
+Generic Linux 2.4.x kernel
+
+=back
+
+=item windows
+
+=over 4
+
+=item winxp
+
+Microsoft Windows XP
+
+=item win2k
+
+Microsoft Windows 2000
+
+=item win2k3
+
+Microsoft Windows 2003
+
+=item vista
+
+Microsoft Windows Vista
+
+=back
+
+=item unix
+
+=over 4
+
+=item solaris9
+
+Sun Solaris 9
+
+=item solaris10
+
+Sun Solaris 10
+
+=item freebsd6
+
+Free BSD 6.x
+
+=item openbsd4
+
+Open BSD 4.x
+
+=back
+
+=item other
+
+=over 4
+
+=item msdos
+
+Microsoft DOS
+
+=item netware4
+
+Novell Netware 4
+
+=item netware5
+
+Novell Netware 5
+
+=item netware6
+
+Novell Netware 6
+
+=back
+
+=back
+
+=item  --noapic
+
+Override the OS type / variant to disables the APIC setting for fully 
+virtualized guest.
+
+=item  --noacpi
+
+Override the OS type / variant to disables the ACPI setting for fully 
+virtualized guest. 
+
 =back
 
 =head1 EXAMPLES
diff --git a/virt-convert b/virt-convert
--- a/virt-convert
+++ b/virt-convert
@@ -73,6 +73,16 @@ def parse_args():
                     help=("This guest should be a fully virtualized guest"))
     opts.add_option("-p", "--paravirt", action="store_true", dest="paravirt",
                     help=("This guest should be a paravirtualized guest"))
+    opts.add_option("", "--os-type", type="string", dest="os_type",
+                      action="callback", callback=cli.check_before_store,
+                      help=("The OS type for fully virtualized guests, e.g. 'linux', 'unix', 'windows'"))
+    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("", "--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",
+        help=("Disables ACPI for fully virtualized guest (overrides value in os-type/os-variant db)"), default=False)
 
     (options, args) = opts.parse_args()
     if len(args) < 1:
@@ -187,6 +197,10 @@ def main():
         vmdef.type = vmconfig.VM_TYPE_HVM
 
     vmdef.arch = options.arch
+    vmdef.os_type = options.os_type
+    vmdef.os_variant = options.os_variant
+    vmdef.noapic = options.noapic
+    vmdef.noacpi = options.noacpi
 
     created_dir = False
     unixname = vmdef.name.replace(" ", "-")
diff --git a/virtconv/parsers/virtimage.py b/virtconv/parsers/virtimage.py
--- a/virtconv/parsers/virtimage.py
+++ b/virtconv/parsers/virtimage.py
@@ -20,12 +20,15 @@
 
 from string import ascii_letters
 import virtconv.vmconfig as vmconfig
+import virtinst.FullVirtGuest as fv
 
 pv_boot_template = """
   <boot type="xen">
    <guest>
     <arch>%(arch)s</arch>
     <features>
+     $(acpi)s
+     $(apic)s
      <pae />
     </features>
    </guest>
@@ -70,6 +73,37 @@ image_template = """
 </image>
 """
 
+def export_os_params(vm):
+    """
+    Export OS-specific parameters.
+    """
+    ostype = None
+    osvariant = None
+
+    ostype = fv.OS_TYPES.get(vm.os_type)
+    if ostype:
+        osvariant = ostype.variants.get(vm.os_variant)
+
+    def get_os_val(key, default):
+        val = None
+        if osvariant:
+            val = osvariant.get(key)
+        if not val and ostype:
+            val = ostype.get(key)
+        if not val:
+            val = default
+        return val
+
+    acpi = ""
+    if vm.noacpi is False and get_os_val("acpi", True):
+        acpi = "<acpi />"
+
+    apic = ""
+    if vm.noapic is False and get_os_val("apic", False):
+        apic = "<apic />"
+
+    return acpi, apic
+
 class virtimage_parser(vmconfig.parser):
     """
     Support for virt-install's image format (see virt-image man page).
@@ -135,6 +169,8 @@ class virtimage_parser(vmconfig.parser):
         if len(vm.netdevs):
             interface = "<interface />"
 
+        acpi, apic = export_os_params(vm)
+
         if vm.type == vmconfig.VM_TYPE_PV:
             boot_template = pv_boot_template
         else:
@@ -144,6 +180,8 @@ class virtimage_parser(vmconfig.parser):
             "pv_disks" : "".join(pv_disks),
             "hvm_disks" : "".join(hvm_disks),
             "arch" : vm.arch,
+            "acpi" : acpi,
+            "apic" : apic,
         }
 
         out = image_template % {
diff --git a/virtconv/parsers/virtinstance.py b/virtconv/parsers/virtinstance.py
--- a/virtconv/parsers/virtinstance.py
+++ b/virtconv/parsers/virtinstance.py
@@ -20,6 +20,7 @@
 
 from string import ascii_letters
 import virtconv.vmconfig as vmconfig
+import virtinst.FullVirtGuest as fv
 
 import re
 
@@ -78,21 +79,131 @@ instance_template = """
   <on_poweroff>destroy</on_poweroff>
   <on_reboot>restart</on_reboot>
   <on_crash>restart</on_crash>
+  <clock offset='%(clock)s'/>
   <features>
-    <acpi />
+    %(acpi)s
+    %(apic)s
     <pae />
   </features>
   <devices>
     %(emulator)s
     %(disks)s
     %(netdevs)s
+    <graphics type='vnc' port='-1' />
     <input type='mouse' bus='ps2' />
-    <input type='tablet' bus='usb' />
-    <graphics type='vnc' port='-1' />
+    %(usbtablet)s
     %(console)s
   </devices>
 </domain>
 """
+
+def export_netdevs(vm):
+    """
+    Export code for the network devices.
+    """
+
+    netdevs = []
+
+    for number, netdev in sorted(vm.netdevs.iteritems()):
+        mac = ""
+        if netdev.mac != "auto":
+            mac = "<mac address='%s' />" % netdev.mac
+
+        nettype = {
+            vmconfig.NETDEV_TYPE_DEV : "ethernet",
+            vmconfig.NETDEV_TYPE_BRIDGE : "bridge",
+            vmconfig.NETDEV_TYPE_UNKNOWN : "bridge",
+            vmconfig.NETDEV_TYPE_NETWORK : "network",
+        }.get(netdev.type)
+
+        source = ""
+        if netdev.source:
+            srcattr = nettype
+            if netdev.type == vmconfig.NETDEV_TYPE_DEV:
+                srcattr = "dev"
+            source = "<source %s='%s' />" % (srcattr, netdev.source)
+
+        # FIXME: should warn here
+        if not nettype:
+            continue
+
+        model = ""
+        if netdev.driver:
+            model = "<model type='%s' />" % netdev.driver
+
+        netdevs.append(netdev_template % {
+            "type" : nettype,
+            "source" : source,
+            "mac" : mac,
+            "model": model,
+        })
+
+    return netdevs
+
+def export_disks(vm):
+    """
+    Export code for the disks.
+    """
+
+    disk_prefix = "xvd"
+    if (vm.type == vmconfig.VM_TYPE_HVM):
+        disk_prefix = "hd"
+
+    disks = []
+
+    for devid, disk in sorted(vm.disks.iteritems()):
+        if disk.type != vmconfig.DISK_TYPE_DISK:
+            continue
+
+        # FIXME: needs updating for later Xen enhancements; need to
+        # implement capabilities checking for max disks etc.
+        drive_nr = ascii_letters[int(devid[1]) % 26]
+
+        disks.append(disk_template % {
+            "path" : disk.path,
+            "prefix" : disk_prefix,
+            "dev" :  drive_nr
+        })
+
+    return disks
+
+def export_os_params(vm):
+    """
+    Export OS-specific parameters.
+    """
+    ostype = None
+    osvariant = None
+
+    ostype = fv.OS_TYPES.get(vm.os_type)
+    if ostype:
+        osvariant = ostype.variants.get(vm.os_variant)
+
+    def get_os_val(key, default):
+        val = None
+        if osvariant:
+            val = osvariant.get(key)
+        if not val and ostype:
+            val = ostype.get(key)
+        if not val:
+            val = default
+        return val
+
+    acpi = ""
+    if vm.noacpi is False and get_os_val("acpi", True):
+        acpi = "<acpi />"
+
+    apic = ""
+    if vm.noapic is False and get_os_val("apic", False):
+        apic = "<apic />"
+
+    clock = get_os_val("clock", "utc")
+
+    usbtablet = ""
+    if get_os_val("input", [ "tablet", "usb" ])[0] == "tablet":
+        usbtablet = "<input type='tablet' bus='usb' />"
+
+    return acpi, apic, clock, usbtablet
+
 
 class virtinstance_parser(vmconfig.parser):
     """
@@ -150,61 +261,13 @@ class virtinstance_parser(vmconfig.parse
         vmname = re.sub(r'[^A-Za-z0-9_.:/+-]+',  '_', vm.name)
 
         vmtype = "xen"
-        disk_prefix = "xvd"
         if (vm.type == vmconfig.VM_TYPE_HVM):
             vmtype = "hvm"
-            disk_prefix = "hd"
-
-        disks = []
-        netdevs = []
-
-        for devid, disk in sorted(vm.disks.iteritems()):
-            if disk.type != vmconfig.DISK_TYPE_DISK:
-                continue
-
-            # FIXME: needs updating for later Xen enhancements; need to
-            # implement capabilities checking for max disks etc.
-            drive_nr = ascii_letters[int(devid[1]) % 26]
-
-            disks.append(disk_template % {
-                "path" : disk.path,
-                "prefix" : disk_prefix,
-                "dev" :  drive_nr
-            })
-
-        for number, netdev in sorted(vm.netdevs.iteritems()):
-            mac = ""
-            if netdev.mac != "auto":
-                mac = "<mac address='%s' />" % netdev.mac
-
-            nettype = {
-                vmconfig.NETDEV_TYPE_DEV : "ethernet",
-                vmconfig.NETDEV_TYPE_BRIDGE : "bridge",
-                vmconfig.NETDEV_TYPE_UNKNOWN : "bridge",
-                vmconfig.NETDEV_TYPE_NETWORK : "network",
-            }.get(netdev.type)
-
-            source = ""
-            if netdev.source:
-                srcattr = nettype
-                if netdev.type == vmconfig.NETDEV_TYPE_DEV:
-                    srcattr = "dev"
-                source = "<source %s='%s' />" % (srcattr, netdev.source)
-
-            # FIXME: should warn here
-            if not nettype:
-                continue
-
-            model = ""
-            if netdev.driver:
-                model = "<model type='%s' />" % netdev.driver
-
-            netdevs.append(netdev_template % {
-                "type" : nettype,
-                "source" : source,
-                "mac" : mac,
-                "model": model,
-            })
+
+        netdevs = export_netdevs(vm)
+        disks = export_disks(vm)
+
+        acpi, apic, clock, usbtablet = export_os_params(vm)
 
         out = instance_template % {
             "name" : vmname.replace(" ", "-"),
@@ -215,9 +278,13 @@ class virtinstance_parser(vmconfig.parse
             # Mb to Kb
             "memory" : int(vm.memory) * 1024,
             "nr_vcpus" : vm.nr_vcpus,
+            "clock" : clock,
+            "acpi" : acpi,
+            "apic" : apic,
             "emulator" : emulators[vm.type],
+            "disks" : "".join(disks),
             "netdevs" : "".join(netdevs),
-            "disks" : "".join(disks),
+            "usbtablet" : usbtablet,
             "console" : consoles[vm.type],
         }
 

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

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux