cli: Add --metadata os_name= and os_full_id=

Allows changing the libosinfo metadata for an existing vm via virt-xml
This commit is contained in:
Cole Robinson 2018-09-30 19:12:19 -04:00
parent b19f94299b
commit 757910a1bb
6 changed files with 39 additions and 3 deletions

View File

@ -0,0 +1,11 @@
</description>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
- <libosinfo:os id="http://fedoraproject.org/fedora/27"/>
+ <libosinfo:os id="http://fedoraproject.org/fedora/23"/>
</libosinfo:libosinfo>
</metadata>
<memory unit="KiB">409600</memory>
Domain 'test-for-virtxml' defined successfully.
Changes will take effect after the domain is fully powered off.

View File

@ -10,7 +10,11 @@
+very,very=new desc'</description>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/27"/>
- <libosinfo:os id="http://fedoraproject.org/fedora/27"/>
+ <libosinfo:os id="http://fedoraproject.org/fedora/13"/>
</libosinfo:libosinfo>
</metadata>
<memory unit="KiB">409600</memory>
@@
</panic>
</devices>

View File

@ -852,9 +852,10 @@ c.add_compare("--connect %(URI-KVM)s test-hyperv-uefi --edit --boot uefi", "hype
c = vixml.add_category("simple edit diff", "test-for-virtxml --edit --print-diff --define")
c.add_compare("""--metadata name=foo-my-new-name,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my
c.add_compare("""--metadata name=foo-my-new-name,os_name=fedora13,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my
new
very,very=new desc\\\'",title="This is my,funky=new title" """, "edit-simple-metadata")
c.add_compare("""--metadata os_full_id=http://fedoraproject.org/fedora/23""", "edit-metadata-full-os")
c.add_compare("--events on_poweroff=destroy,on_reboot=restart,on_crash=preserve", "edit-simple-events")
c.add_compare("--qemu-commandline='-foo bar,baz=\"wib wob\"'", "edit-simple-qemu-commandline")
c.add_compare("--memory 500,maxmemory=1000,hugepages=off", "edit-simple-memory")

View File

@ -117,6 +117,9 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(guest._metadata.libosinfo) # pylint: disable=protected-access
check("os_id", "http://fedoraproject.org/fedora/17")
guest.set_os_full_id("http://fedoraproject.org/fedora/10")
check("os_id", "http://fedoraproject.org/fedora/10")
self.assertEqual(guest.osinfo.name, "fedora10")
guest.set_os_name("generic")
check("os_id", None, "frib")
self.assertEqual(guest.osinfo.name, "generic")

View File

@ -1299,11 +1299,19 @@ def parse_check(checkstr):
class ParserMetadata(VirtCLIParser):
cli_arg_name = "metadata"
def set_os_name_cb(self, inst, val, virtarg):
inst.set_os_name(val)
def set_os_full_id_cb(self, inst, val, virtarg):
inst.set_os_full_id(val)
_register_virt_parser(ParserMetadata)
ParserMetadata.add_arg("name", "name", can_comma=True)
ParserMetadata.add_arg("title", "title", can_comma=True)
ParserMetadata.add_arg("uuid", "uuid")
ParserMetadata.add_arg("description", "description", can_comma=True)
ParserMetadata.add_arg(None, "os_name", cb=ParserMetadata.set_os_name_cb)
ParserMetadata.add_arg(None, "os_full_id", cb=ParserMetadata.set_os_full_id_cb)
####################

View File

@ -262,7 +262,16 @@ class Guest(XMLBuilder):
raise ValueError(
_("Distro '%s' does not exist in our dictionary") % name)
logging.debug("Setting Guest os_name=%s", name)
logging.debug("Setting Guest osinfo %s", obj)
self.__osinfo = obj
self._metadata.libosinfo.os_id = self.__osinfo.full_id
def set_os_full_id(self, full_id):
obj = OSDB.lookup_os_by_full_id(full_id)
if obj is None:
raise ValueError(_("Unknown libosinfo ID '%s'") % full_id)
logging.debug("Setting Guest osinfo %s", obj)
self.__osinfo = obj
self._metadata.libosinfo.os_id = self.__osinfo.full_id