Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 9581b6a

Browse files
committed
cli: Add parsing functions for all devices
Even if they don't do much at the moment. Also, move some soon-to-be common options to cli. Adjust virt-install
1 parent d161465 commit 9581b6a

4 files changed

Lines changed: 290 additions & 228 deletions

File tree

virt-image

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ def main():
162162
cli.get_name(options.name, guest, image.name)
163163
cli.get_memory(options.memory, guest, image.domain.memory)
164164
cli.get_uuid(options.uuid, guest)
165-
cli.get_vcpus(options.vcpus, options.check_cpu,
166-
guest, image.domain.vcpu)
167-
cli.get_cpuset(options.cpuset, guest.memory, guest)
165+
cli.get_vcpus(guest, options.vcpus, options.check_cpu, image.domain.vcpu)
166+
cli.get_cpuset(guest, options.cpuset)
168167
cli.parse_cpu(guest, options.cpu)
169168
get_networks(image.domain, guest, options)
170169

virt-install

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def get_graphics(guest, options):
102102
graphics = cli.digest_graphics(guest, options)
103103
cli.get_graphics(guest, graphics)
104104

105-
def get_chardevs(char_type, opts, guest):
105+
def get_chardevs(char_type, opts, guest, cb):
106106
for optstr in cli.listify(opts):
107107
try:
108-
dev = cli.parse_char(guest, char_type, optstr)
108+
dev = cb(guest, optstr)
109109
guest.add_device(dev)
110110
except Exception, e:
111111
fail(_("Error in %(chartype)s device parameters: %(err)s") %
@@ -466,11 +466,11 @@ def build_guest_instance(conn, options):
466466

467467
# Guest configuration
468468
cli.get_uuid(options.uuid, guest)
469-
cli.get_vcpus(options.vcpus, options.check_cpu, guest)
470-
cli.get_cpuset(options.cpuset, guest.memory, guest)
469+
cli.get_vcpus(guest, options.vcpus, options.check_cpu)
470+
cli.get_cpuset(guest, options.cpuset)
471471
cli.parse_numatune(guest, options.numatune)
472472
cli.parse_cpu(guest, options.cpu)
473-
cli.parse_security(options.security, guest)
473+
cli.parse_security(guest, options.security)
474474
cli.parse_boot(guest, options.bootopts)
475475
guest.autostart = options.autostart
476476
guest.description = options.description
@@ -486,10 +486,14 @@ def build_guest_instance(conn, options):
486486
get_watchdog(options.watchdog, guest)
487487
get_filesystems(options.filesystems, guest)
488488
cli.get_sound(options.sound, options.soundhw, guest)
489-
get_chardevs(VirtualDevice.VIRTUAL_DEV_SERIAL, options.serials, guest)
490-
get_chardevs(VirtualDevice.VIRTUAL_DEV_PARALLEL, options.parallels, guest)
491-
get_chardevs(VirtualDevice.VIRTUAL_DEV_CHANNEL, options.channels, guest)
492-
get_chardevs(VirtualDevice.VIRTUAL_DEV_CONSOLE, options.consoles, guest)
489+
get_chardevs(VirtualDevice.VIRTUAL_DEV_SERIAL, options.serials,
490+
guest, cli.parse_serial)
491+
get_chardevs(VirtualDevice.VIRTUAL_DEV_PARALLEL, options.parallels,
492+
guest, cli.parse_parallel)
493+
get_chardevs(VirtualDevice.VIRTUAL_DEV_CHANNEL, options.channels,
494+
guest, cli.parse_channel)
495+
get_chardevs(VirtualDevice.VIRTUAL_DEV_CONSOLE, options.consoles,
496+
guest, cli.parse_console)
493497
cli.get_hostdevs(options.hostdevs, guest)
494498
cli.get_smartcard(guest, options.smartcard)
495499

@@ -849,10 +853,7 @@ def parse_args():
849853
"--disk vol=poolname:volname,device=cdrom,bus=scsi,..."))
850854
stog.add_option("", "--nodisks", action="store_true",
851855
help=_("Don't set up any disks for the guest."))
852-
stog.add_option("", "--filesystem", dest="filesystems", action="append",
853-
help=_("Pass host directory to the guest. Ex: \n"
854-
"--filesystem /my/source/dir,/dir/in/guest\n"
855-
"--filesystem template_name,/,type=template"))
856+
cli.add_fs_option(stog)
856857

857858
# Deprecated storage options
858859
stog.add_option("-f", "--file", dest="file_paths", action="append",
@@ -879,26 +880,7 @@ def parse_args():
879880
parser.add_option_group(vncg)
880881

881882
devg = optparse.OptionGroup(parser, _("Device Options"))
882-
devg.add_option("", "--serial", dest="serials", action="append",
883-
help=_("Add a serial device to the domain."))
884-
devg.add_option("", "--parallel", dest="parallels", action="append",
885-
help=_("Add a parallel device to the domain."))
886-
geng.add_option("", "--channel", dest="channels", action="append",
887-
help=_("Add a guest communication channel."))
888-
geng.add_option("", "--console", dest="consoles", action="append",
889-
help=_("Add a text console connection between the guest "
890-
"and host."))
891-
devg.add_option("", "--host-device", dest="hostdevs", action="append",
892-
help=_("Physical host device to attach to the domain."))
893-
devg.add_option("", "--soundhw", dest="soundhw", action="append",
894-
help=_("Use sound device emulation"))
895-
devg.add_option("", "--watchdog", dest="watchdog", action="append",
896-
help=_("Add a watchdog device to the domain."))
897-
devg.add_option("", "--video", dest="video", action="append",
898-
help=_("Specify video hardware type."))
899-
devg.add_option("", "--smartcard", dest="smartcard", action="append",
900-
help=_("Add a smartcard device to the domain. Ex:\n"
901-
"--smartcard mode=passthrough"))
883+
cli.add_device_options(devg)
902884

903885
# Deprecated
904886
devg.add_option("", "--sound", action="store_true", dest="sound",

virtinst/DomainNumatune.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import re
2121

22-
import libxml2
23-
2422
import _util
2523
import XMLBuilderDomain
2624
from XMLBuilderDomain import _xml_property

0 commit comments

Comments
 (0)