From 4e4b6b7a3c097dde4d4e7ee5d7082174ebb7de7d Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Date: Mon, 4 Jun 2012 23:52:31 +0300
Subject: [PATCH] Include networks in Makefile and bash completion

Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 Makefile.am                     |  4 ++++
 autotools/build-bash-completion | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 0d90702df..b1e8ee9de 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -263,6 +263,7 @@ pkgpython_PYTHON = \
 	lib/storage.py \
 	lib/uidpool.py \
 	lib/vcluster.py \
+	lib/network.py \
 	lib/workerpool.py
 
 client_PYTHON = \
@@ -274,6 +275,7 @@ client_PYTHON = \
 	lib/client/gnt_instance.py \
 	lib/client/gnt_job.py \
 	lib/client/gnt_node.py \
+	lib/client/gnt_network.py \
 	lib/client/gnt_os.py
 
 hypervisor_PYTHON = \
@@ -591,6 +593,7 @@ gnt_scripts = \
 	scripts/gnt-group \
 	scripts/gnt-instance \
 	scripts/gnt-job \
+	scripts/gnt-network \
 	scripts/gnt-node \
 	scripts/gnt-os
 
@@ -796,6 +799,7 @@ man_MANS = \
 	man/gnt-cluster.8 \
 	man/gnt-debug.8 \
 	man/gnt-group.8 \
+	man/gnt-network.8 \
 	man/gnt-instance.8 \
 	man/gnt-job.8 \
 	man/gnt-node.8 \
diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion
index 511f52199..c48430003 100755
--- a/autotools/build-bash-completion
+++ b/autotools/build-bash-completion
@@ -135,6 +135,15 @@ def WritePreamble(sw, support_debug):
     sw.DecIndent()
   sw.Write("}")
 
+  sw.Write("_ganeti_network() {")
+  sw.IncIndent()
+  try:
+    networks_path = os.path.join(pathutils.DATA_DIR, "ssconf_networks")
+    sw.Write("cat %s 2>/dev/null || :", utils.ShellQuote(networks_path))
+  finally:
+    sw.DecIndent()
+  sw.Write("}")
+
   # Params: <offset> <options with values> <options without values>
   # Result variable: $first_arg_idx
   sw.Write("_ganeti_find_first_arg() {")
@@ -352,6 +361,8 @@ class CompletionWriter:
           WriteCompReply(sw, "-W \"$(_ganeti_iallocator)\"", cur=cur)
         elif suggest == cli.OPT_COMPL_ONE_NODEGROUP:
           WriteCompReply(sw, "-W \"$(_ganeti_nodegroup)\"", cur=cur)
+        elif suggest == cli.OPT_COMPL_ONE_NETWORK:
+          WriteCompReply(sw, "-W \"$(_ganeti_network)\"", cur=cur)
         elif suggest == cli.OPT_COMPL_INST_ADD_NODES:
           sw.Write("local tmp= node1= pfx= curvalue=\"${optcur#*:}\"")
 
@@ -450,6 +461,8 @@ class CompletionWriter:
           choices = "$(_ganeti_nodes)"
         elif isinstance(arg, cli.ArgGroup):
           choices = "$(_ganeti_nodegroup)"
+        elif isinstance(arg, cli.ArgNetwork):
+          choices = "$(_ganeti_network)"
         elif isinstance(arg, cli.ArgJobId):
           choices = "$(_ganeti_jobs)"
         elif isinstance(arg, cli.ArgOs):
-- 
GitLab