Exemplo n.º 1
0
def migrate(input_, output, target):
    """
    migrate command will migrate config file style to specific version
    :input_: is the path of the original config file
    :output: is the destination path of config file, the generated configs will storage in it
    :target: is the the target version of config file will upgrade to
    """
    if target not in accept_versions:
        click.echo('target version {} not supported'.format(target))
        sys.exit(-1)

    if not output:
        output = input_
    input_path = get_realpath(input_)
    output_path = get_realpath(output)

    configs = read_conf(input_path)
    input_version = configs.get('_version')
    if version.parse(input_version) < version.parse('1.9.0'):
        click.echo('the version {} not supported, make sure the version in input file above 1.8.0'.format(input_version))
        sys.exit(-1)
    if input_version == target:
        click.echo("Version of input harbor.yml is identical to target {}, no need to upgrade".format(input_version))
        sys.exit(0)

    current_input_path = input_path
    for m in search(input_version, target):
        current_output_path = "harbor.yml.{}.tmp".format(m.revision)
        click.echo("migrating to version {}".format(m.revision))
        m.migrate(current_input_path, current_output_path)
        current_input_path = current_output_path
    shutil.copy(current_input_path, output_path)
    click.echo("Written new values to {}".format(output))
    for tmp_f in glob.glob("harbor.yml.*.tmp"):
        os.remove(tmp_f)
Exemplo n.º 2
0
def migrate(input_, output, target):
    if not output:
        output = input_
    input_path = get_realpath(input_)
    output_path = get_realpath(output)

    configs = read_conf(input_path)

    input_version = configs.get('_version')

    if input_version == target:
        click.echo(
            "Version of input harbor.yml is identical to target {}, no need to upgrade"
            .format(input_version))
        sys.exit(0)

    current_input_path = input_path
    for m in search(input_version, target):
        current_output_path = "harbor.yml.{}.tmp".format(m.revision)
        click.echo("migrating to version {}".format(m.revision))
        m.migrate(current_input_path, current_output_path)
        current_input_path = current_output_path
    shutil.copy(current_input_path, output_path)
    click.echo("Written new values to {}".format(output))
    for tmp_f in glob.glob("harbor.yml.*.tmp"):
        os.remove(tmp_f)
Exemplo n.º 3
0
def migrate(input_cfg, output_cfg):
    current_dir = os.path.dirname(__file__)
    tpl = Environment(loader=FileSystemLoader(current_dir),
                      undefined=StrictUndefined,
                      trim_blocks=True,
                      lstrip_blocks=True).get_template('harbor.yml.jinja')

    config_dict = read_conf(input_cfg)

    with open(output_cfg, 'w') as f:
        f.write(tpl.render(**config_dict))
Exemplo n.º 4
0
def migrate(input_cfg, output_cfg):
    def max_comm_need_update(db_conf):
        # update value if database configured and max_open_conns value between 100 and 1000.
        if db_conf and db_conf.get('max_open_conns'):
            return 100 <= db_conf['max_open_conns'] < 1000
        # other situations no need to update
        return False

    current_dir = os.path.dirname(__file__)
    tpl = Environment(loader=FileSystemLoader(current_dir),
                      undefined=StrictUndefined,
                      trim_blocks=True,
                      lstrip_blocks=True).get_template('harbor.yml.jinja')

    config_dict = read_conf(input_cfg)

    if max_comm_need_update(config_dict.get('database')):
        config_dict['database']['max_open_conns'] = 1000

    with open(output_cfg, 'w') as f:
        f.write(tpl.render(**config_dict))
Exemplo n.º 5
0
def migrate(input_cfg, output_cfg):
    def db_conn_need_update(db_conf):
        if not db_conf:
            return False

        max_idle_conns = db_conf.get('max_idle_conns', 0)
        max_open_conns = db_conf.get('max_open_conns', 0)

        return max_idle_conns == 50 and max_open_conns == 1000

    current_dir = os.path.dirname(__file__)
    tpl = Environment(loader=FileSystemLoader(current_dir),
                      undefined=StrictUndefined,
                      trim_blocks=True,
                      lstrip_blocks=True).get_template('harbor.yml.jinja')

    config_dict = read_conf(input_cfg)

    if db_conn_need_update(config_dict.get('database')):
        config_dict['database']['max_idle_conns'] = 100
        config_dict['database']['max_open_conns'] = 900

    with open(output_cfg, 'w') as f:
        f.write(tpl.render(**config_dict))