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 Savatieiev | 5118de0 | 2019-02-20 15:50:42 -0600 | [diff] [blame] | 3 | |
| 4 | # instance of the salt client |
| 5 | salt = None |
| 6 | |
| 7 | |
| 8 | def get_salt_remote(config): |
| 9 | """Singleton-like creation of instance |
| 10 | |
| 11 | Arguments: |
| 12 | config {base_config} -- an instance to base_config |
| 13 | with creds and params |
| 14 | |
| 15 | Returns: |
| 16 | SaltRemote -- instance of salt client |
| 17 | """ |
| 18 | |
| 19 | global salt |
| 20 | logger.info("Creating salt remote instance") |
| 21 | # create it once |
| 22 | if salt is None: |
| 23 | salt = SaltRemote(config) |
| 24 | # do most expensive operation with no strict timeout possible |
| 25 | # all nodes that answer ping |
| 26 | salt.nodes_active = salt.get_active_nodes() |
| 27 | |
| 28 | # return once required |
| 29 | return salt |