mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 05:25:18 +00:00
virsh: Insert error messages to avoid a quiet abortion of commands
in case of incorrect option parsing.
This commit is contained in:
parent
013427e6e7
commit
e6a8f9a16a
@ -706,8 +706,10 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(ctl->name);
|
VIR_FREE(ctl->name);
|
||||||
if (vshCommandOptString(cmd, "name", &name) <= 0)
|
if (vshCommandOptString(cmd, "name", &name) < 0) {
|
||||||
|
vshError(ctl, "%s", _("Please specify valid connection URI"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
ctl->name = vshStrdup(ctl, name);
|
ctl->name = vshStrdup(ctl, name);
|
||||||
|
|
||||||
if (!ro) {
|
if (!ro) {
|
||||||
@ -773,7 +775,7 @@ static int
|
|||||||
cmdConsole(vshControl *ctl, const vshCmd *cmd)
|
cmdConsole(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int ret;
|
int ret = FALSE;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
@ -782,11 +784,14 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "devname", &name) < 0)
|
if (vshCommandOptString(cmd, "devname", &name) < 0) {
|
||||||
return FALSE;
|
vshError(ctl, "%s", _("Invalid devname"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = cmdRunConsole(ctl, dom, name);
|
ret = cmdRunConsole(ctl, dom, name);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2410,8 +2415,10 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
int vcpus;
|
int vcpus;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "type", &type) < 0)
|
if (vshCommandOptString(cmd, "type", &type) < 0) {
|
||||||
|
vshError(ctl, "%s", _("Invalid type"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -2856,8 +2863,10 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (vshCommandOptInt(cmd, "count", &count) < 0)
|
if (vshCommandOptInt(cmd, "count", &count) < 0) {
|
||||||
return FALSE;
|
vshError(ctl, "%s", _("Invalid number of virtual CPUs"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!flags) {
|
if (!flags) {
|
||||||
if (virDomainSetVcpus(dom, count) != 0) {
|
if (virDomainSetVcpus(dom, count) != 0) {
|
||||||
@ -3705,8 +3714,10 @@ doMigrate (void *opaque)
|
|||||||
|
|
||||||
if (vshCommandOptString(cmd, "desturi", &desturi) <= 0 ||
|
if (vshCommandOptString(cmd, "desturi", &desturi) <= 0 ||
|
||||||
vshCommandOptString(cmd, "migrateuri", &migrateuri) < 0 ||
|
vshCommandOptString(cmd, "migrateuri", &migrateuri) < 0 ||
|
||||||
vshCommandOptString(cmd, "dname", &dname) < 0)
|
vshCommandOptString(cmd, "dname", &dname) < 0) {
|
||||||
|
vshError(ctl, "%s", _("missing argument"));
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (vshCommandOptBool (cmd, "live"))
|
if (vshCommandOptBool (cmd, "live"))
|
||||||
flags |= VIR_MIGRATE_LIVE;
|
flags |= VIR_MIGRATE_LIVE;
|
||||||
@ -5509,8 +5520,10 @@ static int buildPoolXML(const vshCmd *cmd, const char **retname, char **xml) {
|
|||||||
vshCommandOptString(cmd, "source-dev", &srcDev) < 0 ||
|
vshCommandOptString(cmd, "source-dev", &srcDev) < 0 ||
|
||||||
vshCommandOptString(cmd, "source-name", &srcName) < 0 ||
|
vshCommandOptString(cmd, "source-name", &srcName) < 0 ||
|
||||||
vshCommandOptString(cmd, "source-format", &srcFormat) < 0 ||
|
vshCommandOptString(cmd, "source-format", &srcFormat) < 0 ||
|
||||||
vshCommandOptString(cmd, "target", &target) < 0)
|
vshCommandOptString(cmd, "target", &target) < 0) {
|
||||||
|
vshError(NULL, "%s", _("missing argument"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
|
virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
|
||||||
virBufferVSprintf(&buf, " <name>%s</name>\n", name);
|
virBufferVSprintf(&buf, " <name>%s</name>\n", name);
|
||||||
@ -6314,8 +6327,10 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
if (vshCommandOptString(cmd, "type", &type) <= 0 ||
|
if (vshCommandOptString(cmd, "type", &type) <= 0 ||
|
||||||
vshCommandOptString(cmd, "host", &host) < 0 ||
|
vshCommandOptString(cmd, "host", &host) < 0 ||
|
||||||
vshCommandOptString(cmd, "initiator", &initiator) < 0)
|
vshCommandOptString(cmd, "initiator", &initiator) < 0) {
|
||||||
|
vshError(ctl,"%s", _("missing argument"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -6386,8 +6401,10 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
if (vshCommandOptString(cmd, "type", &type) <= 0)
|
if (vshCommandOptString(cmd, "type", &type) <= 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "srcSpec", &srcSpecFile) < 0)
|
if (vshCommandOptString(cmd, "srcSpec", &srcSpecFile) < 0) {
|
||||||
|
vshError(ctl, "%s", _("missing option"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -8862,8 +8879,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshCommandOptString(cmd, "target", &target) < 0 ||
|
vshCommandOptString(cmd, "target", &target) < 0 ||
|
||||||
vshCommandOptString(cmd, "mac", &mac) < 0 ||
|
vshCommandOptString(cmd, "mac", &mac) < 0 ||
|
||||||
vshCommandOptString(cmd, "script", &script) < 0 ||
|
vshCommandOptString(cmd, "script", &script) < 0 ||
|
||||||
vshCommandOptString(cmd, "model", &model) < 0)
|
vshCommandOptString(cmd, "model", &model) < 0) {
|
||||||
|
vshError(ctl, "missing argument");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/* check interface type */
|
/* check interface type */
|
||||||
if (STREQ(type, "network")) {
|
if (STREQ(type, "network")) {
|
||||||
@ -8969,8 +8988,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptString(cmd, "type", &type) <= 0)
|
if (vshCommandOptString(cmd, "type", &type) <= 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, "mac", &mac) < 0)
|
if (vshCommandOptString(cmd, "mac", &mac) < 0) {
|
||||||
|
vshError(ctl, "%s", _("missing option"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
doc = virDomainGetXMLDesc(dom, 0);
|
doc = virDomainGetXMLDesc(dom, 0);
|
||||||
if (!doc)
|
if (!doc)
|
||||||
@ -9120,6 +9141,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshCommandOptString(cmd, "type", &type) < 0 ||
|
vshCommandOptString(cmd, "type", &type) < 0 ||
|
||||||
vshCommandOptString(cmd, "mode", &mode) < 0 ||
|
vshCommandOptString(cmd, "mode", &mode) < 0 ||
|
||||||
vshCommandOptString(cmd, "sourcetype", &stype) < 0) {
|
vshCommandOptString(cmd, "sourcetype", &stype) < 0) {
|
||||||
|
vshError(ctl, "%s", _("missing option"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11272,8 +11294,10 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
if (vshCommandOptString(cmd, optname, &n) <= 0)
|
if (vshCommandOptString(cmd, optname, &n) <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (vshCommandOptString(cmd, pooloptname, &p) < 0)
|
if (vshCommandOptString(cmd, pooloptname, &p) < 0) {
|
||||||
|
vshError(ctl, "%s", _("missing option"));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flag);
|
pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flag);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user