This patch adds new action called list_pools. It has two modes of
execution, non-verbose and verbose. Non verbose, executed just with
"lnst-ctl list_pools" command, prints out pool names and their paths
in pool_name=/path/to/pool format.
For verbose mode, option -v or --verbose must be entered. It prints
pool names and their paths and in addition, it lists through all
slave machine config files in pool directories and prints their contents
in more human readable format.
Pools are acquired from all the configs lnst-ctl would use in
normal run.
list_pools action can be combined with --pools argument in both verbose
and nonverbose mode so you can filter the output as you wish.
list_pools action replaces --dump-pools option
changes in v2:
* mentioned that list_pools action replaces --dump-pools option
* used SlavePool object with new get method for getting pools instead
of calling private methods
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst-ctl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 56 insertions(+), 3 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl
index f3c2eb2..4686eb2 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -24,6 +24,7 @@ from lnst.Common.Utils import mkdir_p
from lnst.Controller.NetTestController import NetTestController, NetTestError
from lnst.Controller.NetTestController import NoMatchError
from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer
+from lnst.Controller.SlavePool import SlavePool
from lnst.Controller.XmlProcessing import XmlProcessingError
RETVAL_PASS = 0
@@ -35,7 +36,8 @@ def usage(retval=0):
"""
print "Usage: %s [OPTIONS...] ACTION [RECIPES...]" % sys.argv[0]
print ""
- print "ACTION = [ run | config_only | deconfigure | match_setup ]"
+ print "ACTION = [ run | config_only | deconfigure | match_setup | " \
+ "list_pools]"
print ""
print "OPTIONS"
print " -A, --override-alias name=value define top-level alias that " \
@@ -47,6 +49,8 @@ def usage(retval=0):
"configuration files on stdout and exits"
print " --dump-pools dumps the available machine " \
"pools and exits"
+ print " -v, --verbose verbose version of list_pools " \
+ "command"
print " -h, --help print this message"
print " -m, --no-colours disable coloured terminal output"
print " -o, --disable-pool-checks don't check the availability of
" \
@@ -67,6 +71,46 @@ def usage(retval=0):
print " -x, --result=FILE file to write xml_result"
sys.exit(retval)
+def list_pools(restrict_pools, verbose):
+ conf_pools = lnst_config.get_pools()
+ pools = {}
+ if len(restrict_pools) > 0:
+ for pool_name in restrict_pools:
+ if pool_name in conf_pools:
+ pools[pool_name] = conf_pools[pool_name]
+ elif len(restrict_pools) == 1 and os.path.isdir(pool_name):
+ pools = {"cmd_line_pool": pool_name}
+ else:
+ raise NetTestError("Pool %s does not exist!" % pool_name)
+ else:
+ pools = conf_pools
+
+ sp = SlavePool(pools, pool_checks=False)
+
+ out = ""
+ # iterate over all pools
+ sp_pools = sp.get_pools()
+ for pool_name, pool_content in sp_pools.iteritems():
+ out += "%s (%s)\n" % (pool_name, pools[pool_name])
+ # verbose output
+ if verbose:
+ # iterate over all slave machine cfgs
+ for filename, pool in pool_content.iteritems():
+ # print in human-readable format
+ out += 3*" " + filename + ".xml\n"
+ out += 5*" " + "params:\n"
+ for key in pool['params']:
+ out += 7*" " + key+" : " +
pool['params'][key] + "\n"
+ if pool['interfaces']:
+ out += 5*" " + "interfaces:\n"
+ for key in sorted(pool['interfaces']):
+ out += 7*" " + "id : " + key + "\tnetwork :
" + pool['interfaces'][key]['network'] + "\n"
+ for param in pool['interfaces'][key]['params']:
+ out += 9*" " + param+" : " +
pool['interfaces'][key]['params'][param] + "\n"
+ out += "\n"
+ # print wihout newlines on the end of string
+ print out[:-2]
+
def store_alias(alias_def, aliases_dict):
try:
name, value = alias_def.split("=")
@@ -190,7 +234,7 @@ def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
- "A:a:c:dhmoprs:t:ux:",
+ "A:a:c:dhmoprs:t:ux:v",
[
"override_alias=",
"define_alias=",
@@ -208,6 +252,7 @@ def main():
"result=",
"pools=",
"dump-pools"
+ "verbose"
]
)
except getopt.GetoptError as err:
@@ -248,6 +293,7 @@ def main():
multi_match = False
dump_config = False
dump_pools = False
+ verbose = False
pools = []
for opt, arg in opts:
if opt in ("-d", "--debug"):
@@ -286,6 +332,8 @@ def main():
pools.extend(arg.split(","))
elif opt in ("--dump-pools"):
dump_pools = True
+ elif opt in ("-v", "--verbose"):
+ verbose= True
if xslt_url != None:
lnst_config.set_option("environment", "xslt_url", xslt_url)
@@ -316,12 +364,17 @@ def main():
action = args[0]
recipes = args[1:]
- if not action in ['run', 'config_only', 'deconfigure',
'match_setup']:
+ if not action in ['run', 'config_only', 'deconfigure',
'match_setup',
+ 'list_pools']:
logging.error("Action '%s' not recognised" % action)
usage(RETVAL_ERR)
if action == 'deconfigure':
NetTestController.remove_saved_machine_config()
return 0
+ elif action == 'list_pools':
+ logging.disable(logging.CRITICAL)
+ list_pools(pools, verbose)
+ return RETVAL_PASS
if recipes == []:
logging.error("No recipe specified!")
--
2.4.11