fix case of Sfav1Sliver
[sfa.git] / sfa / client / sfiAddSliver.py
index be1c51c..84ffa8b 100755 (executable)
@@ -1,8 +1,13 @@
 #! /usr/bin/env python
 
 import sys
-from sfa.util.rspecHelper import RSpec, Commands
 
+from sfa.util.sfalogging import logger
+from sfa.client.sfi_commands import Commands
+from sfa.rspecs.rspec import RSpec
+from sfa.rspecs.version_manager import VersionManager
+
+logger.enable_console()
 command = Commands(usage="%prog [options] node1 node2...",
                    description="Add slivers to the RSpec. " +
                    "This command reads in an RSpec and outputs a modified " +
@@ -10,13 +15,31 @@ command = Commands(usage="%prog [options] node1 node2...",
 command.add_nodefile_option()
 command.prep()
 
-for node in command.nodes:
-    try:
-        command.rspec.add_sliver(node)
-    except:
-        print >> sys.stderr, "FAILED: %s" % node
-
-print command.rspec
-    
-
+if not command.opts.nodefile:
+    print "Missing node list -- exiting"
+    command.parser.print_help()
+    sys.exit(1)
     
+if command.opts.infile:
+    infile=file(command.opts.infile)
+else:
+    infile=sys.stdin
+if command.opts.outfile:
+    outfile=file(command.opts.outfile,"w")
+else:
+    outfile=sys.stdout
+ad_rspec = RSpec(infile)
+nodes = file(command.opts.nodefile).read().split()
+version_manager = VersionManager()
+try:
+    type = ad_rspec.version.type
+    version_num = ad_rspec.version.version
+    request_version = version_manager._get_version(type, version_num, 'request')    
+    request_rspec = RSpec(version=request_version)
+    request_rspec.version.merge(ad_rspec)
+    request_rspec.version.add_slivers(nodes)
+except:
+    logger.log_exc("sfiAddSliver failed with nodes %s" % nodes)
+    sys.exit(1)
+print >>outfile, request_rspec.toxml()
+sys.exit(0)