def _execute(self, command_line): command_line.extend(['-z', self.location]) commands = ' '.join(command_line) manila_utils.check_ssh_injection(commands) LOG.debug('Executing: %(command)s', {'command': commands}) cli_out = self._ssh_execute(commands) return self._parser(cli_out)
def _execute(self, command_line): commands = ' '.join(command_line) mutils.check_ssh_injection(commands) LOG.debug('Executing: %(command)s', {'command': commands}) rc, result = self._ssh_execute(commands) if rc != 0: msg = _('Failed to execute commands: [%(command)s].') % { 'command': commands} LOG.error(msg) raise exception.InfortrendNASException( err=msg, rc=rc, out=out) return result
def _execute(self, commands): command = ['ssc', '127.0.0.1'] if self.admin_ip0 is not None: command = ['ssc', '--smuauth', self.admin_ip0] command += ['console-context', '--evs', self.evs_id] commands = command + commands mutils.check_ssh_injection(commands) commands = ' '.join(commands) if not self.sshpool: self.sshpool = mutils.SSHPool(ip=self.ip, port=self.port, conn_timeout=None, login=self.user, password=self.password, privatekey=self.priv_key) with self.sshpool.item() as ssh: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: out, err = processutils.ssh_execute(ssh, commands, check_exit_code=True) LOG.debug( "Command %(cmd)s result: out = %(out)s - err = " "%(err)s.", { 'cmd': commands, 'out': out, 'err': err, }) return out, err except processutils.ProcessExecutionError as e: if 'Failed to establish SSC connection' in e.stderr: msg = _("Failed to establish SSC connection.") LOG.debug(msg) raise exception.HNASConnException(msg=msg) else: LOG.debug( "Error running SSH command. " "Command %(cmd)s result: out = %(out)s - err = " "%(err)s - exit = %(exit)s.", { 'cmd': e.cmd, 'out': e.stdout, 'err': e.stderr, 'exit': e.exit_code, }) raise
def _execute(self, commands): command = ['ssc', '127.0.0.1'] if self.admin_ip0 is not None: command = ['ssc', '--smuauth', self.admin_ip0] command += ['console-context', '--evs', self.evs_id] commands = command + commands mutils.check_ssh_injection(commands) commands = ' '.join(commands) if not self.sshpool: self.sshpool = mutils.SSHPool(ip=self.ip, port=self.port, conn_timeout=None, login=self.user, password=self.password, privatekey=self.priv_key) with self.sshpool.item() as ssh: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: out, err = processutils.ssh_execute(ssh, commands, check_exit_code=True) LOG.debug("Command %(cmd)s result: out = %(out)s - err = " "%(err)s.", { 'cmd': commands, 'out': out, 'err': err, }) return out, err except processutils.ProcessExecutionError as e: if 'Failed to establish SSC connection' in e.stderr: msg = _("Failed to establish SSC connection.") LOG.debug(msg) raise exception.HNASConnException(msg=msg) else: LOG.debug("Error running SSH command. " "Command %(cmd)s result: out = %(out)s - err = " "%(err)s - exit = %(exit)s.", { 'cmd': e.cmd, 'out': e.stdout, 'err': e.stderr, 'exit': e.exit_code, }) raise
def __call__(self, cmd_list, check_exit_code=True, attempts=1): """SSH tool""" manila_utils.check_ssh_injection(cmd_list) command = ' '.join(cmd_list) if not self.sshpool: try: self.sshpool = manila_utils.SSHPool( self.host, self.port, self.ssh_conn_timeout, self.login, password=self.password, privatekey=self.privatekey, min_size=self.ssh_min_pool_size, max_size=self.ssh_max_pool_size) except paramiko.SSHException: LOG.error("Unable to create SSHPool") raise try: return self._ssh_execute(self.sshpool, command, check_exit_code, attempts) except Exception: LOG.error("Error running SSH command: %s", command) raise
def test_check_ssh_injection(self, cmd): cmd_list = cmd self.assertIsNone(utils.check_ssh_injection(cmd_list))