]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add support for virDomainGetControlInfo
authorJiri Denemark <jdenemar@redhat.com>
Tue, 31 May 2011 16:21:58 +0000 (18:21 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 16 Jun 2011 17:13:08 +0000 (19:13 +0200)
tools/virsh.c
tools/virsh.pod

index 1c0b1dc83c3196749e83b06d176413197ae58d03..2e1abbdc8244675aefb802a067cfa56b250b240d 100644 (file)
@@ -352,6 +352,7 @@ static void vshDebug(vshControl *ctl, int level, const char *format, ...)
 static int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
 static const char *vshDomainStateToString(int state);
 static const char *vshDomainStateReasonToString(int state, int reason);
+static const char *vshDomainControlStateToString(int state);
 static const char *vshDomainVcpuStateToString(int state);
 static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn);
 
@@ -978,6 +979,53 @@ cleanup:
     return ret;
 }
 
+/*
+ * "domcontrol" command
+ */
+static const vshCmdInfo info_domcontrol[] = {
+    {"help", N_("domain control interface state")},
+    {"desc", N_("Returns state of a control interface to the domain.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_domcontrol[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDomControl(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    bool ret = true;
+    virDomainControlInfo info;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (virDomainGetControlInfo(dom, &info, 0) < 0) {
+        ret = false;
+        goto cleanup;
+    }
+
+    if (info.state != VIR_DOMAIN_CONTROL_OK &&
+        info.state != VIR_DOMAIN_CONTROL_ERROR) {
+        vshPrint(ctl, "%s (%0.3fs)\n",
+                 _(vshDomainControlStateToString(info.state)),
+                 info.stateTime / 1000.0);
+    } else {
+        vshPrint(ctl, "%s\n",
+                 _(vshDomainControlStateToString(info.state)));
+    }
+
+cleanup:
+    virDomainFree(dom);
+    return ret;
+}
+
 /* "domblkstat" command
  */
 static const vshCmdInfo info_domblkstat[] = {
@@ -11513,6 +11561,7 @@ static const vshCmdDef domManagementCmds[] = {
 static const vshCmdDef domMonitoringCmds[] = {
     {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
     {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
+    {"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0},
     {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
     {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
     {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0},
@@ -13041,6 +13090,23 @@ vshDomainStateReasonToString(int state, int reason)
     return N_("unknown");
 }
 
+static const char *
+vshDomainControlStateToString(int state)
+{
+    switch ((virDomainControlState) state) {
+    case VIR_DOMAIN_CONTROL_OK:
+        return N_("ok");
+    case VIR_DOMAIN_CONTROL_JOB:
+        return N_("background job");
+    case VIR_DOMAIN_CONTROL_OCCUPIED:
+        return N_("occupied");
+    case VIR_DOMAIN_CONTROL_ERROR:
+        return N_("error");
+    }
+
+    return N_("unknown");
+}
+
 static const char *
 vshDomainVcpuStateToString(int state)
 {
index c6879cb7daf03476040b95ee5b90ed147f66ca98..755f34a5f9b51c7c208b4b5741f89d57ac7e1ea7 100644 (file)
@@ -463,6 +463,12 @@ Convert a domain Id (or UUID) to domain name
 Returns state about a domain.  I<--reason> tells virsh to also print
 reason for the state.
 
+=item B<domcontrol> I<domain-id>
+
+Returns state of an interface to VMM used to control a domain.  For
+states other than "ok" or "error" the command also prints number of
+seconds elapsed since the control interface entered its current state.
+
 =item B<domxml-from-native> I<format> I<config>
 
 Convert the file I<config> in the native guest configuration format