diff --git a/tools/Makefile.am b/tools/Makefile.am index 4d46a98fb66446742ed52511ac370201f4664a4d..595d64a666213c40ff4b17bdf44abd89f072b272 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -110,8 +110,8 @@ virsh_SOURCES = \ virsh-domain-monitor.c virsh-domain-monitor.h \ virsh-host.c virsh-host.h \ virsh-interface.c virsh-interface.h \ + virsh-network.c virsh-network.h \ $(NULL) -# virsh-network.c virsh-network.h \ # virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ diff --git a/tools/virsh-network.c b/tools/virsh-network.c index b891c910689258137665d767a2e1ec6e8ad33f4c..37fa3bad71c2da2d506a82b374277d12c4919d6c 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -23,18 +23,29 @@ * */ -/* default is lookup by Name and UUID */ -#define vshCommandOptNetwork(_ctl, _cmd, _name) \ - vshCommandOptNetworkBy(_ctl, _cmd, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include +#include "virsh-network.h" -static virNetworkPtr +#include +#include +#include +#include + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) + const char **name, unsigned int flags) { virNetworkPtr network = NULL; const char *n = NULL; const char *optname = "network"; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; @@ -48,13 +59,13 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, *name = n; /* try it by UUID */ - if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n", cmd->def->name, optname); network = virNetworkLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (network==NULL && (flag & VSH_BYNAME)) { + if (!network && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network NAME\n", cmd->def->name, optname); network = virNetworkLookupByName(ctl->conn, n); @@ -686,7 +697,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef networkCmds[] = { +const vshCmdDef networkCmds[] = { {"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart, 0}, {"net-create", cmdNetworkCreate, opts_network_create, diff --git a/tools/virsh-network.h b/tools/virsh-network.h new file mode 100644 index 0000000000000000000000000000000000000000..b5d151ca0b0a58dcc5a804d4672cfee5bac63d86 --- /dev/null +++ b/tools/virsh-network.h @@ -0,0 +1,42 @@ +/* + * virsh-network.c: Commands to manage network + * + * Copyright (C) 2005, 2007-2012 Red Hat, Inc. + * + * 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 + * License along with this library; If not, see + * . + * + * Daniel Veillard + * Karel Zak + * Daniel P. Berrange + * + */ + +#ifndef VIRSH_NETWORK_H +# define VIRSH_NETWORK_H + +# include "virsh.h" + +virNetworkPtr +vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +# define vshCommandOptNetwork(_ctl, _cmd, _name) \ + vshCommandOptNetworkBy(_ctl, _cmd, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef networkCmds[]; + +#endif /* VIRSH_NETWORK_H */ diff --git a/tools/virsh.c b/tools/virsh.c index d7fd408a9e9060867375f6a5999402a8f6155735..2a9c673a241a3331d8945533c39dd88e132d160a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -78,6 +78,7 @@ #include "virsh-domain-monitor.h" #include "virsh-host.h" #include "virsh-interface.h" +#include "virsh-network.h" static char *progname; @@ -2816,7 +2817,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-network.c" #include "virsh-nodedev.c" #include "virsh-nwfilter.c" #include "virsh-pool.c"