a >h @s@ddlZddlmZddlmZddlmZGdddeZdS)N)JujuNotInstalledException)RemoteTransport)sos_get_command_outputc@sbeZdZdZdZdZddZddZdd d Zd d Z e d dZ e ddZ ddZ ddZdS)JujuSSHa A "transport" that leverages `juju ssh` to perform commands on the remote hosts. This transport is expected to be used in juju managed environment, and the user should have the necessary credential for accessing the controller. When using this transport, the --nodes option will be expected to be a comma separated machine IDs, **not** IP addr, since `juju ssh` identifies the ssh target by machine ID. Examples: sos collect --nodes 0,1,2 --no-local --transport juju --batch Zjuju_sshZubuntuc CsVd}ztj|tjddWn6tjyP}z|dt|WYd}~n d}~00dS)Nz juju versionTstderrshellzFailed to check `juju` version) subprocess check_outputSTDOUTCalledProcessError log_errorr)selfcmderrrA/usr/lib/python3.9/site-packages/sos/collector/transports/juju.py_check_juju_installed's zJujuSSH._check_juju_installedcCsT|jd|}ztj|tjddWn(tjyN|d|dYn0dS)Nz sudo chmod o+r TrzFailed to make z world-readable) remote_execr r r r r )rfnamerrrr_chmod0szJujuSSH._chmodcCs||_|jSN)r _connected)rpasswordrrr_connect9s zJujuSSH._connectcCsdS)NTrrrrr _disconnect=szJujuSSH._disconnectcCs|jSr)rrrrr connected@szJujuSSH.connectedcCs:|jd\}}|rd|nd}|d|}d|S)N:-m r z juju ssh )addresssplit)rmodelZ target_option model_optionoptionrrrrDszJujuSSH.remote_execcCsV|jd\}}|rd|nd}d|d|d|d|}t|dd}|d d kS) Nrr r juju scp z -- r!)timeoutstatusr)r"r#rrrdestr$Zunitr%rresrrr_copy_file_to_remoteKs  zJujuSSH._copy_file_to_remotecCs\|||jd\}}|r(d|nd}d|d|d|d|}t|}|ddkS) Nrr rr'z -- -r r!r*r)rr"r#rr+rrr_retrieve_fileRs  zJujuSSH._retrieve_fileN)r)__name__ __module__ __qualname____doc__nameZ default_userrrrrpropertyrrr.r/rrrrrs    r)r Zsos.collector.exceptionsrZsos.collector.transportsrZ sos.utilitiesrrrrrr s