9 def GetMyPLCURL(): return g_url
14 # Get all currently registered roles
15 g_role_names = [ role['name'] for role in GetRoles()]
18 def SetRole(level, role):
20 if role not in g_role_names:
22 g_role_names.append(role)
25 # Get list of existing tag types
26 g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
27 g_known_tag_types.sort()
29 def SetTagType(tag_type):
30 global g_known_tag_types
31 # Create/update default slice tag types
32 if tag_type['tagname'] not in g_known_tag_types:
34 g_known_tag_types.append(tag_type['tagname'])
35 g_known_tag_types.sort()
37 UpdateTagType(tag_type['tagname'], tag_type)
38 if 'roles' in tag_type:
39 for role in tag_type['roles']:
40 AddRoleToTagType(role,tag_type['tagname'])
42 # Get list of existing (enabled, global) files
43 g_conf_files = GetConfFiles()
44 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
45 not conf_file['node_ids'] and \
46 not conf_file['nodegroup_ids'],
48 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
49 g_conf_files = dict(zip(g_dests, g_conf_files))
51 # Get list of existing initscripts
52 g_oldinitscripts = GetInitScripts()
53 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
54 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
56 def SetInitScript(initscript):
57 global g_oldinitscripts, g_oldinitscript_names
58 if initscript['name'] not in g_oldinitscript_names:
59 initscript_id = AddInitScript(initscript)
60 g_oldinitscript_names.append(initscript['name'])
61 initscript['initscript_id']=initscript_id
62 g_oldinitscripts[initscript['name']]=initscript
64 orig_initscript = g_oldinitscripts[initscript['name']]
65 initscript_id = orig_initscript['initscript_id']
66 UpdateInitScript(initscript_id, initscript)
68 def SetConfFile(conf_file):
69 global g_conf_files, g_dests
70 if conf_file['dest'] not in g_dests:
71 AddConfFile(conf_file)
73 orig_conf_file = g_conf_files[conf_file['dest']]
74 conf_file_id = orig_conf_file['conf_file_id']
75 UpdateConfFile(conf_file_id, conf_file)
77 def SetSlice(slice, tags):
78 # Create or Update slice
79 slice_name = slice['name']
80 slices = GetSlices([slice_name])
82 slice_id = slices[0]['slice_id']
83 if slice.has_key('name'):
85 UpdateSlice(slice_id, slice)
86 slice['name']=slice_name
89 if slice.has_key('expires'):
90 expires = slice['expires']
92 slice_id = AddSlice(slice)
94 UpdateSlice(slice_id, {'expires':expires})
96 # Get slice structure with all fields
97 slice = GetSlices([slice_name])[0]
99 # Create/delete all tags
100 # NOTE: update is not needed, since unspecified tags are deleted,
101 # and new tags are added
103 if slice['slice_tag_ids']:
104 # Delete unknown attributes
105 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
106 # ignore sliver tags, as those are custom/run-time values
107 if slice_tag['node_id'] <> None: continue
108 if (slice_tag['tagname'], slice_tag['value']) not in tags:
109 DeleteSliceTag(slice_tag['slice_tag_id'])
111 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
113 # only add slice tags that are new
114 for (name, value) in tags:
115 if (name,value) not in slice_tags:
116 AddSliceTag(slice_name, name, value)
118 # NOTE: this confirms that the user-specified tag is
119 # returned by GetSliceTags
122 def SetMessage(message):
123 messages = GetMessages([message['message_id']])
127 UpdateMessage(message['message_id'],message)
129 # Get all model names
130 g_pcu_models = [type['model'] for type in GetPCUTypes()]
132 def SetPCUType(pcu_type):
134 if 'pcu_protocol_types' in pcu_type:
135 protocol_types = pcu_type['pcu_protocol_types']
136 # Take this value out of the struct.
137 del pcu_type['pcu_protocol_types']
141 if pcu_type['model'] not in g_pcu_models:
142 # Add the name/model info into DB
143 id = AddPCUType(pcu_type)
144 # for each protocol, also add this.
145 for ptype in protocol_types:
146 AddPCUProtocolType(id, ptype)