Setting tag planetlab-umts-tools-0.7-1
[planetlab-umts-tools.git] / utils / remove_from_nodegroup.py
1 #!/usr/bin/python
2
3 # remove a node from nodegroup - to be called with an argument (the ip or hostname of the plc)
4
5 import sys
6 import xmlrpclib
7
8 import sys
9 import getpass
10
11
12 sys.path.append('/usr/share/plc_api')
13
14
15 if (len(sys.argv)<2):
16         print('I need the first argument (the pi or hostname address of the plc)')
17         exit(1)
18
19 plc_ip=sys.argv[1]
20
21
22 user = raw_input('Insert your user:')
23 password= getpass.getpass('Insert your password:')
24 hostname = raw_input('Insert the node hostname:')
25 nodegroup=raw_input('Insert the group:')
26
27
28 auth = {}
29
30 auth['AuthMethod'] = 'password'
31 auth['Username'] = user
32 auth['AuthString'] = password
33
34
35 plc = xmlrpclib.ServerProxy('https://'+plc_ip+'/PLCAPI/', allow_none=True)
36
37         
38 authorized = plc.AuthCheck(auth)
39
40 if authorized:
41         print 'We are authorized!'
42         
43 node_fields = {'nodegroups' : [] }
44
45 nodes = plc.GetNodes(auth, hostname, ['node_id'])
46
47 if len(nodes)>1:
48         print 'I found  %d node with that hostname' % len(nodes)
49         exit(1)
50         
51 if len(nodes)==0:
52         print 'I haven\'t found any nodes with that hostname'
53         exit(1)
54
55 node_id=nodes[0]['node_id']
56
57 if plc.UpdateNode (auth, node_id, node_fields) != 1:
58         print "Couldn't remove from nodegroup - error in UpdateNode api";
59