|
176 | 176 | VIRT_UNAVAILABLE = 2 |
177 | 177 |
|
178 | 178 | ALL_COMMANDS = [] |
179 | | -VM_COMMANDS = ['create', 'define', 'destroy', 'get_xml', 'pause', 'shutdown', 'status', 'start', 'stop', 'undefine', 'unpause'] |
| 179 | +VM_COMMANDS = ['create', 'define', 'destroy', 'get_xml', 'pause', 'shutdown', 'status', 'start', 'stop', 'undefine', 'unpause', 'uuid'] |
180 | 180 | HOST_COMMANDS = ['freemem', 'info', 'list_vms', 'nodeinfo', 'virttype'] |
181 | 181 | ALL_COMMANDS.extend(VM_COMMANDS) |
182 | 182 | ALL_COMMANDS.extend(HOST_COMMANDS) |
@@ -311,6 +311,10 @@ def set_autostart(self, vmid, val): |
311 | 311 | def define_from_xml(self, xml): |
312 | 312 | return self.conn.defineXML(xml) |
313 | 313 |
|
| 314 | + def get_uuid(self, vmid): |
| 315 | + vm = self.conn.lookupByName(vmid) |
| 316 | + return vm.UUIDString() |
| 317 | + |
314 | 318 |
|
315 | 319 | class Virt(object): |
316 | 320 |
|
@@ -482,6 +486,10 @@ def define(self, xml): |
482 | 486 | self.__get_conn() |
483 | 487 | return self.conn.define_from_xml(xml) |
484 | 488 |
|
| 489 | + def get_uuid(self, vmid): |
| 490 | + self.__get_conn() |
| 491 | + return self.conn.get_uuid(vmid) |
| 492 | + |
485 | 493 |
|
486 | 494 | # A dict of interface types (found in their `type` attribute) to the |
487 | 495 | # corresponding "source" attribute name of their <source> elements |
@@ -767,6 +775,9 @@ def core(module): |
767 | 775 | if not isinstance(res, dict): |
768 | 776 | res = {command: res} |
769 | 777 |
|
| 778 | + elif command == 'uuid': |
| 779 | + res = {'uuid': v.get_uuid(guest)} |
| 780 | + |
770 | 781 | else: |
771 | 782 | res = getattr(v, command)(guest) |
772 | 783 | if not isinstance(res, dict): |
|
0 commit comments