Skip to content

Commit 757910a

Browse files
committed
cli: Add --metadata os_name= and os_full_id=
Allows changing the libosinfo metadata for an existing vm via virt-xml
1 parent b19f942 commit 757910a

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
</description>
2+
<metadata>
3+
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
4+
- <libosinfo:os id="http://fedoraproject.org/fedora/27"/>
5+
+ <libosinfo:os id="http://fedoraproject.org/fedora/23"/>
6+
</libosinfo:libosinfo>
7+
</metadata>
8+
<memory unit="KiB">409600</memory>
9+
10+
Domain 'test-for-virtxml' defined successfully.
11+
Changes will take effect after the domain is fully powered off.

tests/cli-test-xml/compare/virt-xml-edit-simple-metadata.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
+very,very=new desc'</description>
1111
<metadata>
1212
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
13-
<libosinfo:os id="http://fedoraproject.org/fedora/27"/>
13+
- <libosinfo:os id="http://fedoraproject.org/fedora/27"/>
14+
+ <libosinfo:os id="http://fedoraproject.org/fedora/13"/>
15+
</libosinfo:libosinfo>
16+
</metadata>
17+
<memory unit="KiB">409600</memory>
1418
@@
1519
</panic>
1620
</devices>

tests/clitest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,10 @@ def add_compare(self, cat, args, compfile, **kwargs):
852852

853853

854854
c = vixml.add_category("simple edit diff", "test-for-virtxml --edit --print-diff --define")
855-
c.add_compare("""--metadata name=foo-my-new-name,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my
855+
c.add_compare("""--metadata name=foo-my-new-name,os_name=fedora13,uuid=12345678-12F4-1234-1234-123456789AFA,description="hey this is my
856856
new
857857
very,very=new desc\\\'",title="This is my,funky=new title" """, "edit-simple-metadata")
858+
c.add_compare("""--metadata os_full_id=http://fedoraproject.org/fedora/23""", "edit-metadata-full-os")
858859
c.add_compare("--events on_poweroff=destroy,on_reboot=restart,on_crash=preserve", "edit-simple-events")
859860
c.add_compare("--qemu-commandline='-foo bar,baz=\"wib wob\"'", "edit-simple-qemu-commandline")
860861
c.add_compare("--memory 500,maxmemory=1000,hugepages=off", "edit-simple-memory")

tests/xmlparse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def testAlterGuest(self):
117117

118118
check = self._make_checker(guest._metadata.libosinfo) # pylint: disable=protected-access
119119
check("os_id", "http://fedoraproject.org/fedora/17")
120+
guest.set_os_full_id("http://fedoraproject.org/fedora/10")
121+
check("os_id", "http://fedoraproject.org/fedora/10")
122+
self.assertEqual(guest.osinfo.name, "fedora10")
120123
guest.set_os_name("generic")
121124
check("os_id", None, "frib")
122125
self.assertEqual(guest.osinfo.name, "generic")

virtinst/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,19 @@ def parse_check(checkstr):
12991299
class ParserMetadata(VirtCLIParser):
13001300
cli_arg_name = "metadata"
13011301

1302+
def set_os_name_cb(self, inst, val, virtarg):
1303+
inst.set_os_name(val)
1304+
1305+
def set_os_full_id_cb(self, inst, val, virtarg):
1306+
inst.set_os_full_id(val)
1307+
13021308
_register_virt_parser(ParserMetadata)
13031309
ParserMetadata.add_arg("name", "name", can_comma=True)
13041310
ParserMetadata.add_arg("title", "title", can_comma=True)
13051311
ParserMetadata.add_arg("uuid", "uuid")
13061312
ParserMetadata.add_arg("description", "description", can_comma=True)
1313+
ParserMetadata.add_arg(None, "os_name", cb=ParserMetadata.set_os_name_cb)
1314+
ParserMetadata.add_arg(None, "os_full_id", cb=ParserMetadata.set_os_full_id_cb)
13071315

13081316

13091317
####################

virtinst/guest.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,16 @@ def set_os_name(self, name):
262262
raise ValueError(
263263
_("Distro '%s' does not exist in our dictionary") % name)
264264

265-
logging.debug("Setting Guest os_name=%s", name)
265+
logging.debug("Setting Guest osinfo %s", obj)
266+
self.__osinfo = obj
267+
self._metadata.libosinfo.os_id = self.__osinfo.full_id
268+
269+
def set_os_full_id(self, full_id):
270+
obj = OSDB.lookup_os_by_full_id(full_id)
271+
if obj is None:
272+
raise ValueError(_("Unknown libosinfo ID '%s'") % full_id)
273+
274+
logging.debug("Setting Guest osinfo %s", obj)
266275
self.__osinfo = obj
267276
self._metadata.libosinfo.os_id = self.__osinfo.full_id
268277

0 commit comments

Comments
 (0)