#define VSH_BYNAME (1 << 3)
static virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
- const char *optname, char **name, int flag);
+ char **name, int flag);
/* default is lookup by Id, Name and UUID */
-#define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \
- vshCommandOptDomainBy(_ctl, _cmd, _optname, _name, \
- VSH_BYID|VSH_BYUUID|VSH_BYNAME)
+#define vshCommandOptDomain(_ctl, _cmd, _name) \
+ vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME)
static virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
- const char *optname, char **name, int flag);
+ char **name, int flag);
/* default is lookup by Name and UUID */
-#define vshCommandOptNetwork(_ctl, _cmd, _optname, _name) \
- vshCommandOptNetworkBy(_ctl, _cmd, _optname, _name, \
+#define vshCommandOptNetwork(_ctl, _cmd, _name) \
+ vshCommandOptNetworkBy(_ctl, _cmd, _name, \
VSH_BYUUID|VSH_BYNAME)
static virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd,
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
autostart = !vshCommandOptBool(cmd, "disable");
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
if (virDomainGetInfo(dom, &info) == 0)
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
return FALSE;
if (!(device = vshCommandOptString (cmd, "device", NULL)))
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
return FALSE;
if (!(device = vshCommandOptString (cmd, "interface", NULL)))
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainSuspend(dom) == 0) {
virDomainFree(dom);
return FALSE;
}
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", &name,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, &name,
VSH_BYNAME|VSH_BYUUID)))
return FALSE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, VSH_BYNAME)))
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL, VSH_BYNAME)))
return FALSE;
if (virDomainGetID(dom) != (unsigned int)-1) {
if (!(to = vshCommandOptString(cmd, "file", NULL)))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainSave(dom, to) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
/* Deprecated Xen-only options */
if (!(to = vshCommandOptString(cmd, "file", NULL)))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainCoreDump(dom, to, 0) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainResume(dom) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainShutdown(dom) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainReboot(dom, 0) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainDestroy(dom) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
id = virDomainGetID(dom);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
vcpu = vshCommandOptInt(cmd, "vcpu", &vcpufound);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
count = vshCommandOptInt(cmd, "count", &count);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
dump = virDomainGetXMLDesc(dom, 0);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYID|VSH_BYUUID)))
return FALSE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYNAME|VSH_BYUUID)))
return FALSE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYNAME|VSH_BYID)))
return FALSE;
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, NULL)))
return FALSE;
desturi = vshCommandOptString (cmd, "desturi", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
autostart = !vshCommandOptBool(cmd, "disable");
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
if (virNetworkDestroy(network) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", NULL)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return FALSE;
dump = virNetworkGetXMLDesc(network, 0);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYUUID)))
return FALSE;
};
static const vshCmdOptDef opts_network_start[] = {
- {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
+ {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
{NULL, 0, 0, NULL}
};
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, VSH_BYNAME)))
return FALSE;
if (virNetworkCreate(network) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
if (virNetworkUndefine(network) == 0) {
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYNAME)))
return FALSE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
from = vshCommandOptString(cmd, "file", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
from = vshCommandOptString(cmd, "file", &found);
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(type = vshCommandOptString(cmd, "type", NULL)))
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(type = vshCommandOptString(cmd, "type", NULL)))
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(source = vshCommandOptString(cmd, "source", NULL)))
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(target = vshCommandOptString(cmd, "target", NULL)))
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- dom = vshCommandOptDomain (ctl, cmd, "domain", NULL);
+ dom = vshCommandOptDomain (ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
return vshCommandOpt(cmd, name) ? TRUE : FALSE;
}
+/* Determine whether CMD->opts includes an option with name OPTNAME.
+ If not, give a diagnostic and return false.
+ If so, return true. */
+static bool
+cmd_has_option (vshControl *ctl, const vshCmd *cmd, const char *optname)
+{
+ /* Iterate through cmd->opts, to ensure that there is an entry
+ with name OPTNAME and type VSH_OT_DATA. */
+ bool found = false;
+ const vshCmdOpt *opt;
+ for (opt = cmd->opts; opt; opt = opt->next) {
+ if (STREQ (opt->def->name, optname) && opt->def->type == VSH_OT_DATA) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ vshError(ctl, FALSE,
+ _("internal error: virsh %s: no %s VSH_OT_DATA option"),
+ cmd->def->name, optname);
+ return found;
+}
static virDomainPtr
-vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
+vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
char **name, int flag)
{
virDomainPtr dom = NULL;
char *n;
int id;
+ const char *optname = "domain";
+ if (!cmd_has_option (ctl, cmd, optname))
+ return NULL;
if (!(n = vshCommandOptString(cmd, optname, NULL))) {
vshError(ctl, FALSE, "%s", _("undefined domain name or id"));
}
static virNetworkPtr
-vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
+vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
char **name, int flag)
{
virNetworkPtr network = NULL;
char *n;
+ const char *optname = "network";
+ if (!cmd_has_option (ctl, cmd, optname))
+ return NULL;
if (!(n = vshCommandOptString(cmd, optname, NULL))) {
vshError(ctl, FALSE, "%s", _("undefined network name"));