Skip to content

Commit

Permalink
[collect] Additional transports
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Benson <trevor.benson@gmail.com>
  • Loading branch information
TrevorBenson committed Nov 26, 2024
1 parent d6bc604 commit 24cdb35
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sos/collector/transports/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def remote_exec(self):
option = f"{model_option} {target_option}"
return f"juju ssh {option}"

def _copy_file_to_remote(self, fname, dest):
model, unit = self.address.split(":")
model_option = f"-m {model}" if model else ""
cmd = f"juju scp {model_option} -- {fname} {unit}:{dest}"
res = sos_get_command_output(cmd)
return res["status"] == 0

def _retrieve_file(self, fname, dest):
self._chmod(fname) # juju scp needs the archive to be world-readable
model, unit = self.address.split(":")
Expand Down
3 changes: 3 additions & 0 deletions sos/collector/transports/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def _retrieve_file(self, fname, dest):
def _format_cmd_for_exec(self, cmd):
return cmd

def _copy_file_to_remote(self, fname, dest):
pass

def _read_file(self, fname):
if os.path.exists(fname):
with open(fname, 'r', encoding='utf-8') as rfile:
Expand Down
6 changes: 6 additions & 0 deletions sos/collector/transports/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def remote_exec(self):
return (f"oc -n {self.project} exec --request-timeout=0 "
f"{self.pod_name} -- /bin/bash -c")

def _copy_file_to_remote(self, fname, dest):
result = self.run_oc("cp --retries", stderr=True)
flags = '' if "unknown flag" in result["output"] else '--retries=5'
cmd = self.run_oc(f"cp {flags} {fname} {self.pod_name}:{dest}")
return cmd['status'] == 0

def _retrieve_file(self, fname, dest):
# check if --retries flag is available for given version of oc
result = self.run_oc("cp --retries", stderr=True)
Expand Down
24 changes: 24 additions & 0 deletions sos/collector/transports/saltstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def run_command(self, cmd, timeout=180, need_root=False, env=None,
ret['output'] = self._convert_output_json(ret['output'])
return ret

def _salt_copy_file(self, node, fname, dest):
"""
Execute cp.get_file on the remote host using SaltStack Master
"""
cmd = f"salt-cp {node} {fname} {dest}"
res = sos_get_command_output(cmd)
return res['status'] == 0

def _salt_retrieve_file(self, node, fname, dest):
"""
Execute cp.push on the remote host using SaltStack Master
Expand Down Expand Up @@ -119,6 +127,22 @@ def remote_exec(self):
salt_args = "--out json --static --no-color"
return f"salt {salt_args} {self.address} cmd.shell "

def _copy_file_to_remote(self, fname, dest):
"""Copy a file to the remote host using SaltStack Master
Parameters
fname The path to the file on the master
dest The path to the destination directory on the remote host
Returns
True if the file was copied, else False
"""
return (
self._salt_copy_file(self.address, fname, dest)
if self.connected
else False
)

def _retrieve_file(self, fname, dest):
"""Retrieve a file from the remote host using saltstack
Expand Down

0 comments on commit 24cdb35

Please sign in to comment.