Merge branch 'upstreammaster'
[sfa.git] / sfa / client / sfiDeleteAttribute.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
7 command = Commands(usage="%prog [options] [node1 node2...]",
8                    description="Delete sliver attributes from the RSpec. " +
9                    "This command reads in an RSpec and outputs a modified " +
10                    "RSpec. Use this to remove attributes from nodes " +
11                    "in your slice.  If no nodes are specified, the " +
12                    "attributes will be removed from ALL nodes.",
13                    epilog="NOTE: Only admins can actually set these " +
14                    "attributes, with the exception of --delegations")
15 command.add_nodefile_option()
16 command.add_attribute_options()
17 command.prep()
18
19 if command.opts.infile:
20     attrs = command.get_attribute_dict()
21     rspec = RSpec(command.opts.infile)
22     nodes = []
23     if command.opts.nodefile:
24         f = open(command.opts.nodefile, "r")
25         nodes = f.read().split()
26         f.close()
27
28
29     for name in attrs:
30         print >> sys.stderr, name, attrs[name]
31         for value in attrs[name]:
32             if not nodes:
33                 try:
34                     rspec.version.remove_default_sliver_attribute(name, value)
35                 except:
36                     print >> sys.stderr, "FAILED: on all nodes: %s=%s" % (name, value)
37             else:
38                 for node in nodes:
39                     try:
40                         rspec.version.remove_sliver_attribute(node, name, value)
41                     except:
42                         print >> sys.stderr, "FAILED: on node %s: %s=%s" % (node, name, value)
43
44     print rspec.toxml()