Exemplo n.º 1
0
def sync(args):
    srcConfigFile = common.getConfig(args['--src-gate-endpoint'])
    dstConfigFile = common.getConfig(args['--dst-gate-endpoint'])
    srcConfig = common.loadconfig(srcConfigFile)
    srcAppInUse = srcConfig.get("appInUse", [])
    dstAppList = common.getAppList(args['--dst-gate-endpoint'],
                                   args['--dst-cookieheader'])
    dstEnvList = dstconfig["environment"]
    dstAppSetting = dstconfig["application_setting"]
    notExistApp = numpy.setdiff1d(srcAppInUse, dstAppList)
    print('Create non exist application in %s' % args['--dst-gate-endpoint'])
    for app in tqdm(notExistApp):
        common.createApplication(app, srcAppSetting['ownerEmail'],
                                 ",".join(srcAppSetting['cloudProvider']),
                                 args['--dst-gate-endpoint'],
                                 args['--dst-cookieheader'])
    print('Create pipeline in %s' % args['--dst-gate-endpoint'])
    for app in tqdm(srcAppInUse):
        for env in dstEnvList:
            pipelineFile = os.path.join(os.getcwd(),
                                        "%s_%s.json" % (app, args['--env']))
            common.render_template(
                common.read_template(pipelineTemplate),
                common.generate_pipeline_setting(app, args['--env'],
                                                 config['pipeline_setting']),
                pipelineFile)
            common.createPipeline(pipelineFile, args['--dst-gate-endpoint'],
                                  args['--dst-cookieheader'])
    print("Completed!")
Exemplo n.º 2
0
def create(args):
    configFile = common.getConfig(args['--gate-endpoint'])
    config = common.loadconfig(configFile)
    appSetting = config['application_setting']
    if common.appExists(args['--appname'], args['--gate-endpoint'],
                        args['--cookieheader']):
        print('Application %s already exists!' % args['--appname'])
    else:
        common.createApplication(args['--appname'], appSetting['ownerEmail'],
                                 ",".join(appSetting['cloudProvider']),
                                 args['--gate-endpoint'],
                                 args['--cookieheader'])
Exemplo n.º 3
0
def create(args):
    configFile = common.getConfig(args['--gate-endpoint'])
    config = common.loadconfig(configFile)
    appSetting = config['application_setting']
    pipelineTemplate = ""

    pipelineName = ''
    if args['--trigger']:
        pipelineName = "iac-%s-%s" % (args['--env'], args['--trigger'])
    else:
        pipelineName = "iac-%s" % (args['--env'])
    config['pipeline_setting']['default']['pipelineName'] = pipelineName

    if args['--template']:
        pipelineTemplate = os.path.join(os.getcwd(), args['--template'])
    elif args['--trigger']:
        pipelineTemplate = os.path.join(
            common.getTemplateDir(), 'pipeline_%s.json.j2' % args['--trigger'])
    else:
        pipelineTemplate = os.path.join(common.getTemplateDir(),
                                        'pipeline.json.j2')

    appList = config[args['--applist']] if args['--applist'] else [
        args['--app']
    ]
    currentAppList = common.getAppList(args['--gate-endpoint'],
                                       args['--cookieheader'])
    for app in tqdm(appList):
        if args['--force-update'] or not common.pipelineExists(
                app, pipelineName, args['--gate-endpoint'],
                args['--cookieheader'], currentAppList):
            if args['--create-application'] and not common.appExists(
                    app, args['--gate-endpoint'], args['--cookieheader'],
                    currentAppList):
                common.createApplication(app, appSetting['ownerEmail'],
                                         ",".join(appSetting['cloudProvider']),
                                         args['--gate-endpoint'],
                                         args['--cookieheader'])
            pipelineFile = os.path.join(
                os.getcwd(),
                "%s_%s_%s.json" % (app, args['--env'], args['--trigger']))
            common.render_template(
                common.read_template(pipelineTemplate),
                common.generate_pipeline_setting(app, args['--env'],
                                                 config['pipeline_setting']),
                pipelineFile)
            common.createPipeline(pipelineFile, args['--gate-endpoint'],
                                  args['--cookieheader'])
        else:
            print("Skip pipeline %s in application %s due to exists!" %
                  ("iac-%s" % args['--env'], app))
Exemplo n.º 4
0
def status(args):
    tmpDict = {}
    configFile = common.getConfig(args['--gate-endpoint'])
    config = common.loadconfig(configFile)
    appList = config[args['--applist']] if args['--applist'] else [
        args['--app']
    ]
    for app in tqdm(appList):
        triggerStatus = common.getPipelineTriggerStatus(
            app, args['--gate-endpoint'], args['--cookieheader'])
        pipelineStatus = common.getPipelineStatus(app, args['--gate-endpoint'],
                                                  args['--cookieheader'])
        tmpDict[app] = {}
        for k, v in triggerStatus.items():
            v.update(pipelineStatus.get(k, {"lastExecutiontime": None}))
            tmpDict[app].update({k: v})
    print(yaml.dump(tmpDict))
Exemplo n.º 5
0
def scan(args):
    configFile = common.getConfig(args['--gate-endpoint'])
    config = common.loadconfig(configFile)
    appInUse = config.get("appInUse", [])
    appUnUse = config.get("appUnUse", [])
    appAll = appInUse + appUnUse
    print("scan application from spinnaker api.")
    applist = common.getAppList(args['--gate-endpoint'],
                                args['--cookieheader'])
    for app in tqdm(applist):
        executeCount = common.getAppExcutionCount(app, args['--gate-endpoint'],
                                                  args['--cookieheader'])
        if executeCount:
            appInUse.append(app)
        else:
            appUnUse.append(app)
    config["appInUse"] = sorted(list(set(appInUse)))
    config["appUnUse"] = sorted(list(set(appUnUse)))
    common.saveconfig(config, configFile)
Exemplo n.º 6
0
def delete(args):
    configFile = common.getConfig(args['--gate-endpoint'])
    config = common.loadconfig(configFile)
    appList = config[args['--applist']] if args['--applist'] else [
        args['--app']
    ]
    currentAppList = common.getAppList(args['--gate-endpoint'],
                                       args['--cookieheader'])
    pipelineName = ''
    if args['--trigger']:
        pipelineName = "iac-%s-%s" % (args['--env'], args['--trigger'])
    else:
        pipelineName = "iac-%s" % (args['--env'])
    for app in tqdm(appList):
        if common.pipelineExists(app, pipelineName, args['--gate-endpoint'],
                                 args['--cookieheader'], currentAppList):
            common.deletePipeline(app, pipelineName, args['--gate-endpoint'],
                                  args['--cookieheader'])
        else:
            print(
                "Skip delete pipeline due to application %s or pipeline %s not exists!"
                % (app, "iac-%s" % args['--env']))