def pre_run(self): LOG.debug('Entering FabricRunner.pre_run() for liveaction_id="%s"', self.liveaction_id) LOG.debug(' runner_parameters = %s', self.runner_parameters) hosts = self.runner_parameters.get(RUNNER_HOSTS, '').split(',') self._hosts = [h.strip() for h in hosts if len(h) > 0] if len(self._hosts) < 1: raise ActionRunnerPreRunError( 'No hosts specified to run action for action %s.', self.liveaction_id) self._username = self.runner_parameters.get(RUNNER_USERNAME, cfg.CONF.system_user.user) self._username = self._username or cfg.CONF.system_user.user self._password = self.runner_parameters.get(RUNNER_PASSWORD, None) self._private_key = self.runner_parameters.get(RUNNER_PRIVATE_KEY, None) self._parallel = self.runner_parameters.get(RUNNER_PARALLEL, True) self._sudo = self.runner_parameters.get(RUNNER_SUDO, False) self._sudo = self._sudo if self._sudo else False self._on_behalf_user = self.context.get(RUNNER_ON_BEHALF_USER, env.user) self._cwd = self.runner_parameters.get(RUNNER_CWD, None) self._env = self.runner_parameters.get(RUNNER_ENV, {}) self._kwarg_op = self.runner_parameters.get(RUNNER_KWARG_OP, '--') self._timeout = self.runner_parameters.get( RUNNER_TIMEOUT, FABRIC_RUNNER_DEFAULT_ACTION_TIMEOUT) LOG.info('[FabricRunner="%s", liveaction_id="%s"] Finished pre_run.', self.runner_id, self.liveaction_id)
def pre_run(self): LOG.debug('Entering BaseParallelSSHRunner.pre_run() for liveaction_id="%s"', self.liveaction_id) hosts = self.runner_parameters.get(RUNNER_HOSTS, '').split(',') self._hosts = [h.strip() for h in hosts if len(h) > 0] if len(self._hosts) < 1: raise ActionRunnerPreRunError('No hosts specified to run action for action %s.', self.liveaction_id) self._username = self.runner_parameters.get(RUNNER_USERNAME, cfg.CONF.system_user.user) self._username = self._username or cfg.CONF.system_user.user self._password = self.runner_parameters.get(RUNNER_PASSWORD, None) self._ssh_port = self.runner_parameters.get(RUNNER_SSH_PORT, 22) self._private_key = self.runner_parameters.get(RUNNER_PRIVATE_KEY, self._ssh_key_file) self._parallel = self.runner_parameters.get(RUNNER_PARALLEL, True) self._sudo = self.runner_parameters.get(RUNNER_SUDO, False) self._sudo = self._sudo if self._sudo else False self._on_behalf_user = self.context.get(RUNNER_ON_BEHALF_USER, self._on_behalf_user) self._cwd = self.runner_parameters.get(RUNNER_CWD, None) self._env = self.runner_parameters.get(RUNNER_ENV, {}) self._kwarg_op = self.runner_parameters.get(RUNNER_KWARG_OP, '--') self._timeout = self.runner_parameters.get(RUNNER_TIMEOUT, FABRIC_RUNNER_DEFAULT_ACTION_TIMEOUT) LOG.info('[BaseParallelSSHRunner="%s", liveaction_id="%s"] Finished pre_run.', self.runner_id, self.liveaction_id) concurrency = int(len(self._hosts) / 3) + 1 if self._parallel else 1 if concurrency > self._max_concurrency: LOG.debug('Limiting parallel SSH concurrency to %d.', concurrency) concurrency = self._max_concurrency if self._password: self._parallel_ssh_client = ParallelSSHClient( hosts=self._hosts, user=self._username, password=self._password, port=self._ssh_port, concurrency=concurrency, raise_on_error=False, connect=True ) else: self._parallel_ssh_client = ParallelSSHClient( hosts=self._hosts, user=self._username, pkey=self._ssh_key_file, port=self._ssh_port, concurrency=concurrency, raise_on_error=False, connect=True )
def pre_run(self): LOG.debug('Entering FabricRunner.pre_run() for actionexec_id="%s"', self.action_execution_id) LOG.debug(' runner_parameters = %s', self.runner_parameters) hosts = self.runner_parameters.get(RUNNER_HOSTS, '').split(',') self._hosts = [h.strip() for h in hosts if len(h) > 0] if len(self._hosts) < 1: raise ActionRunnerPreRunError( 'No hosts specified to run action for action %s.', self.action_execution_id) self._parallel = self.runner_parameters.get(RUNNER_PARALLEL, True) self._sudo = self.runner_parameters.get(RUNNER_SUDO, False) self._sudo = self._sudo if self._sudo else False self._on_behalf_user = self.context.get(RUNNER_ON_BEHALF_USER, env.user) self._user = cfg.CONF.system_user.user self._kwarg_op = self.runner_parameters.get(RUNNER_KWARG_OP, '--') LOG.info('[FabricRunner="%s", actionexec_id="%s"] Finished pre_run.', self._runner_id, self.action_execution_id)
def pre_run(self): super(BaseParallelSSHRunner, self).pre_run() LOG.debug( 'Entering BaseParallelSSHRunner.pre_run() for liveaction_id="%s"', self.liveaction_id) hosts = self.runner_parameters.get(RUNNER_HOSTS, '').split(',') self._hosts = [h.strip() for h in hosts if len(h) > 0] if len(self._hosts) < 1: raise ActionRunnerPreRunError( 'No hosts specified to run action for action %s.', self.liveaction_id) self._username = self.runner_parameters.get(RUNNER_USERNAME, None) self._password = self.runner_parameters.get(RUNNER_PASSWORD, None) self._private_key = self.runner_parameters.get(RUNNER_PRIVATE_KEY, None) self._passphrase = self.runner_parameters.get(RUNNER_PASSPHRASE, None) self._ssh_port = self.runner_parameters.get(RUNNER_SSH_PORT, None) self._ssh_key_file = self._private_key self._parallel = self.runner_parameters.get(RUNNER_PARALLEL, True) self._sudo = self.runner_parameters.get(RUNNER_SUDO, False) self._sudo = self._sudo if self._sudo else False self._sudo_password = self.runner_parameters.get( RUNNER_SUDO_PASSWORD, None) if self.context: self._on_behalf_user = self.context.get(RUNNER_ON_BEHALF_USER, self._on_behalf_user) self._cwd = self.runner_parameters.get(RUNNER_CWD, None) self._env = self.runner_parameters.get(RUNNER_ENV, {}) self._kwarg_op = self.runner_parameters.get(RUNNER_KWARG_OP, '--') self._timeout = self.runner_parameters.get( RUNNER_TIMEOUT, REMOTE_RUNNER_DEFAULT_ACTION_TIMEOUT) self._bastion_host = self.runner_parameters.get( RUNNER_BASTION_HOST, None) LOG.info( '[BaseParallelSSHRunner="%s", liveaction_id="%s"] Finished pre_run.', self.runner_id, self.liveaction_id) concurrency = int(len(self._hosts) / 3) + 1 if self._parallel else 1 if concurrency > self._max_concurrency: LOG.debug('Limiting parallel SSH concurrency to %d.', concurrency) concurrency = self._max_concurrency client_kwargs = { 'hosts': self._hosts, 'user': self._username, 'port': self._ssh_port, 'concurrency': concurrency, 'bastion_host': self._bastion_host, 'raise_on_any_error': False, 'connect': True } def make_store_stdout_line_func(execution_db, action_db): def store_stdout_line(line): if cfg.CONF.actionrunner.stream_output: store_execution_output_data(execution_db=execution_db, action_db=action_db, data=line, output_type='stdout') return store_stdout_line def make_store_stderr_line_func(execution_db, action_db): def store_stderr_line(line): if cfg.CONF.actionrunner.stream_output: store_execution_output_data(execution_db=execution_db, action_db=action_db, data=line, output_type='stderr') return store_stderr_line handle_stdout_line_func = make_store_stdout_line_func( execution_db=self.execution, action_db=self.action) handle_stderr_line_func = make_store_stderr_line_func( execution_db=self.execution, action_db=self.action) if len(self._hosts) == 1: # We only support streaming output when running action on one host. That is because # the action output is tied to a particulat execution. User can still achieve output # streaming for multiple hosts by running one execution per host. client_kwargs['handle_stdout_line_func'] = handle_stdout_line_func client_kwargs['handle_stderr_line_func'] = handle_stderr_line_func if self._password: client_kwargs['password'] = self._password elif self._private_key: # Determine if the private_key is a path to the key file or the raw key material is_key_material = self._is_private_key_material( private_key=self._private_key) if is_key_material: # Raw key material client_kwargs['pkey_material'] = self._private_key else: # Assume it's a path to the key file, verify the file exists client_kwargs['pkey_file'] = self._private_key if self._passphrase: client_kwargs['passphrase'] = self._passphrase else: # Default to stanley key file specified in the config client_kwargs['pkey_file'] = self._ssh_key_file if self._sudo_password: client_kwargs['sudo_password'] = True self._parallel_ssh_client = ParallelSSHClient(**client_kwargs)
def pre_run(self): super(BaseParallelSSHRunner, self).pre_run() LOG.debug('Entering BaseParallelSSHRunner.pre_run() for liveaction_id="%s"', self.liveaction_id) hosts = self.runner_parameters.get(RUNNER_HOSTS, '').split(',') self._hosts = [h.strip() for h in hosts if len(h) > 0] if len(self._hosts) < 1: raise ActionRunnerPreRunError('No hosts specified to run action for action %s.', self.liveaction_id) self._username = self.runner_parameters.get(RUNNER_USERNAME, None) self._password = self.runner_parameters.get(RUNNER_PASSWORD, None) self._private_key = self.runner_parameters.get(RUNNER_PRIVATE_KEY, None) self._passphrase = self.runner_parameters.get(RUNNER_PASSPHRASE, None) self._ssh_port = self.runner_parameters.get(RUNNER_SSH_PORT, None) self._ssh_key_file = self._private_key self._parallel = self.runner_parameters.get(RUNNER_PARALLEL, True) self._sudo = self.runner_parameters.get(RUNNER_SUDO, False) self._sudo = self._sudo if self._sudo else False if self.context: self._on_behalf_user = self.context.get(RUNNER_ON_BEHALF_USER, self._on_behalf_user) self._cwd = self.runner_parameters.get(RUNNER_CWD, None) self._env = self.runner_parameters.get(RUNNER_ENV, {}) self._kwarg_op = self.runner_parameters.get(RUNNER_KWARG_OP, '--') self._timeout = self.runner_parameters.get(RUNNER_TIMEOUT, REMOTE_RUNNER_DEFAULT_ACTION_TIMEOUT) self._bastion_host = self.runner_parameters.get(RUNNER_BASTION_HOST, None) LOG.info('[BaseParallelSSHRunner="%s", liveaction_id="%s"] Finished pre_run.', self.runner_id, self.liveaction_id) concurrency = int(len(self._hosts) / 3) + 1 if self._parallel else 1 if concurrency > self._max_concurrency: LOG.debug('Limiting parallel SSH concurrency to %d.', concurrency) concurrency = self._max_concurrency client_kwargs = { 'hosts': self._hosts, 'user': self._username, 'port': self._ssh_port, 'concurrency': concurrency, 'bastion_host': self._bastion_host, 'raise_on_any_error': False, 'connect': True } if self._password: client_kwargs['password'] = self._password elif self._private_key: # Determine if the private_key is a path to the key file or the raw key material is_key_material = self._is_private_key_material(private_key=self._private_key) if is_key_material: # Raw key material client_kwargs['pkey_material'] = self._private_key else: # Assume it's a path to the key file, verify the file exists client_kwargs['pkey_file'] = self._private_key if self._passphrase: client_kwargs['passphrase'] = self._passphrase else: # Default to stanley key file specified in the config client_kwargs['pkey_file'] = self._ssh_key_file self._parallel_ssh_client = ParallelSSHClient(**client_kwargs)