예제 #1
0
    def __init__(self, ops, data):
        super().__init__(ops, data)
        global FABRIC_PATCHED

        if not FABRIC_PATCHED:
            Connection.open_orig = Connection.open
            Connection.open = unsafe_open
            FABRIC_PATCHED = True

        # Load configuration
        config = get_config()
        ssh_user = config.get('ssh', 'user', fallback=None)
        ssh_key_file = config.get('ssh', 'ssh_key_file', fallback=None)
        connect_kwargs = {
            'key_filename': ssh_key_file
        } if ssh_key_file else None

        ilo_user = config.get('ilo', 'user', fallback=None)
        ilo_password = config.get('ilo', 'password', fallback=None)

        # Setup SSH connection
        self._connection = Connection(self['name'],
                                      user=ssh_user,
                                      connect_kwargs=connect_kwargs)

        # Setup ILO connection
        ilo_address = self['name'].split('.')
        ilo_address.insert(1, 'ilom')
        ilo_address = '.'.join(ilo_address)
        self._ilo = hpilo.Ilo(ilo_address,
                              login=ilo_user,
                              password=ilo_password)

        self.vms_with_shutdown_policy = []
예제 #2
0
    def _configure_slack():
        config = get_config()

        slack_hook_url = config.get('slack', 'hookurl', fallback=None)

        if slack_hook_url:
            return Slack(url=slack_hook_url)
        else:
            print(f"warning: No Slack connection details found in configuration file")
            return None
    def test_get_config_file(self, tmp):
        config_data = (b"[test_local_dir]\n" b"dummy = local\n")
        tmp.write('config', config_data)
        with patch('pathlib.Path.cwd') as path_cwd_mock:
            path_cwd_mock.return_value = Path(tmp.path)
            config = get_config()

        self.assertIn('test_local_dir', config)
        self.assertIn('dummy', config['test_local_dir'])
        self.assertEqual('local', config['test_local_dir']['dummy'])
    def test_get_config_file_fallback(self, tmp):
        config_data = (b"[test_home_dir]\n" b"dummy = home\n")
        tmp.makedir('.cosmicops')
        tmp.write('.cosmicops/config', config_data)
        with patch('pathlib.Path.home') as path_home_mock:
            with patch('pathlib.Path.cwd') as path_cwd_mock:
                path_cwd_mock.return_value = Path(tmp.path)
                path_home_mock.return_value = Path(tmp.path)

                config = get_config()

        self.assertIn('test_home_dir', config)
        self.assertIn('dummy', config['test_home_dir'])
        self.assertEqual('home', config['test_home_dir']['dummy'])
예제 #5
0
    def __init__(self, ops, data):
        super(CosmicSystemVM, self).__init__(ops, data)

        # Load configuration
        config = get_config()
        ssh_user = config.get('ssh', 'user', fallback=None)
        ssh_key_file = config.get('ssh', 'ssh_key_file', fallback=None)
        connect_kwargs = {'banner_timeout': 60}
        if ssh_key_file:
            connect_kwargs['key_filename'] = ssh_key_file

        # Setup SSH connection
        self._connection = Connection(self['hostname'],
                                      user=ssh_user,
                                      connect_kwargs=connect_kwargs,
                                      forward_agent=True,
                                      connect_timeout=60)
예제 #6
0
    def _connect(self):
        if not self.password:
            config = get_config()
            logging.debug(f"Loading SQL server details for '{self.server}''")

            if self.server not in config:
                logging.error(
                    f"Could not find configuration section for '{self.server}'"
                )
                raise RuntimeError

            try:
                self.password = config.get(self.server, 'password')
                self.user = config.get(self.server, 'user', fallback=self.user)
                self.port = config.getint(self.server,
                                          'port',
                                          fallback=self.port)
                self.database = config.get(self.server,
                                           'database',
                                           fallback=self.database)
                self.server = config.get(self.server,
                                         'host',
                                         fallback=self.server)
            except NoOptionError as e:
                logging.error(
                    f"Unable to read details for '{self.server}': {e}")
                raise

        try:
            self.conn = pymysql.connect(host=self.server,
                                        port=self.port,
                                        user=self.user,
                                        password=self.password,
                                        database=self.database)
        except pymysql.Error as e:
            logging.error(f"Error connecting to server '{self.server}': {e}")
            raise

        self.conn.autocommit = False
예제 #7
0
    def get_all_dbs_from_config():
        config = get_config()

        return [section for section in config if 'host' in config[section]]