cls_cmd: print the host on which a command is executed
This commit is contained in:
@@ -101,7 +101,7 @@ class LocalCmd(Cmd):
|
|||||||
|
|
||||||
def run(self, line, timeout=300, silent=False, reportNonZero=True):
|
def run(self, line, timeout=300, silent=False, reportNonZero=True):
|
||||||
if not silent:
|
if not silent:
|
||||||
logging.info(line)
|
logging.info(f"local> {line}")
|
||||||
try:
|
try:
|
||||||
if line.strip().endswith('&'):
|
if line.strip().endswith('&'):
|
||||||
# if we wait for stdout, subprocess does not return before the end of the command
|
# if we wait for stdout, subprocess does not return before the end of the command
|
||||||
@@ -168,6 +168,7 @@ class RemoteCmd(Cmd):
|
|||||||
|
|
||||||
def __init__(self, hostname, d=None):
|
def __init__(self, hostname, d=None):
|
||||||
cIdx = 0
|
cIdx = 0
|
||||||
|
self.hostname = hostname
|
||||||
logging.getLogger('paramiko').setLevel(logging.ERROR) # prevent spamming through Paramiko
|
logging.getLogger('paramiko').setLevel(logging.ERROR) # prevent spamming through Paramiko
|
||||||
self.client = paramiko.SSHClient()
|
self.client = paramiko.SSHClient()
|
||||||
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
@@ -205,7 +206,7 @@ class RemoteCmd(Cmd):
|
|||||||
|
|
||||||
def run(self, line, timeout=300, silent=False, reportNonZero=True):
|
def run(self, line, timeout=300, silent=False, reportNonZero=True):
|
||||||
if not silent:
|
if not silent:
|
||||||
logging.info(line)
|
logging.info(f"ssh[{self.hostname}]> {line}")
|
||||||
if self.cwd:
|
if self.cwd:
|
||||||
line = f"cd {self.cwd} && {line}"
|
line = f"cd {self.cwd} && {line}"
|
||||||
try:
|
try:
|
||||||
@@ -235,7 +236,7 @@ class RemoteCmd(Cmd):
|
|||||||
# if recursive is True, tgt must be a directory (and src is file or directory)
|
# if recursive is True, tgt must be a directory (and src is file or directory)
|
||||||
# if recursive is False, tgt and src must be a file name
|
# if recursive is False, tgt and src must be a file name
|
||||||
def copyout(self, src, tgt, recursive=False):
|
def copyout(self, src, tgt, recursive=False):
|
||||||
logging.debug(f"copyout: local:{src} -> remote:{tgt}")
|
logging.debug(f"copyout: local:{src} -> {self.hostname}:{tgt}")
|
||||||
if recursive:
|
if recursive:
|
||||||
tmpfile = f"{uuid.uuid4()}.tar"
|
tmpfile = f"{uuid.uuid4()}.tar"
|
||||||
abstmpfile = f"/tmp/{tmpfile}"
|
abstmpfile = f"/tmp/{tmpfile}"
|
||||||
@@ -253,7 +254,7 @@ class RemoteCmd(Cmd):
|
|||||||
# if recursive is True, tgt must be a directory (and src is file or directory)
|
# if recursive is True, tgt must be a directory (and src is file or directory)
|
||||||
# if recursive is False, tgt and src must be a file name
|
# if recursive is False, tgt and src must be a file name
|
||||||
def copyin(self, src, tgt, recursive=False):
|
def copyin(self, src, tgt, recursive=False):
|
||||||
logging.debug(f"copyin: remote:{src} -> local:{tgt}")
|
logging.debug(f"copyin: {self.hostname}:{src} -> local:{tgt}")
|
||||||
if recursive:
|
if recursive:
|
||||||
tmpfile = f"{uuid.uuid4()}.tar"
|
tmpfile = f"{uuid.uuid4()}.tar"
|
||||||
abstmpfile = f"/tmp/{tmpfile}"
|
abstmpfile = f"/tmp/{tmpfile}"
|
||||||
|
|||||||
Reference in New Issue
Block a user