示例#1
0
文件: qcow.py 项目: j5boot/isard
def get_host_and_path_diskoperations_to_write_in_path(type_path,
                                                      relative_path,
                                                      pool='default'):
    if type_path not in ['bases', 'groups', 'templates']:
        log.error('type disk operations must be bases, groups or templates')
        return False
    pool_paths = get_pool(pool)['paths']
    paths_for_type = pool_paths[type_path]
    list_paths_with_weights = [{
        'w': v['weight'],
        'k': k
    } for k, v in paths_for_type.items()]
    weights = [v['w'] for v in list_paths_with_weights]
    index_list_path_selected = weighted_choice(weights)
    path_selected = list_paths_with_weights[index_list_path_selected]['k']
    host_disk_operations_selected = False
    for h in paths_for_type[path_selected]['disk_operations']:
        if ('disk_op_' + h) in get_threads_names_running():
            host_disk_operations_selected = h
            log.debug(
                'host {} selected in pool {}, type_path: {}, path: {}'.format(
                    host_disk_operations_selected, pool, type_path,
                    path_selected))
            break
    if host_disk_operations_selected is False:
        log.error(
            'no host with thread for disk_operations in pool {}, type_path: {}, path: {}'
            .format(pool, type_path, path_selected))
        return False
    else:
        path_absolute = path_selected + '/' + relative_path
        return host_disk_operations_selected, path_absolute
示例#2
0
文件: qcow.py 项目: isard-vdi/isard
def get_host_and_path_diskoperations_to_write_in_path(type_path, relative_path, pool='default'):
    if type_path not in ['bases', 'groups', 'templates']:
        log.error('type disk operations must be bases, groups or templates')
        return False
    pool_paths = get_pool(pool)['paths']
    paths_for_type = pool_paths[type_path]
    list_paths_with_weights = [{'w': v['weight'], 'k': k} for k, v in paths_for_type.items()]
    weights = [v['w'] for v in list_paths_with_weights]
    index_list_path_selected = weighted_choice(weights)
    path_selected = list_paths_with_weights[index_list_path_selected]['k']
    host_disk_operations_selected = False
    for h in paths_for_type[path_selected]['disk_operations']:
        if ('disk_op_' + h) in get_threads_names_running():
            host_disk_operations_selected = h
            log.debug('host {} selected in pool {}, type_path: {}, path: {}'.format(
                host_disk_operations_selected,
                pool,
                type_path,
                path_selected))
            break
    if host_disk_operations_selected is False:
        log.error('no host with thread for disk_operations in pool {}, type_path: {}, path: {}'.format(
            pool,
            type_path,
            path_selected))
        return False
    else:
        path_absolute = path_selected + '/' + relative_path
        return host_disk_operations_selected, path_absolute
示例#3
0
文件: qcow.py 项目: isard-vdi/isard
def get_path_to_disk(relative_path, pool='default', type_path='groups'):
    pool_paths = get_pool(pool)['paths']
    paths_for_type = pool_paths[type_path]
    list_paths_with_weights = [{'w': v['weight'], 'k': v['path']} for v in paths_for_type]
    weights = [v['w'] for v in list_paths_with_weights]
    index_list_path_selected = weighted_choice(weights)
    path_selected = list_paths_with_weights[index_list_path_selected]['k']
    path_absolute = path_selected + '/' + relative_path
    return path_absolute, path_selected
示例#4
0
文件: qcow.py 项目: j5boot/isard
def get_path_to_disk(relative_path, pool='default', type_path='groups'):
    pool_paths = get_pool(pool)['paths']
    paths_for_type = pool_paths[type_path]
    list_paths_with_weights = [{
        'w': v['weight'],
        'k': v['path']
    } for v in paths_for_type]
    weights = [v['w'] for v in list_paths_with_weights]
    index_list_path_selected = weighted_choice(weights)
    path_selected = list_paths_with_weights[index_list_path_selected]['k']
    path_absolute = path_selected + '/' + relative_path
    return path_absolute, path_selected