%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/swarm.pyc

�
���^c@@sdZddlmZmZmZddlZyddlZeZ	Wne
k
r]eZ	nXdZd�Z
d�Zd�Zeeed�Zeeed	�Zed
�Zeeeeeeed�Zed�Zed
�Zed�Zeed�Zeeeeed�ZdS(u�
Docker Swarm Module using Docker's Python SDK
=============================================

:codeauthor: Tyler Jones <jonestyler806@gmail.com>

.. versionadded:: 2018.3.0

The Docker Swarm Module is used to manage and create Docker Swarms.

Dependencies
------------

- Docker installed on the host
- Docker python sdk >= 2.5.1

Docker Python SDK
-----------------

.. code-block:: bash

    pip install -U docker

More information: https://docker-py.readthedocs.io/en/stable/
i(tabsolute_importtunicode_literalstprint_functionNuswarmcC@str
tStdfS(uC
    Load this module if the docker python module is installed
    uGThe swarm module failed to load: Docker python module is not available.(t
HAS_DOCKERt__virtualname__tFalse(((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyt__virtual__*scC@s+trtj�td<ntdtd<dS(Nuclientuiduserver_name(Rtdockertfrom_envt__context__t
__grains__(tself((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyt__init__3scC@s&tjdd�}|j�}|dS(u�
    Get the Docker Swarm Manager or Worker join tokens

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.swarm_tokens
    tbase_urluunix://var/run/docker.socku
JoinTokens(Rt	APIClientt
inspect_swarm(tclienttservice((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pytswarm_tokens9s
cC@s�yUi}tdjj|||�djtd�}|ji|d6t�d6�Wn+tk
r�i}|jidd6�nX|S(u�
    Initalize Docker on Minion as a Swarm Manager

    advertise_addr
        The ip of the manager

    listen_addr
        Listen address used for inter-manager communication,
        as well as determining the networking interface used
        for the VXLAN Tunnel Endpoint (VTEP).
        This can either be an address/port combination in
        the form 192.168.1.1:4567,
        or an interface followed by a port number,
        like eth0:4567

    force_new_cluster
        Force a new cluster if True is passed

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.swarm_init advertise_addr='192.168.50.10' listen_addr='0.0.0.0' force_new_cluster=False
    uclientuSDocker swarm has been initialized on {0} and the worker/manager Join token is belowuserver_nameuCommentuTokensu]Please make sure you are passing advertise_addr, listen_addr and force_new_cluster correctly.uError(R	tswarmtinittformattupdateRt	TypeError(tadvertise_addrtlisten_addrtforce_new_clustertsalt_returntoutput((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyt
swarm_initHs

cC@s�yYi}tdjjd|gd|d|�tdd}|ji|d6|d6�Wn+tk
r�i}|jid	d
6�nX|S(u�
    Join a Swarm Worker to the cluster

    remote_addr
        The manager node you want to connect to for the swarm

    listen_addr
        Listen address used for inter-manager communication if the node gets promoted to manager,
        as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP)

    token
        Either the manager join token or the worker join token.
        You can get the worker or manager token via ``salt '*' swarm.swarm_tokens``

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.joinswarm remote_addr=192.168.50.10 listen_addr='0.0.0.0'             token='SWMTKN-1-64tux2g0701r84ofq93zppcih0pe081akq45owe9ts61f30x4t-06trjugdu7x2z47j938s54il'
    uclienttremote_addrsRt
join_tokenuserver_nameu has joined the SwarmuCommentuManager_AddruuPlease make sure this minion is not part of a swarm and you are passing remote_addr, listen_addr and token correctly.uError(R	RtjoinRR(tremote_addrRttokenRR((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyt	joinswarmss
cC@sCi}tdjjd|�tdd}|ji|d6�|S(u�
    Force the minion to leave the swarm

    force
        Will force the minion/worker/manager to leave the swarm

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.leave_swarm force=False
    uclienttforceuserver_nameu has left the swarmuComment(R	RtleaveR(R$RR((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pytleave_swarm�s

cC@sy�i}tjjdd|�}tjjdi||6�}	tdjjd|d|d|d|d	|	�td
d|}
|ji	|
d6td
d
6|d6|d6|d6|d6|d6|d6|d6�Wn+tk
r�i}|jidd6�nX|S(u~
    Create Docker Swarm Service Create

    image
        The docker image

    name
        Is the service name

    command
        The docker command to run in the container at launch

    hostname
        The hostname of the containers

    replicas
        How many replicas you want running in the swarm

    target_port
        The target port on the container

    published_port
        port thats published on the host/os

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.service_create image=httpd name=Test_Service             command=None hostname=salthttpd replicas=6 target_port=80 published_port=80
    u
replicatedtreplicastportsuclienttnametimagetcommandtmodet
endpoint_specuserver_nameu* has a Docker Swarm Service running named uInfouMinionuNameuImageuCommanduHostnameuReplicasuTarget_PortuPublished_PortuPlease make sure you are passing arguments correctly [image, name, command, hostname, replicas, target_port and published_port]uError(	RttypestServiceModetEndpointSpecR	tservicestcreateRR(R*R)R+thostnameR'ttarget_porttpublished_portRtreplica_modeR(techoback((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pytservice_create�s.&
cC@s�y�i}tjdd�}|jd|�}tjjj|�}tjjj|�}|dd}|dd}|ddd	}|ddd
}	|d}
|d}|d
}|dd}
|dd	dd}|dd}|dddd}x�|	D]�}|d}|d}|d}|d}|ji|d6|d6|
d6|d6|d6|d6|d6|d 6|d!6|d"6|d6|d#6t	d$d%6|d6�qWWn+t
k
r�i}|jid&d'6�nX|S((u�
    Swarm Service Information

    service_name
        The name of the service that you want information on about the service

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.swarm_service_info service_name=Test_Service
    R
uunix://var/run/docker.sockRuVersionuIndexuSpecuNameuEndpointSpecuModeuPortsuIDu	CreatedAtu	UpdatedAtuLabelsu
ReplicateduReplicasuEndpointu
VirtualIPsuTaskTemplateu
ContainerSpecuImageu
PublishedPortu
TargetPortuPublishModeuProtocoluService Nameu
Service IDuNetworkuNetwork Modeu
Creation DateuUpdate DateuPublished PortuTarget PortuPublished ModeuDocker Imageuserver_nameu	Minion Iduservice_name arg is missing?uError(RRtinspect_servicetsalttutilstjsontdumpstloadsRR	R(tservice_nameRRRtgetdatatdumptversionR)tnetwork_modeR(tswarm_idtcreate_datetupdate_datetlabelsR'tnetworkR*titemsR5R4tpublished_modetprotocol((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pytswarm_service_info�sP









cC@s|yJi}tjdd�}|j|�}|ji|d6tdd6�Wn+tk
rwi}|jidd6�nX|S(u�
    Remove Swarm Service

    service
        The name of the service

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.remove_service service=Test_Service
    R
uunix://var/run/docker.sockuService Deleteduserver_nameu	Minion IDuservice arg is missing?uError(RRtremove_serviceRR	R(RRR((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyRM$s

cC@sSy!i}tjdd�}|jdi|d6�}tjjj|�}tjjj|�}x�|D]�}|ddd}|dd}|dd	}	|d
}
|dd}|dd
}|d}
|dd}|ji|d6|d6|	d	6|
d
6|d6|d
6|
d6|d6�qeWWn+t	k
rNi}|jidd6�nX|S(u�
    Displays Information about Swarm Nodes with passing in the server

    server
        The minion/server name

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.node_ls server=minion1
    R
uunix://var/run/docker.socktfiltersunameuDescriptionuEngineu
EngineVersionuPlatformuHostnameuIDuSpecuRoleuAvailabilityuStatusuVersionuIndexuDocker VersionuRolesu>The server arg is missing or you not targeting a Manager node?uError(
RRtnodesR:R;R<R=R>RR(tserverRRRR@RARItdocker_versiontplatformt	hostnamestidstroletavailabilitytstatusRB((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pytnode_ls=s6




cC@s�tjdd�}yB|dkr:|j|dt�}|S|j|dt�}|SWn,tk
r�i}|jidd6�|SXdS(uU
    Remove a node from a swarm and the target needs to be a swarm manager

    node_id
        The node id from the return of swarm.node_ls

    force
        Forcefully remove the node/minion from the service

    CLI Example:

    .. code-block:: bash

        salt '*' swarm.remove_node node_id=z4gjbe9rwmqahc2a91snvolm5 force=false
    R
uunix://var/run/docker.sockuTrueR$u/Is the node_id and/or force=True/False missing?uErrorN(RRtremove_nodetTrueRRR(tnode_idR$RRR((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyRYgs
cC@s�tjdd�}yUi}i|d6|d6|d6}|jd|d|d|�|ji|d	6�Wn+tk
r�i}|jid
d6�nX|S(u�
    Updates docker swarm nodes/needs to target a manager node/minion

    availability
        Drain or Active

    node_name
        minion/node

    role
        role of manager or worker

    node_id
        The Id and that can be obtained via swarm.node_ls

    version
        Is obtained by swarm.node_ls

    CLI Example:

    .. code-block:: bash

        salt '*' docker_util.update_node availability=drain node_name=minion2             role=worker node_id=3k9x7t8m4pel9c0nqr3iajnzp version=19
    R
uunix://var/run/docker.sockuAvailabilityuNameuRoleR[RBt	node_specuNode InformationuOMake sure all args are passed [availability, node_name, role, node_id, version]uError(RRtupdate_nodeRR(RVt	node_nameRUR[RBRRR\((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyR]�s


(t__doc__t
__future__RRRtsalt.utils.jsonR:RRZRtImportErrorRRRRRtstrtinttboolRR#R&R8RLRMRXRYR](((s6/usr/lib/python2.7/site-packages/salt/modules/swarm.pyt<module>sD


				)$:7*

Zerion Mini Shell 1.0