def handle_set_pool_value(request, service):
    # Set arbitrary pool values
    params = {
        'pool': request.get('name'),
        'key': request.get('key'),
        'value': request.get('value')
    }
    if params['key'] not in POOL_KEYS:
        msg = "Invalid key '%s'" % params['key']
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    # Get the validation method
    validator_params = POOL_KEYS[params['key']]
    if len(validator_params) is 1:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0])
    else:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0], validator_params[1])

    # Set the value
    pool_set(service=service,
             pool_name=params['pool'],
             key=params['key'],
             value=params['value'])
Пример #2
0
def handle_set_pool_value(request, service):
    """Sets an arbitrary pool value.

    :param request: dict of request operations and params
    :param service: The ceph client to run the command under.
    :returns: dict. exit-code and reason if not 0
    """
    # Set arbitrary pool values
    params = {'pool': request.get('name'),
              'key': request.get('key'),
              'value': request.get('value')}
    if params['key'] not in POOL_KEYS:
        msg = "Invalid key '{}'".format(params['key'])
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    # Get the validation method
    validator_params = POOL_KEYS[params['key']]
    if len(validator_params) is 1:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0])
    else:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0], validator_params[1])

    # Set the value
    pool_set(service=service, pool_name=params['pool'], key=params['key'],
             value=params['value'])
Пример #3
0
def handle_set_pool_value(request, service):
    """Sets an arbitrary pool value.

    :param request: dict of request operations and params
    :param service: The ceph client to run the command under.
    :returns: dict. exit-code and reason if not 0
    """
    # Set arbitrary pool values
    params = {'pool': request.get('name'),
              'key': request.get('key'),
              'value': request.get('value')}
    if params['key'] not in POOL_KEYS:
        msg = "Invalid key '{}'".format(params['key'])
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    # Get the validation method
    validator_params = POOL_KEYS[params['key']]
    if len(validator_params) is 1:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0])
    else:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0], validator_params[1])

    # Set the value
    pool_set(service=service, pool_name=params['pool'], key=params['key'],
             value=params['value'])
Пример #4
0
def handle_set_pool_value(request, service, coerce=False):
    """Sets an arbitrary pool value.

    :param request: dict of request operations and params
    :param service: The ceph client to run the command under.
    :param coerce: Try to parse/coerce the value into the correct type.
                   Used by the action code that only gets Str from Juju
    :returns: dict. exit-code and reason if not 0
    """
    # Set arbitrary pool values
    params = {
        'pool': request.get('name'),
        'key': request.get('key'),
        'value': request.get('value')
    }
    if params['key'] not in POOL_KEYS:
        msg = "Invalid key '{}'".format(params['key'])
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    # Get the validation method
    validator_params = POOL_KEYS[params['key']]
    # BUG: #1838650 - the function needs to try to coerce the value param to
    # the type required for the validator to pass.  Note, if this blows, then
    # the param isn't parsable to the correct type.
    if coerce:
        try:
            params['value'] = validator_params[0](params['value'])
        except ValueError:
            raise RuntimeError("Value {} isn't of type {}".format(
                params['value'], validator_params[0]))
    # end of BUG: #1838650
    if len(validator_params) == 1:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0])
    else:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0], validator_params[1])

    # Set the value
    pool_set(service=service,
             pool_name=params['pool'],
             key=params['key'],
             value=params['value'])
Пример #5
0
def handle_set_pool_value(request, service):
    # Set arbitrary pool values
    params = {'pool': request.get('name'),
              'key': request.get('key'),
              'value': request.get('value')}
    if params['key'] not in POOL_KEYS:
        msg = "Invalid key '%s'" % params['key']
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    # Get the validation method
    validator_params = POOL_KEYS[params['key']]
    if len(validator_params) is 1:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0])
    else:
        # Validate that what the user passed is actually legal per Ceph's rules
        validator(params['value'], validator_params[0], validator_params[1])
    # Set the value
    pool_set(service=service, pool_name=params['pool'], key=params['key'],
             value=params['value'])