def volume_backend_update(config_parser, cinder_client, arguments):
    if arguments.get("all"):
        for _volume_backend in config.get_volume_backends(config_parser):
            infinisdk = get_infinisdk_for_volume_backend(_volume_backend)
            pool = infinisdk.pools.get(id=_volume_backend['pool_id'])
            config.update_volume_type(cinder_client, _volume_backend['key'], infinisdk.get_name(), pool.get_name())
    else:
        volume_backend = get_existing_volume_backend(config_parser, arguments, "update")
        infinisdk = get_infinisdk_for_volume_backend(volume_backend)
        pool = infinisdk.pools.get(id=volume_backend['pool_id'])
        config.update_volume_type(cinder_client, volume_backend['key'], infinisdk.get_name(), pool.get_name())
    print_done_message(should_restart=False)
def volume_backend_enable(config_parser, cinder_client, arguments):
    volume_backend = get_existing_volume_backend(config_parser, arguments, "enable")
    config.enable(config_parser, volume_backend['key'])
    if arguments.commit:
        infinisdk = get_infinisdk_for_volume_backend(volume_backend)
        pool = infinisdk.objects.pools.get(id=arguments.pool_id)
        config.update_volume_type(cinder_client, volume_backend['key'], infinisdk.get_name(), pool.get_name())
    print_done_message(arguments.commit)
def volume_backend_rename(config_parser, cinder_client, arguments):
    volume_backend = get_existing_volume_backend(config_parser, arguments, "rename")
    new_backend_name = arguments.get('<new-volume-backend-name>')
    config.rename_backend(cinder_client,
                          config_parser,
                          arguments.address,
                          arguments.pool_id,
                          volume_backend['key'],
                          new_backend_name)
    if arguments.commit:
        infinisdk = get_infinisdk_for_volume_backend(volume_backend)
        pool = infinisdk.objects.pools.get(id=arguments.pool_id)
        config.update_volume_type(cinder_client, new_backend_name, infinisdk.get_name(), pool.get_name())
    print_done_message(arguments.commit)
def volume_backend_list(config_parser, cinder_client, arguments):
    from prettytable import PrettyTable
    from .config import get_volume_backends, get_enabled_backends
    volume_backends = get_volume_backends(config_parser)
    if not volume_backends:
        print(NO_VOLUME_BACKEND_MESSAGE, file=sys.stderr)
        return
    table = PrettyTable(TABLE_HEADER)  # v0.6.1 installed by openstack does not print empty tables
    backends = get_enabled_backends(config_parser)
    for volume_backend in volume_backends:
        status = "connection successful"
        system_serial = system_name = pool_name = 'n/a'
        try:
            infinisdk = get_infinisdk_for_volume_backend(volume_backend)
            system_serial = infinisdk.get_serial()
            system_name = infinisdk.get_name()
            pool = infinisdk.pools.get(id=volume_backend['pool_id'])
            pool_name = pool.get_name()
        except Exception as error:
            status = error.message
        table.add_row([volume_backend['address'], volume_backend['username'], volume_backend['key'] in backends, status,
                       system_serial, system_name, volume_backend['pool_id'], pool_name])
    print(table)