Skip to content

Add baremetal API #36

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

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
1 change: 1 addition & 0 deletions scaleway/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,6 @@ def query(self, serialize=True, **kwargs):

from .api_account import AccountAPI # noqa # isort:skip
from .api_compute import ComputeAPI # noqa # isort:skip
from .api_baremetal import BaremetalAPI # noqa # isort:skip
from .api_metadata import MetadataAPI # noqa # isort:skip
from .api_billing import BillingAPI # noqa # isort:skip
40 changes: 40 additions & 0 deletions scaleway/apis/api_baremetal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013-2016 Online SAS and Contributors. All Rights Reserved.
# Julien Castets <jcastets@scaleway.com>
# Kevin Deldycke <kdeldycke@scaleway.com>
#
# 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-2': {
'url': 'https://api.scaleway.com/baremetal/v1/zones/fr-par-2/',
},
}


class BaremetalAPI(API):
""" The default region is fr-par-2 as it was the first availability zone
provided by Scaleway for baremetal servers, 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-2'

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

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

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