mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 19:45:21 +00:00
Several bug fixes to list of domains. Display '-' instead of '-1' for inactive domains
This commit is contained in:
parent
4028abe6b3
commit
9302933f09
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Sun Sep 3 12:34:23 EDT 2006 Daniel Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/virsh.c: use the return value of virConnectListDomains when
|
||||||
|
iterating over list of ids/names, because it is not neccessarily
|
||||||
|
the same as the value returned by virConnectNumOfDomains. Use qsort
|
||||||
|
to sort active domains by Id, and inactive domains by name, since
|
||||||
|
there is no guarenteed sort ordering when listing domains. For inactive
|
||||||
|
domains display a '-' instead of '-1' to make it clear they have no
|
||||||
|
sensible ID number.
|
||||||
|
|
||||||
Sat Sep 2 22:28:18 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
Sat Sep 2 22:28:18 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/xen_internal.c: converting to handle the new incompatible
|
* src/xen_internal.c: converting to handle the new incompatible
|
||||||
|
53
src/virsh.c
53
src/virsh.c
@ -321,7 +321,22 @@ static vshCmdOptDef opts_list[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int domidsorter(const void *a, const void *b) {
|
||||||
|
const int *ia = (const int *)a;
|
||||||
|
const int *ib = (const int *)b;
|
||||||
|
|
||||||
|
if (*ia > *ib)
|
||||||
|
return 1;
|
||||||
|
else if (*ia < *ib)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int domnamesorter(const void *a, const void *b) {
|
||||||
|
const char **sa = (const char**)a;
|
||||||
|
const char **sb = (const char**)b;
|
||||||
|
|
||||||
|
return strcasecmp(*sa, *sb);
|
||||||
|
}
|
||||||
static int
|
static int
|
||||||
cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
@ -345,11 +360,13 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
if (maxid) {
|
if (maxid) {
|
||||||
ids = vshMalloc(ctl, sizeof(int) * maxid);
|
ids = vshMalloc(ctl, sizeof(int) * maxid);
|
||||||
|
|
||||||
if (virConnectListDomains(ctl->conn, &ids[0], maxid) < 0) {
|
if ((maxid = virConnectListDomains(ctl->conn, &ids[0], maxid)) < 0) {
|
||||||
vshError(ctl, FALSE, "failed to list active domains.");
|
vshError(ctl, FALSE, "failed to list active domains.");
|
||||||
free(ids);
|
free(ids);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsort(&ids[0], maxid, sizeof(int), domidsorter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inactive) {
|
if (inactive) {
|
||||||
@ -361,15 +378,17 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (maxname) {
|
if (maxname) {
|
||||||
names = vshMalloc(ctl, sizeof(int) * maxname);
|
names = vshMalloc(ctl, sizeof(char *) * maxname);
|
||||||
|
|
||||||
if (virConnectListDefinedDomains(ctl->conn, names, maxname) < 0) {
|
if ((maxname = virConnectListDefinedDomains(ctl->conn, names, maxname)) < 0) {
|
||||||
vshError(ctl, FALSE, "failed to list inactive domains.");
|
vshError(ctl, FALSE, "failed to list inactive domains.");
|
||||||
if (ids)
|
if (ids)
|
||||||
free(ids);
|
free(ids);
|
||||||
free(names);
|
free(names);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsort(&names[0], maxname, sizeof(char*), domnamesorter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
|
vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
|
||||||
@ -394,6 +413,7 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
for (i = 0; i < maxname; i++) {
|
for (i = 0; i < maxname; i++) {
|
||||||
int ret;
|
int ret;
|
||||||
|
unsigned int id;
|
||||||
virDomainInfo info;
|
virDomainInfo info;
|
||||||
virDomainPtr dom = virDomainLookupByName(ctl->conn, names[i]);
|
virDomainPtr dom = virDomainLookupByName(ctl->conn, names[i]);
|
||||||
|
|
||||||
@ -401,12 +421,21 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
if (!dom)
|
if (!dom)
|
||||||
continue;
|
continue;
|
||||||
ret = virDomainGetInfo(dom, &info);
|
ret = virDomainGetInfo(dom, &info);
|
||||||
|
id = virDomainGetID(dom);
|
||||||
|
|
||||||
vshPrint(ctl, "%3d %-20s %s\n",
|
if (id == ((unsigned int)-1)) {
|
||||||
virDomainGetID(dom),
|
vshPrint(ctl, "%3s %-20s %s\n",
|
||||||
|
"-",
|
||||||
names[i],
|
names[i],
|
||||||
ret <
|
ret <
|
||||||
0 ? "no state" : vshDomainStateToString(info.state));
|
0 ? "no state" : vshDomainStateToString(info.state));
|
||||||
|
} else {
|
||||||
|
vshPrint(ctl, "%3d %-20s %s\n",
|
||||||
|
id,
|
||||||
|
names[i],
|
||||||
|
ret <
|
||||||
|
0 ? "no state" : vshDomainStateToString(info.state));
|
||||||
|
}
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
}
|
}
|
||||||
if (ids)
|
if (ids)
|
||||||
@ -950,6 +979,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
|
|||||||
virDomainInfo info;
|
virDomainInfo info;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int ret = TRUE;
|
int ret = TRUE;
|
||||||
|
unsigned int id;
|
||||||
char *str, uuid[37];
|
char *str, uuid[37];
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
||||||
@ -958,7 +988,11 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
|
|||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %d\n", "Id:", virDomainGetID(dom));
|
id = virDomainGetID(dom);
|
||||||
|
if (id == ((unsigned int)-1))
|
||||||
|
vshPrint(ctl, "%-15s %s\n", "Id:", "-");
|
||||||
|
else
|
||||||
|
vshPrint(ctl, "%-15s %d\n", "Id:", id);
|
||||||
vshPrint(ctl, "%-15s %s\n", "Name:", virDomainGetName(dom));
|
vshPrint(ctl, "%-15s %s\n", "Name:", virDomainGetName(dom));
|
||||||
if (virDomainGetUUIDString(dom, &uuid[0])==0)
|
if (virDomainGetUUIDString(dom, &uuid[0])==0)
|
||||||
vshPrint(ctl, "%-15s %s\n", "UUID:", uuid);
|
vshPrint(ctl, "%-15s %s\n", "UUID:", uuid);
|
||||||
@ -1415,6 +1449,7 @@ static int
|
|||||||
cmdDomid(vshControl * ctl, vshCmd * cmd)
|
cmdDomid(vshControl * ctl, vshCmd * cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
|
unsigned int id;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1422,7 +1457,11 @@ cmdDomid(vshControl * ctl, vshCmd * cmd)
|
|||||||
VSH_DOMBYNAME|VSH_DOMBYUUID)))
|
VSH_DOMBYNAME|VSH_DOMBYUUID)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
vshPrint(ctl, "%d\n", virDomainGetID(dom));
|
id = virDomainGetID(dom);
|
||||||
|
if (id == ((unsigned int)-1))
|
||||||
|
vshPrint(ctl, "%s\n", "-");
|
||||||
|
else
|
||||||
|
vshPrint(ctl, "%d\n", id);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user