Exemplo n.º 1
0
def worker_objects():
    proxy = ObjectStorageApi(NS)
    while True:
        try:
            name = QUEUE.get(timeout=TIMEOUT)
        except eventlet.queue.Empty:
            if VERBOSE:
                print("Leaving worker")
            break

        while True:
            try:
                items = proxy.object_list(ACCOUNT, name)
                objs = [_item['name'] for _item in items['objects']]
                size = sum([_item['size'] for _item in items['objects']])
                if len(objs) == 0:
                    break
                if VERBOSE:
                    print("Deleting", len(objs), "objects")
                proxy.object_delete_many(ACCOUNT, name, objs=objs)
                COUNTERS.add(len(objs), size)
                break
            except Exception as ex:
                if "Election failed" in str(ex):
                    # wait default Election wait delay
                    ELECTIONS.add(1, 0)
                    time.sleep(20)
                    continue
                print("Objs %s: %s" % (name, str(ex)), file=sys.stderr)
                break

        QUEUE.task_done()
Exemplo n.º 2
0
def main():
    args = options()

    global ACCOUNT, PROXY
    ACCOUNT = args.account
    PROXY = ObjectStorageApi("OPENIO")

    args.path = args.path.rstrip('/')
    if '/' in args.path:
        bucket, path = args.path.split('/', 1)
    else:
        bucket = args.path
        path = ""

    containers = []

    _bucket = container_hierarchy(bucket, path)
    # we don't use placeholders, we use prefix path as prefix
    for entry in full_list(prefix=container_hierarchy(bucket, path)):
        name, _files, _size, _ = entry
        if name != _bucket and not name.startswith(_bucket + '%2F'):
            continue

        if _files:
            items = PROXY.object_list(ACCOUNT, name)
            objs = [_item['name'] for _item in items['objects']]
            PROXY.object_delete_many(ACCOUNT, name, objs=objs)
            print("Deleting", len(objs), "objects")

        containers.append(name)

    print("We have to delete", len(containers), "containers")

    for container in containers:
        print("Deleting", container)
        PROXY.container_delete(ACCOUNT, container)