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