7 def GetMyPLCURL(): return g_url
12 # Get all currently registered roles
13 g_role_names = [ role['name'] for role in GetRoles()]
16 def SetRole(level, role):
18 if role not in g_role_names:
20 g_role_names.append(role)
23 # Get list of existing tag types
24 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
25 g_known_tag_types.sort()
27 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:
38 print "WARNING: ignoring deprecated field min_role_id for tagtype %s"%tagname
39 del tag_type['min_role_id']
40 # Create/update default slice tag types
41 if tagname not in g_known_tag_types:
43 g_known_tag_types.append(tagname)
44 g_known_tag_types.sort()
46 UpdateTagType(tagname, tag_type)
47 # 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 AddRoleToType(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 roles on tagtype %s"%tagname
60 # Get list of existing (enabled, global) files
61 g_conf_files = GetConfFiles()
62 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
63 not conf_file['node_ids'] and \
64 not conf_file['nodegroup_ids'],
66 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
67 g_conf_files = dict(zip(g_dests, g_conf_files))
69 # Get list of existing initscripts
70 g_oldinitscripts = GetInitScripts()
71 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
72 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
74 def SetInitScript(initscript):
75 global g_oldinitscripts, g_oldinitscript_names
76 if initscript['name'] not in g_oldinitscript_names:
77 initscript_id = AddInitScript(initscript)
78 g_oldinitscript_names.append(initscript['name'])
79 initscript['initscript_id']=initscript_id
80 g_oldinitscripts[initscript['name']]=initscript
82 orig_initscript = g_oldinitscripts[initscript['name']]
83 initscript_id = orig_initscript['initscript_id']
84 UpdateInitScript(initscript_id, initscript)
86 def SetConfFile(conf_file):
87 global g_conf_files, g_dests
88 if conf_file['dest'] not in g_dests:
89 AddConfFile(conf_file)
91 orig_conf_file = g_conf_files[conf_file['dest']]
92 conf_file_id = orig_conf_file['conf_file_id']
93 UpdateConfFile(conf_file_id, conf_file)
95 def SetSlice(slice, tags):
96 # Create or Update slice
97 slice_name = slice['name']
98 slices = GetSlices([slice_name])
100 slice_id = slices[0]['slice_id']
101 if slice.has_key('name'):
103 UpdateSlice(slice_id, slice)
104 slice['name']=slice_name
107 if slice.has_key('expires'):
108 expires = slice['expires']
110 slice_id = AddSlice(slice)
112 UpdateSlice(slice_id, {'expires':expires})
114 # Get slice structure with all fields
115 slice = GetSlices([slice_name])[0]
117 # Create/delete all tags
118 # NOTE: update is not needed, since unspecified tags are deleted,
119 # and new tags are added
121 if slice['slice_tag_ids']:
122 # Delete unknown attributes
123 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
124 # ignore sliver tags, as those are custom/run-time values
125 if slice_tag['node_id'] <> None: continue
126 if (slice_tag['tagname'], slice_tag['value']) not in tags:
127 DeleteSliceTag(slice_tag['slice_tag_id'])
129 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
131 # only add slice tags that are new
132 for (name, value) in tags:
133 if (name,value) not in slice_tags:
134 AddSliceTag(slice_name, name, value)
136 # NOTE: this confirms that the user-specified tag is
137 # returned by GetSliceTags
140 def SetMessage(message):
141 messages = GetMessages([message['message_id']])
145 UpdateMessage(message['message_id'],message)
147 # Get all model names
148 g_pcu_models = [type['model'] for type in GetPCUTypes()]
150 def SetPCUType(pcu_type):
152 if 'pcu_protocol_types' in pcu_type:
153 protocol_types = pcu_type['pcu_protocol_types']
154 # Take this value out of the struct.
155 del pcu_type['pcu_protocol_types']
159 if pcu_type['model'] not in g_pcu_models:
160 # Add the name/model info into DB
161 id = AddPCUType(pcu_type)
162 # for each protocol, also add this.
163 for ptype in protocol_types:
164 AddPCUProtocolType(id, ptype)