3 # Register the monitor user with your instance of PLC.
5 # NOTE: Need some way of collecting information about where the target PLC is
6 # located. Clearly this script needs to be run by someone with ADMIN
7 # privilges in order to setup an ssh key, add a user, and upload the key to
8 # the user, make the user a member of the PLC site, etc.
16 Create a file named: 'auth.py' which contains two variables:
18 plc = "https://yourplc.hostname.org/PLCAPI/"
19 auth = {'Username': 'root@localhost.localdomain',
20 'AuthMethod': 'password',
28 def filevalue(filename):
29 f = open(filename, 'r')
34 api = plc.PLC(auth.auth, auth.plc)
36 # Add user : 'Site', 'Assistant', 'monitor@planet-lab.org'
37 person = { 'first_name': 'Site',
38 'last_name' : 'Assistant',
39 'email' : 'monitor@planet-lab.org',
40 'url' : 'http://monitor.planet-lab.org', }
41 ret = api.GetPersons(person['email'], ['person_id'])
43 # entry does not exist in Database, so Add it.
44 id = api.AddPerson(person)
47 id = ret[0]['person_id']
50 if not os.path.exists("%s.pub" % keyname):
51 keyname = "monitor_rsa"
52 print "Creating ssh key pair for %s" % person['email']
53 os.system("ssh-keygen -t rsa -b 2048 -f %s < /dev/null" % keyname)
55 if not os.path.exists("%s.pub" % keyname):
56 print "Error generating public/private key pair."
57 print "Please try running the command manually."
58 print "ssh-keygen -t rsa -b 2048 -f %s < /dev/null" % keyname
62 keys = api.GetKeys({ 'person_id' : id })
64 key_id = api.AddPersonKey(id, { 'key_type' : 'ssh',
65 'key' : filevalue("%s.pub" % keyname)} )
67 key_id = keys[0]['key_id']
69 # Copy private key into the directory from which the monitor scripts will be
71 ### os.system("cp %s /usr/local/monitor/keys" % keyname)
73 # Add cron entries to periodically poll nodes, and PCUs.
74 ### os.system("crontab ---")