Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/clustering/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/clustering/consul.pyc

�
�Udac@`svddlmZmZmZeZidd6dgd6dd6ZdZd	ZyEdd
l	Z	ddl
mZde	jj
jfd
��YZeZWnek
r�eZnXddlmZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd
d�Zd�Zd�Z d�Z!dd!d��YZ"de#fd��YZ$d�Z%d�Z&e'd krre&�nd
S("i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bysy
module: consul
short_description: "Add, modify & delete services within a consul cluster."
description:
 - Registers services and checks for an agent with a consul cluster.
   A service is some process running on the agent node that should be advertised by
   consul's discovery mechanism. It may optionally supply a check definition,
   a periodic service test to notify the consul cluster of service's health.
 - "Checks may also be registered per node e.g. disk usage, or cpu usage and
   notify the health of the entire node to the cluster.
   Service level checks do not require a check name or id as these are derived
   by Consul from the Service name and id respectively by appending 'service:'
   Node level checks require a I(check_name) and optionally a I(check_id)."
 - Currently, there is no complete way to retrieve the script, interval or ttl
   metadata for a registered check. Without this metadata it is  not possible to
   tell if the data supplied with ansible represents a change to a check. As a
   result this does not attempt to determine changes and will always report a
   changed occurred. An API method is planned to supply this metadata so at that
   stage change management will be added.
 - "See U(http://consul.io) for more details."
requirements:
  - python-consul
  - requests
version_added: "2.0"
author: "Steve Gargan (@sgargan)"
options:
    state:
        description:
          - register or deregister the consul service, defaults to present
        default: present
        choices: ['present', 'absent']
    service_name:
        type: str
        description:
          - Unique name for the service on a node, must be unique per node,
            required if registering a service. May be omitted if registering
            a node level check
    service_id:
        type: str
        description:
          - the ID for the service, must be unique per node. If I(state=absent),
            defaults to the service name if supplied.
    host:
        type: str
        description:
          - host of the consul agent defaults to localhost
        default: localhost
    port:
        type: int
        description:
          - the port on which the consul agent is running
        default: 8500
    scheme:
        type: str
        description:
          - the protocol scheme on which the consul agent is running
        default: http
        version_added: "2.1"
    validate_certs:
        description:
          - whether to verify the TLS certificate of the consul agent
        type: bool
        default: 'yes'
        version_added: "2.1"
    notes:
        type: str
        description:
          - Notes to attach to check when registering it.
    service_port:
        type: int
        description:
          - the port on which the service is listening. Can optionally be supplied for
            registration of a service, i.e. if I(service_name) or I(service_id) is set
    service_address:
        type: str
        description:
          - the address to advertise that the service will be listening on.
            This value will be passed as the I(address) parameter to Consul's
            U(/v1/agent/service/register) API method, so refer to the Consul API
            documentation for further details.
        version_added: "2.1"
    tags:
        type: list
        description:
          - tags that will be attached to the service registration.
    script:
        type: str
        description:
          - the script/command that will be run periodically to check the health
            of the service. Scripts require I(interval) and vice versa.
    interval:
        type: str
        description:
          - the interval at which the service check will be run. This is a number
            with a s or m suffix to signify the units of seconds or minutes e.g
            C(15s) or C(1m). If no suffix is supplied, m will be used by default e.g.
            C(1) will be C(1m). Required if the I(script) parameter is specified.
    check_id:
        type: str
        description:
          - an ID for the service check. If I(state=absent), defaults to
            I(check_name). Ignored if part of a service definition.
    check_name:
        type: str
        description:
          - a name for the service check. Required if standalone, ignored if
            part of service definition.
    ttl:
        type: str
        description:
          - checks can be registered with a ttl instead of a I(script) and I(interval)
            this means that the service will check in with the agent before the
            ttl expires. If it doesn't the check will be considered failed.
            Required if registering a check and the script an interval are missing
            Similar to the interval this is a number with a s or m suffix to
            signify the units of seconds or minutes e.g C(15s) or C(1m). If no suffix
            is supplied, C(m) will be used by default e.g. C(1) will be C(1m)
    http:
        type: str
        description:
          - checks can be registered with an HTTP endpoint. This means that consul
            will check that the http endpoint returns a successful HTTP status.
            I(interval) must also be provided with this option.
        version_added: "2.0"
    timeout:
        type: str
        description:
          - A custom HTTP check timeout. The consul default is 10 seconds.
            Similar to the interval this is a number with a C(s) or C(m) suffix to
            signify the units of seconds or minutes, e.g. C(15s) or C(1m).
        version_added: "2.0"
    token:
        type: str
        description:
          - the token key identifying an ACL rule set. May be required to register services.
s
- name: register nginx service with the local consul agent
  consul:
    service_name: nginx
    service_port: 80

- name: register nginx service with curl check
  consul:
    service_name: nginx
    service_port: 80
    script: curl http://localhost
    interval: 60s

- name: register nginx with an http check
  consul:
    service_name: nginx
    service_port: 80
    interval: 60s
    http: http://localhost:80/status

- name: register external service nginx available at 10.1.5.23
  consul:
    service_name: nginx
    service_port: 80
    service_address: 10.1.5.23

- name: register nginx with some service tags
  consul:
    service_name: nginx
    service_port: 80
    tags:
      - prod
      - webservers

- name: remove nginx service
  consul:
    service_name: nginx
    state: absent

- name: register celery worker service
  consul:
    service_name: celery-worker
    tags:
      - prod
      - worker

- name: create a node level check to test disk usage
  consul:
    check_name: Disk usage
    check_id: disk_usage
    script: /opt/disk_usage.py
    interval: 5m

- name: register an http check against a service that's already registered
  consul:
    check_name: nginx-check2
    check_id: nginx-check2
    service_id: nginx
    interval: 60s
    http: http://localhost:80/morestatus
N(tConnectionErrortPatchedConsulAgentServicecB`seZdd�ZRS(cC`sEi}|r||d<n|jjjtjjj�d|d|�S(Nttokens/v1/agent/service/deregister/%stparams(tagentthttptputtconsultbasetCBtbool(tselft
service_idR
R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyt
deregister�s

N(t__name__t
__module__tNoneR(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR	�s(t
AnsibleModulecC`s9|jjd�}|dkr+t|�n
t|�dS(Ntstatetpresent(Rtgettaddtremove(tmoduleR((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pytregister_with_consul�s
cC`st|�}t|�}|r9|r9|jdd�n|re|rU|j|�nt||�n|r{t||�ndS(s> adds a service or a check depending on supplied configurationtmsgs2a name and port are required to register a serviceN(tparse_checkt
parse_servicet	fail_jsont	add_checktadd_service(Rtchecktservice((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR�scC`s�|jjd�p!|jjd�}|jjd�pE|jjd�}|pQ|sg|jdd�n|r}t||�n
t||�dS(s removes a service or a check Rtservice_nametcheck_idt
check_nameR!saservices and checks are removed by id or name. please supply a service id/name or a check id/nameN(RRR$tremove_servicetremove_check(RRR*((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRs$$cC`s�|jr'|jr'|jdd�nt|�}|j|�|jdtd|jd|jd|jd|j	d|j
d	|jd
|jd|j�	dS(
s� registers a check with the given agent. currently there is no way
    retrieve the full metadata of an existing check  through the consul api.
    Without this we can't compare to the supplied check and so we must assume
    a change. R!sNa check name is required for a node level check, one not attached to a servicetchangedR*R+tscripttintervaltttlR
ttimeoutRN(
tnameRR$tget_consul_apitregistert	exit_jsontTrueR*R/R0R1R
R2(RR't
consul_api((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR%s
							cC`sgt|�}||jj�krM|jjj|�|jdtd|�n|jdtd|�dS(s removes a check using its id R.tidN(R4RtchecksR'RR6R7tFalse(RR*R8((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR-%s
cC`s�|}t}t|�}t||j�}|j�sJ|sJ||kr�|j|�t||j�}|r�|}t}q�n|jd|d|jd|jd|j	dg|j
D]}|j�^q�d|j�dS(s, registers a service with the current agent R.RR)tservice_portR:ttagsN(
R;R4tget_service_by_id_or_nameR9t
has_checksR5R7R6R3tportR:tto_dictR=(RR(tresultR.R8texistingt
registeredR'((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR&0s  
			"cC`syt|�}t||�}|r_|jjj|d|jjd��|jdtd|�n|jdt	d|�dS(s@ deregister a service from the given agent using its service id R
R.R9N(
R4R>RR(RRRR6R7R;(RRR8R(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR,Ks%cC`s|tjd|jjd�d|jjd�d|jjd�d|jjd�d|jjd��}t|�|j_|S(NthostR@tschemetverifytvalidate_certsR
(RtConsulRRR	RR((RR
tconsulClient((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR4VscC`sWxP|jj�j�D]9\}}|d|ksB|d|krtd|�SqWdS(s@ iterate the registered services and find one with the given id tIDtServicetloadedN(Rtservicestitemst
ConsulService(R8tservice_id_or_nameR3R(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR>`s" cC`sctg|jjd�|jjd�|jjd�fD]}|r7|^q7�dkrk|jdd�n|jjd�s�|jjd�s�|jjd�s�|jjd�r_t|jjd�|jjd�|jjd	�|jjd
�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd
�|jjd��SdS(NR/R1R
iR!sYchecks are either script, http or ttl driven, supplying more than one does not make senseR*R+t
check_nodet
check_hostR0tnotesR2R(tlenRRR$tConsulCheck(Rtp((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR"gs X	
HcC`s�|jjd�rdt|jjd�|jjd�|jjd�|jjd�|jjd��S|jjd�s�|jdd�ndS(NR)Rtservice_addressR<R=R!s0service_name is required to configure a service.(RRRPR$(R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR#}sRPcB`sbeZd	d	d	dd	d	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(
i����cC`s�||_|_|r"||_n||_||_||_g|_|r�|d|_|d|_|d|_|d|_ndS(NRKRLtPorttTags(R9R3taddressR@R=R:(RRR3R[R@R=RM((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyt__init__�s				


c	C`s�i}|jr|j|d<nt|j�dkrK|jdj|d<n|jjj|jd|jd|j	d|j
|�dS(NR@iR'RR[R=(R@RUR:R'RR(R5R3R9R[R=(RR8toptional((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR5�s				cC`s|jj|�dS(N(R:tappend(RR'((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR%�scC`s|jS(N(R:(R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR:�scC`st|j�dkS(Ni(RUR:(R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR?�scC`sXt||j�oW|j|jkoW|j|jkoW|j|jkoW|j|jkS(N(t
isinstancet	__class__R9R3R@R=(Rtother((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyt__eq__�s
cC`s|j|�S(N(Rb(RRa((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyt__ne__�scC`s�i|jd6|jd6}|jr3|j|d<n|jrat|j�dkra|j|d<nt|j�dkr�|jdj�|d<n|S(NR9R3R@iR=R'(R9R3R@R=RUR:RA(Rtdata((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRA�s	N(RRRR\R5R%R:R?RbRcRA(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRP�s						RVc
B`seeZdddddddddd�	Zd�Zd�Zd�Zd�Zd�Zdd�Z	RS(	t	localhostcC`s.||_|_|r"||_n||_||_||_||_|jd|�|_|jd|�|_||_	|	|_
|jd|
�|_d|_
|r�tjj	||j�|_
n|r�tjj|j�|_
n|	r*|dkrtd��ntjj
|	|j|j�|_
ndS(NR0R1R2s http check must specify interval(R*R3RRTtnodeREtvalidate_durationR0R1R/R
R2RR'RtCheckt	Exception(RR*R3RfRER/R0R1RTR
R2R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR\�s*							c`sS�rOddddddg}t�fd�|D��sOdj���qOn�S(	Ntnstustmststmthc3`s|]}�j|�VqdS(N(tendswith(t.0tsuffix(tduration(sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pys	<genexpr>�ss{0}s(tanytformat(RR3Rstduration_units((RssE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRg�s
c
C`s>|jjj|jd|jd|jd|jd|j�dS(NR*RRTR'(RR'R5R3R*RRT(RR8((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyR5�s'	cC`sjt||j�oi|j|jkoi|j|jkoi|j|jkoi|j|jkoi|j|jkS(N(R_R`R*RR3R/R0(RRa((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRb�scC`s|j|�S(N(Rb(RRa((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRc�scC`s�i}|j|ddd�|j|ddd�|j|d�|j|d�|j|d�|j|d	�|j|d
�|j|d�|j|d�|j|d
�|j|d�|S(NR9tattrR*R3R+R/RfRTRER0R1R
R2R(t_add(RRd((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRAscC`sDy,|dkr|}nt||�||<Wntk
r?nXdS(N(RtgetattrRi(RRdtkeyRw((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRxs	
N(
RRRR\RgR5RbRcRARx(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyRV�s					cC`sts|jdd�ndS(NR!shpython-consul required for this module. see https://python-consul.readthedocs.io/en/latest/#installation(tpython_consul_installedR$(R((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyttest_dependenciessc1C`sHtdtdtdd�dtdddd�d	td
tdd�dtd
tdtdd
�dtd
t�dtd
t�dtd
t�dtd
t�dtd
t�dtd
t�dtd
t�dtd
t�dtd
tdddd�dtd
tdddd�dtdddddg�dtd
tdd�dtd
tdd�dtd
tdd�dtd
tdd�d td
tdd!�d"td
td#t��d$t�}t|�yt|�Wnvtk
r}|jd%d&|j	j
d�|j	j
d�t|�f�n)tk
rC}|jd%t|��nXdS('Nt
argument_specREtdefaultReR@i4!ttypetintRFtrequiredR
RHRR*R+RRRSRTR/RR)RXtstrR<RRtchoicestabsentR0R1R2R=tlistR
tno_logtsupports_check_modeR!s8Could not connect to consul agent at %s:%s, error was %s(
RtdictR;R7RR|R RR$RRR�Ri(Rte((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pytmains@	
2t__main__(((t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESRtrequests.exceptionsRRItAgentRLR	R7R{tImportErrorR;tansible.module_utils.basicRR RRR%R-R&R,RR4R>R"R#RPtobjectRVR|R�R(((sE/usr/lib/python2.7/site-packages/ansible/modules/clustering/consul.pyt<module>s>


�>	


								
			
?O		'

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