now uses new RSpec libraries
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 28 Apr 2011 20:17:35 +0000 (16:17 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Thu, 28 Apr 2011 20:17:35 +0000 (16:17 -0400)
sfa/client/sfiAddAttribute.py

index f4e613c..0242a13 100755 (executable)
@@ -2,6 +2,8 @@
 
 import sys
 from sfa.util.rspecHelper import RSpec, Commands
+from sfa.client.sfi_commands import Commands
+from sfa.rspecs.rspec_parser import parse_rspec
 
 command = Commands(usage="%prog [options] [node1 node2...]",
                    description="Add sliver attributes to the RSpec. " +
@@ -15,19 +17,29 @@ command.add_nodefile_option()
 command.add_attribute_options()
 command.prep()
 
-attrs = command.get_attribute_dict()
-for name in attrs:
-    for value in attrs[name]:
-        if not command.nodes:
-            try:
-                command.rspec.add_default_sliver_attribute(name, value)
-            except:
-                print >> sys.stderr, "FAILED: on all nodes: %s=%s" % (name, value)
-        else:
-            for node in command.nodes:
+if command.opts.infile:
+    attrs = command.get_attribute_dict()
+    rspec = parse_rspec(command.opts.infile)
+    nodes = []
+    if command.opts.nodefile:
+        f = open(command.opts.nodefile, "r")
+        nodes = f.read().split()
+        f.close()
+
+
+    for name in attrs:
+        print >> sys.stderr, name, attrs[name]
+        for value in attrs[name]:
+            if not nodes:
                 try:
-                    command.rspec.add_sliver_attribute(node, name, value)
+                    rspec.add_default_sliver_attribute(name, value)
                 except:
-                    print >> sys.stderr, "FAILED: on node %s: %s=%s" % (node, name, value)
+                    print >> sys.stderr, "FAILED: on all nodes: %s=%s" % (name, value)
+            else:
+                for node in nodes:
+                    try:
+                        rspec.add_sliver_attribute(node, name, value)
+                    except:
+                        print >> sys.stderr, "FAILED: on node %s: %s=%s" % (node, name, value)
 
-print command.rspec
+    print rspec.toxml()