remove --id/name from virsh

This commit is contained in:
Karel Zak 2005-12-15 17:00:43 +00:00
parent 5b282f0e10
commit 4dcc4c2d8b
2 changed files with 86 additions and 120 deletions

View File

@ -1,3 +1,9 @@
Thu Dec 15 17:56:27 CET 2005 Karel Zak <kzak@redhat.com>
* src/virsh.c: remove --id / --name options
* include/libvir.h: add missing declaration of virDomainGetXMLDesc()
Wed Dec 14 16:28:24 CET 2005 Daniel Veillard <veillard@redhat.com> Wed Dec 14 16:28:24 CET 2005 Daniel Veillard <veillard@redhat.com>
* src/xml.c: add dump of os/boot informations * src/xml.c: add dump of os/boot informations

View File

@ -178,9 +178,12 @@ static vshCmdOpt *vshCommandOpt(vshCmd *cmd, const char *name);
static int vshCommandOptInt(vshCmd *cmd, const char *name, int *found); static int vshCommandOptInt(vshCmd *cmd, const char *name, int *found);
static char *vshCommandOptString(vshCmd *cmd, const char *name, int *found); static char *vshCommandOptString(vshCmd *cmd, const char *name, int *found);
static int vshCommandOptBool(vshCmd *cmd, const char *name); static int vshCommandOptBool(vshCmd *cmd, const char *name);
static virDomainPtr vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name);
static void vshPrint(vshControl *ctl, vshOutType out, const char *format, ...); static void vshPrint(vshControl *ctl, vshOutType out, const char *format, ...);
static const char *vshDomainStateToString(int state); static const char *vshDomainStateToString(int state);
static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror); static int vshConnectionUsability(vshControl *ctl, virConnectPtr conn, int showerror);
@ -313,38 +316,27 @@ cmdList(vshControl *ctl, vshCmd *cmd ATTRIBUTE_UNUSED) {
* "dstate" command * "dstate" command
*/ */
static vshCmdInfo info_dstate[] = { static vshCmdInfo info_dstate[] = {
{ "syntax", "dstate [--id <number> | --name <string> ]" }, { "syntax", "dstate <domain>" },
{ "help", "domain state" }, { "help", "domain state" },
{ "desc", "Returns state about the domain." }, { "desc", "Returns state about a running domain." },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_dstate[] = { static vshCmdOptDef opts_dstate[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" }, { NULL, 0, 0, NULL }
{ NULL, 0, 0, NULL }
}; };
static int static int
cmdDstate(vshControl *ctl, vshCmd *cmd) { cmdDstate(vshControl *ctl, vshCmd *cmd) {
virDomainInfo info; virDomainInfo info;
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; int ret = TRUE;
char *name = vshCommandOptString(cmd, "name", NULL);
int id = vshCommandOptInt(cmd, "id", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
if (virDomainGetInfo(dom, &info)==0) if (virDomainGetInfo(dom, &info)==0)
@ -360,44 +352,31 @@ cmdDstate(vshControl *ctl, vshCmd *cmd) {
* "suspend" command * "suspend" command
*/ */
static vshCmdInfo info_suspend[] = { static vshCmdInfo info_suspend[] = {
{ "syntax", "suspend [--id <number> | --name <string> ]" }, { "syntax", "suspend <domain>" },
{ "help", "domain state" }, { "help", "suspend a domain" },
{ "desc", "Suspend a running domain." }, { "desc", "Suspend a running domain." },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_suspend[] = { static vshCmdOptDef opts_suspend[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" }, { NULL, 0, 0, NULL }
{ NULL, 0, 0, NULL }
}; };
static int static int
cmdSuspend(vshControl *ctl, vshCmd *cmd) { cmdSuspend(vshControl *ctl, vshCmd *cmd) {
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; char *name;
char *name = vshCommandOptString(cmd, "name", NULL); int ret = TRUE;
int id = vshCommandOptInt(cmd, "id", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
if (virDomainSuspend(dom)==0) { if (virDomainSuspend(dom)==0) {
if (found) vshPrint(ctl, VSH_MESG, "Domain %s suspended\n", name);
vshPrint(ctl, VSH_MESG, "Domain %d suspended\n", found);
else
vshPrint(ctl, VSH_MESG, "Domain %s suspended\n", name);
} else { } else {
vshError(ctl, FALSE, "Failed to suspend domain\n"); vshError(ctl, FALSE, "Failed to suspend domain\n");
ret = FALSE; ret = FALSE;
@ -411,44 +390,31 @@ cmdSuspend(vshControl *ctl, vshCmd *cmd) {
* "resume" command * "resume" command
*/ */
static vshCmdInfo info_resume[] = { static vshCmdInfo info_resume[] = {
{ "syntax", "resume [--id <number> | --name <string> ]" }, { "syntax", "resume <domain>" },
{ "help", "domain state" }, { "help", "resume a domain" },
{ "desc", "Resume a previously suspended domain." }, { "desc", "Resume a previously suspended domain." },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_resume[] = { static vshCmdOptDef opts_resume[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" }, { NULL, 0, 0, NULL }
{ NULL, 0, 0, NULL }
}; };
static int static int
cmdResume(vshControl *ctl, vshCmd *cmd) { cmdResume(vshControl *ctl, vshCmd *cmd) {
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; int ret = TRUE;
char *name = vshCommandOptString(cmd, "name", NULL); char *name;
int id = vshCommandOptInt(cmd, "id", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
if (virDomainResume(dom)==0) { if (virDomainResume(dom)==0) {
if (found) vshPrint(ctl, VSH_MESG, "Domain %s resumed\n", name);
vshPrint(ctl, VSH_MESG, "Domain %d resumed\n", found);
else
vshPrint(ctl, VSH_MESG, "Domain %s resumed\n", name);
} else { } else {
vshError(ctl, FALSE, "Failed to resume domain\n"); vshError(ctl, FALSE, "Failed to resume domain\n");
ret = FALSE; ret = FALSE;
@ -462,44 +428,31 @@ cmdResume(vshControl *ctl, vshCmd *cmd) {
* "destroy" command * "destroy" command
*/ */
static vshCmdInfo info_destroy[] = { static vshCmdInfo info_destroy[] = {
{ "syntax", "destroy [--id <number> | --name <string> ]" }, { "syntax", "destroy <domain>" },
{ "help", "domain state" }, { "help", "destroy a domain" },
{ "desc", "Destroy a given domain." }, { "desc", "Destroy a given domain." },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_destroy[] = { static vshCmdOptDef opts_destroy[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" }, { NULL, 0, 0, NULL }
{ NULL, 0, 0, NULL }
}; };
static int static int
cmdDestroy(vshControl *ctl, vshCmd *cmd) { cmdDestroy(vshControl *ctl, vshCmd *cmd) {
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; int ret = TRUE;
char *name = vshCommandOptString(cmd, "name", NULL); char *name;
int id = vshCommandOptInt(cmd, "id", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
if (virDomainDestroy(dom)==0) { if (virDomainDestroy(dom)==0) {
if (found) vshPrint(ctl, VSH_MESG, "Domain %s destroyed\n", name);
vshPrint(ctl, VSH_MESG, "Domain %d destroyed\n", found);
else
vshPrint(ctl, VSH_MESG, "Domain %s destroyed\n", name);
} else { } else {
vshError(ctl, FALSE, "Failed to destroy domain\n"); vshError(ctl, FALSE, "Failed to destroy domain\n");
ret = FALSE; ret = FALSE;
@ -513,15 +466,14 @@ cmdDestroy(vshControl *ctl, vshCmd *cmd) {
* "dinfo" command * "dinfo" command
*/ */
static vshCmdInfo info_dinfo[] = { static vshCmdInfo info_dinfo[] = {
{ "syntax", "dinfo [--id <number> | --name <string> ]" }, { "syntax", "dinfo <domain>" },
{ "help", "domain information" }, { "help", "domain information" },
{ "desc", "Returns basic information about the domain." }, { "desc", "Returns basic information about the domain." },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_dinfo[] = { static vshCmdOptDef opts_dinfo[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" },
{ NULL, 0, 0, NULL } { NULL, 0, 0, NULL }
}; };
@ -529,22 +481,12 @@ static int
cmdDinfo(vshControl *ctl, vshCmd *cmd) { cmdDinfo(vshControl *ctl, vshCmd *cmd) {
virDomainInfo info; virDomainInfo info;
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; int ret = TRUE;
char *name = vshCommandOptString(cmd, "name", NULL);
int id = vshCommandOptInt(cmd, "id", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
if (virDomainGetInfo(dom, &info)==0) { if (virDomainGetInfo(dom, &info)==0) {
@ -557,12 +499,12 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):", vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):",
info.nrVirtCpu); info.nrVirtCpu);
if (info.cpuTime != 0) if (info.cpuTime != 0)
{ {
float cpuUsed = info.cpuTime; float cpuUsed = info.cpuTime;
cpuUsed /= 1000000000; cpuUsed /= 1000000000;
vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed); vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed);
} }
vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Max memory:", vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Max memory:",
@ -582,38 +524,27 @@ cmdDinfo(vshControl *ctl, vshCmd *cmd) {
* "dumpxml" command * "dumpxml" command
*/ */
static vshCmdInfo info_dumpxml[] = { static vshCmdInfo info_dumpxml[] = {
{ "syntax", "dumpxml [--id <number> | --name <string> ]" }, { "syntax", "dumpxml <name>" },
{ "help", "domain information in XML" }, { "help", "domain information in XML" },
{ "desc", "Ouput the domain informations as an XML dump to stdout" }, { "desc", "Ouput the domain informations as an XML dump to stdout" },
{ NULL, NULL } { NULL, NULL }
}; };
static vshCmdOptDef opts_dumpxml[] = { static vshCmdOptDef opts_dumpxml[] = {
{ "name", VSH_OT_STRING, 0, "domain name" }, { "domain", VSH_OT_DATA, 0, "domain name or id" },
{ "id", VSH_OT_INT, 0, "domain id" },
{ NULL, 0, 0, NULL } { NULL, 0, 0, NULL }
}; };
static int static int
cmdDumpXML(vshControl *ctl, vshCmd *cmd) { cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
virDomainPtr dom; virDomainPtr dom;
int found, ret = TRUE; int ret = TRUE;
char *name = vshCommandOptString(cmd, "name", NULL);
int id = vshCommandOptInt(cmd, "id", &found);
char *dump; char *dump;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE; return FALSE;
if (found) { if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
if (!(dom = virDomainLookupByID(ctl->conn, id)))
vshError(ctl, FALSE, "failed to get domain '%d'", id);
} else {
if (!(dom = virDomainLookupByName(ctl->conn, name)))
vshError(ctl, FALSE, "failed to get domain '%s'", name);
}
if (!dom)
return FALSE; return FALSE;
dump = virDomainGetXMLDesc(dom, 0); dump = virDomainGetXMLDesc(dom, 0);
@ -633,7 +564,7 @@ cmdDumpXML(vshControl *ctl, vshCmd *cmd) {
*/ */
static vshCmdInfo info_nameof[] = { static vshCmdInfo info_nameof[] = {
{ "syntax", "nameof <id>" }, { "syntax", "nameof <id>" },
{ "help", "convert domain Id to domain name" }, { "help", "convert a domain Id to domain name" },
{ NULL, NULL } { NULL, NULL }
}; };
@ -669,7 +600,7 @@ cmdNameof(vshControl *ctl, vshCmd *cmd) {
*/ */
static vshCmdInfo info_idof[] = { static vshCmdInfo info_idof[] = {
{ "syntax", "idof <name>" }, { "syntax", "idof <name>" },
{ "help", "convert domain name to domain Id" }, { "help", "convert a domain name to domain Id" },
{ NULL, NULL } { NULL, NULL }
}; };
@ -989,6 +920,35 @@ vshCommandOptBool(vshCmd *cmd, const char *name) {
return vshCommandOpt(cmd, name) ? TRUE : FALSE; return vshCommandOpt(cmd, name) ? TRUE : FALSE;
} }
static virDomainPtr
vshCommandOptDomain(vshControl *ctl, vshCmd *cmd, const char *optname, char **name) {
virDomainPtr dom = NULL;
char *n, *end = NULL;
int id;
if (!(n = vshCommandOptString(cmd, optname, NULL))) {
vshError(ctl, FALSE, "undefined domain name or id");
return NULL;
}
if (name)
*name = n;
/* try it by ID */
id = (int) strtol(n, &end, 10);
if (id >= 0 && end && *end=='\0')
dom = virDomainLookupByID(ctl->conn, id);
/* try it by NAME */
if (!dom)
dom = virDomainLookupByName(ctl->conn, n);
if (!dom)
vshError(ctl, FALSE, "failed to get domain '%s'", n);
return dom;
}
/* /*
* Executes command(s) and returns return code from last command * Executes command(s) and returns return code from last command
*/ */