3 ܓi @ s@ d dl Z d dlmZ d dlmZ d dlmZ G dd deZdS ) N)JujuNotInstalledException)RemoteTransport)sos_get_command_outputc @ sb e Zd ZdZdZdZdd Zdd Zdd d Zdd Z e d d Ze dd Zdd Z dd ZdS )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 C sT d}yt j|t jdd W n4 t jk rN } z| jd t|W Y d d }~X nX dS )Nzjuju versionT)stderrshellzFailed to check `juju` version) subprocesscheck_outputSTDOUTCalledProcessError log_errorr )selfcmderr r /usr/lib/python3.6/juju.py_check_juju_installed' s zJujuSSH._check_juju_installedc C sV | j d| }ytj|tjdd W n* tjk rP | jd| d Y nX dS )Nz sudo chmod o+r T)r r zFailed to make z world-readable)remote_execr r r r r )r fnamer r r r _chmod0 s zJujuSSH._chmod c C s | j | _| jS )N)r _connected)r Zpasswordr r r _connect9 s zJujuSSH._connectc C s dS )NTr )r r r r _disconnect= s zJujuSSH._disconnectc C s | j S )N)r )r r r r connected@ s zJujuSSH.connectedc C s: | j jd\}}|rd| nd}| d| }d| S )N:z-m r z juju ssh )addresssplit)r modelZ target_optionmodel_optionZoptionr r r r D s zJujuSSH.remote_execc C sV | j jd\}}|rd| nd}d| d| d| d| }t|dd}|d d kS )Nr z-m r z juju scp z -- r )Ztimeoutstatusr )r r r )r r destr unitr r resr r r _copy_file_to_remoteK s zJujuSSH._copy_file_to_remotec C s\ | j | | jjd\}}|r(d| nd}d| d| d| d| }t|}|d dkS ) Nr z-m r z juju scp z -- -r r r" r )r r r r )r r r# r r$ r r r% r r r _retrieve_fileR s zJujuSSH._retrieve_fileN)r )__name__ __module____qualname____doc__nameZdefault_userr r r r propertyr r r&