InterfaceBase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B __init__() 0 24 4
1
#!/usr/bin/env python
2
# -*- encoding: utf-8 -*-
3
4
import ovh
5
import logging
6
import os
7
8
9
class InterfaceBase:
10
    """
11
    This class represent the base of each class in ovh_interface. I contains some utils object like logger and ovh_client
12
    """
13
14
    """
15
    The default logger for all subclass ;)
16
    """
17
    logger = None
18
19
    def __init__(self, ovh_client=None):
20
        """
21
        Constructor
22
        :param ovh_client: the ovh client you want to use. If none use environment variable to initialize the ovh client.
23
        """
24
25
        if ovh_client is None:
26
            self.ovh_client = ovh.Client(endpoint=os.getenv('endpoint', 'ovh-eu'),
27
                                         application_key=os.getenv('application_key'),
28
                                         application_secret=os.getenv('application_secret'),
29
                                         consumer_key=os.getenv('consumer_key')
30
                                         )
31
        else:
32
            self.ovh_client = ovh_client
33
34
        if not InterfaceBase.logger:
35
            InterfaceBase.logger = logging.getLogger('InterfaceBase')
36
            InterfaceBase.logger.addHandler(logging.StreamHandler())
37
38
            if os.getenv('DEBUG'):
39
                InterfaceBase.logger.setLevel(logging.DEBUG)
40
            else:
41
                InterfaceBase.logger.setLevel(logging.INFO)
42
            self.logger = InterfaceBase.logger
43