6 def GetMyPLCURL(): return g_url
11 # Get all currently registered roles
12 g_role_names = [ role['name'] for role in GetRoles()]
15 def SetRole(level, role):
17 if role not in g_role_names:
19 g_role_names.append(role)
22 # Get list of existing tag types
23 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
24 g_known_tag_types.sort()
26 def AllPersonRoles (): return [ 'pi','user','tech' ]
28 def SetTagType(tag_type):
30 tagname=tag_type['tagname']
31 global g_known_tag_types
32 # handle 'roles' field differently
33 if 'roles' in tag_type:
34 roles=tag_type['roles']
39 if 'min_role_id' in tag_type:
40 print "WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname
41 del tag_type['min_role_id']
42 # Create/update default slice tag types
43 if tagname not in g_known_tag_types:
45 g_known_tag_types.append(tagname)
46 g_known_tag_types.sort()
48 UpdateTagType(tagname, tag_type)
49 # enforce provided roles if present
50 old_roles=GetTagTypes(tagname)[0]['roles']
51 for minus_role in set(old_roles).difference(set(roles)):
52 DeleteRoleFromTagType(minus_role,tagname)
53 for plus_role in set(roles).difference(set(old_roles)):
54 AddRoleToTagType(plus_role,tagname)
56 # something went wrong for that tagname,
57 # but don't want to break the whole startup sequence
58 print "Could not enforce tagtype %s --- beg"%tagname
61 print "Could not enforce tagtype %s --- end"%tagname
63 # Get list of existing (enabled, global) files
64 g_conf_files = GetConfFiles()
65 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
66 not conf_file['node_ids'] and \
67 not conf_file['nodegroup_ids'],
69 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
70 g_conf_files = dict(zip(g_dests, g_conf_files))
72 # Get list of existing initscripts
73 g_oldinitscripts = GetInitScripts()
74 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
75 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
77 def SetInitScript(initscript):
78 global g_oldinitscripts, g_oldinitscript_names
79 if initscript['name'] not in g_oldinitscript_names:
80 initscript_id = AddInitScript(initscript)
81 g_oldinitscript_names.append(initscript['name'])
82 initscript['initscript_id']=initscript_id
83 g_oldinitscripts[initscript['name']]=initscript
85 orig_initscript = g_oldinitscripts[initscript['name']]
86 initscript_id = orig_initscript['initscript_id']
87 UpdateInitScript(initscript_id, initscript)
89 def SetConfFile(conf_file):
90 global g_conf_files, g_dests
91 if conf_file['dest'] not in g_dests:
92 AddConfFile(conf_file)
94 orig_conf_file = g_conf_files[conf_file['dest']]
95 conf_file_id = orig_conf_file['conf_file_id']
96 UpdateConfFile(conf_file_id, conf_file)
98 def SetSlice(slice, tags):
100 # Create or Update slice
101 slice_name = slice['name']
102 slices = GetSlices([slice_name])
104 slice_id = slices[0]['slice_id']
105 if slice.has_key('name'):
107 UpdateSlice(slice_id, slice)
108 slice['name']=slice_name
111 if slice.has_key('expires'):
112 expires = slice['expires']
114 slice_id = AddSlice(slice)
116 UpdateSlice(slice_id, {'expires':expires})
118 # Get slice structure with all fields
119 slice = GetSlices([slice_name])[0]
121 # Create/delete all tags
122 # NOTE: update is not needed, since unspecified tags are deleted,
123 # and new tags are added
125 if slice['slice_tag_ids']:
126 # Delete unknown attributes
127 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
128 # ignore sliver tags, as those are custom/run-time values
129 if slice_tag['node_id'] <> None: continue
130 if (slice_tag['tagname'], slice_tag['value']) not in tags:
131 DeleteSliceTag(slice_tag['slice_tag_id'])
133 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
135 # only add slice tags that are new
136 for (name, value) in tags:
137 if (name,value) not in slice_tags:
138 AddSliceTag(slice_name, name, value)
140 # NOTE: this confirms that the user-specified tag is
141 # returned by GetSliceTags
144 # something went wrong for that tagname,
145 print "Could not create init slice %s --- beg"%slice['name']
147 traceback.print_exc()
148 print "Could not create init slice %s --- end"%slice['name']
150 def SetMessage(message):
151 messages = GetMessages([message['message_id']])
155 # let people customize their messages if they want to
157 # UpdateMessage(message['message_id'],message)
159 # Get all model names
160 g_pcu_models = [type['model'] for type in GetPCUTypes()]
162 def SetPCUType(pcu_type):
164 if 'pcu_protocol_types' in pcu_type:
165 protocol_types = pcu_type['pcu_protocol_types']
166 # Take this value out of the struct.
167 del pcu_type['pcu_protocol_types']
171 if pcu_type['model'] not in g_pcu_models:
172 # Add the name/model info into DB
173 id = AddPCUType(pcu_type)
174 # for each protocol, also add this.
175 for ptype in protocol_types:
176 AddPCUProtocolType(id, ptype)