Giter Site home page Giter Site logo

python-radosgw-admin's Introduction

python-radosgw-admin

Python REST API for the Ceph RADOS Gateway (radosgw) admin operations

http://docs.ceph.com/docs/master/radosgw/adminops/

NOTICE: The library support Ceph version >= 10.2 (Jewel).

Changes

  • Version 1.6: Support for Ceph Hammer or older have been dropped.
  • Version 1.7: Functions get_buckets() and get_users() returns an iterator, not a list anymore.
  • Version 1.7.1: Function get_uids() added.
  • Version 1.7.2: Functions get_policy(bucket, object=None, ...) and delete_usage() added. Function set_quota(...) returns None.

Requirement

  • boto

Installation

The package is available on https://pypi.python.org/pypi/radosgw-admin. To install it use pip:

pip install radosgw-admin

Or clone this repository and install it locally:

python setup.py install

Configuration of the admin user

To create or modify a bucket/user in radosgw, the admin user require the following read,write capabilities (caps):

"caps": [
   { "type": "buckets",
     "perm": "*" },
   { "type": "usage",
     "perm": "read" },
   { "type": "metadata",
     "perm": "read" },
   { "type": "users",
     "perm": "*" }
]

You can use the radosgw-admin command to add capabilities to an existing user:

radosgw-admin caps add --uid <USER_ID> --caps "buckets=read,write"
radosgw-admin caps add --uid <USER_ID> --caps "users=read,write"

Examples

See the example in examples/radosgw-admin-example.py

Here is a simple example:

import radosgw

rgwadmin = radosgw.connection.RadosGWAdminConnection(host='hostname.example.org',
                                                     access_key='<ADMIN_ACCESS_KEY>',
                                                     secret_key='<ADMIN_SECRET_KEY>')
# user operations
testuser2 = rgwadmin.create_user('testuser2',
                                 display_name='A test user',
                                 email='[email protected]')

testuser2.update(display_name='Second test user', suspended=True)

testuser1 = rgwadmin.get_user('testuser1')

# bucket operations
buckets = rgwadmin.get_buckets()
for bucket in buckets:
    print(bucket)

testuser1_buckets = testuser1.get_buckets()
for bucket in testuser1_buckets:
    # transfer buckets to testuser2
    rgwadmin.link_bucket(bucket.name, bucket.id, testuser2.id)

python-radosgw-admin's People

Contributors

bmeekhof avatar clempi avatar josecastroleon avatar lj-hust avatar neo-no93 avatar valerytschopp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-radosgw-admin's Issues

Long buckets list problem

Hi,

I developed a script based on your library to extract stats from all buckets via rgw.get_bucket(stats=True).
It was working fine until today. Now I get None back.
I think it comes from the large number of buckets (+2500) because when I use the CLI radosgw-admin bucket stats, I get a response containing all the stats of my all buckets.
So I did an rgw.get_buckets() followed by a for loop on each bucket to retrieve the stats but the processing time is infinitely longer.

Is there a solution to get all stats of all bucket with one request only please ?

Thanks

connection error

I use the command " python radosgw-admin-example.py --hostname=172.16.154.* -a C3H********** -s gEl4uaoGWDd3oH78kCo***********
" but I get message"ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)“. I have cofigured the ssl for my apache .
How can I fix the problem?

User info breaks on Swift keys

I'll have to return with the specific Ceph/RadowGW version, but get_users breaks here due to key_dict not having an access_key property.

My dicts have only secret_key and user.

Python3 Incompatibility

Issue

Line 360 of connection.py makes this library only work with Python 2 due to the it's check for type unicode which was renamed to str in Python 3. Could we update this please?

Error

  File "/Users/c81298/.local/share/virtualenvs/symphony-s3-xs1SLCJ5/lib/python3.6/site-packages/radosgw/connection.py", line 360, in get_buckets
    if isinstance(body_json[0], unicode) or isinstance(body_json[0], str):
NameError: name 'unicode' is not defined

Modfying user capabilities

Hi,

Thanks for making this client library, I'm finding it immensely useful.

I'm having an issue modifying caps for a given user post-creation. It seems fine to create a user with a set of caps but post-creation doesn't seem to work. Looking at the logs in RGW it doesn't seem to be complaining about anything. Not sure if it's an issue with RGW or the library.

for example:

testuser2 = rgwadmin.create_user('testuser2',
                                 display_name='A test user',
                                 email='[email protected]')

testuser2.update(display_name='Second test user', user_caps='buckets=*')

The request returns 200 and the RGW logs all look good.
Keen to know if you've seen this issue.

Thanks

Create bucket operation

I noticed this library can create users and it can do various admin operations on buckets, it can't create buckets. Also I noticed this operation is not on https://docs.ceph.com/docs/nautilus/radosgw/adminops/ . Likely it's not there because it's part of the standard S3 API already which makes sense.

For completeness though, would this still be a useful call to add?

Any plans to port to boto3?

Hi,

Many thanks for this useful library.

I was wondering if you have any plans to switch to using boto3: boto is at this point no longer properly maintained and bugs are no longer being addressed or pull requests merged.

I am hit for example by this bug, which affects me with python-radosgw-admin, as I try to connect to an endpoint with self-signed certificates. I can get around it with the https_connection_factory hack, but it's not pretty...

Feature request: user stats

It would be nice, if support for user stats could be added.

CLI command: radosgw-admin user stats --uid=xxxx --sync-stats

Proxy connection failing.

Hi!

I need to send requests for rados gateway behind a http proxy and I'm applying the following settings on my connector:

# -*- coding: utf-8 -*-
#!/usr/bin/env python3
from radosgw.connection import RadosGWAdminConnection

rgwadmin = RadosGWAdminConnection(host="rados_gateway_server",
                                  access_key="ACCESS_KEY",
                                  secret_key="SECRET_KEY",
                                  proxy="http_proxy_server",
                                  proxy_port=3128,
                                  proxy_user="http_proxy_user",
                                  proxy_pass="http_proxy_pass",
                                  debug=True)

users = rgwadmin.get_users()
for u in users:
    print(f"Username: {u.display_name}")
    print(f"User ID: {u.user_id}")

I'm getting the error bellow:

2020-10-22 17:00:53,855 boto [DEBUG]:http_request:method:(GET) protocol:(https) host(rados_gateway) port(443) path(https://rados_gateway/admin/metadata/user?format=json) params({'format': 'json'}) headers({}) body()
2020-10-22 17:00:53,855 boto [DEBUG]:Method: GET
2020-10-22 17:00:53,856 boto [DEBUG]:Path: https://rados_gateway/admin/metadata/user?format=json
2020-10-22 17:00:53,856 boto [DEBUG]:Data: 
2020-10-22 17:00:53,856 boto [DEBUG]:Headers: {}
2020-10-22 17:00:53,856 boto [DEBUG]:Host: rados_gateway
2020-10-22 17:00:53,856 boto [DEBUG]:Port: 443
2020-10-22 17:00:53,856 boto [DEBUG]:Params: {'format': 'json'}
2020-10-22 17:00:53,856 boto [DEBUG]:establishing HTTPS connection: host=rados_gateway, kwargs={'timeout': 30, 'port': 443}
2020-10-22 17:00:53,860 boto [DEBUG]:Proxy connection: CONNECT rados_gateway:443 HTTP/1.0

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python/venv/lib/python3.7/site-packages/radosgw/connection.py", line 162, in get_users
    response = self.make_request('GET', path='/metadata/user', query_params=params)
  File "/opt/python/venv/lib/python3.7/site-packages/radosgw/connection.py", line 120, in make_request
    retry_handler=retry_handler)
  File "/opt/python/venv/lib/python3.7/site-packages/boto/connection.py", line 913, in _mexe
    self.is_secure)
  File "/opt/python/venv/lib/python3.7/site-packages/boto/connection.py", line 705, in get_http_connection
    return self.new_http_connection(host, port, is_secure)
  File "/opt/python/venv/lib/python3.7/site-packages/boto/connection.py", line 747, in new_http_connection
    connection = self.proxy_ssl(host, is_secure and 443 or 80)
  File "/opt/python/venv/lib/python3.7/site-packages/boto/connection.py", line 796, in proxy_ssl
    sock.sendall("CONNECT %s HTTP/1.0\r\n" % host)
TypeError: a bytes-like object is required, not 'str'

What's gone wrong? Can you help me?

Tks!

NameError: name 'query' is not defined

There is an error in: python-radosgw-admin/radosgw/connection.py

In line 101 you are using the variable "query" which does not exist..
I think you forgot to init this variable in line 97:
urlencode(query_params)
should be:
query = urlencode(query_params)

Not going to bother creating a new pull request , i think it's a hot fix sort of bug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.