ComputeAPI   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 16 4
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright (c) 2013-2016 Online SAS and Contributors. All Rights Reserved.
4
#                         Julien Castets <[email protected]>
5
#                         Kevin Deldycke <[email protected]>
6
#
7
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
8
# file except in compliance with the License. You may obtain a copy of the
9
# License at https://opensource.org/licenses/BSD-2-Clause
10
11
from . import API
12
13
REGIONS = {
14
    'par1': {
15
        'url': 'https://cp-par1.scaleway.com/',
16
    },
17
    'ams1': {
18
        'url': 'https://cp-ams1.scaleway.com/',
19
    }
20
}
21
22
23
class ComputeAPI(API):
24
    """ The default region is par1 as it was the first availability zone
25
    provided by Scaleway, but it could change in the future.
26
    """
27
28
    def __init__(self, **kwargs):
29
        region = kwargs.pop('region', None)
30
        base_url = kwargs.pop('base_url', None)
31
32
        assert region is None or base_url is None, \
33
            "Specify either region or base_url, not both."
34
35
        if base_url is None:
36
            region = region or 'par1'
37
38
            assert region in REGIONS, \
39
                "'%s' is not a valid Scaleway region." % region
40
41
            base_url = REGIONS.get(region)['url']
42
43
        super(ComputeAPI, self).__init__(base_url=base_url, **kwargs)
44