some occurrences of items() that need being converted into list()
[sfa.git] / clientbin / sfiAddSliver.py
1 #! /usr/bin/env python
2
3 import sys
4
5 from sfa.util.sfalogging import logger
6 from sfa.client.sfi_commands import Commands
7 from sfa.rspecs.rspec import RSpec
8 from sfa.rspecs.version_manager import VersionManager
9
10 logger.enable_console()
11 command = Commands(usage="%prog [options] node1 node2...",
12                    description="Add slivers to the RSpec. " +
13                    "This command reads in an RSpec and outputs a modified " +
14                    "RSpec. Use this to add nodes to your slice.")
15 command.add_nodefile_option()
16 command.prep()
17
18 if not command.opts.nodefile:
19     print "Missing node list -- exiting"
20     command.parser.print_help()
21     sys.exit(1)
22     
23 if command.opts.infile:
24     infile=file(command.opts.infile)
25 else:
26     infile=sys.stdin
27 if command.opts.outfile:
28     outfile=file(command.opts.outfile,"w")
29 else:
30     outfile=sys.stdout
31 ad_rspec = RSpec(infile)
32 nodes = file(command.opts.nodefile).read().split()
33 version_manager = VersionManager()
34 try:
35     type = ad_rspec.version.type
36     version_num = ad_rspec.version.version
37     request_version = version_manager._get_version(type, version_num, 'request')    
38     request_rspec = RSpec(version=request_version)
39     request_rspec.version.merge(ad_rspec)
40     request_rspec.version.add_slivers(nodes)
41 except:
42     logger.log_exc("sfiAddSliver failed with nodes %s" % nodes)
43     sys.exit(1)
44 print >>outfile, request_rspec.toxml()
45 sys.exit(0)