147
144
fail(_("Error in %(chartype)s device parameters: %(err)s") %
148
145
{"chartype": char_type, "err": str(e) })
147
def parse_watchdog(guest, optstring):
148
# Peel the model type off the front
149
model, ignore, optstring = partition(optstring, ",")
150
opts = cli.parse_optstr(optstring)
151
dev = virtinst.VirtualWatchdog(guest.conn)
153
def set_param(paramname, dictname, val=None):
155
if opts.has_key(dictname):
161
setattr(dev, paramname, val)
163
set_param("model", "model", model)
164
set_param("action", "action")
166
# If extra parameters, then user passed some garbage param
168
raise ValueError(_("Unknown option(s) %s") % opts.keys())
172
def get_watchdog(watchdogs, guest):
173
for optstr in cli.listify(watchdogs):
175
dev = parse_watchdog(guest, optstr)
176
guest.add_device(dev)
178
fail(_("Error in watchdog device parameters: %s") % str(e))
180
def get_security(security, guest):
181
seclist = cli.listify(security)
182
secopts = seclist and seclist[0] or None
186
# Parse security opts
187
opts = cli.parse_optstr(secopts)
188
secmodel = virtinst.Seclabel(guest.conn)
190
def get_and_clear(dictname):
192
if opts.has_key(dictname):
197
mode = get_and_clear("type")
198
label = get_and_clear("label")
201
secmodel.label = label
203
mode = secmodel.SECLABEL_TYPE_STATIC
207
# If extra parameters, then user passed some garbage param
209
raise ValueError(_("Unknown option(s) %s") % opts.keys())
211
secmodel.get_xml_config()
212
guest.seclabel = secmodel
151
214
def parse_disk_option(guest, path, size):
152
215
"""helper to properly parse --disk options"""
523
579
geng.add_option("-r", "--ram", type="int", dest="memory",
524
580
help=_("Memory to allocate for guest instance in "
526
geng.add_option("", "--arch", type="string", dest="arch",
527
action="callback", callback=cli.check_before_store,
528
help=_("The CPU architecture to simulate"))
529
geng.add_option("-u", "--uuid", type="string", dest="uuid",
530
action="callback", callback=cli.check_before_store,
531
help=_("UUID for the guest."))
532
582
geng.add_option("", "--vcpus", type="int", dest="vcpus",
533
583
help=_("Number of vcpus to configure for your guest"))
534
geng.add_option("", "--check-cpu", action="store_true", dest="check_cpu",
535
help=_("Check that vcpus do not exceed physical CPUs "
536
"and warn if they do."))
537
584
geng.add_option("", "--cpuset", type="string", dest="cpuset",
538
585
action="callback", callback=cli.check_before_store,
539
586
help=_("Set which physical CPUs Domain can use."))
540
geng.add_option("", "--os-type", type="string", dest="distro_type",
541
action="callback", callback=cli.check_before_store,
542
help=_("The OS type for fully virtualized guests, e.g. "
543
"'linux', 'unix', 'windows'"))
544
geng.add_option("", "--os-variant", type="string", dest="distro_variant",
545
action="callback", callback=cli.check_before_store,
546
help=_("The OS variant for fully virtualized guests, "
547
"e.g. 'fedora6', 'rhel5', 'solaris10', 'win2k'"))
548
geng.add_option("", "--serial", type="string", dest="serials",
549
action="callback", callback=cli.check_before_append,
550
help=_("Add a serial device to the domain."))
551
geng.add_option("", "--parallel", type="string", dest="parallels",
552
action="callback", callback=cli.check_before_append,
553
help=_("Add a parallel device to the domain."))
554
geng.add_option("", "--host-device", type="string", dest="hostdevs",
555
action="callback", callback=cli.check_before_append,
556
help=_("Physical host device to attach to the domain."))
587
geng.add_option("", "--description", type="string", dest="description",
588
action="callback", callback=cli.check_before_store,
589
help=_("Human readable description of the VM to store in "
590
"the generated XML."))
591
geng.add_option("", "--security", type="string", dest="security",
592
action="callback", callback=cli.check_before_store,
593
help=_("Set domain security driver configuration."))
557
594
parser.add_option_group(geng)
559
fulg = OptionGroup(parser, _("Full Virtualization specific options"))
560
fulg.add_option("", "--sound", action="store_true", dest="sound",
561
default=False, help=_("Use sound device emulation"))
562
fulg.add_option("", "--noapic", action="store_true", dest="noapic",
564
help=_("Disables APIC for fully virtualized guest "
565
"(overrides value in os-type/os-variant db)"))
566
fulg.add_option("", "--noacpi", action="store_true", dest="noacpi",
568
help=_("Disables ACPI for fully virtualized guest "
569
"(overrides value in os-type/os-variant db)"))
570
parser.add_option_group(fulg)
572
virg = OptionGroup(parser, _("Virtualization Type Options"))
573
virg.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
574
help=_("This guest should be a fully virtualized guest"))
575
virg.add_option("-p", "--paravirt", action="store_true", dest="paravirt",
576
help=_("This guest should be a paravirtualized guest"))
577
virg.add_option("", "--virt-type", type="string", dest="hv_type",
579
help=_("Hypervisor name to use (kvm, qemu, xen, ...)"))
580
virg.add_option("", "--accelerate", action="store_true",
581
dest="accelerate", default=False,
582
help=optparse.SUPPRESS_HELP)
583
parser.add_option_group(virg)
585
596
insg = OptionGroup(parser, _("Installation Method Options"))
586
597
insg.add_option("-c", "--cdrom", type="string", dest="cdrom",
587
598
action="callback", callback=cli.check_before_store,
601
612
help=_("Additional arguments to pass to the kernel "
602
613
"booted from --location"))
614
insg.add_option("", "--os-type", type="string", dest="distro_type",
615
action="callback", callback=cli.check_before_store,
616
help=_("The OS type being installed, e.g. "
617
"'linux', 'unix', 'windows'"))
618
insg.add_option("", "--os-variant", type="string", dest="distro_variant",
619
action="callback", callback=cli.check_before_store,
620
help=_("The OS variant being installed guests, "
621
"e.g. 'fedora6', 'rhel5', 'solaris10', 'win2k'"))
603
622
parser.add_option_group(insg)
605
624
stog = OptionGroup(parser, _("Storage Configuration"))
644
663
parser.add_option_group(netg)
646
665
vncg = cli.graphics_option_group(parser)
647
vncg.add_option("", "--video", dest="video", type="string",
648
action="callback", callback=cli.check_before_append,
649
help=_("Specify video hardware type."))
650
666
vncg.add_option("", "--noautoconsole", action="store_false",
651
667
dest="autoconsole",
652
668
help=_("Don't automatically try to connect to the guest "
654
670
parser.add_option_group(vncg)
672
devg = OptionGroup(parser, _("Device Options"))
673
devg.add_option("", "--serial", type="string", dest="serials",
674
action="callback", callback=cli.check_before_append,
675
help=_("Add a serial device to the domain."))
676
devg.add_option("", "--parallel", type="string", dest="parallels",
677
action="callback", callback=cli.check_before_append,
678
help=_("Add a parallel device to the domain."))
679
devg.add_option("", "--host-device", type="string", dest="hostdevs",
680
action="callback", callback=cli.check_before_append,
681
help=_("Physical host device to attach to the domain."))
682
devg.add_option("", "--soundhw", type='string', action="callback",
683
callback=cli.check_before_append, dest="soundhw",
684
help=_("Use sound device emulation"))
685
devg.add_option("", "--watchdog", type="string", dest="watchdog",
686
action="callback", callback=cli.check_before_append,
687
help=_("Add a watchdog device to the domain."))
688
devg.add_option("", "--video", dest="video", type="string",
689
action="callback", callback=cli.check_before_append,
690
help=_("Specify video hardware type."))
693
devg.add_option("", "--sound", action="store_true", dest="sound",
694
default=False, help=optparse.SUPPRESS_HELP)
695
parser.add_option_group(devg)
697
virg = OptionGroup(parser, _("Virtualization Platform Options"))
698
virg.add_option("-v", "--hvm", action="store_true", dest="fullvirt",
699
help=_("This guest should be a fully virtualized guest"))
700
virg.add_option("-p", "--paravirt", action="store_true", dest="paravirt",
701
help=_("This guest should be a paravirtualized guest"))
702
virg.add_option("", "--virt-type", type="string", dest="hv_type",
704
help=_("Hypervisor name to use (kvm, qemu, xen, ...)"))
705
virg.add_option("", "--accelerate", action="store_true",
706
dest="accelerate", default=False,
707
help=optparse.SUPPRESS_HELP)
708
virg.add_option("", "--arch", type="string", dest="arch",
709
action="callback", callback=cli.check_before_store,
710
help=_("The CPU architecture to simulate"))
711
virg.add_option("", "--noapic", action="store_true", dest="noapic",
713
help=_("Disables APIC for fully virtualized guest "
714
"(overrides value in os-type/os-variant db)"))
715
virg.add_option("", "--noacpi", action="store_true", dest="noacpi",
717
help=_("Disables ACPI for fully virtualized guest "
718
"(overrides value in os-type/os-variant db)"))
719
virg.add_option("-u", "--uuid", type="string", dest="uuid",
720
action="callback", callback=cli.check_before_store,
721
help=_("UUID for the guest."))
722
parser.add_option_group(virg)
656
724
misc = OptionGroup(parser, _("Miscellaneous Options"))
657
misc.add_option("-d", "--debug", action="store_true", dest="debug",
658
help=_("Print debugging information"))
725
misc.add_option("", "--autostart", action="store_true", default=False,
727
help=_("Have domain autostart on host boot up."))
659
728
misc.add_option("", "--noreboot", action="store_true", dest="noreboot",
660
729
help=_("Disables the automatic rebooting when the "
661
730
"installation is complete."))
753
827
cli.get_uuid(options.uuid, guest)
754
828
cli.get_vcpus(options.vcpus, options.check_cpu, guest, conn)
755
829
cli.get_cpuset(options.cpuset, guest.memory, guest, conn)
757
cli.get_sound(options.sound, guest)
758
get_chardevs(VirtualDevice.VIRTUAL_DEV_SERIAL, options.serials, guest)
759
get_chardevs(VirtualDevice.VIRTUAL_DEV_PARALLEL, options.parallels,
762
cli.get_video(options.video, guest)
830
get_security(options.security, guest)
832
get_watchdog(options.watchdog, guest)
833
cli.get_sound(options.sound, options.soundhw, guest)
834
get_chardevs(VirtualDevice.VIRTUAL_DEV_SERIAL, options.serials, guest)
835
get_chardevs(VirtualDevice.VIRTUAL_DEV_PARALLEL, options.parallels, guest)
837
guest.autostart = options.autostart
838
guest.description = options.description
765
841
get_disks(options.file_path, options.diskopts, options.disksize,
869
945
except Exception, e:
871
print (_("Domain installation may not have been\n successful. If it "
872
"was, you can restart your domain\n by running 'virsh start "
873
"%s'; otherwise, please\n restart your installation.") %
947
print _("Domain installation does not appear to have been\n "
948
"successful. If it was, you can restart your domain\n "
949
"by running 'virsh start %s'; otherwise, please\n "
950
"restart your installation.") % guest.name
877
def domain_is_shutdown(dom):
882
if state == libvirt.VIR_DOMAIN_SHUTOFF:
885
# If --wait was specified, the dom object we have was looked up
886
# before initially shutting down, which seems to bogus up the
887
# info data (all 0's). So, if it is bogus, assume the domain is
888
# shutdown. We will catch the error later.
889
return state == libvirt.VIR_DOMAIN_NOSTATE and cpu_time == 0
891
954
def do_install(guest, conscb, progresscb, wait, wait_time, start_time,
894
957
dom = install_func(conscb, progresscb, wait=(not wait))
897
print _("Guest installation failed.")
900
if domain_is_shutdown(dom):
959
# Wait a bit so info is accurate
960
def check_domain_state():
964
if guest.domain_is_crashed():
965
print _("Domain has crashed.")
968
if guest.domain_is_shutdown():
973
do_sleep = bool(conscb)
975
ret, state = check_domain_state()
979
# Sometimes we see errors from libvirt here due to races
984
# Sleep a bit and try again to be sure the HV has caught up
987
ret, state = check_domain_state()
991
logging.debug("Domain state after install: %s" % state)
903
993
# Domain seems to be running
904
994
if wait and wait_time != 0: