summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-05-06 12:21:01 -0400
committerRichard W.M. Jones <rjones@redhat.com>2011-05-06 13:04:18 -0400
commitbe3b028d7f2fadd8d2107a419393511e4510d0a4 (patch)
treef5fa9c4f8bd1c38a337416174bc4aae421dc3ab7
parenta4c28b4ed1c5a102c8de2a7425568eb504d05c34 (diff)
downloadlibguestfs-be3b028d7f2fadd8d2107a419393511e4510d0a4.tar.gz
libguestfs-be3b028d7f2fadd8d2107a419393511e4510d0a4.tar.xz
libguestfs-be3b028d7f2fadd8d2107a419393511e4510d0a4.zip
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.
-rw-r--r--generator/generator_actions.ml7
-rw-r--r--src/virt.c12
2 files changed, 17 insertions, 2 deletions
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index abf3475a..5db24af7 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -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>.");
diff --git a/src/virt.c b/src/virt.c
index cd488886..58cb999d 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"),