Total Complexity | 4 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | #!/usr/bin/env python |
||
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 |