9 def GetMyPLCURL(): return g_url
17 # Get list of existing tag types
18 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
19 g_known_tag_types.sort()
23 return ['pi', 'user', 'tech']
26 def SetTagType(tag_type):
28 tagname = tag_type['tagname']
29 global g_known_tag_types
30 # handle 'roles' field differently
31 if 'roles' in tag_type:
32 roles = tag_type['roles']
37 if 'min_role_id' in tag_type:
39 "WARNING: ignoring deprecated field min_role_id for tagtype %s" % tagname)
40 del tag_type['min_role_id']
41 # Create/update default slice tag types
42 if tagname not in g_known_tag_types:
44 g_known_tag_types.append(tagname)
45 g_known_tag_types.sort()
47 UpdateTagType(tagname, tag_type)
48 # enforce provided roles if present
49 old_roles = GetTagTypes(tagname)[0]['roles']
50 for minus_role in set(old_roles).difference(set(roles)):
51 DeleteRoleFromTagType(minus_role, tagname)
52 for plus_role in set(roles).difference(set(old_roles)):
53 AddRoleToTagType(plus_role, tagname)
55 # something went wrong for that tagname,
56 # but don't want to break the whole startup sequence
57 print("Could not enforce tagtype %s --- beg" % tagname)
60 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 = [conf_file for conf_file in g_conf_files if conf_file['enabled'] and
66 not conf_file['node_ids'] and
67 not conf_file['nodegroup_ids']]
68 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
69 g_conf_files = dict(list(zip(g_dests, g_conf_files)))
71 # Get list of existing initscripts
72 g_oldinitscripts = GetInitScripts()
73 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
74 g_oldinitscripts = dict(list(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)
90 def SetConfFile(conf_file):
91 global g_conf_files, g_dests
92 if conf_file['dest'] not in g_dests:
93 AddConfFile(conf_file)
95 orig_conf_file = g_conf_files[conf_file['dest']]
96 conf_file_id = orig_conf_file['conf_file_id']
97 UpdateConfFile(conf_file_id, conf_file)
100 def SetSlice(slice, tags):
102 # Create or Update slice
103 slice_name = slice['name']
104 slices = GetSlices([slice_name])
106 slice_id = slices[0]['slice_id']
109 UpdateSlice(slice_id, slice)
110 slice['name'] = slice_name
113 if 'expires' in slice:
114 expires = slice['expires']
116 slice_id = AddSlice(slice)
117 if expires is not None:
118 UpdateSlice(slice_id, {'expires': expires})
120 # Get slice structure with all fields
121 slice = GetSlices([slice_name])[0]
123 # Create/delete all tags
124 # NOTE: update is not needed, since unspecified tags are deleted,
125 # and new tags are added
127 if slice['slice_tag_ids']:
128 # Delete unknown attributes
129 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
130 # ignore sliver tags, as those are custom/run-time values
131 if slice_tag['node_id'] is not None:
133 if (slice_tag['tagname'], slice_tag['value']) not in tags:
134 DeleteSliceTag(slice_tag['slice_tag_id'])
137 (slice_tag['tagname'], slice_tag['value']))
139 # only add slice tags that are new
140 for (name, value) in tags:
141 if (name, value) not in slice_tags:
142 AddSliceTag(slice_name, name, value)
144 # NOTE: this confirms that the user-specified tag is
145 # returned by GetSliceTags
148 # something went wrong for that tagname,
149 print("Could not create init slice %s --- beg" % slice['name'])
151 traceback.print_exc()
152 print("Could not create init slice %s --- end" % slice['name'])
155 def SetMessage(message):
156 messages = GetMessages([message['message_id']])
157 if len(messages) == 0:
160 # let people customize their messages if they want to
162 # UpdateMessage(message['message_id'],message)
165 # Get all model names
166 g_pcu_models = [type['model'] for type in GetPCUTypes()]
169 def SetPCUType(pcu_type):
171 if 'pcu_protocol_types' in pcu_type:
172 protocol_types = pcu_type['pcu_protocol_types']
173 # Take this value out of the struct.
174 del pcu_type['pcu_protocol_types']
178 if pcu_type['model'] not in g_pcu_models:
179 # Add the name/model info into DB
180 id = AddPCUType(pcu_type)
181 # for each protocol, also add this.
182 for ptype in protocol_types:
183 AddPCUProtocolType(id, ptype)