Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/module_utils/docker/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyo

�
�Udac@`s�ddlmZmZmZeZddlZddlmZyddl	m
Z
mZWnek
rknXddl
mZddlmZmZdefd��YZdS(	i(tabsolute_importtdivisiontprint_functionN(tsleep(tAPIErrortNotFound(t	to_native(tAnsibleDockerClienttLooseVersiontAnsibleDockerSwarmClientcB`s�eZd�Zd�Zdd�Zd�Zd�Zd�Zddd�Z	de
d�Zd	�Zd
d�Z
d�Zd
�Ze
d�ZRS(cK`stt|�j|�dS(N(tsuperR	t__init__(tselftkwargs((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyRscC`s�y|j�}Wn*tk
r<}|jdt|��nX|r�tj|dt�}tj|�}|ddr�|ddSndS(s�
        Get the 'NodeID' of the Swarm node or 'None' if host is not in Swarm. It returns the NodeID
        of Docker host the module is executed on
        :return:
            NodeID of host or 'None' if not part of Swarm
        s%Failed to get node information for %stensure_asciitSwarmtNodeIDN(	tinfoRtfailRtjsontdumpstFalsetloadstNone(RRtexctjson_strt
swarm_info((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytget_swarm_node_idscC`s�|d
kr�y|j�}Wntk
r<|jd�nX|r�tj|dt�}tj|�}|ddrytS|dddkr�tSntSy|j	d	|�}Wntk
r�d
SX|dd
k	r�tStSd
S(
s�
        Checking if host is part of Docker Swarm. If 'node_id' is not provided it reads the Docker host
        system information looking if specific key in output exists. If 'node_id' is provided then it tries to
        read node information assuming it is run on Swarm manager. The get_node_inspect() method handles exception if
        it is not executed on Swarm manager

        :param node_id: Node identifier
        :return:
            bool: True if node is part of Swarm, False otherwise
        sFailed to get host information.RRRtLocalNodeStatetactivetpendingtlockedtnode_idNtID(RRR(
RRRRRRRRtTruetget_node_inspect(RR RRRt	node_info((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytcheck_if_swarm_node2s(

cC`s+y|j�tSWntk
r&tSXdS(s
        Checks if node role is set as Manager in Swarm. The node is the docker host on which module action
        is performed. The inspect_swarm() will fail if node is not a manager

        :return: True if node is Swarm Manager, False otherwise
        N(t
inspect_swarmR"RR(R((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytcheck_if_swarm_managerVs


cC`s |j�s|jd�ndS(sn
        If host is not a swarm manager then Ansible task on this host should end with 'failed' state
        sAError running docker swarm module: must run on swarm manager nodeN(R'R(R((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytfail_task_if_not_swarm_managerdscC`s!|j�r|j�rtStS(s
        Checks if node role is set as Worker in Swarm. The node is the docker host on which module action
        is performed. Will fail if run on host that is not part of Swarm via check_if_swarm_node()

        :return: True if node is Swarm Worker, False otherwise
        (R%R'R"R(R((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytcheck_if_swarm_workerksicC`s�|dkrd}n|dkr0|j�}nxZtd|�D]I}|dkr_td�n|jd|�}|dddkr@tSq@WtS(	s[
        Checks if node status on Swarm manager is 'down'. If node_id is provided it query manager about
        node specified in parameter, otherwise it query manager itself. If run on Swarm Worker node or
        host that is not part of Swarm it will fail the playbook

        :param repeat_check: number of check attempts with 5 seconds delay between them, by default check only once
        :param node_id: node ID or name, if None then method will try to get node_id of host module run on
        :return:
            True if node is part of swarm but its state is down, False otherwise
        iiiR tStatustStatetdownN(RRtrangeRR#R"R(RR trepeat_checktretryR$((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytcheck_if_swarm_node_is_downws	
cC`s�|dkr|j�}n|dkr7|jd�ny|jd|�}Wn�tk
r�}|jdkr~|jd�n|jdkr�|r�dSn|jdt|��n$tk
r�}|jd|�nXtj	|dt
�}tj|�}d	|kr�|d	jd
�r�|d	dj
d�}|d
krm|d	djdd
�dpg|dd}n|dd}||dd<q�n|S(sj
        Returns Swarm node info as in 'docker node inspect' command about single node

        :param skip_missing: if True then function will return None instead of failing the task
        :param node_id: node ID or name, if None then method will try to get node_id of host module run on
        :return:
            Single node information structure
        sFailed to get node information.R i�sDCannot inspect node: To inspect node execute module on Swarm Manageri�s*Error while reading from Swarm manager: %ssError inspecting swarm node: %sRt
ManagerStatustLeadertAddrt:iiR*N(RRRtinspect_nodeRtstatus_codeRt	ExceptionRRRRtgettcounttsplit(RR tskip_missingR$RRtcount_colonstswarm_leader_ip((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyR#�s2
/cC`s�y|j�}Wnltk
r[}|jdkrA|jd�n|jdt|��n$tk
r~}|jd|�nXtj|dt�}tj	|�}|S(s�
        Returns Swarm node info as in 'docker node inspect' command about all registered nodes

        :return:
            Structure with information about all nodes
        i�sDCannot inspect node: To inspect node execute module on Swarm Managers*Error while reading from Swarm manager: %ssError inspecting swarm node: %sR(
tnodesRR6RRR7RRRR(RR$RR((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytget_all_nodes_inspect�stshortcC`stg}|j�}|dkr"dS|dkrWx?|D]}|j|dd�q5Wn|dkrlx
|D]�}i}|ji|dd6�|ji|ddd6�|ji|ddd6�|ji|dd	d	6�d
|kr8|d
dtkr|jitd6�n|ji|d
dd
6�n|ji|dd
dd6�|j|�qjWndS|S(s{
        Returns list of nodes registered in Swarm

        :param output: Defines format of returned data
        :return:
            If 'output' is 'short' then return data is list of nodes hostnames registered in Swarm,
            if 'output' is 'long' then returns data is list of dict containing the attributes as in
            output of command 'docker node ls'
        R@tDescriptiontHostnametlongR!R*R+tSpectAvailabilityR1R2tReachabilitytEnginet
EngineVersionN(R?RtappendtupdateR"(Rtoutputt
nodes_listt
nodes_inspecttnodet
node_property((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytget_all_nodes_list�s,


 cC`s|j|�ddS(NRARB(R#(Rtnodeid((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytget_node_name_by_id�scC`s,|jtd�krdStt|�j�S(Ns2.7.0(tdocker_py_versionRRR
R	tget_unlock_key(R((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyRT�scC`s�y|j|�}Wn�tk
rR}|tkrK|jdt|��q�dSnftk
r�}|jdkr�|jd�n|jd|�n$tk
r�}|jd|�nXt	j
|dt�}t	j|�}|S(s9
        Returns Swarm service info as in 'docker service inspect' command about single service

        :param service_id: service ID or name
        :param skip_missing: if True then function will return None instead of failing the task
        :return:
            Single service information structure
        s*Error while reading from Swarm manager: %si�sJCannot inspect service: To inspect service execute module on Swarm Managers"Error inspecting swarm service: %sRN(tinspect_serviceRRRRRRR6R7RRR(Rt
service_idR;tservice_infoRR((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pytget_service_inspect�s	N(t__name__t
__module__RRRR%R'R(R)R0RR#R?RPRRRTRX(((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyR	s		$			+	'		(t
__future__RRRttypet
__metaclass__RttimeRt
docker.errorsRRtImportErrortansible.module_utils._textRt"ansible.module_utils.docker.commonRRR	(((sE/usr/lib/python2.7/site-packages/ansible/module_utils/docker/swarm.pyt<module>s


Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]