summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kraft <george.kraft@calxeda.com>2012-08-08 14:47:03 -0500
committerGeorge Kraft <george.kraft@calxeda.com>2012-08-08 14:47:03 -0500
commitd3bf633fb5c7c97b5f5d8aef8df2ad9594758aef (patch)
treeface3b651439a80738bd76e4cb65a61f64afd2ff
parentf455728f1d97cac0ac82416783ba4d690a4d1447 (diff)
downloadcxmanage-d3bf633fb5c7c97b5f5d8aef8df2ad9594758aef.tar.gz
cxmanage: Add option to read hosts from a hostfile
This is specified by using a "hostfile=" entry in the hostname argument. For example, to run the info command using a file called "example_file": cxmanage info hostfile=example_file The hostfile itself can just be a simple list of entries, separated by spaces, newlines, or commas. The # character can be used for comments.
-rwxr-xr-xscripts/cxmanage37
1 files changed, 26 insertions, 11 deletions
diff --git a/scripts/cxmanage b/scripts/cxmanage
index 93faf91..3651cb2 100755
--- a/scripts/cxmanage
+++ b/scripts/cxmanage
@@ -279,19 +279,34 @@ def set_tftp(controller, args):
controller.set_internal_tftp_server()
-def add_targets(controller, args):
+def add_targets(controller, args, hosts=None):
"""add targets to controller addresses"""
- for entry in args.hostname.split(','):
- try:
- # Treat the entry as an IP range
- start, end = entry.split('-')
- for address in controller.get_addresses_in_range(start, end):
- controller.add_target(address, args.user,
+ if hosts == None:
+ hosts = args.hostname.split(',')
+
+ for entry in hosts:
+ # Check if it's a hostfile
+ if entry.startswith('hostfile='):
+ try:
+ hostfile_entries = []
+ for line in open(entry[9:]):
+ elements = line.partition('#')[0].split()
+ for element in elements:
+ hostfile_entries.extend(element.split(','))
+ add_targets(controller, args, hostfile_entries)
+ except IOError:
+ print 'ERROR: %s is not a valid hostfile entry' % entry
+ sys.exit(1)
+ else:
+ # Not a hostfile, is it an IP range?
+ try:
+ start, end = entry.split('-')
+ addresses = controller.get_addresses_in_range(start, end)
+ add_targets(controller, args, addresses)
+ except ValueError:
+ # Not a hostfile or IP range, add it as a regular host
+ controller.add_target(entry, args.user,
args.password, args.all_nodes)
- except ValueError:
- # Not an IP range, just add the host directly
- controller.add_target(entry, args.user,
- args.password, args.all_nodes)
def power_command(controller, args):