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)
39 # Get list of existing (enabled, global) files
40 g_conf_files = GetConfFiles()
41 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
42 not conf_file['node_ids'] and \
43 not conf_file['nodegroup_ids'],
45 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
46 g_conf_files = dict(zip(g_dests, g_conf_files))
48 # Get list of existing initscripts
49 g_oldinitscripts = GetInitScripts()
50 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
51 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
53 def SetInitScript(initscript):
54 global g_oldinitscripts, g_oldinitscript_names
55 if initscript['name'] not in g_oldinitscript_names:
56 initscript_id = AddInitScript(initscript)
57 g_oldinitscript_names.append(initscript['name'])
58 initscript['initscript_id']=initscript_id
59 g_oldinitscripts[initscript['name']]=initscript
61 orig_initscript = g_oldinitscripts[initscript['name']]
62 initscript_id = orig_initscript['initscript_id']
63 UpdateInitScript(initscript_id, initscript)
65 def SetConfFile(conf_file):
66 global g_conf_files, g_dests
67 if conf_file['dest'] not in g_dests:
68 AddConfFile(conf_file)
70 orig_conf_file = g_conf_files[conf_file['dest']]
71 conf_file_id = orig_conf_file['conf_file_id']
72 UpdateConfFile(conf_file_id, conf_file)
74 def SetSlice(slice, tags):
75 # Create or Update slice
76 slice_name = slice['name']
77 slices = GetSlices([slice_name])
79 slice_id = slices[0]['slice_id']
80 if slice.has_key('name'):
82 UpdateSlice(slice_id, slice)
83 slice['name']=slice_name
86 if slice.has_key('expires'):
87 expires = slice['expires']
89 slice_id = AddSlice(slice)
91 UpdateSlice(slice_id, {'expires':expires})
93 # Get slice structure with all fields
94 slice = GetSlices([slice_name])[0]
96 # Create/delete all tags
97 # NOTE: update is not needed, since unspecified tags are deleted,
98 # and new tags are added
100 if slice['slice_tag_ids']:
101 # Delete unknown attributes
102 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
103 # ignore sliver tags, as those are custom/run-time values
104 if slice_tag['node_id'] <> None: continue
105 if (slice_tag['tagname'], slice_tag['value']) not in tags:
106 DeleteSliceTag(slice_tag['slice_tag_id'])
108 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
110 # only add slice tags that are new
111 for (name, value) in tags:
112 if (name,value) not in slice_tags:
113 AddSliceTag(slice_name, name, value)
115 # NOTE: this confirms that the user-specified tag is
116 # returned by GetSliceTags
119 def SetMessage(message):
120 messages = GetMessages([message['message_id']])
124 UpdateMessage(message['message_id'],message)
126 # Get all model names
127 g_pcu_models = [type['model'] for type in GetPCUTypes()]
129 def SetPCUType(pcu_type):
131 if 'pcu_protocol_types' in pcu_type:
132 protocol_types = pcu_type['pcu_protocol_types']
133 # Take this value out of the struct.
134 del pcu_type['pcu_protocol_types']
138 if pcu_type['model'] not in g_pcu_models:
139 # Add the name/model info into DB
140 id = AddPCUType(pcu_type)
141 # for each protocol, also add this.
142 for ptype in protocol_types:
143 AddPCUProtocolType(id, ptype)