postinstall for signing pkgs - noderepo requires myplc - using Provides: on the myplc...
[myplc.git] / siriusnodes.py
1 #!/usr/bin/python
2 '''
3 Subscribes new nodes to princeton_sirius slice.
4
5 $Id$
6 '''
7 import sys
8 from sets import Set
9
10 # Load shell with default configuration
11 sys.path.append('/usr/share/plc_api')
12 from PLC.Shell import Shell
13 plc = Shell(globals())
14
15
16
17 def main(argv = None):
18         debug = False
19         allnodes = []
20         whitelist = []
21         newnodes = []
22
23         # Get All Nodes
24         for node in GetNodes(None, ['node_id']): allnodes.append(node['node_id'])
25
26         # Get WhiteListed nodes
27         for node in GetWhitelist(None, ['node_id']): whitelist.append(node['node_id'])
28
29         # Nodes already running slice
30         siriusnodes = GetSlices("princeton_sirius")[0]['node_ids']
31
32         available = Set(allnodes) - Set(whitelist)
33
34         nodestoadd = available - Set(siriusnodes)
35
36         for node in nodestoadd: newnodes.append(node)
37
38         print "Adding %s nodes to Sirius slice." % newnodes.__len__()
39         # Add to Sirius slice
40         if debug:
41                 print newnodes
42         else:
43                 AddSliceToNodes("princeton_sirius", [newnodes])