>From be3b028d7f2fadd8d2107a419393511e4510d0a4 Mon Sep 17 00:00:00 2001 From: Richard W.M. Jones Date: Fri, 6 May 2011 12:21:01 -0400 Subject: [PATCH 2/3] add-domain: Add allowuuid flag to allow UUIDs to be used for names. This makes a backwards-compatible change to the add-domain API. If the optional allowuuid flag is true then UUIDs can be used instead of names in the domain name parameter. --- generator/generator_actions.ml | 7 ++++++- src/virt.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index abf3475..5db24af 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -1096,7 +1096,7 @@ Please read L for more details."); This returns the internal QEMU command line. 'debug' commands are not part of the formal API and can be removed or changed at any time."); - ("add_domain", (RInt "nrdisks", [String "dom"], [String "libvirturi"; Bool "readonly"; String "iface"; Bool "live"]), -1, [FishAlias "domain"], + ("add_domain", (RInt "nrdisks", [String "dom"], [String "libvirturi"; Bool "readonly"; String "iface"; Bool "live"; Bool "allowuuid"]), -1, [FishAlias "domain"], [], "add the disk(s) from a named libvirt domain", "\ @@ -1130,6 +1130,11 @@ XML definition. The default (if the flag is omitted) is never to try. See L for more information. +If the C flag is true (default is false) then a UUID +I be passed instead of the domain name. The C string is +treated as a UUID first and looked up, and if that lookup fails +then we treat C as a name as usual. + The other optional parameters are passed directly through to C."); diff --git a/src/virt.c b/src/virt.c index cd48888..58cb999 100644 --- a/src/virt.c +++ b/src/virt.c @@ -82,6 +82,7 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name, const char *libvirturi; int readonly; int live; + int allowuuid; const char *iface; struct guestfs___add_libvirt_dom_argv optargs2 = { .bitmask = 0 }; @@ -93,6 +94,8 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name, ? optargs->iface : NULL; live = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIVE_BITMASK ? optargs->live : 0; + allowuuid = optargs->bitmask & GUESTFS_ADD_DOMAIN_ALLOWUUID_BITMASK + ? optargs->allowuuid : 0; if (live && readonly) { error (g, _("you cannot set both live and readonly flags")); @@ -114,7 +117,14 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name, */ virConnSetErrorFunc (conn, NULL, ignore_errors); - dom = virDomainLookupByName (conn, domain_name); + /* Try UUID first. */ + if (allowuuid) + dom = virDomainLookupByUUIDString (conn, domain_name); + + /* Try ordinary domain name. */ + if (!dom) + dom = virDomainLookupByName (conn, domain_name); + if (!dom) { err = virGetLastError (); error (g, _("no libvirt domain called '%s': %s"), -- 1.7.4.4