3 # adds a node to a nodegroup - to be called with an argument (the ip or hostname of the plc)
12 sys.path.append('/usr/share/plc_api')
16 print('I need the first argument (the pi or hostname address of the plc)')
22 user = raw_input('Insert your user:')
23 #password= getpass('Insert your password:')
24 password = raw_input('Insert your password:')
25 hostname = raw_input('Insert the node hostname:')
26 nodegroup=raw_input('Insert the group:')
31 auth['AuthMethod'] = 'password'
32 auth['Username'] = user
33 auth['AuthString'] = password
36 plc = xmlrpclib.ServerProxy('https://'+plc_ip+'/PLCAPI/', allow_none=True)
39 authorized = plc.AuthCheck(auth)
42 print 'We are authorized!'
44 node_fields = {'nodegroups' : [nodegroup] }
46 nodes = plc.GetNodes(auth, hostname, ['node_id'])
49 print 'I found %d node with that hostname' % len(nodes)
53 print 'I haven\'t found any nodes with that hostname'
56 node_id=nodes[0]['node_id']
58 if plc.UpdateNode (auth, node_id, node_fields) != 1:
59 print "Couldn't set the nodegroup - error in UpdateNode api";