Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(object-storage): be able to query bucket stats #42

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ Examples
{u'servers': [...]}


- Get bucket informations:

.. code-block:: python

>>> from scaleway.apis import ObjectStorageAPI
>>> api = ObjectStorageAPI(auth_token='') # Set your token here!
>>> params = {'project_id': '12345678-9abc-def0-1234-567899abcdef', 'buckets_name': ['your_bucket_name']}
# Tiny hack due to slumber as we cant call directly .buckets-infos.post()
>>> print getattr(api.query(), 'buckets-info').post(params)
{u'buckets': {...}
# Or choose your region, as in apis/api_compute.py
>>> api = ComputeAPI(region='nl-ams', auth_token='') # Set your token here!


- Get details of a server:

.. code-block:: python
Expand Down
1 change: 1 addition & 0 deletions scaleway/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,4 @@ def query(self, serialize=True, **kwargs):
from .api_compute import ComputeAPI # noqa # isort:skip
from .api_metadata import MetadataAPI # noqa # isort:skip
from .api_billing import BillingAPI # noqa # isort:skip
from .api_object_storage import ObjectStorageAPI # noqa # isort:skip
43 changes: 43 additions & 0 deletions scaleway/apis/api_object_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013-2016 Online SAS and Contributors. All Rights Reserved.
# Julien Castets <[email protected]>
# Kevin Deldycke <[email protected]>
#
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at https://opensource.org/licenses/BSD-2-Clause

from . import API

REGIONS = {
'fr-par': {
'url': 'https://api-fr-par.scaleway.com/object-private/v1/regions/fr-par/',
},
'nl-ams': {
'url': 'https://api-nl-ams.scaleway.com/object-private/v1/regions/nl-ams/',
}
}


class ObjectStorageAPI(API):
""" The default region is par1 as it was the first availability zone
provided by Scaleway, but it could change in the future.
"""

def __init__(self, **kwargs):
region = kwargs.pop('region', None)
base_url = kwargs.pop('base_url', None)

assert region is None or base_url is None, \
"Specify either region or base_url, not both."

if base_url is None:
region = region or 'fr-par'

assert region in REGIONS, \
"'%s' is not a valid Scaleway region." % region

base_url = REGIONS.get(region)['url']

super(ObjectStorageAPI, self).__init__(base_url=base_url, **kwargs)