
    Vht
                     Z    d dl mZmZmZ eZd dlZd dlmZ d dl	m
Z
mZ d Zd Zd	dZd Zy)
    )absolute_importdivisionprint_functionN)	urlencode)BASE_URLfetch_url_jsonc                     dj                  t        |      }t        | |      \  }}d|vr6| j                  dj                  t	        j
                  |d                   |d   S )z
    Get information record of failover IP.

    See https://robot.your-server.de/doc/webservice/en.html#get-failover-failover-ip
    {0}/failover/{1}failoverzCannot interpret result: {0}T)	sort_keys)msg)formatr   r   	fail_jsonjsondumps)moduleipurlresulterrors        r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/hrobot/plugins/module_utils/failover.pyget_failover_recordr      sb     
#
#Hb
1C"63/MFE;BB4::f`dCefg*    c                      t        | |      d   S )z
    Get current routing target of failover IP.

    The value ``None`` represents unrouted.

    See https://robot.your-server.de/doc/webservice/en.html#get-failover-failover-ip
    active_server_ip)r   )r   r   s     r   get_failoverr   "   s     vr*+=>>r   c           	          dj                  t        |      }|t        | |d|dg      \  }}n/ddi}t        |      }t        | |d|t	        |      |dg	      \  }}||d
fS |d   d   dfS )aB  
    Set current routing target of failover IP.

    Return a pair ``(value, changed)``. The value ``None`` for ``value`` represents unrouted.

    See https://robot.your-server.de/doc/webservice/en.html#post-failover-failover-ip
    and https://robot.your-server.de/doc/webservice/en.html#delete-failover-failover-ip
    r
   DELETEFAILOVER_ALREADY_ROUTED)methodtimeoutaccept_errorszContent-typez!application/x-www-form-urlencoded)r   POST)r    r!   dataheadersr"   Fr   r   T)r   r   r   dictr   )	r   r   valuer!   r   r   r   r%   r$   s	            r   set_failoverr(   -   s     
#
#Hb
1C}&45
 "#FG"
 '445
 e|j!"45t;;r   c                 .    t        | | rd      S d      S )zh
    Create result dictionary for failover IP's value.

    The value ``None`` represents unrouted.
    routedunrouted)r'   state)r&   )r'   s    r   get_failover_stater-   S   s&     h %/ r   )   )
__future__r   r   r   type__metaclass__r   +ansible.module_utils.six.moves.urllib.parser   ?ansible_collections.community.hrobot.plugins.module_utils.robotr   r   r   r   r(   r-    r   r   <module>r5      s5    A @  A
?#<L	r   