MCPcopy Index your code
hub / github.com/saltstack/salt / _run_cmd

Method _run_cmd

salt/client/ssh/shell.py:406–509  ·  view source on GitHub ↗

Execute a shell command via VT. This is blocking and assumes that ssh is being run

(self, cmd, key_accept=False, passwd_retries=3)

Source from the content-addressed store, hash-verified

404 return re.sub(r"\b" + re.escape(sanitize_text) + r"\b", replace_str, text)
405
406 def _run_cmd(self, cmd, key_accept=False, passwd_retries=3):
407 """
408 Execute a shell command via VT. This is blocking and assumes that ssh
409 is being run
410 """
411 if not cmd:
412 return "", "No command or passphrase", 245
413
414 log_sanitize = None
415 if self.passwd:
416 log_sanitize = self.passwd
417 term = salt.utils.vt.Terminal(
418 self._split_cmd(cmd),
419 log_stdout=True,
420 log_stdout_level="trace",
421 log_stderr=True,
422 log_stderr_level="trace",
423 log_sanitize=log_sanitize,
424 stream_stdout=False,
425 stream_stderr=False,
426 )
427 sent_passwd = 0
428 send_password = True
429 ret_stdout = ""
430 ret_stderr = ""
431 old_stdout = ""
432
433 try:
434 while term.has_unread_data:
435 stdout, stderr = term.recv()
436 if stdout:
437 ret_stdout += stdout
438 buff = old_stdout + stdout
439 else:
440 buff = stdout
441 if stderr:
442 ret_stderr += stderr
443 if buff and RSTR_RE.search(buff):
444 # We're getting results back, don't try to send passwords
445 send_password = False
446 if buff and SSH_PRIVATE_KEY_PASSWORD_PROMPT_RE.search(buff):
447 if not self.priv_passwd:
448 return "", "Private key file need passphrase", 254
449 term.sendline(self.priv_passwd)
450 continue
451 if buff and SSH_PASSWORD_PROMPT_RE.search(buff) and send_password:
452 if not self.passwd:
453 return (
454 "",
455 "Permission denied, no authentication information",
456 254,
457 )
458 if sent_passwd < passwd_retries:
459 term.sendline(self.passwd)
460 sent_passwd += 1
461 continue
462 else:
463 # asking for a password, and we can't seem to send it

Callers 4

copy_idMethod · 0.95
exec_cmdMethod · 0.95
sendMethod · 0.95

Calls 9

_split_cmdMethod · 0.95
recvMethod · 0.95
sendlineMethod · 0.95
_sanitize_strMethod · 0.95
closeMethod · 0.95
warningMethod · 0.80
searchMethod · 0.45
dumpsMethod · 0.45
sleepMethod · 0.45

Tested by 1