def create_and_move_buckets_list(cluster, location, crush_map, containerized=None):  # noqa: E501
    '''
    Creates Ceph CRUSH buckets and arrange the hierarchy
    '''
    def bucket_exists(bucket_name, bucket_type):
        for item in crush_map['nodes']:
            if item['name'] == bucket_name and item['type'] == bucket_type:
                return True
        return False

    def bucket_in_place(bucket_name, target_bucket_name, target_bucket_type):  # noqa: E501
        bucket_id = None
        target_bucket = None
        for item in crush_map['nodes']:
            if item['name'] == bucket_name:
                bucket_id = item['id']
            if item['name'] == target_bucket_name and item['type'] == target_bucket_type:  # noqa: E501
                target_bucket = item

        if not bucket_id or not target_bucket:
            return False

        return bucket_id in target_bucket['children']

    previous_bucket = None
    cmd_list = []
    for item in location:
        bucket_type, bucket_name = item
        # ceph osd crush add-bucket maroot root
        if not bucket_exists(bucket_name, bucket_type):
            cmd_list.append(generate_cmd(cluster, "add-bucket", bucket_name, bucket_type, containerized))  # noqa: E501
        if previous_bucket:
            # ceph osd crush move monrack root=maroot
            if not bucket_in_place(previous_bucket, bucket_name, bucket_type):  # noqa: E501
                cmd_list.append(generate_cmd(cluster, "move", previous_bucket, "%s=%s" % (bucket_type, bucket_name), containerized))  # noqa: E501
        previous_bucket = item[1]
    return cmd_list

    Creates Ceph CRUSH buckets and arrange the hierarchy
    
library/ceph_crush.py