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 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
48 old_roles=GetTagTypes(tagname)[0]['roles']
49 for minus_role in set(old_roles).difference(set(roles)):
50 DeleteRoleFromTagType(minus_role,tagname)
51 for plus_role in set(roles).difference(set(old_roles)):
52 AddRoleToTagType(plus_role,tagname)
54 # something went wrong for that tagname,
55 # but don't want to break the whole startup sequence
56 print "Could not enforce tagtype %s --- beg"%tagname
59 print "Could not enforce tagtype %s --- end"%tagname
61 # Get list of existing (enabled, global) files
62 g_conf_files = GetConfFiles()
63 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
64 not conf_file['node_ids'] and \
65 not conf_file['nodegroup_ids'],
67 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
68 g_conf_files = dict(zip(g_dests, g_conf_files))
70 # Get list of existing initscripts
71 g_oldinitscripts = GetInitScripts()
72 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
73 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
75 def SetInitScript(initscript):
76 global g_oldinitscripts, g_oldinitscript_names
77 if initscript['name'] not in g_oldinitscript_names:
78 initscript_id = AddInitScript(initscript)
79 g_oldinitscript_names.append(initscript['name'])
80 initscript['initscript_id']=initscript_id
81 g_oldinitscripts[initscript['name']]=initscript
83 orig_initscript = g_oldinitscripts[initscript['name']]
84 initscript_id = orig_initscript['initscript_id']
85 UpdateInitScript(initscript_id, initscript)
87 def SetConfFile(conf_file):
88 global g_conf_files, g_dests
89 if conf_file['dest'] not in g_dests:
90 AddConfFile(conf_file)
92 orig_conf_file = g_conf_files[conf_file['dest']]
93 conf_file_id = orig_conf_file['conf_file_id']
94 UpdateConfFile(conf_file_id, conf_file)
96 def SetSlice(slice, tags):
98 # Create or Update slice
99 slice_name = slice['name']
100 slices = GetSlices([slice_name])
102 slice_id = slices[0]['slice_id']
103 if slice.has_key('name'):
105 UpdateSlice(slice_id, slice)
106 slice['name']=slice_name
109 if slice.has_key('expires'):
110 expires = slice['expires']
112 slice_id = AddSlice(slice)
114 UpdateSlice(slice_id, {'expires':expires})
116 # Get slice structure with all fields
117 slice = GetSlices([slice_name])[0]
119 # Create/delete all tags
120 # NOTE: update is not needed, since unspecified tags are deleted,
121 # and new tags are added
123 if slice['slice_tag_ids']:
124 # Delete unknown attributes
125 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
126 # ignore sliver tags, as those are custom/run-time values
127 if slice_tag['node_id'] <> None: continue
128 if (slice_tag['tagname'], slice_tag['value']) not in tags:
129 DeleteSliceTag(slice_tag['slice_tag_id'])
131 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
133 # only add slice tags that are new
134 for (name, value) in tags:
135 if (name,value) not in slice_tags:
136 AddSliceTag(slice_name, name, value)
138 # NOTE: this confirms that the user-specified tag is
139 # returned by GetSliceTags
142 # something went wrong for that tagname,
143 print "Could not create init slice %s --- beg"%slice['name']
145 traceback.print_exc()
146 print "Could not create init slice %s --- end"%slice['name']
148 def SetMessage(message):
149 messages = GetMessages([message['message_id']])
153 UpdateMessage(message['message_id'],message)
155 # Get all model names
156 g_pcu_models = [type['model'] for type in GetPCUTypes()]
158 def SetPCUType(pcu_type):
160 if 'pcu_protocol_types' in pcu_type:
161 protocol_types = pcu_type['pcu_protocol_types']
162 # Take this value out of the struct.
163 del pcu_type['pcu_protocol_types']
167 if pcu_type['model'] not in g_pcu_models:
168 # Add the name/model info into DB
169 id = AddPCUType(pcu_type)
170 # for each protocol, also add this.
171 for ptype in protocol_types:
172 AddPCUProtocolType(id, ptype)