Alex | 0989ecf | 2022-03-29 13:43:21 -0500 | [diff] [blame] | 1 | # Author: Alex Savatieiev (osavatieiev@mirantis.com; a.savex@gmail.com) |
| 2 | # Copyright 2019-2022 Mirantis, Inc. |
Alex Savatieiev | 5118de0 | 2019-02-20 15:50:42 -0600 | [diff] [blame] | 3 | from cfg_checker.common import logger |
Alex | 3ebc563 | 2019-04-18 16:47:18 -0500 | [diff] [blame] | 4 | from cfg_checker.common.salt_utils import SaltRemote |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 5 | from cfg_checker.common.kube_utils import KubeRemote |
| 6 | |
Alex Savatieiev | 5118de0 | 2019-02-20 15:50:42 -0600 | [diff] [blame] | 7 | |
| 8 | # instance of the salt client |
| 9 | salt = None |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 10 | kube = None |
Alex Savatieiev | 5118de0 | 2019-02-20 15:50:42 -0600 | [diff] [blame] | 11 | |
| 12 | |
| 13 | def get_salt_remote(config): |
| 14 | """Singleton-like creation of instance |
| 15 | |
| 16 | Arguments: |
| 17 | config {base_config} -- an instance to base_config |
| 18 | with creds and params |
| 19 | |
| 20 | Returns: |
| 21 | SaltRemote -- instance of salt client |
| 22 | """ |
| 23 | |
| 24 | global salt |
| 25 | logger.info("Creating salt remote instance") |
| 26 | # create it once |
| 27 | if salt is None: |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 28 | salt = SaltRemote(config) |
Alex Savatieiev | 5118de0 | 2019-02-20 15:50:42 -0600 | [diff] [blame] | 29 | # return once required |
| 30 | return salt |
Alex | 9a4ad21 | 2020-10-01 18:04:25 -0500 | [diff] [blame] | 31 | |
| 32 | |
| 33 | def get_kube_remote(config): |
| 34 | """Singleton-like creation of instance |
| 35 | |
| 36 | Arguments: |
| 37 | config {base_config} -- an instance to base_config |
| 38 | with creds and params |
| 39 | |
| 40 | Returns: |
| 41 | KubeRemote -- instance of kube client |
| 42 | """ |
| 43 | global kube |
| 44 | logger.info("Creating kube remote client instance") |
| 45 | # Create it once |
| 46 | if kube is None: |
| 47 | kube = KubeRemote(config) |
| 48 | return kube |