[libvirt] [PATCH 11/4] virsh: split out virsh-network.c

Eric Blake eblake at redhat.com
Mon Aug 20 21:47:05 UTC 2012


Another relatively easy file split.

* tools/virsh-network.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-network.c: Likewise.
---
 tools/Makefile.am     |  2 +-
 tools/virsh-network.c | 29 ++++++++++++++++++++---------
 tools/virsh-network.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.c         |  2 +-
 4 files changed, 64 insertions(+), 11 deletions(-)
 create mode 100644 tools/virsh-network.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4d46a98..595d64a 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 b891c91..37fa3ba 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 <config.h>
+#include "virsh-network.h"

-static virNetworkPtr
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xmlsave.h>
+
+#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 0000000..b5d151c
--- /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
+ * <http://www.gnu.org/licenses/>.
+ *
+ *  Daniel Veillard <veillard at redhat.com>
+ *  Karel Zak <kzak at redhat.com>
+ *  Daniel P. Berrange <berrange at redhat.com>
+ *
+ */
+
+#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 d7fd408..2a9c673 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"
-- 
1.7.11.4




More information about the libvir-list mailing list