# $Id$
# $HeadURL$
-from plc_config import PLCConfiguration
-import sys
-import resource
-
-g_url = ""
-def GetMyPLCURL(): return g_url
-def SetMyPLCURL(url):
- global g_url
- g_url = url
-
-# Get list of existing tag types
-g_known_tag_types = [tag_type['tagname'] for tag_type in GetTagTypes()]
-g_known_tag_types.sort()
-
-def SetTagType(tag_type):
- global g_known_tag_types
- # Create/update default slice tag types
- if tag_type['tagname'] not in g_known_tag_types:
- AddTagType(tag_type)
- g_known_tag_types.append(tag_type['tagname'])
- g_known_tag_types.sort()
- else:
- UpdateTagType(tag_type['tagname'], tag_type)
-
-# Get list of existing (enabled, global) files
-g_conf_files = GetConfFiles()
-g_conf_files = filter(lambda conf_file: conf_file['enabled'] and \
- not conf_file['node_ids'] and \
- not conf_file['nodegroup_ids'],
- g_conf_files)
-g_dests = [conf_file['dest'] for conf_file in g_conf_files]
-g_conf_files = dict(zip(g_dests, g_conf_files))
-
-# Get list of existing initscripts
-g_oldinitscripts = GetInitScripts()
-g_oldinitscript_names = [script['name'] for script in g_oldinitscripts]
-g_oldinitscripts = dict(zip(g_dests, g_conf_files))
-
-def SetInitScript(initscript):
- global g_oldinitscripts, g_oldinitscript_names
- if initscript['name'] not in g_oldinitscript_names:
- AddInitScript(initscript)
- g_oldinitscript_names.append(initscript['name'])
- else:
- orig_initscript = g_oldinitscripts[initscript['name']]
- initscript_id = orig_initscript['initscript_id']
- UpdateConfFile(initscript_id, initscript)
-
-def SetConfFile(conf_file):
- global g_conf_files, g_dests
- if conf_file['dest'] not in g_dests:
- AddConfFile(conf_file)
- else:
- orig_conf_file = g_conf_files[conf_file['dest']]
- conf_file_id = orig_conf_file['conf_file_id']
- UpdateConfFile(conf_file_id, conf_file)
-
-def SetSlice(slice, tags):
- # Create or Update slice
- slices = GetSlices([slice['name']])
- if len(slices)==1:
- slice_id = slices[0]['slice_id']
- UpdateSlice(slice_id, slice)
- else:
- AddSlice(slice)
-
- # Get slice structure with all fields
- slice = GetSlices([slice['name']])[0]
+import os,sys
+from optparse import OptionParser
- # Create/update all tags
- slice_tags = {}
- if slice['slice_tag_ids']:
- # Delete unknown attributes
- for slice_tag in GetSliceTags(slice['slice_tag_ids']):
- if (slice_tag['tagname'], slice_tag['value']) not in tags:
- DeleteSliceTag(slice_tag['slice_tag_id'])
- else:
- slice_tags[slice_tag['tagname']]=slice_tag['value']
-
- # only update slice tags that have changed
- for (name, value) in tags:
- if name not in slice_tags:
- AddSliceTag(slice['name'], name, value)
- elif value <> slice_tags[name]:
- UpdateSliceTag(slice['name'],value)
-
-def SetMessage(message):
- messages = GetMessages([message['message_id']])
- if len(messages)==0:
- AddMessage(message)
- else:
- UpdateMessage(message['message_id'],message)
-
-# Get all model names
-g_pcu_models = [type['model'] for type in GetPCUTypes()]
-
-def SetPCUType(pcu_type):
- global g_pcu_models
- if 'pcu_protocol_types' in pcu_type:
- protocol_types = pcu_type['pcu_protocol_types']
- # Take this value out of the struct.
- del pcu_type['pcu_protocol_types']
- else:
- protocol_types = []
-
- if pcu_type['model'] not in g_pcu_models:
- # Add the name/model info into DB
- id = AddPCUType(pcu_type)
- # for each protocol, also add this.
- for ptype in protocol_types:
- AddPCUProtocolType(id, ptype)
+from plc_config import PLCConfiguration
def GetSnippets(directory):
filenames = []
cfg.load()
variables = cfg.variables()
+ usage="%prog [-- options] [steps]"
+ release_url = "$URL$"
+ parser = OptionParser(usage=usage, version="%prog " + release_url )
+ parser.add_option("-l","--list",dest="list_steps",action="store_true",default=False,
+ help="Lists available steps")
+ parser.add_option("-v","--verbose",dest="verbose",action="store_true",default=False,
+ help="Run verbosely")
+
+ (options,args) = parser.parse_args()
+
# Load variables into dictionaries
for category_id, (category, variablelist) in variables.iteritems():
globals()[category_id] = dict(zip(variablelist.keys(),
directory="/etc/planetlab/db-config.d"
snippets = GetSnippets(directory)
+
+ if options.list_steps:
+ for snippet in snippets:
+ if not options.verbose:
+ print snippet
+ else:
+ print "Found step %s/%s"%(directory,snippet)
+ os.system("rpm -qf %s/%s"%(directory,snippet))
+ sys.exit(0)
+
for snippet in snippets:
fullpath = os.path.join(directory, snippet)
+ if options.verbose:
+ print "Running step %s"%fullpath
execfile(fullpath)
if __name__ == '__main__':