diff options
author | Cole Robinson <crobinso@redhat.com> | 2014-01-24 20:03:30 -0500 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2014-01-25 17:20:29 -0500 |
commit | 927a7ef2659d9b087a41aa63ce227dc13bc2e91a (patch) | |
tree | 50e4e5e0ef45a56e23a283f670d0d2f4328d4f7b | |
parent | ed25983d14d0a95f384c4791c6c0dc5aac96ad22 (diff) | |
download | virt-manager-927a7ef2659d9b087a41aa63ce227dc13bc2e91a.tar.gz |
cli: Add --metadata option
Can take name, description, uuid, and title (new). This deprecates the
separate --description and --uuid element, but we won't require it for
specifying a name with virt-install/virt-image since that's quite
overkill. Allowing --name with this option is mostly for the benefit
of virt-xml.
-rw-r--r-- | man/virt-image.pod | 5 | ||||
-rw-r--r-- | man/virt-install.pod | 14 | ||||
-rw-r--r-- | tests/cli-test-xml/compare/virtxml-edit-simple-metadata.xml | 25 | ||||
-rw-r--r-- | tests/clitest.py | 3 | ||||
-rwxr-xr-x | virt-install | 12 | ||||
-rwxr-xr-x | virt-xml | 1 | ||||
-rw-r--r-- | virtinst/cli.py | 18 |
7 files changed, 57 insertions, 21 deletions
diff --git a/man/virt-image.pod b/man/virt-image.pod index 0e961994..6ff7c22e 100644 --- a/man/virt-image.pod +++ b/man/virt-image.pod @@ -58,11 +58,6 @@ Memory to allocate for the guest, in megabytes. Defaults to C</image/devices/mem See L<virt-install(1)> for more details. -=item -u UUID, --uuid=UUID - -UUID for the guest; if none is given a random UUID will be generated. If -you specify UUID, you should use a 32-digit hexadecimal number. - =item --vcpus=VCPUS Number of vcpus to configure for your guest. Defaults to diff --git a/man/virt-install.pod b/man/virt-install.pod index 568ba461..89c27301 100644 --- a/man/virt-install.pod +++ b/man/virt-install.pod @@ -107,12 +107,11 @@ The machine type to emulate. This will typically not need to be specified for Xen or KVM, but is useful for choosing machine types of more exotic architectures. -=item -u UUID, --uuid=UUID +=item --metadata OPT=VAL,[...] -UUID for the guest; if none is given a random UUID will be generated. If you -specify UUID, you should use a 32-digit hexadecimal number. UUID are intended -to be unique across the entire data center, and indeed world. Bear this in -mind if manually specifying a UUID +Specify metadata values for the guest. Possible options include name, uuid, title, and description. This option deprecates -u/--uuid and --description. + +Use --metadata=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsMetadata> =item --vcpus=VCPUS[,maxvcpus=MAX][,sockets=#][,cores=#][,threads=#][,cpuset=CPUSET] @@ -175,11 +174,6 @@ may cause issues if migrating the guest to a host without an identical CPU. Use --cpu=? to see a list of all available sub options. Complete details at L<http://libvirt.org/formatdomain.html#elementsCPU> -=item --description - -Human readable text description of the virtual machine. This will be stored -in the guests XML configuration for access by other applications. - =item --security type=TYPE[,label=LABEL][,relabel=yes|no] Configure domain security driver settings. Type can be either 'static' or diff --git a/tests/cli-test-xml/compare/virtxml-edit-simple-metadata.xml b/tests/cli-test-xml/compare/virtxml-edit-simple-metadata.xml new file mode 100644 index 00000000..99b9cb68 --- /dev/null +++ b/tests/cli-test-xml/compare/virtxml-edit-simple-metadata.xml @@ -0,0 +1,25 @@ +--- Original XML ++++ Altered XML +@@ -1,9 +1,9 @@ + <domain type="test" id="3"> +- <name>test-many-devices</name> +- <uuid>12345678-12f4-1234-1234-123456789012</uuid> +- <description>Foo bar baz & +- yeah boii < > yeahfoo +- </description> ++ <name>foo-my-new-name</name> ++ <uuid>12345678-12F4-1234-1234-123456789AFA</uuid> ++ <description>hey this is my ++new ++very,very=new desc'</description> + <memory unit="KiB">409600</memory> + <currentMemory unit="KiB">204800</currentMemory> + <memoryBacking> +@@ -303,4 +303,5 @@ + </backend> + </rng> + </devices> ++ <title>This is my,funky=new title</title> + </domain> + +Domain 'foo-my-new-name' defined successfully.
\ No newline at end of file diff --git a/tests/clitest.py b/tests/clitest.py index dec25c9a..8122479a 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -759,6 +759,9 @@ 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("""--metadata name=foo-my-new-name,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my +new +very,very=new desc\\\'",title="This is my,funky=new title" """, "virtxml-edit-simple-metadata") 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") diff --git a/virt-install b/virt-install index f26c4bdf..ca78d1ef 100755 --- a/virt-install +++ b/virt-install @@ -516,10 +516,11 @@ def build_guest_instance(conn, options, parsermap): cli.get_name(guest, options.name) - # Guest configuration if options.uuid: guest.uuid = options.uuid - guest.description = options.description + # This might be difficult to convert into options.metadata + if options.description: + guest.description = options.description # We don't want to auto-parse --disk, but we wanted it for earlier # parameter introspection @@ -882,12 +883,11 @@ def parse_args(): geng = parser.add_argument_group(_("General Options")) geng.add_argument("-n", "--name", help=_("Name of the guest instance")) - 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 " - "the generated XML.")) + cli.add_metadata_option(geng) + geng.add_argument("-u", "--uuid", help=argparse.SUPPRESS) + geng.add_argument("--description", help=argparse.SUPPRESS) cli.add_guest_xml_options(geng) insg = parser.add_argument_group(_("Installation Method Options")) @@ -197,6 +197,7 @@ def parse_args(): cli.add_disk_option(g) cli.add_net_option(g) cli.add_gfx_option(g) + cli.add_metadata_option(g) cli.add_memory_option(g) cli.vcpu_cli_options(g) cli.add_guest_xml_options(g) diff --git a/virtinst/cli.py b/virtinst/cli.py index f8eeb899..ecef5296 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -769,6 +769,13 @@ def add_misc_options(grp, prompt=False, replace=False, help=_("Print debugging information")) +def add_metadata_option(grp): + grp.add_argument("--metadata", + help=_("Configure guest metadata. Ex:\n" + "--metadata name=foo,title=\"My pretty title\",uuid=...\n" + "--metadata description=\"My nice long description\"")) + + def add_memory_option(grp, backcompat=False): grp.add_argument("--memory", help=_("Configure guest memory allocation. Ex:\n" @@ -1292,6 +1299,16 @@ class VirtCLIParser(object): raise NotImplementedError() +###################### +# --metadata parsing # +###################### + +class ParserMetadata(VirtCLIParser): + def _init_params(self): + self.set_param("name", "name", can_comma=True) + self.set_param("title", "title", can_comma=True) + self.set_param("uuid", "uuid") + self.set_param("description", "description", can_comma=True) ###################### @@ -2122,6 +2139,7 @@ def build_parser_map(options, skip=None, only=None): parserobj.cli_arg_name, parserclass)) parsermap[parserobj.option_variable_name] = parserobj + register_parser("metadata", ParserMetadata) register_parser("memory", ParserMemory) register_parser("vcpus", ParserVCPU) register_parser("cpu", ParserCPU) |