keystone-light implements a Python interface to a very limited subset of the OpenStack Identity API v3.
Initial goal: access to OpenStack Swift, using the Identity API v3, but with a lot fewer dependencies.
As of this writing, the python-keystoneclient requires keystoneauth1 and oslo.*, which in turn require some more. We only require the ubiquitous requests (and PyYAML), which you generally already have installed anyway.
Example usage
#!/usr/bin/env python3
from urllib.parse import urljoin
import requests
from keystone_light import Cloud, CloudConfig, PermissionDenied
def get_projects(cloud):
"Yields projects, sorted by domain and project name"
domains = cloud.get_domains()
for domain in sorted(domains, key=(lambda x: x.name)):
if domain.name == 'Default':
# print('WARN: skipping domain Default (fixme?)')
continue
projects = domain.get_projects()
for project in sorted(projects, key=(lambda x: x.name)):
project.domain = domain
yield project
def get_swift_stat_ensuring_permissions(project):
"Get Swift v1 stat on a project (previously: tenant)"
try:
stat = project.get_swift().get_stat()
except PermissionDenied:
# We don't have permission to access the project? Upgrade the
# permissions and try again.
cloud = project.cloud
admin_role = cloud.get_role(name='admin') # or 'reader'
dom_admin_group = project.domain.get_admin_group()
url = urljoin(
cloud.base_url,
('/v3/projects/{project_id}/groups/{group_id}/'
'roles/{role_id}').format(
project_id=project.id, group_id=dom_admin_group.id,
role_id=admin_role.id))
out = requests.put(
url, headers={'X-Auth-Token': str(cloud.get_system_token())})
assert out.status_code in (201, 204), (out.status_code, out.text)
# Try again. Should succeed if the cloud admin user is in the
# dom_admin_group.
stat = project.get_swift().get_stat()
return stat
# Take config from ~/.config/openstack/clouds.yaml and select
# 'my-cloud-admin', like the openstack(1) --os-cloud option.
config = CloudConfig('my-cloud-admin')
cloud = Cloud(config)
for project in get_projects(cloud):
swift_stat = get_swift_stat_ensuring_permissions(project)
print('{:15s} {:23s} {:21d} B ({} objects, {} containers)'.format(
project.domain.name[0:15], project.name,
int(swift_stat['X-Account-Bytes-Used']),
swift_stat['X-Account-Object-Count'],
swift_stat['X-Account-Container-Count']))
Example output
$ python3 example.py
domainx project 3489 B (2 objects, 1 containers)
domainx otherproject 1455042022 B (267 objects, 1 containers)
...
Metadata
Release files for keystone-light 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keystone-light-0.2.tar.gz | 8.3 kB | Details |
Release files / keystone-light-0.2.tar.gz
| Download URL | keystone-light-0.2.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39d1dfabbc3e1da9baa5bfb458571cba5bd200ce4c229df82ce30abcbd8b4c99
|
|
BLAKE2b-256 checksum How to use checksums |
de2ceacf8341fde766f3a9fc5819ec7d3466802275c0a23030d55f26e2f051c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.9.1 pkginfo/1.4.1 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/2.7.17
|