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.
This commit is contained in:
Richard W.M. Jones
2011-05-06 12:21:01 -04:00
parent a4c28b4ed1
commit be3b028d7f
2 changed files with 17 additions and 2 deletions

View File

@@ -1096,7 +1096,7 @@ Please read L<guestfs(3)/INSPECTION> 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<guestfs(3)/ATTACHING TO RUNNING DAEMONS> for more
information.
If the C<allowuuid> flag is true (default is false) then a UUID
I<may> be passed instead of the domain name. The C<dom> string is
treated as a UUID first and looked up, and if that lookup fails
then we treat C<dom> as a name as usual.
The other optional parameters are passed directly through to
C<guestfs_add_drive_opts>.");

View File

@@ -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"),