Esempio n. 1
0
 def exposecreate():
     """
     create plan
     """
     if 'plan' in request.form:
         plan = request.form['plan']
         if plan not in self.plans:
             return 'Invalid plan name %s' % plan
         elif self.plans[plan] == config.client:
             currentconfig = self.config
             client = config.client
         else:
             client = self.plans[plan]
             currentconfig = self.extraconfigs[client]
         parameters = {}
         for p in request.form:
             if p.startswith('parameter'):
                 value = request.form[p]
                 if value.isdigit():
                     value = int(value)
                 elif value.lower() in ['true', 'false']:
                     value = value.lower() == "true"
                 key = p.replace('parameter_', '')
                 parameters[key] = value
         try:
             overrides = parameters
             paramfile = self.clients[client][plan]
             if paramfile is not None:
                 fileoverrides = get_overrides(paramfile=paramfile)
                 fileoverrides.update(overrides)
                 overrides = fileoverrides
             if 'mail' in currentconfig.notifymethods and 'mailto' in overrides and overrides[
                     'mailto'] != "":
                 newmails = overrides['mailto'].split(',')
                 if currentconfig.mailto:
                     currentconfig.mailto.extend(newmails)
                 else:
                     currentconfig.mailto = newmails
             if 'owner' in overrides and overrides['owner'] == '':
                 del overrides['owner']
             currentconfig.delete_plan(plan)
             result = currentconfig.plan(plan,
                                         inputfile=inputfile,
                                         overrides=overrides)
         except Exception as e:
             error = 'Hit issue when running plan: %s' % str(e)
             return render_template('error.html',
                                    plan=plan,
                                    error=error)
         if result['result'] == 'success':
             return render_template('success.html', plan=plan)
         else:
             return render_template('error.html',
                                    plan=plan,
                                    error=result['reason'])
     else:
         return 'Invalid data'
Esempio n. 2
0
 def exposecreate():
     """
     create plan
     """
     if 'plan' in request.form:
         plan = request.form['plan']
         print(plan)
         if plan not in self.plans:
             return 'Invalid plan name %s' % plan
         if '_' in plan and plan.split('_')[0] in self.extraconfigs:
             currentconfig = self.extraconfigs[plan.split('_')[0]]
         else:
             currentconfig = self.config
         parameters = {}
         for p in request.form:
             if p.startswith('parameter'):
                 value = request.form[p]
                 if value.isdigit():
                     value = int(value)
                 key = p.replace('parameter_', '')
                 parameters[key] = value
         try:
             overrides = parameters
             if self.parametersfiles:
                 for paramfile in self.parametersfiles:
                     if paramfile.startswith("%s/parameters_%s" %
                                             (self.basedir, plan)):
                         fileoverrides = get_overrides(
                             paramfile=paramfile)
                         fileoverrides.update(overrides)
                 overrides = fileoverrides
             if 'mail' in currentconfig.notifymethods and 'mailto' in overrides and overrides[
                     'mailto'] != "":
                 newmails = overrides['mailto'].split(',')
                 if currentconfig.mailto:
                     currentconfig.mailto.extend(newmails)
                 else:
                     currentconfig.mailto = newmails
             if 'owner' in overrides and overrides['owner'] == '':
                 del overrides['owner']
             currentconfig.plan(plan, delete=True)
             result = currentconfig.plan(plan,
                                         inputfile=inputfile,
                                         overrides=overrides)
         except Exception as e:
             error = 'Hit issue when running plan: %s' % str(e)
             return render_template('error.html',
                                    plan=plan,
                                    error=error)
         if result['result'] == 'success':
             return render_template('success.html', plan=plan)
         else:
             return render_template('error.html',
                                    plan=plan,
                                    error=result['reason'])
     else:
         return 'Invalid data'
Esempio n. 3
0
def render(args):
    """

    :param args:
    """
    info = args.info
    inputfile = args.inputfile
    inputfile = os.path.expanduser(inputfile)
    if not os.path.exists(inputfile):
        pprint("No input file found.Leaving....", color='red')
        os._exit(1)
    overrides = get_overrides(paramfile=args.paramfile, param=args.param)
    parameters = get_parameters(inputfile)
    if parameters is not None:
        parameters = yaml.load(parameters)['parameters']
        numparameters = len(parameters)
        for parameter in parameters:
            if parameter not in overrides:
                overrides[parameter] = parameters[parameter]
    if info:
        for parameter in overrides:
            print("Using parameter %s: %s" % (parameter, overrides[parameter]))
        os._exit(0)
    basedir = os.path.dirname(
        inputfile) if os.path.dirname(inputfile) != '' else '.'
    env = Environment(block_start_string='[%',
                      block_end_string='%]',
                      variable_start_string='[[',
                      variable_end_string=''
                      ']]',
                      loader=FileSystemLoader(basedir))
    templ = env.get_template(os.path.basename(inputfile))
    fileentries = templ.render(overrides)
    parametersfound = -1
    for line in fileentries.split('\n'):
        if line.strip() == '':
            continue
        elif line.startswith('parameters:'):
            parametersfound = 0
        elif -1 < parametersfound < numparameters:
            parametersfound += 1
        else:
            print(line.strip())