3 from monitor.wrapper import plc
7 email_list = [ 'soltesz@cs.princeton.edu',
8 # 'soltesz@cs.princeton.edu',
9 # 'justin@cs.arizona.edu',
10 # 'bakers@cs.arizona.edu',
11 # 'jhh@cs.arizona.edu',
12 # 'mfreed@cs.nyu.edu',
13 # 'kyoungso@cs.princeton.edu',
14 # 'nspring@cs.umd.edu',
15 # 'vivek@cs.princeton.edu',
18 from monitor import config
19 api = plc.PLC(plc.Auth(config.API_AUTH_USER, config.API_AUTH_PASSWORD).auth, config.API_SERVER)
20 api06 = plc.PLC(plc.Auth(config.API06_AUTH_USER, config.API06_AUTH_PASSWORD).auth, config.API06_SERVER)
22 # add planetlab-15.cs.princeton.edu, and use the key on the CD.
23 #id = api06.AddNode(1, {'boot_state': 'rins', 'model': 'Dell Optiplex',
24 # 'hostname' : 'planetlab-15.cs.princeton.edu',
26 #api06.AddNodeNetwork(id, {'ip': '128.112.139.39',
28 ## 'is_primary' : True,
29 # 'method' : 'dhcp', })
30 #api06.UpdateNode(id, {'key': "wptNagk8SgRxzN1lXfKMAjUYhQbOBymKnKg9Uv0LwGM"})
33 #print "adding vsys attributes"
34 #api06.AddSliceAttribute('princeton_slicestat', 'vsys', 'pl-ps')
35 #api06.AddSliceAttribute('princeton_slicestat', 'vsys', 'vtop')
36 #api06.AddSliceAttribute('pl_netflow', 'vsys', 'pfmount')
38 #print "preserve princeton_chopstix"
42 #attr_types = api.GetSliceAttributeTypes()
43 #attr_types06 = api06.GetSliceAttributeTypes()
44 #attr_types06_names = [a['name'] for a in attr_types06]
45 #for type in attr_types:
46 # if type['name'] not in attr_types06_names:
47 # print "adding %s " % type
48 # api06.AddSliceAttributeType(type)
49 def person_exists(user):
51 x = api06.GetPersons({'email':user['email']})
59 def site_exists(site):
61 x = api06.GetSites({'login_base':site['login_base']})
69 def slice_exists(slice):
71 x = api06.GetSlices({'name':slice['name']})
79 def node_exists(node):
80 x = api06.GetNodes({'hostname':node['hostname']})
87 slices = api06.GetSlices()
89 print "Updating expiration of %s" % slice['name']
90 api06.UpdateSlice(slice['name'], {'expires': int(time.time()) + 7*24*60*60})
94 for email in email_list:
95 user = api.GetPersons({'email': email})
97 print "User not found: %s" % email
102 print "adding person %s " % user['email']
103 if not person_exists(user):
104 api06.AddPerson(user)
106 api06.UpdatePerson(email, {'enabled': True})
108 print "adding person keys %s " % user['email']
109 key = api.GetKeys({'person_id': user['person_id']})[0]
110 key06 = {'key': key['key'], 'key_type': key['key_type']}
111 api06.AddPersonKey(user['email'], key06)
113 print "updating person roles: ",
114 for role in user['roles']:
116 api06.AddRoleToPerson(role, user['email'])
120 sites = api.GetSites(user['site_ids'])
121 print "Adding sites:",
123 nodes = api.GetNodes(site['node_ids'])
125 if not site_exists(site):
126 print "%s" % site['login_base']
128 api06.AddPersonToSite(user['email'], site['login_base'])
132 if not node_exists(node):
133 id = api06.AddNode(site['login_base'], {'boot_state': node['boot_state'],
134 'model': node['model'],
135 'hostname' : node['hostname'],
136 'version' : node['version']})
137 nnets = api.GetInterfaces(node['interface_ids'])
139 del nnet['interface_id']
140 del nnet['nodenetwork_setting_ids']
141 api06.AddNodeNetwork(id, nnet)
144 nodes = api06.GetNodes()
145 slices = api.GetSlices(user['slice_ids'])
149 if not slice_exists(slice):
150 print "Adding slice %s" % slice['name']
152 api06.AddSlice(slice)
153 attr = api.GetSliceAttributes({'slice_attribute_id' :
154 slice['slice_attribute_ids']})
155 print "adding attributes:",
158 print "%s" % a['name'],
159 #if a['name'] not in added_attr:
160 api06.AddSliceAttribute(slice['name'], a['name'], a['value'])
161 # added_attr.append(a['name'])
166 print "error with ", slice['name']
169 print "adding nodes and %s to slice %s" % (user['email'], slice['name'])
170 # add all api06 nodes to slice
171 api06.AddSliceToNodes(slice['name'], [n['hostname'] for n in nodes])
173 api06.AddPersonToSlice(user['email'], slice['name'])