o id @s@ddlZddlmZddlmZddlmZGdddeZdS)N)JujuNotInstalledException)RemoteTransport)sos_get_command_outputc@sZeZdZdZdZdZddZddZdd d Zd d Z e d dZ e ddZ ddZ dS)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 juju_sshubuntucCs<d}z tj|tjddWdStjy|dtw)Nz juju versionTstderrshellzFailed to check `juju` version) subprocess check_outputSTDOUTCalledProcessError log_errorr)selfcmdr?/usr/lib/python3/dist-packages/sos/collector/transports/juju.py_check_juju_installed's zJujuSSH._check_juju_installedcCsN|jd|}z tj|tjddWdStjy&|d|dw)Nz sudo chmod o+r TrzFailed to make z world-readable) remote_execr r r rr)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)rmodel target_option model_optionoptionrrrrDs zJujuSSH.remote_execcCs\|||jd\}}|rd|nd}d|d|d|d|}t|}|ddkS) Nr r!rz juju scp z -- -r r"statusr)rr#r$r)rrdestr%unitr'rresrrr_retrieve_fileKs  zJujuSSH._retrieve_fileN)r)__name__ __module__ __qualname____doc__name default_userrrrrpropertyrrr-rrrrrs    r)r sos.collector.exceptionsrsos.collector.transportsr sos.utilitiesrrrrrrs