def handle_replicated_pool(request, service):
    pool_name = request.get('name')
    replicas = request.get('replicas')
    quota = request.get('max-bytes')

    # Optional params
    pg_num = request.get('pg_num')
    if pg_num:
        # Cap pg_num to max allowed just in case.
        osds = get_osds(service)
        if osds:
            pg_num = min(pg_num, (len(osds) * 100 // replicas))

    # Check for missing params
    if pool_name is None or replicas is None:
        msg = "Missing parameter. name and replicas are required"
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    pool = ReplicatedPool(service=service,
                          name=pool_name,
                          replicas=replicas,
                          pg_num=pg_num)
    if not pool_exists(service=service, name=pool_name):
        log("Creating pool '%s' (replicas=%s)" % (pool.name, replicas),
            level=INFO)
        pool.create()
    else:
        log("Pool '%s' already exists - skipping create" % pool.name,
            level=DEBUG)

    # Set a quota if requested
    if quota is not None:
        set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
def handle_replicated_pool(request, service):
    pool_name = request.get('name')
    replicas = request.get('replicas')
    quota = request.get('max-bytes')

    # Optional params
    pg_num = request.get('pg_num')
    if pg_num:
        # Cap pg_num to max allowed just in case.
        osds = get_osds(service)
        if osds:
            pg_num = min(pg_num, (len(osds) * 100 // replicas))

    # Check for missing params
    if pool_name is None or replicas is None:
        msg = "Missing parameter. name and replicas are required"
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    pool = ReplicatedPool(service=service,
                          name=pool_name,
                          replicas=replicas,
                          pg_num=pg_num)
    if not pool_exists(service=service, name=pool_name):
        log("Creating pool '%s' (replicas=%s)" % (pool.name, replicas),
            level=INFO)
        pool.create()
    else:
        log("Pool '%s' already exists - skipping create" % pool.name,
            level=DEBUG)

    # Set a quota if requested
    if quota is not None:
        set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
Beispiel #3
0
def handle_replicated_pool(request, service):
    """Create a new replicated pool.

    :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.
    """
    pool_name = request.get('name')
    replicas = request.get('replicas')
    quota = request.get('max-bytes')
    weight = request.get('weight')
    group_name = request.get('group')

    # Optional params
    pg_num = request.get('pg_num')
    if pg_num:
        # Cap pg_num to max allowed just in case.
        osds = get_osds(service)
        if osds:
            pg_num = min(pg_num, (len(osds) * 100 // replicas))

    app_name = request.get('app-name')
    # Check for missing params
    if pool_name is None or replicas is None:
        msg = "Missing parameter. name and replicas are required"
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    if group_name:
        group_namespace = request.get('group-namespace')
        # Add the pool to the group named "group_name"
        add_pool_to_group(pool=pool_name,
                          group=group_name,
                          namespace=group_namespace)

    kwargs = {}
    if pg_num:
        kwargs['pg_num'] = pg_num
    if weight:
        kwargs['percent_data'] = weight
    if replicas:
        kwargs['replicas'] = replicas
    if app_name:
        kwargs['app_name'] = app_name

    pool = ReplicatedPool(service=service,
                          name=pool_name, **kwargs)
    if not pool_exists(service=service, name=pool_name):
        log("Creating pool '{}' (replicas={})".format(pool.name, replicas),
            level=INFO)
        pool.create()
    else:
        log("Pool '{}' already exists - skipping create".format(pool.name),
            level=DEBUG)

    # Set a quota if requested
    if quota is not None:
        set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
Beispiel #4
0
def process_requests_v1(reqs):
    """Process v1 requests.

    Takes a list of requests (dicts) and processes each one. If an error is
    found, processing stops and the client is notified in the response.

    Returns a response dict containing the exit code (non-zero if any
    operation failed along with an explanation).
    """
    log("Processing %s ceph broker requests" % (len(reqs)), level=INFO)
    for req in reqs:
        op = req.get('op')
        log("Processing op='%s'" % (op), level=DEBUG)
        # Use admin client since we do not have other client key locations
        # setup to use them for these operations.
        svc = 'admin'
        if op == "create-pool":
            params = {'pool': req.get('name'), 'replicas': req.get('replicas')}
            if not all(params.iteritems()):
                msg = (
                    "Missing parameter(s): %s" %
                    (' '.join([k
                               for k in params.iterkeys() if not params[k]])))
                log(msg, level=ERROR)
                return {'exit-code': 1, 'stderr': msg}

            # Mandatory params
            pool = params['pool']
            replicas = params['replicas']

            # Optional params
            pg_num = req.get('pg_num')
            if pg_num:
                # Cap pg_num to max allowed just in case.
                osds = get_osds(svc)
                if osds:
                    pg_num = min(pg_num, (len(osds) * 100 // replicas))

                # Ensure string
                pg_num = str(pg_num)

            if not pool_exists(service=svc, name=pool):
                log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
                    level=INFO)
                create_pool(service=svc,
                            name=pool,
                            replicas=replicas,
                            pg_num=pg_num)
            else:
                log("Pool '%s' already exists - skipping create" % (pool),
                    level=DEBUG)
        else:
            msg = "Unknown operation '%s'" % (op)
            log(msg, level=ERROR)
            return {'exit-code': 1, 'stderr': msg}

    return {'exit-code': 0}
Beispiel #5
0
def handle_replicated_pool(request, service):
    """Create a new replicated pool.

    :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.
    """
    pool_name = request.get('name')
    replicas = request.get('replicas')
    quota = request.get('max-bytes')
    weight = request.get('weight')
    group_name = request.get('group')

    # Optional params
    pg_num = request.get('pg_num')
    if pg_num:
        # Cap pg_num to max allowed just in case.
        osds = get_osds(service)
        if osds:
            pg_num = min(pg_num, (len(osds) * 100 // replicas))

    app_name = request.get('app-name')
    # Check for missing params
    if pool_name is None or replicas is None:
        msg = "Missing parameter. name and replicas are required"
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    if group_name:
        group_namespace = request.get('group-namespace')
        # Add the pool to the group named "group_name"
        add_pool_to_group(pool=pool_name,
                          group=group_name,
                          namespace=group_namespace)

    kwargs = {}
    if pg_num:
        kwargs['pg_num'] = pg_num
    if weight:
        kwargs['percent_data'] = weight
    if replicas:
        kwargs['replicas'] = replicas
    if app_name:
        kwargs['app_name'] = app_name

    pool = ReplicatedPool(service=service, name=pool_name, **kwargs)
    if not pool_exists(service=service, name=pool_name):
        log("Creating pool '{}' (replicas={})".format(pool.name, replicas),
            level=INFO)
        pool.create()
    else:
        log("Pool '{}' already exists - skipping create".format(pool.name),
            level=DEBUG)

    # Set a quota if requested
    if quota is not None:
        set_pool_quota(service=service, pool_name=pool_name, max_bytes=quota)
Beispiel #6
0
def process_requests_v1(reqs):
    """Process v1 requests.

    Takes a list of requests (dicts) and processes each one. If an error is
    found, processing stops and the client is notified in the response.

    Returns a response dict containing the exit code (non-zero if any
    operation failed along with an explanation).
    """
    log("Processing %s ceph broker requests" % (len(reqs)), level=INFO)
    for req in reqs:
        op = req.get('op')
        log("Processing op='%s'" % (op), level=DEBUG)
        # Use admin client since we do not have other client key locations
        # setup to use them for these operations.
        svc = 'admin'
        if op == "create-pool":
            params = {'pool': req.get('name'),
                      'replicas': req.get('replicas')}
            if not all(params.iteritems()):
                msg = ("Missing parameter(s): %s" %
                       (' '.join([k for k in params.iterkeys()
                                  if not params[k]])))
                log(msg, level=ERROR)
                return {'exit-code': 1, 'stderr': msg}

            # Mandatory params
            pool = params['pool']
            replicas = params['replicas']

            # Optional params
            pg_num = req.get('pg_num')
            if pg_num:
                # Cap pg_num to max allowed just in case.
                osds = get_osds(svc)
                if osds:
                    pg_num = min(pg_num, (len(osds) * 100 // replicas))

                # Ensure string
                pg_num = str(pg_num)

            if not pool_exists(service=svc, name=pool):
                log("Creating pool '%s' (replicas=%s)" % (pool, replicas),
                    level=INFO)
                create_pool(service=svc, name=pool, replicas=replicas,
                            pg_num=pg_num)
            else:
                log("Pool '%s' already exists - skipping create" % (pool),
                    level=DEBUG)
        else:
            msg = "Unknown operation '%s'" % (op)
            log(msg, level=ERROR)
            return {'exit-code': 1, 'stderr': msg}

    return {'exit-code': 0}
Beispiel #7
0
def handle_replicated_pool(request, service):
    """Create a new replicated pool.

    :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.
    """
    pool_name = request.get('name')
    group_name = request.get('group')

    # Optional params
    # NOTE: Check this against the handling in the Pool classes, reconcile and
    # remove.
    pg_num = request.get('pg_num')
    replicas = request.get('replicas')
    if pg_num:
        # Cap pg_num to max allowed just in case.
        osds = get_osds(service)
        if osds:
            pg_num = min(pg_num, (len(osds) * 100 // replicas))
            request.update({'pg_num': pg_num})

    if group_name:
        group_namespace = request.get('group-namespace')
        # Add the pool to the group named "group_name"
        add_pool_to_group(pool=pool_name,
                          group=group_name,
                          namespace=group_namespace)

    try:
        pool = ReplicatedPool(service=service,
                              op=request)
    except KeyError:
        msg = "Missing parameter."
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}

    if not pool_exists(service=service, name=pool_name):
        log("Creating pool '{}' (replicas={})".format(pool.name, replicas),
            level=INFO)
        pool.create()
    else:
        log("Pool '{}' already exists - skipping create".format(pool.name),
            level=DEBUG)

    # Set/update properties that are allowed to change after pool creation.
    pool.update()
def purge_osd(osd):
    """Run the OSD purge action.

    :param osd: the OSD ID to operate on
    """
    svc = 'admin'
    osd_str = str(osd)
    osd_name = "osd.{}".format(osd_str)
    current_osds = ceph.get_osds(svc)
    if osd not in current_osds:
        function_fail("OSD {} is not in the current list of OSDs".format(osd))
        return

    osd_weight = get_osd_weight(osd_name)
    if osd_weight > 0:
        function_fail("OSD has weight {}, must have zero weight before "
                      "this operation".format(osd_weight))
        return

    luminous_or_later = cmp_pkgrevno('ceph-common', '12.0.0') >= 0
    if not function_get('i-really-mean-it'):
        function_fail('i-really-mean-it is a required parameter')
        return
    if luminous_or_later:
        cmds = [["ceph", "osd", "out", osd_name],
                ['ceph', 'osd', 'purge', osd_str, '--yes-i-really-mean-it']]
    else:
        cmds = [
            ["ceph", "osd", "out", osd_name],
            ["ceph", "osd", "crush", "remove", "osd.{}".format(osd)],
            ["ceph", "auth", "del", osd_name],
            ['ceph', 'osd', 'rm', osd_str],
        ]
    for cmd in cmds:
        try:
            check_call(cmd)
        except CalledProcessError as e:
            log(e)
            function_fail("OSD Purge for OSD {} failed".format(osd))
            return
Beispiel #9
0
 def test_get_osds_none(self, version):
     version.return_value = '0.56.2'
     self.check_output.return_value = json.dumps(None).encode('UTF-8')
     self.assertEquals(ceph_utils.get_osds('test'), None)
Beispiel #10
0
 def test_get_osds_argonaut(self, version):
     version.return_value = '0.48.3'
     self.assertEquals(ceph_utils.get_osds('test'), None)