cli: Add --memory, deprecates -r/--ram
This is a compound option like we use elsewhere, with suboptions for maxmemory and hugepages.
This commit is contained in:
parent
cf626c3afe
commit
7ba76b5748
|
@ -52,10 +52,11 @@ General configuration parameters that apply to all types of guest installs.
|
|||
|
||||
Name of the guest instance
|
||||
|
||||
=item -r MEMORY, --ram=MEMORY
|
||||
=item --memory=MEMORY
|
||||
|
||||
Memory to allocate for guest instance in megabytes. Defaults to
|
||||
C</image/devices/memory> in the XML descriptor.
|
||||
Memory to allocate for the guest, in megabytes. Defaults to C</image/devices/memory> in the XML descriptor. This deprecates the -r/--ram option.
|
||||
|
||||
See L<virt-install(1)> for more details.
|
||||
|
||||
=item -u UUID, --uuid=UUID
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ argument, example: virt-install --disk=?
|
|||
|
||||
=head1 OPTIONS
|
||||
|
||||
Most options are not required. Minimum requirements are --name, --ram,
|
||||
Most options are not required. Minimum requirements are --name, --memory,
|
||||
guest storage (--disk, --filesystem or --nodisks), and an install option.
|
||||
|
||||
=over 2
|
||||
|
@ -89,11 +89,12 @@ currently active. To re-define an existing guest, use the C<virsh(1)> tool
|
|||
to shut it down ('virsh shutdown') & delete ('virsh undefine') it prior to
|
||||
running C<virt-install>.
|
||||
|
||||
=item -r MEMORY, --ram=MEMORY
|
||||
=item --memory=MEM[,OPT1=VAL][...]
|
||||
|
||||
Memory to allocate for guest instance in megabytes. If the hypervisor does
|
||||
not have enough free memory, it is usual for it to automatically take memory
|
||||
away from the host operating system to satisfy this allocation.
|
||||
Memory to allocate for the guest, in megabytes. Sub options are available,
|
||||
like 'maxmemory' and 'hugepages'. This deprecates the -r/--ram option.
|
||||
|
||||
Use --memory=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsMemoryAllocation>
|
||||
|
||||
=item --arch=ARCH
|
||||
|
||||
|
@ -1433,7 +1434,7 @@ CDROM drive, auto launching a graphical VNC viewer
|
|||
--connect qemu:///system \
|
||||
--virt-type kvm \
|
||||
--name demo \
|
||||
--ram 500 \
|
||||
--memory 500 \
|
||||
--disk path=/var/lib/libvirt/images/demo.img,size=8 \
|
||||
--graphics vnc \
|
||||
--cdrom /dev/cdrom \
|
||||
|
@ -1445,7 +1446,7 @@ booting from PXE, using VNC server/viewer
|
|||
# virt-install \
|
||||
--connect qemu:///system \
|
||||
--name demo \
|
||||
--ram 500 \
|
||||
--memory 500 \
|
||||
--disk path=/dev/HostVG/DemoVM \
|
||||
--network network=default \
|
||||
--virt-type qemu
|
||||
|
@ -1459,7 +1460,7 @@ pair:
|
|||
# virt-install \
|
||||
--connect qemu:///system \
|
||||
--name demo \
|
||||
--ram 500 \
|
||||
--memory 500 \
|
||||
--disk path=/dev/hdc \
|
||||
--network bridge=eth1 \
|
||||
--arch ppc64 \
|
||||
|
@ -1471,7 +1472,7 @@ Run a Live CD image under Xen fullyvirt, in diskless environment
|
|||
# virt-install \
|
||||
--hvm \
|
||||
--name demo \
|
||||
--ram 500 \
|
||||
--memory 500 \
|
||||
--nodisks \
|
||||
--livecd \
|
||||
--graphics vnc \
|
||||
|
@ -1483,7 +1484,7 @@ at 512 MB of ram and 2 host cpus:
|
|||
# virt-install \
|
||||
--connect lxc:/// \
|
||||
--name httpd_guest \
|
||||
--ram 512 \
|
||||
--memory 512 \
|
||||
--vcpus 2 \
|
||||
--init /usr/bin/httpd
|
||||
|
||||
|
@ -1496,7 +1497,7 @@ The host dir "/home/test" will be mounted at
|
|||
# virt-install \
|
||||
--connect lxc:/// \
|
||||
--name container \
|
||||
--ram 128 \
|
||||
--memory 128 \
|
||||
--filesystem /home/LXC,/ \
|
||||
--filesystem /home/test,/mnt \
|
||||
--init /bin/sh
|
||||
|
@ -1508,7 +1509,7 @@ options:
|
|||
# virt-install \
|
||||
--paravirt \
|
||||
--name demo \
|
||||
--ram 500 \
|
||||
--memory 500 \
|
||||
--file /var/lib/xen/images/demo.img \
|
||||
--file-size 6 \
|
||||
--graphics none \
|
||||
|
@ -1519,7 +1520,7 @@ the rest of the options.
|
|||
|
||||
# virt-install \
|
||||
--name demo \
|
||||
--ram 512 \
|
||||
--memory 512 \
|
||||
--disk /home/user/VMs/mydisk.img \
|
||||
--import
|
||||
|
||||
|
@ -1527,7 +1528,7 @@ Start serial QEMU ARM VM, which requires specifying a manual kernel.
|
|||
|
||||
# virt-install \
|
||||
--name armtest \
|
||||
--ram 1024 \
|
||||
--memory 1024 \
|
||||
--arch armv7l --machine vexpress-a9 \
|
||||
--disk /home/user/VMs/myarmdisk.img \
|
||||
--boot kernel=/tmp/my-arm-kernel,initrd=/tmp/my-arm-initrd,dtb=/tmp/my-arm-dtb,kernel_args="console=ttyAMA0 rw root=/dev/mmcblk0p3" \
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<domain type="test">
|
||||
<name>foobar</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>65536</memory>
|
||||
<currentMemory>65536</currentMemory>
|
||||
<memory>262144</memory>
|
||||
<currentMemory>131072</currentMemory>
|
||||
<vcpu>7</vcpu>
|
||||
<bootloader>/usr/bin/pygrub</bootloader>
|
||||
<features>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
--- Original XML
|
||||
+++ Altered XML
|
||||
@@ -4,10 +4,9 @@
|
||||
<description>Foo bar baz &
|
||||
yeah boii < > yeahfoo
|
||||
</description>
|
||||
- <memory unit="KiB">409600</memory>
|
||||
- <currentMemory unit="KiB">204800</currentMemory>
|
||||
+ <memory unit="KiB">1024000</memory>
|
||||
+ <currentMemory unit="KiB">512000</currentMemory>
|
||||
<memoryBacking>
|
||||
- <hugepages/>
|
||||
</memoryBacking>
|
||||
<vcpu placement="static" cpuset="1-2,5-9,11,13-14">9</vcpu>
|
||||
<numatune>
|
||||
|
||||
Domain 'test-many-devices' defined successfully.
|
|
@ -604,7 +604,7 @@ c.add_valid("--controller usb,model=ich9-ehci1,address=0:0:4.7,index=1")
|
|||
c.add_valid("--controller usb2 --controller usb3")
|
||||
|
||||
|
||||
c = vinst.add_category("lxc", "--connect %(LXCURI)s --noautoconsole --name foolxc --ram 64")
|
||||
c = vinst.add_category("lxc", "--connect %(LXCURI)s --noautoconsole --name foolxc --memory 64")
|
||||
c.add_compare("", "default")
|
||||
c.add_compare("--filesystem /source,/", "fs-default")
|
||||
c.add_compare("--init /usr/bin/httpd", "manual-init")
|
||||
|
@ -759,6 +759,7 @@ c.add_invalid("--domain test-many-devices --edit 5 --tpm /dev/tpm") # device ed
|
|||
c.add_compare("--domain test --print-xml --edit --vcpus 7", "virtxml-print-xml") # test --print-xml
|
||||
|
||||
c = vixml.add_category("simple edit diff", "--domain test-many-devices --edit --print-diff --define")
|
||||
c.add_compare("--memory 500,maxmemory=1000,hugepages=off", "virtxml-edit-simple-memory")
|
||||
c.add_compare("--vcpus 10,maxvcpus=20,cores=5,sockets=4,threads=1", "virtxml-edit-simple-vcpus")
|
||||
c.add_compare("--cpu model=pentium2,+x2apic,forbid=pbe", "virtxml-edit-simple-cpu")
|
||||
c.add_compare("--numatune 1-5,7,mode=strict", "virtxml-edit-simple-numatune")
|
||||
|
@ -803,7 +804,7 @@ c.add_valid("--vnc --keymap ja --vncport 5950 --vnclisten 1.2.3.4") # VNC w/ lo
|
|||
|
||||
c = vimag.add_category("misc", "")
|
||||
c.add_valid("--network=?") # Make sure introspection doesn't blow up
|
||||
c.add_compare("--name foobar --ram 64 --os-variant winxp --boot 0 %(IMAGE_XML)s", "image-boot0")
|
||||
c.add_compare("--name foobar --memory 128,maxmemory=256 --os-variant winxp --boot 0 %(IMAGE_XML)s", "image-boot0")
|
||||
c.add_compare("--name foobar --ram 64 --network user,model=e1000 --boot 1 %(IMAGE_XML)s", "image-boot1")
|
||||
c.add_compare("--name foobar --ram 64 --boot 0 %(IMAGE_NOGFX_XML)s", "image-nogfx")
|
||||
c.add_valid("--name test --replace %(IMAGE_XML)s") # Colliding VM name w/ --replace
|
||||
|
|
11
virt-image
11
virt-image
|
@ -44,10 +44,8 @@ def parse_args():
|
|||
|
||||
geng = parser.add_argument_group(_("General Options"))
|
||||
geng.add_argument("-n", "--name", help=_("Name of the guest instance"))
|
||||
geng.add_argument("-r", "--ram", type=int, dest="memory",
|
||||
help=_("Memory to allocate for guest instance in "
|
||||
"megabytes"))
|
||||
geng.add_argument("-u", "--uuid", help=argparse.SUPPRESS)
|
||||
cli.add_memory_option(geng, backcompat=True)
|
||||
cli.vcpu_cli_options(geng)
|
||||
cli.add_distro_options(geng)
|
||||
cli.add_old_feature_options(geng)
|
||||
|
@ -77,7 +75,7 @@ def main(conn=None):
|
|||
|
||||
cli.convert_old_features(options)
|
||||
parsermap = cli.build_parser_map(options,
|
||||
only=["vcpus", "cpu", "network", "graphics", "features"])
|
||||
only=["memory", "vcpus", "cpu", "network", "graphics", "features"])
|
||||
if cli.check_option_introspection(options, parsermap):
|
||||
return 0
|
||||
|
||||
|
@ -104,19 +102,20 @@ def main(conn=None):
|
|||
guest = conn.caps.build_virtinst_guest(conn, *installer.get_caps_guest())
|
||||
guest.installer = installer
|
||||
|
||||
cli.convert_old_memory(options)
|
||||
cli.convert_old_networks(guest, options, image.domain.interface)
|
||||
cli.convert_old_graphics(guest, options,
|
||||
default_override=bool(image.domain.graphics))
|
||||
cli.convert_old_cpuset(options)
|
||||
if not options.vcpus:
|
||||
options.vcpus = image.domain.vcpu or ""
|
||||
if not options.memory and image.domain.memory:
|
||||
options.memory = image.domain.memory
|
||||
|
||||
guest.replace = options.replace
|
||||
cli.set_os_variant(guest, options.distro_type, options.distro_variant)
|
||||
|
||||
cli.get_name(guest, options.name or image.name)
|
||||
cli.get_memory(guest, options.memory or (image.domain.memory and
|
||||
int(image.domain.memory)))
|
||||
if options.uuid:
|
||||
guest.uuid = options.uuid
|
||||
|
||||
|
|
14
virt-install
14
virt-install
|
@ -385,7 +385,7 @@ def validate_required_options(options, guest):
|
|||
msg += "\n" + cli.name_missing
|
||||
|
||||
if not options.memory:
|
||||
msg += "\n" + cli.ram_missing
|
||||
msg += "\n" + cli.memory_missing
|
||||
|
||||
if (not guest.os.is_container() and
|
||||
not storage_specified(options.disk,
|
||||
|
@ -499,6 +499,7 @@ def build_guest_instance(conn, options, parsermap):
|
|||
|
||||
guest.installer = build_installer(options, conn, guest.os.os_type)
|
||||
|
||||
cli.convert_old_memory(options)
|
||||
convert_old_sound(options)
|
||||
cli.convert_old_networks(guest, options, not options.nonetworks and 1 or 0)
|
||||
cli.convert_old_graphics(guest, options)
|
||||
|
@ -514,8 +515,6 @@ def build_guest_instance(conn, options, parsermap):
|
|||
guest.autostart = options.autostart
|
||||
|
||||
cli.get_name(guest, options.name)
|
||||
# Memory needs to come before the vcpu setting
|
||||
cli.get_memory(guest, options.memory)
|
||||
|
||||
# Guest configuration
|
||||
if options.uuid:
|
||||
|
@ -533,6 +532,9 @@ def build_guest_instance(conn, options, parsermap):
|
|||
guest.add_default_usb_controller()
|
||||
guest.add_default_channels()
|
||||
|
||||
if cli.is_prompt():
|
||||
cli.get_memory(guest, guest.memory and (guest.memory / 1024) or None)
|
||||
|
||||
# Do this after setting up all optional parameters, so we report error
|
||||
# about those first.
|
||||
need_storage, need_install = validate_required_options(options, guest)
|
||||
|
@ -880,9 +882,8 @@ def parse_args():
|
|||
geng = parser.add_argument_group(_("General Options"))
|
||||
geng.add_argument("-n", "--name",
|
||||
help=_("Name of the guest instance"))
|
||||
geng.add_argument("-r", "--ram", type=int, dest="memory",
|
||||
help=_("Memory to allocate for guest instance in "
|
||||
"megabytes"))
|
||||
geng.add_argument("-u", "--uuid", help=argparse.SUPPRESS)
|
||||
cli.add_memory_option(geng, backcompat=True)
|
||||
cli.vcpu_cli_options(geng)
|
||||
geng.add_argument("--description",
|
||||
help=_("Human readable description of the VM to store in "
|
||||
|
@ -960,7 +961,6 @@ def parse_args():
|
|||
help=_("The CPU architecture to simulate"))
|
||||
virg.add_argument("--machine",
|
||||
help=_("The machine type to emulate"))
|
||||
virg.add_argument("-u", "--uuid", help=argparse.SUPPRESS)
|
||||
cli.add_old_feature_options(virg)
|
||||
|
||||
misc = parser.add_argument_group(_("Miscellaneous Options"))
|
||||
|
|
1
virt-xml
1
virt-xml
|
@ -197,6 +197,7 @@ def parse_args():
|
|||
cli.add_disk_option(g)
|
||||
cli.add_net_option(g)
|
||||
cli.add_gfx_option(g)
|
||||
cli.add_memory_option(g)
|
||||
cli.vcpu_cli_options(g)
|
||||
cli.add_guest_xml_options(g)
|
||||
cli.add_boot_option(g)
|
||||
|
|
|
@ -544,7 +544,7 @@ def disk_prompt(conn, origpath, origsize, origsparse,
|
|||
#######################
|
||||
|
||||
name_missing = _("--name is required")
|
||||
ram_missing = _("--ram amount in MB is required")
|
||||
memory_missing = _("--memory amount in MB is required")
|
||||
|
||||
|
||||
def get_name(guest, name):
|
||||
|
@ -555,7 +555,7 @@ def get_name(guest, name):
|
|||
|
||||
def get_memory(guest, memory):
|
||||
prompt_txt = _("How much RAM should be allocated (in megabytes)?")
|
||||
err_txt = ram_missing
|
||||
err_txt = memory_missing
|
||||
|
||||
def check_memory(mem):
|
||||
mem = int(mem)
|
||||
|
@ -568,6 +568,14 @@ def get_memory(guest, memory):
|
|||
func=check_memory)
|
||||
|
||||
|
||||
def convert_old_memory(options):
|
||||
if options.memory:
|
||||
return
|
||||
if not options.oldmemory:
|
||||
return
|
||||
options.memory = str(options.oldmemory)
|
||||
|
||||
|
||||
def convert_old_cpuset(options):
|
||||
if not options.cpuset:
|
||||
return
|
||||
|
@ -760,6 +768,16 @@ def add_misc_options(grp, prompt=False, replace=False,
|
|||
help=_("Print debugging information"))
|
||||
|
||||
|
||||
def add_memory_option(grp, backcompat=False):
|
||||
grp.add_argument("--memory",
|
||||
help=_("Configure guest memory allocation. Ex:\n"
|
||||
"--memory 1024 (in megabytes)\n"
|
||||
"--memory 512,maxmemory=1024,hugepages=on"))
|
||||
if backcompat:
|
||||
grp.add_argument("-r", "--ram", type=int, dest="oldmemory",
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
|
||||
def vcpu_cli_options(grp, backcompat=True):
|
||||
grp.add_argument("--vcpus",
|
||||
help=_("Number of vcpus to configure for your guest. Ex:\n"
|
||||
|
@ -1287,6 +1305,22 @@ class ParserNumatune(VirtCLIParser):
|
|||
self.set_param("numatune.memory_mode", "mode")
|
||||
|
||||
|
||||
####################
|
||||
# --memory parsing #
|
||||
####################
|
||||
|
||||
class ParserMemory(VirtCLIParser):
|
||||
def _init_params(self):
|
||||
self.remove_first = "memory"
|
||||
|
||||
def set_memory_cb(opts, inst, cliname, val):
|
||||
ignore = opts
|
||||
setattr(inst, cliname, int(val) * 1024)
|
||||
self.set_param("memory", "memory", setter_cb=set_memory_cb)
|
||||
self.set_param("maxmemory", "maxmemory", setter_cb=set_memory_cb)
|
||||
self.set_param("hugepage", "hugepages", is_onoff=True)
|
||||
|
||||
|
||||
###################
|
||||
# --vcpus parsing #
|
||||
###################
|
||||
|
@ -2085,6 +2119,7 @@ def build_parser_map(options, skip=None, only=None):
|
|||
parserobj.cli_arg_name, parserclass))
|
||||
parsermap[parserobj.option_variable_name] = parserobj
|
||||
|
||||
register_parser("memory", ParserMemory)
|
||||
register_parser("vcpus", ParserVCPU)
|
||||
register_parser("cpu", ParserCPU)
|
||||
register_parser("numatune", ParserNumatune)
|
||||
|
|
Loading…
Reference in New Issue