1016b90f4c7c4255edbc35c8d2ecf3af81dd6912
[sfa.git] / sfa / client / sfiAddSliver.py
1 #! /usr/bin/env python
2
3 import sys
4 from sfa.client.sfi_commands import Commands
5 from sfa.rspecs.rspec_parser import parse_rspec
6
7 command = Commands(usage="%prog [options] node1 node2...",
8                    description="Add slivers to the RSpec. " +
9                    "This command reads in an RSpec and outputs a modified " +
10                    "RSpec. Use this to add nodes to your slice.")
11 command.add_nodefile_option()
12 command.prep()
13
14 if not command.opts.nodefile:
15     print "Missing node list -- exiting"
16     command.parser.print_help()
17     sys.exit(1)
18     
19 if command.opts.infile:
20     infile=file(command.opts.infile)
21 else:
22     infile=sys.stdin
23 if command.opts.outfile:
24     outfile=file(command.opts.outfile,"w")
25 else:
26     outfile=sys.stdout
27
28 rspec = parse_rspec(infile)
29 nodes = file(command.opts.nodefile).read().split()
30 try:
31     rspec.add_slivers(nodes)
32 except:
33     print >> sys.stderr, "FAILED: %s" % nodes
34 print >>outfile, rspec.toxml()