small bugfix. NT.
[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 import RSpec
6 from sfa.rspecs.version_manager import VersionManager
7
8 command = Commands(usage="%prog [options] node1 node2...",
9                    description="Add slivers to the RSpec. " +
10                    "This command reads in an RSpec and outputs a modified " +
11                    "RSpec. Use this to add nodes to your slice.")
12 command.add_nodefile_option()
13 command.prep()
14
15 if not command.opts.nodefile:
16     print "Missing node list -- exiting"
17     command.parser.print_help()
18     sys.exit(1)
19     
20 if command.opts.infile:
21     infile=file(command.opts.infile)
22 else:
23     infile=sys.stdin
24 if command.opts.outfile:
25     outfile=file(command.opts.outfile,"w")
26 else:
27     outfile=sys.stdout
28 request_rspec = RSpec(infile)
29 nodes = file(command.opts.nodefile).read().split()
30 version_manager = VersionManager()
31 try:
32     type = request_rspec.version.type
33     version_num = request_rspec.version.version
34     manifest_version = version_manager._get_version(type, version_num, 'manifest')    
35     manifest_rspec = RSpec(version=manifest_version)
36     slivers = [{'hostname': node} for node in nodes]
37     manifest_rspec.version.merge(request_rspec)
38     manifest_rspec.version.add_slivers(slivers)
39 except:
40     print >> sys.stderr, "FAILED: %s" % nodes
41     sys.exit(1)
42 print >>outfile, manifest_rspec.toxml()
43 sys.exit(0)