6 def GetMyPLCURL(): return g_url
12 # Get list of existing tag types
13 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
14 g_known_tag_types.sort()
16 def AllPersonRoles (): return [ 'pi','user','tech' ]
18 def SetTagType(tag_type):
20 tagname=tag_type['tagname']
21 global g_known_tag_types
22 # handle 'roles' field differently
23 if 'roles' in tag_type:
24 roles=tag_type['roles']
29 if 'min_role_id' in tag_type:
30 print("WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname)
31 del tag_type['min_role_id']
32 # Create/update default slice tag types
33 if tagname not in g_known_tag_types:
35 g_known_tag_types.append(tagname)
36 g_known_tag_types.sort()
38 UpdateTagType(tagname, tag_type)
39 # enforce provided roles if present
40 old_roles=GetTagTypes(tagname)[0]['roles']
41 for minus_role in set(old_roles).difference(set(roles)):
42 DeleteRoleFromTagType(minus_role,tagname)
43 for plus_role in set(roles).difference(set(old_roles)):
44 AddRoleToTagType(plus_role,tagname)
46 # something went wrong for that tagname,
47 # but don't want to break the whole startup sequence
48 print("Could not enforce tagtype %s --- beg"%tagname)
51 print("Could not enforce tagtype %s --- end"%tagname)
53 # Get list of existing (enabled, global) files
54 g_conf_files = GetConfFiles()
55 g_conf_files = [conf_file for conf_file in g_conf_files if conf_file['enabled'] and \
56 not conf_file['node_ids'] and \
57 not conf_file['nodegroup_ids']]
58 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
59 g_conf_files = dict(list(zip(g_dests, g_conf_files)))
61 # Get list of existing initscripts
62 g_oldinitscripts = GetInitScripts()
63 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
64 g_oldinitscripts = dict(list(zip(g_oldinitscript_names, g_oldinitscripts)))
66 def SetInitScript(initscript):
67 global g_oldinitscripts, g_oldinitscript_names
68 if initscript['name'] not in g_oldinitscript_names:
69 initscript_id = AddInitScript(initscript)
70 g_oldinitscript_names.append(initscript['name'])
71 initscript['initscript_id']=initscript_id
72 g_oldinitscripts[initscript['name']]=initscript
74 orig_initscript = g_oldinitscripts[initscript['name']]
75 initscript_id = orig_initscript['initscript_id']
76 UpdateInitScript(initscript_id, initscript)
78 def SetConfFile(conf_file):
79 global g_conf_files, g_dests
80 if conf_file['dest'] not in g_dests:
81 AddConfFile(conf_file)
83 orig_conf_file = g_conf_files[conf_file['dest']]
84 conf_file_id = orig_conf_file['conf_file_id']
85 UpdateConfFile(conf_file_id, conf_file)
87 def SetSlice(slice, tags):
89 # Create or Update slice
90 slice_name = slice['name']
91 slices = GetSlices([slice_name])
93 slice_id = slices[0]['slice_id']
96 UpdateSlice(slice_id, slice)
97 slice['name']=slice_name
100 if 'expires' in slice:
101 expires = slice['expires']
103 slice_id = AddSlice(slice)
104 if expires is not None:
105 UpdateSlice(slice_id, {'expires':expires})
107 # Get slice structure with all fields
108 slice = GetSlices([slice_name])[0]
110 # Create/delete all tags
111 # NOTE: update is not needed, since unspecified tags are deleted,
112 # and new tags are added
114 if slice['slice_tag_ids']:
115 # Delete unknown attributes
116 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
117 # ignore sliver tags, as those are custom/run-time values
118 if slice_tag['node_id'] is not None:
120 if (slice_tag['tagname'], slice_tag['value']) not in tags:
121 DeleteSliceTag(slice_tag['slice_tag_id'])
123 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
125 # only add slice tags that are new
126 for (name, value) in tags:
127 if (name,value) not in slice_tags:
128 AddSliceTag(slice_name, name, value)
130 # NOTE: this confirms that the user-specified tag is
131 # returned by GetSliceTags
134 # something went wrong for that tagname,
135 print("Could not create init slice %s --- beg"%slice['name'])
137 traceback.print_exc()
138 print("Could not create init slice %s --- end"%slice['name'])
140 def SetMessage(message):
141 messages = GetMessages([message['message_id']])
145 # let people customize their messages if they want to
147 # UpdateMessage(message['message_id'],message)
149 # Get all model names
150 g_pcu_models = [type['model'] for type in GetPCUTypes()]
152 def SetPCUType(pcu_type):
154 if 'pcu_protocol_types' in pcu_type:
155 protocol_types = pcu_type['pcu_protocol_types']
156 # Take this value out of the struct.
157 del pcu_type['pcu_protocol_types']
161 if pcu_type['model'] not in g_pcu_models:
162 # Add the name/model info into DB
163 id = AddPCUType(pcu_type)
164 # for each protocol, also add this.
165 for ptype in protocol_types:
166 AddPCUProtocolType(id, ptype)