8 def GetMyPLCURL(): return g_url
13 # Get all currently registered roles
14 g_role_names = [ role['name'] for role in GetRoles()]
17 def SetRole(level, role):
19 if role not in g_role_names:
21 g_role_names.append(role)
24 # Get list of existing tag types
25 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
26 g_known_tag_types.sort()
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 AddRoleToType(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
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 = 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):
99 # Create or Update slice
100 slice_name = slice['name']
101 slices = GetSlices([slice_name])
103 slice_id = slices[0]['slice_id']
104 if slice.has_key('name'):
106 UpdateSlice(slice_id, slice)
107 slice['name']=slice_name
110 if slice.has_key('expires'):
111 expires = slice['expires']
113 slice_id = AddSlice(slice)
115 UpdateSlice(slice_id, {'expires':expires})
117 # Get slice structure with all fields
118 slice = GetSlices([slice_name])[0]
120 # Create/delete all tags
121 # NOTE: update is not needed, since unspecified tags are deleted,
122 # and new tags are added
124 if slice['slice_tag_ids']:
125 # Delete unknown attributes
126 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
127 # ignore sliver tags, as those are custom/run-time values
128 if slice_tag['node_id'] <> None: continue
129 if (slice_tag['tagname'], slice_tag['value']) not in tags:
130 DeleteSliceTag(slice_tag['slice_tag_id'])
132 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
134 # only add slice tags that are new
135 for (name, value) in tags:
136 if (name,value) not in slice_tags:
137 AddSliceTag(slice_name, name, value)
139 # NOTE: this confirms that the user-specified tag is
140 # returned by GetSliceTags
143 def SetMessage(message):
144 messages = GetMessages([message['message_id']])
148 UpdateMessage(message['message_id'],message)
150 # Get all model names
151 g_pcu_models = [type['model'] for type in GetPCUTypes()]
153 def SetPCUType(pcu_type):
155 if 'pcu_protocol_types' in pcu_type:
156 protocol_types = pcu_type['pcu_protocol_types']
157 # Take this value out of the struct.
158 del pcu_type['pcu_protocol_types']
162 if pcu_type['model'] not in g_pcu_models:
163 # Add the name/model info into DB
164 id = AddPCUType(pcu_type)
165 # for each protocol, also add this.
166 for ptype in protocol_types:
167 AddPCUProtocolType(id, ptype)