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 global g_known_tag_types
29 # Create/update default slice tag types
30 if tag_type['tagname'] not in g_known_tag_types:
32 g_known_tag_types.append(tag_type['tagname'])
33 g_known_tag_types.sort()
35 UpdateTagType(tag_type['tagname'], tag_type)
36 if 'roles' in tag_type:
37 for role in tag_type['roles']:
38 AddRoleToTagType(role,tag_type['tagname'])
40 # Get list of existing (enabled, global) files
41 g_conf_files = GetConfFiles()
42 g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
43 not conf_file['node_ids'] and \
44 not conf_file['nodegroup_ids'],
46 g_dests = [conf_file['dest'] for conf_file in g_conf_files]
47 g_conf_files = dict(zip(g_dests, g_conf_files))
49 # Get list of existing initscripts
50 g_oldinitscripts = GetInitScripts()
51 g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
52 g_oldinitscripts = dict(zip(g_oldinitscript_names, g_oldinitscripts))
54 def SetInitScript(initscript):
55 global g_oldinitscripts, g_oldinitscript_names
56 if initscript['name'] not in g_oldinitscript_names:
57 initscript_id = AddInitScript(initscript)
58 g_oldinitscript_names.append(initscript['name'])
59 initscript['initscript_id']=initscript_id
60 g_oldinitscripts[initscript['name']]=initscript
62 orig_initscript = g_oldinitscripts[initscript['name']]
63 initscript_id = orig_initscript['initscript_id']
64 UpdateInitScript(initscript_id, initscript)
66 def SetConfFile(conf_file):
67 global g_conf_files, g_dests
68 if conf_file['dest'] not in g_dests:
69 AddConfFile(conf_file)
71 orig_conf_file = g_conf_files[conf_file['dest']]
72 conf_file_id = orig_conf_file['conf_file_id']
73 UpdateConfFile(conf_file_id, conf_file)
75 def SetSlice(slice, tags):
76 # Create or Update slice
77 slice_name = slice['name']
78 slices = GetSlices([slice_name])
80 slice_id = slices[0]['slice_id']
81 if slice.has_key('name'):
83 UpdateSlice(slice_id, slice)
84 slice['name']=slice_name
87 if slice.has_key('expires'):
88 expires = slice['expires']
90 slice_id = AddSlice(slice)
92 UpdateSlice(slice_id, {'expires':expires})
94 # Get slice structure with all fields
95 slice = GetSlices([slice_name])[0]
97 # Create/delete all tags
98 # NOTE: update is not needed, since unspecified tags are deleted,
99 # and new tags are added
101 if slice['slice_tag_ids']:
102 # Delete unknown attributes
103 for slice_tag in GetSliceTags(slice['slice_tag_ids']):
104 # ignore sliver tags, as those are custom/run-time values
105 if slice_tag['node_id'] <> None: continue
106 if (slice_tag['tagname'], slice_tag['value']) not in tags:
107 DeleteSliceTag(slice_tag['slice_tag_id'])
109 slice_tags.append((slice_tag['tagname'],slice_tag['value']))
111 # only add slice tags that are new
112 for (name, value) in tags:
113 if (name,value) not in slice_tags:
114 AddSliceTag(slice_name, name, value)
116 # NOTE: this confirms that the user-specified tag is
117 # returned by GetSliceTags
120 def SetMessage(message):
121 messages = GetMessages([message['message_id']])
125 UpdateMessage(message['message_id'],message)
127 # Get all model names
128 g_pcu_models = [type['model'] for type in GetPCUTypes()]
130 def SetPCUType(pcu_type):
132 if 'pcu_protocol_types' in pcu_type:
133 protocol_types = pcu_type['pcu_protocol_types']
134 # Take this value out of the struct.
135 del pcu_type['pcu_protocol_types']
139 if pcu_type['model'] not in g_pcu_models:
140 # Add the name/model info into DB
141 id = AddPCUType(pcu_type)
142 # for each protocol, also add this.
143 for ptype in protocol_types:
144 AddPCUProtocolType(id, ptype)