2012-07-23 06:15:55 +00:00
|
|
|
/*
|
2012-08-20 22:56:03 +00:00
|
|
|
* virsh-nwfilter.c: Commands to manage network filters
|
2012-07-23 06:15:55 +00:00
|
|
|
*
|
2016-01-09 13:36:29 +00:00
|
|
|
* Copyright (C) 2005, 2007-2016 Red Hat, Inc.
|
2012-07-23 06:15:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-23 06:15:55 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
* Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-08-20 22:56:03 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include "virsh-nwfilter.h"
|
2012-07-23 06:15:55 +00:00
|
|
|
|
2012-08-20 22:56:03 +00:00
|
|
|
#include "internal.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2013-05-09 18:59:04 +00:00
|
|
|
#include "virfile.h"
|
2012-12-13 17:44:57 +00:00
|
|
|
#include "virutil.h"
|
2012-08-20 22:56:03 +00:00
|
|
|
|
|
|
|
virNWFilterPtr
|
2015-06-15 16:53:58 +00:00
|
|
|
virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
|
|
|
|
const char **name, unsigned int flags)
|
2012-07-23 06:15:55 +00:00
|
|
|
{
|
|
|
|
virNWFilterPtr nwfilter = NULL;
|
|
|
|
const char *n = NULL;
|
|
|
|
const char *optname = "nwfilter";
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
|
|
|
|
|
|
|
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
|
2012-08-20 22:56:03 +00:00
|
|
|
|
2013-01-21 17:18:41 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
2012-07-23 06:15:55 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n",
|
|
|
|
cmd->def->name, optname, n);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
*name = n;
|
|
|
|
|
|
|
|
/* try it by UUID */
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
|
2012-07-23 06:15:55 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n",
|
|
|
|
cmd->def->name, optname);
|
2015-06-15 16:53:58 +00:00
|
|
|
nwfilter = virNWFilterLookupByUUIDString(priv->conn, n);
|
2012-07-23 06:15:55 +00:00
|
|
|
}
|
|
|
|
/* try it by NAME */
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!nwfilter && (flags & VIRSH_BYNAME)) {
|
2012-07-23 06:15:55 +00:00
|
|
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n",
|
|
|
|
cmd->def->name, optname);
|
2015-06-15 16:53:58 +00:00
|
|
|
nwfilter = virNWFilterLookupByName(priv->conn, n);
|
2012-07-23 06:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nwfilter)
|
|
|
|
vshError(ctl, _("failed to get nwfilter '%s'"), n);
|
|
|
|
|
|
|
|
return nwfilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "nwfilter-define" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_nwfilter_define[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("define or update a network filter from an XML file")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Define a new network filter or update an existing one.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_nwfilter_define[] = {
|
2016-01-09 13:36:29 +00:00
|
|
|
VIRSH_COMMON_OPT_FILE(N_("file containing an XML network "
|
|
|
|
"filter description")),
|
2013-01-14 14:32:22 +00:00
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virNWFilterPtr nwfilter;
|
|
|
|
const char *from = NULL;
|
|
|
|
bool ret = true;
|
|
|
|
char *buffer;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-23 06:15:55 +00:00
|
|
|
|
2013-01-21 17:18:41 +00:00
|
|
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
2012-07-23 06:15:55 +00:00
|
|
|
return false;
|
|
|
|
|
virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-19 04:10:17 +00:00
|
|
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
|
2012-07-23 06:15:55 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
nwfilter = virNWFilterDefineXML(priv->conn, buffer);
|
2012-07-23 06:15:55 +00:00
|
|
|
VIR_FREE(buffer);
|
|
|
|
|
|
|
|
if (nwfilter != NULL) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Network filter %s defined from %s\n"),
|
|
|
|
virNWFilterGetName(nwfilter), from);
|
2012-07-23 06:15:55 +00:00
|
|
|
virNWFilterFree(nwfilter);
|
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to define network filter from %s"), from);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "nwfilter-undefine" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_nwfilter_undefine[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("undefine a network filter")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Undefine a given network filter.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_nwfilter_undefine[] = {
|
2013-01-14 14:32:22 +00:00
|
|
|
{.name = "nwfilter",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("network filter name or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virNWFilterPtr nwfilter;
|
|
|
|
bool ret = true;
|
|
|
|
const char *name;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, &name)))
|
2012-07-23 06:15:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (virNWFilterUndefine(nwfilter) == 0) {
|
2016-08-24 14:14:23 +00:00
|
|
|
vshPrintExtra(ctl, _("Network filter %s undefined\n"), name);
|
2012-07-23 06:15:55 +00:00
|
|
|
} else {
|
|
|
|
vshError(ctl, _("Failed to undefine network filter %s"), name);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virNWFilterFree(nwfilter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "nwfilter-dumpxml" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_nwfilter_dumpxml[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("network filter information in XML")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Output the network filter information as an XML dump to stdout.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_nwfilter_dumpxml[] = {
|
2013-01-14 14:32:22 +00:00
|
|
|
{.name = "nwfilter",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("network filter name or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
virNWFilterPtr nwfilter;
|
|
|
|
bool ret = true;
|
|
|
|
char *dump;
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL)))
|
2012-07-23 06:15:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
dump = virNWFilterGetXMLDesc(nwfilter, 0);
|
|
|
|
if (dump != NULL) {
|
|
|
|
vshPrint(ctl, "%s", dump);
|
|
|
|
VIR_FREE(dump);
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virNWFilterFree(nwfilter);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-05 06:02:07 +00:00
|
|
|
static int
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterSorter(const void *a, const void *b)
|
2012-09-05 06:02:07 +00:00
|
|
|
{
|
|
|
|
virNWFilterPtr *fa = (virNWFilterPtr *) a;
|
|
|
|
virNWFilterPtr *fb = (virNWFilterPtr *) b;
|
|
|
|
|
|
|
|
if (*fa && !*fb)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!*fa)
|
|
|
|
return *fb != NULL;
|
|
|
|
|
|
|
|
return vshStrcasecmp(virNWFilterGetName(*fa),
|
|
|
|
virNWFilterGetName(*fb));
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
struct virshNWFilterList {
|
2012-09-05 06:02:07 +00:00
|
|
|
virNWFilterPtr *filters;
|
|
|
|
size_t nfilters;
|
|
|
|
};
|
2015-06-15 16:53:58 +00:00
|
|
|
typedef struct virshNWFilterList *virshNWFilterListPtr;
|
2012-09-05 06:02:07 +00:00
|
|
|
|
|
|
|
static void
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterListFree(virshNWFilterListPtr list)
|
2012-09-05 06:02:07 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-09-05 06:02:07 +00:00
|
|
|
|
2013-08-27 11:27:50 +00:00
|
|
|
if (list && list->filters) {
|
2012-09-05 06:02:07 +00:00
|
|
|
for (i = 0; i < list->nfilters; i++) {
|
|
|
|
if (list->filters[i])
|
|
|
|
virNWFilterFree(list->filters[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(list->filters);
|
|
|
|
}
|
|
|
|
VIR_FREE(list);
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
static virshNWFilterListPtr
|
|
|
|
virshNWFilterListCollect(vshControl *ctl,
|
|
|
|
unsigned int flags)
|
2012-09-05 06:02:07 +00:00
|
|
|
{
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-09-05 06:02:07 +00:00
|
|
|
int ret;
|
|
|
|
virNWFilterPtr filter;
|
|
|
|
bool success = false;
|
|
|
|
size_t deleted = 0;
|
|
|
|
int nfilters = 0;
|
|
|
|
char **names = NULL;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-09-05 06:02:07 +00:00
|
|
|
|
|
|
|
/* try the list with flags support (0.10.2 and later) */
|
2015-06-15 16:53:58 +00:00
|
|
|
if ((ret = virConnectListAllNWFilters(priv->conn,
|
2012-09-05 06:02:07 +00:00
|
|
|
&list->filters,
|
|
|
|
flags)) >= 0) {
|
|
|
|
list->nfilters = ret;
|
|
|
|
goto finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the command is actually supported */
|
|
|
|
if (last_error && last_error->code == VIR_ERR_NO_SUPPORT) {
|
|
|
|
vshResetLibvirtError();
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there was an error during the call */
|
|
|
|
vshError(ctl, "%s", _("Failed to list node filters"));
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
fallback:
|
2012-09-05 06:02:07 +00:00
|
|
|
/* fall back to old method (0.9.13 and older) */
|
|
|
|
vshResetLibvirtError();
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
nfilters = virConnectNumOfNWFilters(priv->conn);
|
2012-09-05 06:02:07 +00:00
|
|
|
if (nfilters < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to count network filters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nfilters == 0)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
names = vshMalloc(ctl, sizeof(char *) * nfilters);
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
nfilters = virConnectListNWFilters(priv->conn, names, nfilters);
|
2012-09-05 06:02:07 +00:00
|
|
|
if (nfilters < 0) {
|
|
|
|
vshError(ctl, "%s", _("Failed to list network filters"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->filters = vshMalloc(ctl, sizeof(virNWFilterPtr) * nfilters);
|
|
|
|
list->nfilters = 0;
|
|
|
|
|
|
|
|
/* get the network filters */
|
2013-05-21 07:44:53 +00:00
|
|
|
for (i = 0; i < nfilters; i++) {
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(filter = virNWFilterLookupByName(priv->conn, names[i])))
|
2012-09-05 06:02:07 +00:00
|
|
|
continue;
|
|
|
|
list->filters[list->nfilters++] = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* truncate network filters that weren't found */
|
|
|
|
deleted = nfilters - list->nfilters;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
finished:
|
2012-09-05 06:02:07 +00:00
|
|
|
/* sort the list */
|
|
|
|
if (list->filters && list->nfilters)
|
|
|
|
qsort(list->filters, list->nfilters,
|
2015-06-15 16:53:58 +00:00
|
|
|
sizeof(*list->filters), virshNWFilterSorter);
|
2012-09-05 06:02:07 +00:00
|
|
|
|
|
|
|
/* truncate the list for not found filter objects */
|
|
|
|
if (deleted)
|
|
|
|
VIR_SHRINK_N(list->filters, list->nfilters, deleted);
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
for (i = 0; nfilters != -1 && i < nfilters; i++)
|
2012-09-05 06:02:07 +00:00
|
|
|
VIR_FREE(names[i]);
|
|
|
|
VIR_FREE(names);
|
|
|
|
|
|
|
|
if (!success) {
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterListFree(list);
|
2012-09-05 06:02:07 +00:00
|
|
|
list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2012-07-23 06:15:55 +00:00
|
|
|
/*
|
|
|
|
* "nwfilter-list" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_nwfilter_list[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("list network filters")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Returns list of network filters.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_nwfilter_list[] = {
|
2013-01-14 14:32:22 +00:00
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-07-23 06:15:55 +00:00
|
|
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterListPtr list = NULL;
|
2012-07-23 06:15:55 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
if (!(list = virshNWFilterListCollect(ctl, 0)))
|
2012-07-23 06:15:55 +00:00
|
|
|
return false;
|
|
|
|
|
2013-11-12 16:30:48 +00:00
|
|
|
vshPrintExtra(ctl, " %-36s %-20s \n", _("UUID"), _("Name"));
|
|
|
|
vshPrintExtra(ctl, "---------------------------------"
|
|
|
|
"---------------------------------\n");
|
2012-07-23 06:15:55 +00:00
|
|
|
|
2012-09-05 06:02:07 +00:00
|
|
|
for (i = 0; i < list->nfilters; i++) {
|
|
|
|
virNWFilterPtr nwfilter = list->filters[i];
|
2012-07-23 06:15:55 +00:00
|
|
|
|
|
|
|
virNWFilterGetUUIDString(nwfilter, uuid);
|
2013-11-12 16:30:48 +00:00
|
|
|
vshPrint(ctl, " %-36s %-20s\n",
|
2012-07-23 06:15:55 +00:00
|
|
|
uuid,
|
|
|
|
virNWFilterGetName(nwfilter));
|
|
|
|
}
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
virshNWFilterListFree(list);
|
2012-07-23 06:15:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "nwfilter-edit" command
|
|
|
|
*/
|
|
|
|
static const vshCmdInfo info_nwfilter_edit[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "help",
|
|
|
|
.data = N_("edit XML configuration for a network filter")
|
|
|
|
},
|
|
|
|
{.name = "desc",
|
|
|
|
.data = N_("Edit the XML configuration for a network filter.")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const vshCmdOptDef opts_nwfilter_edit[] = {
|
2013-01-14 14:32:22 +00:00
|
|
|
{.name = "nwfilter",
|
|
|
|
.type = VSH_OT_DATA,
|
|
|
|
.flags = VSH_OFLAG_REQ,
|
|
|
|
.help = N_("network filter name or uuid")
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 06:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
virNWFilterPtr nwfilter = NULL;
|
|
|
|
virNWFilterPtr nwfilter_edited = NULL;
|
2015-06-15 16:53:58 +00:00
|
|
|
virshControlPtr priv = ctl->privData;
|
2012-07-23 06:15:55 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
|
2012-07-23 06:15:55 +00:00
|
|
|
if (nwfilter == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
#define EDIT_GET_XML virNWFilterGetXMLDesc(nwfilter, 0)
|
2014-11-14 14:57:17 +00:00
|
|
|
#define EDIT_NOT_CHANGED \
|
|
|
|
do { \
|
2016-11-04 14:22:26 +00:00
|
|
|
vshPrintExtra(ctl, _("Network filter %s XML " \
|
2014-11-14 14:57:17 +00:00
|
|
|
"configuration not changed.\n"), \
|
|
|
|
virNWFilterGetName(nwfilter)); \
|
|
|
|
ret = true; \
|
|
|
|
goto edit_cleanup; \
|
|
|
|
} while (0)
|
2012-07-23 06:15:55 +00:00
|
|
|
#define EDIT_DEFINE \
|
2015-06-15 16:53:58 +00:00
|
|
|
(nwfilter_edited = virNWFilterDefineXML(priv->conn, doc_edited))
|
2012-07-23 06:15:55 +00:00
|
|
|
#include "virsh-edit.c"
|
|
|
|
|
2016-11-04 14:22:26 +00:00
|
|
|
vshPrintExtra(ctl, _("Network filter %s XML configuration edited.\n"),
|
|
|
|
virNWFilterGetName(nwfilter_edited));
|
2012-07-23 06:15:55 +00:00
|
|
|
|
|
|
|
ret = true;
|
|
|
|
|
2014-03-25 06:53:59 +00:00
|
|
|
cleanup:
|
2012-07-23 06:15:55 +00:00
|
|
|
if (nwfilter)
|
|
|
|
virNWFilterFree(nwfilter);
|
|
|
|
if (nwfilter_edited)
|
|
|
|
virNWFilterFree(nwfilter_edited);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-07-23 07:19:04 +00:00
|
|
|
|
2012-08-20 22:56:03 +00:00
|
|
|
const vshCmdDef nwfilterCmds[] = {
|
2013-02-07 15:25:10 +00:00
|
|
|
{.name = "nwfilter-define",
|
|
|
|
.handler = cmdNWFilterDefine,
|
|
|
|
.opts = opts_nwfilter_define,
|
|
|
|
.info = info_nwfilter_define,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "nwfilter-dumpxml",
|
|
|
|
.handler = cmdNWFilterDumpXML,
|
|
|
|
.opts = opts_nwfilter_dumpxml,
|
|
|
|
.info = info_nwfilter_dumpxml,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "nwfilter-edit",
|
|
|
|
.handler = cmdNWFilterEdit,
|
|
|
|
.opts = opts_nwfilter_edit,
|
|
|
|
.info = info_nwfilter_edit,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "nwfilter-list",
|
|
|
|
.handler = cmdNWFilterList,
|
|
|
|
.opts = opts_nwfilter_list,
|
|
|
|
.info = info_nwfilter_list,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = "nwfilter-undefine",
|
|
|
|
.handler = cmdNWFilterUndefine,
|
|
|
|
.opts = opts_nwfilter_undefine,
|
|
|
|
.info = info_nwfilter_undefine,
|
|
|
|
.flags = 0
|
|
|
|
},
|
|
|
|
{.name = NULL}
|
2012-07-23 07:19:04 +00:00
|
|
|
};
|