Exemplo n.º 1
0
def upgrade_cmdb_repo_to_v1_1_0_settings(root_dir, dry_run, target_dir):
    # Create the shared file location for default segment
    shared_dir = os.path.join(target_dir, 'shared')
    os.makedirs(shared_dir, exist_ok=True)
    sub_files = Search.list_files(root_dir)
    for sub_file in sub_files:
        src = os.path.join(root_dir, sub_file)
        dst = os.path.join(shared_dir, sub_file)
        logger.debug('Copying %s to %s', src, dst)
        if dry_run:
            continue
        shutil.copy2(src, dst)
    sub_dirs = Search.list_dirs(root_dir)
    for sub_dir in sub_dirs:
        environment = sub_dir
        sub_dir = os.path.join(root_dir, sub_dir)
        segment_dir = os.path.join(target_dir, environment, 'default')
        os.makedirs(segment_dir, exist_ok=True)
        logger.debug('Copying %s to %s', sub_dir, segment_dir)
        if dry_run:
            continue
        for name in Search.list_all(sub_dir):
            src = os.path.join(sub_dir, name)
            dst = os.path.join(segment_dir, name)
            if os.path.isdir(src):
                shutil.copytree(src, dst)
            else:
                shutil.copy2(src, dst)

        # Remove anything unwanted
        segment_files = Search.match_files(os.path.join('**', '*.ref'),
                                           os.path.join(
                                               '**', 'container.json'),
                                           root=segment_dir)
        for segment_file in segment_files:
            logger.debug('Deleting %s', segment_file)
            os.remove(segment_file)
    return True
Exemplo n.º 2
0
def upgrade_cmdb_repo_to_v1_1_0_state(root_dir, dry_run, target_dir):
    # Create the shared file location
    shared_dir = os.path.join(target_dir, 'shared')
    os.makedirs(shared_dir, exist_ok=True)
    # Copy across the shared files
    cf_dir = os.path.join(root_dir, 'cf')
    if os.path.isdir(cf_dir):
        sub_files = Search.list_files(cf_dir)
        for sub_file in sub_files:
            src = os.path.join(cf_dir, sub_file)
            dst = os.path.join(shared_dir, sub_file)
            logger.debug('Copying %s to %s', src, dst)
            if dry_run:
                continue
            shutil.copy2(src, dst)
    # Process each sub dir
    sub_dirs = Search.list_dirs(root_dir)
    for sub_dir in sub_dirs:
        if sub_dir == 'cf':
            continue
        environment = sub_dir
        segment_dir = os.path.join(target_dir, environment, 'default')
        cf_dir = os.path.join(root_dir, sub_dir, 'cf')
        if not os.path.isdir(cf_dir):
            continue
        os.makedirs(segment_dir, exist_ok=True)
        logger.debug('Copying %s to %s', cf_dir, segment_dir)
        if dry_run:
            continue
        for name in Search.list_all(cf_dir):
            src = os.path.join(cf_dir, name)
            dst = os.path.join(segment_dir, name)
            if os.path.isdir(src):
                shutil.copytree(src, dst)
            else:
                shutil.copy2(src, dst)