예제 #1
0
def handle_put_osd_in_bucket(request, service):
    """Move an osd into a specified crush bucket.

    :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
    """
    osd_id = request.get('osd')
    target_bucket = request.get('bucket')
    if not osd_id or not target_bucket:
        msg = "Missing OSD ID or Bucket"
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}
    crushmap = Crushmap()
    try:
        crushmap.ensure_bucket_is_present(target_bucket)
        check_output(
            [
                'ceph',
                '--id', service,
                'osd',
                'crush',
                'set',
                str(osd_id),
                str(get_osd_weight(osd_id)),
                "root={}".format(target_bucket)
            ]
        )

    except Exception as exc:
        msg = "Failed to move OSD " \
              "{} into Bucket {} :: {}".format(osd_id, target_bucket, exc)
        log(msg, level=ERROR)
        return {'exit-code': 1, 'stderr': msg}
예제 #2
0
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