3 ܓi @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_sshZubuntucCsTd}ytj|tjddWn4tjk rN}z|jdt|WYdd}~XnXdS)Nz juju versionT)stderrshellzFailed to check `juju` version) subprocess check_outputSTDOUTCalledProcessError log_errorr)selfcmderrr/usr/lib/python3.6/juju.py_check_juju_installed's zJujuSSH._check_juju_installedc CsV|jd|}ytj|tjddWn*tjk rP|jd|dYnXdS)Nz sudo chmod o+r T)rrzFailed to make z world-readable) remote_execrr r r r )r fnamerrrr_chmod0szJujuSSH._chmodcCs|j|_|jS)N)r _connected)r Zpasswordrrr_connect9s zJujuSSH._connectcCsdS)NTr)r rrr _disconnect=szJujuSSH._disconnectcCs|jS)N)r)r rrr connected@szJujuSSH.connectedcCs:|jjd\}}|rd|nd}|d|}d|S)N:z-m r z juju ssh )addresssplit)r modelZ target_option model_optionZoptionrrrrDszJujuSSH.remote_execcCsV|jjd\}}|rd|nd}d|d|d|d|}t|dd}|d d kS) Nrz-m rz juju scp z -- r)Ztimeoutstatusr)rrr)r rdestrunitr rresrrr_copy_file_to_remoteKs  zJujuSSH._copy_file_to_remotecCs\|j||jjd\}}|r(d|nd}d|d|d|d|}t|}|ddkS) Nrz-m rz juju scp z -- -r rr"r)rrrr)r rr#rr$r rr%rrr_retrieve_fileRs  zJujuSSH._retrieve_fileN)r)__name__ __module__ __qualname____doc__nameZ default_userrrrrpropertyrrr&r'rrrrrs    r)rZsos.collector.exceptionsrZsos.collector.transportsrZ sos.utilitiesrrrrrr s