HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/bigip.cpython-310.pyc
o

�N�gW�@s�dZddlZddlZzddlZddlZdZWney!dZYnwdZdd�Z	dZ
dOd	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdPdd �ZdOd!d"�Z										dQd#d$�ZdOd%d&�ZdOd'd(�Z																							dRd)d*�Z																						dSd+d,�Zd-d.�Zd/d0�Zd1d2�Z												dTd3d4�Z d5d6�Z!dOd7d8�Z"																																						dUd9d:�Z#																																							dVd;d<�Z$d=d>�Z%	dOd?d@�Z&dAdB�Z'dCdD�Z(dEdF�Z)	dOdGdH�Z*dIdJ�Z+dKdL�Z,dMdN�Z-dS)Wz�
An execution module which can manipulate an f5 bigip via iControl REST
    :maturity:      develop
    :platform:      f5_bigip_11.6
�NTF�bigipcCstrtSdS)z.
    Only return if requests is installed
    )FzSThe bigip execution module cannot be loaded: python requests library not available.)�HAS_LIBS�__virtualname__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/bigip.py�__virtual__srzhttps://{host}/mgmt/tmcCsjt��}||f|_d|_|j�ddi�|r3tdd|���}|r+|j�d|i�|S|j�ddi�|S)zG
    Create a session to be used when connecting to iControl REST.
    TzContent-Typezapplication/json�
grains.get�bigip_f5_trans:zX-F5-REST-Coordination-IdN)�requests�sessionZauthZverify�headers�update�__salt__)�username�password�trans_labelr�trans_idrrr�_build_session's
�rcCs>z
tjj�|j�}Wnty|j}Ynw|j|d�}|S)zM
    Load the response from json data, return the dictionary or raw text
    ��code�content)�salt�utils�json�loads�text�
ValueErrorZstatus_code)�response�data�retrrr�_load_response=s
�r cCsddj||d�d�}|S)z.
    Format and Return a connection error
    Nz<Error: Unable to connect to the bigip device: {host}
{error})�host�errorr)�format)�hostnamer"rrrr�_load_connection_errorLs��	r%cCs*i}|��D]\}}|dur|||<q|S)z�
    Pass in a dictionary of parameters, loop through them and build a payload containing,
    parameters who's values are not None.
    N��items)�params�payload�param�valuerrr�
_loop_payload]s�r,cCsh|dur2g}|dkr|St|t�s|�d�}n|}|D]}|dur'|�|�q|�||d��q|SdS)zy
    pass in an option to check for a list of items, create a list of dictionary of items to set
    for this option
    N�none�,)�kind�name)�
isinstance�list�split�append)Zoption_valueZ	item_kindr'�valuesr+rrr�_build_listns
r6cCs�|��D]d\}}|ddurh|ddus|ddkr%|ddkr%d||<n|ddus1|ddkr;|ddkr;d||<|ddusG|ddkrR|dd	krRd||<q|ddus^|ddkrh|dd	krhd||<q|S)
z�
    BigIP can't make up its mind if it likes yes / no or true or false.
    Figure out what it likes to hear without confusing the user.
    r+NTZyes�type�yes_noF�no�
true_falser&)r)�togglesZtoggleZ
definitionrrr�_determine_toggles�s 

�r<c	Cs^t|t�st|t�st|t�r|S|�d�r;|�d�r;|�dd�}|�dd�}ztjj	�
|�WSty:tjj
�wd|vrXd|vrX|�d�}g}|D]	}|�t|��qL|Sd|vr�d|vr�i}|�d	�}|D]}|�d�d
}|�d�d}|||<qi|Sd	|vr�d|vr�|�d	�}|Sd|vr�|�dd�}d|vr�|�dd�}d|vr�|�dd	�}|S)
z�
    A function to detect if user is trying to pass a dictionary or list.  parse it and return a
    dictionary list or a string
    zj{z}j�{�}�|z\|�:z\:r.r�z\,)r1�bool�dictr2�
startswith�endswith�replacerrrr�	Exception�
exceptions�CommandExecutionErrorr3r4�
_set_value)	r+r5r'�optionsZ	key_pairsZkey_pair�k�vZvalue_itemsrrrrJ�sD�



rJc

Cs�t||�}i}z|jtj|d�dtjj�|�d�}Wntj	j
y4}zt||�WYd}~Sd}~wwt|�}|ddkrU|dd}	t
d	d
||	i�dj|	|d�S|S)
a�
    A function to connect to a bigip device and start a new transaction.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    label
        The name / alias for this transaction.  The actual transaction
        id will be stored within a grain called ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.start_transaction bigip admin admin my_transaction

    �r!z/transaction�rNr��rZtransIdz
grains.setvalZbigip_f5_transz[Transaction: {trans_id} - has successfully been stored in the grain: bigip_f5_trans:{label})r�label)r�post�BIG_IP_URL_BASEr#rrr�dumpsr
rH�ConnectionErrorr%r r)
r$rrrQ�
bigip_sessionr)r�errrrr�start_transaction�s(

�����rXc
Cs�t||�}tdd|���}|r>z|�tj|d�d|�d��}t|�WStjjy=}zt	||�WYd}~Sd}~ww	dS)a�
    A function to connect to a bigip device and list an existing transaction.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    label
        the label of this transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_transaction bigip admin admin my_transaction

    rr	rN�
/transaction/z	/commandsN��Error: the label for this transaction was not defined as a grain.  Begin a new transaction using the bigip.start_transaction function)
rr�getrSr#r r
rHrUr%�r$rrrQrVrrrWrrr�list_transactions 


��
���r]c	
Cs�t||�}tdd|���}|rJi}d|d<z|jtj|d�d|��tjj�|�d�}t	|�WSt
jjyI}zt
||�WYd}~Sd}~ww	d	S)
a�
    A function to connect to a bigip device and commit an existing transaction.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    label
        the label of this transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.commit_transaction bigip admin admin my_transaction
    rr	Z
VALIDATING�staterNrYrONrZ)rrZpatchrSr#rrrrTr r
rHrUr%)	r$rrrQrVrr)rrWrrr�commit_transactionLs"
�
���r_c
Cs�t||�}tdd|���}|r=z|�tj|d�d|���}t|�WStjjy<}zt	||�WYd}~Sd}~ww	dS)a�
    A function to connect to a bigip device and delete an existing transaction.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    label
        The label of this transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_transaction bigip admin admin my_transaction
    rr	rNrYNrZ)
rr�deleterSr#r r
rHrUr%r\rrr�delete_transaction|s
�
���rac
Cs�t|||�}z&|r|�tj|d�d|���}n|�tj|d�d�}Wt|�SWt|�StjjyE}zt||�WYd}~Sd}~ww)a;
    A function to connect to a bigip device and list all nodes or a specific node.


    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the node to list. If no name is specified than all nodes
        will be listed.
    trans_label
        The label of the transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_node bigip admin admin my-node
    rN�
/ltm/node/�	/ltm/nodeN�	rr[rSr#r
rHrUr%r �r$rrr0rrVrrWrrr�	list_node�s ���
���rfc

Cs�t|||�}i}||d<||d<z|jtj|d�dtjj�|�d�}Wt|�Stj	j
y@}	zt||	�WYd}	~	Sd}	~	ww)a

    A function to connect to a bigip device and create a node.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the node
    address
        The address of the node
    trans_label
        The label of the transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.create_node bigip admin admin 10.1.1.2
    r0�addressrNrcrON)
rrRrSr#rrrrTr
rHrUr%r )
r$rrr0rgrrVr)rrWrrr�create_node�s����rhc
Cs�||||||	|
||d�	}t|||
�}t|�}||d<z|jtj|d�d|��tjj�|�d�}Wt
|�St	j
jyM}zt||�WYd}~Sd}~ww)ai
    A function to connect to a bigip device and modify an existing node.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the node to modify
    connection_limit
        [integer]
    description
        [string]
    dynamic_ratio
        [integer]
    logging
        [enabled | disabled]
    monitor
        [[name] | none | default]
    rate_limit
        [integer]
    ratio
        [integer]
    session
        [user-enabled | user-disabled]
    state
        [user-down | user-up ]
    trans_label
        The label of the transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_node bigip admin admin 10.1.1.2 ratio=2 logging=enabled
    )	�connection-limit�description�
dynamic-ratio�logging�monitor�
rate-limit�ratiorr^r0rNrbrON�rr,�putrSr#rrrrTr
rHrUr%r )r$rrr0�connection_limitrj�
dynamic_ratiorlrm�
rate_limitrorr^rr(rVr)rrWrrr�modify_nodes.9�
����ruc
Csxt|||�}z|�tj|d�d|���}Wntjjy/}zt||�WYd}~Sd}~wwt|�dkr8dSt|�S)a
    A function to connect to a bigip device and delete a specific node.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the node which will be deleted.
    trans_label
        The label of the transaction stored within the grain:
        ``bigip_f5_trans:<label>``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_node bigip admin admin my-node
    rNrbN�T�	rr`rSr#r
rHrUr%r rerrr�delete_nodeXs���rxc
C�t||�}z'|r|�tj|d�d|�d��}n|�tj|d�d�}Wt|�SWt|�StjjyE}zt||�WYd}~Sd}~ww)a�
    A function to connect to a bigip device and list all pools or a specific pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to list. If no name is specified then all pools
        will be listed.

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_pool bigip admin admin my-pool
    rN�
/ltm/pool/�/?expandSubcollections=true�	/ltm/poolNrd�r$rrr0rVrrWrrr�	list_pool��$


�������r~c!
Cs(id|�d|�d|	�d|
�d|�d|�d|
�d|�d	|�d
|�d|�d|�d
|�d|�d|�d|�d|�|||d��}d|d�d|d�d�}t|�}||d<t||�}|dur^t|d�|d<t||�}z|jtj|d�dtjj	�
|�d�}Wt|�Stjj
y�} zt|| �WYd} ~ Sd} ~ ww)a
    A function to connect to a bigip device and create a pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to create.
    members
        List of comma delimited pool members to add to the pool.
        i.e. 10.1.1.1:80,10.1.1.2:80,10.1.1.3:80
    allow_nat
        [yes | no]
    allow_snat
        [yes | no]
    description
        [string]
    gateway_failsafe_device
        [string]
    ignore_persisted_weight
        [enabled | disabled]
    ip_tos_to_client
        [pass-through | [integer]]
    ip_tos_to_server
        [pass-through | [integer]]
    link_qos_to_client
        [pass-through | [integer]]
    link_qos_to_server
        [pass-through | [integer]]
    load_balancing_mode
        [dynamic-ratio-member | dynamic-ratio-node |
        fastest-app-response | fastest-node |
        least-connections-members |
        least-connections-node |
        least-sessions |
        observed-member | observed-node |
        predictive-member | predictive-node |
        ratio-least-connections-member |
        ratio-least-connections-node |
        ratio-member | ratio-node | ratio-session |
        round-robin | weighted-least-connections-member |
        weighted-least-connections-node]
    min_active_members
        [integer]
    min_up_members
        [integer]
    min_up_members_action
        [failover | reboot | restart-all]
    min_up_members_checking
        [enabled | disabled]
    monitor
        [name]
    profiles
        [none | profile_name]
    queue_depth_limit
        [integer]
    queue_on_connection_limit
        [enabled | disabled]
    queue_time_limit
        [integer]
    reselect_tries
        [integer]
    service_down_action
        [drop | none | reselect | reset]
    slow_ramp_time
        [integer]

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.create_pool bigip admin admin my-pool 10.1.1.1:80,10.1.1.2:80,10.1.1.3:80 monitor=http
    rj�gateway-failsafe-device�ignore-persisted-weight�ip-tos-to-client�ip-tos-to-server�link-qos-to-client�link-qos-to-server�load-balancing-mode�min-active-members�min-up-memberszmin-up-members-action�min-up-members-checkingrm�profiles�queue-on-connection-limit�queue-depth-limit�queue-time-limit�zreselect-trieszservice-down-actionzslow-ramp-timer8�r7r+�z	allow-natz
allow-snatr0Nzltm:pool:members�membersrNr|rO)r,r<r6rrRrSr#rrrrTr
rHrUr%r )!r$rrr0r��	allow_nat�
allow_snatrj�gateway_failsafe_device�ignore_persisted_weight�ip_tos_to_client�ip_tos_to_server�link_qos_to_client�link_qos_to_server�load_balancing_mode�min_active_members�min_up_members�min_up_members_action�min_up_members_checkingrmr��queue_depth_limit�queue_on_connection_limit�queue_time_limit�reselect_tries�service_down_action�slow_ramp_timer(r;r)rVrrWrrr�create_pool�stj��������	�
���
�������

����r�c 
Csid|�d|�d|�d|	�d|
�d|�d|�d|
�d	|�d
|�d|�d|�d
|�d|�d|�d|�d|�|||d��}d|d�d|d�d�}t|�}||d<t||�}t||�}z|jtj|d�d|��tjj�	|�d�}Wt|�St
jjy�}zt
||�WYd}~Sd}~ww)a�
    A function to connect to a bigip device and modify an existing pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to modify.
    allow_nat
        [yes | no]
    allow_snat
        [yes | no]
    description
        [string]
    gateway_failsafe_device
        [string]
    ignore_persisted_weight
        [yes | no]
    ip_tos_to_client
        [pass-through | [integer]]
    ip_tos_to_server
        [pass-through | [integer]]
    link_qos_to_client
        [pass-through | [integer]]
    link_qos_to_server
        [pass-through | [integer]]
    load_balancing_mode
        [dynamic-ratio-member | dynamic-ratio-node |
        fastest-app-response | fastest-node |
        least-connections-members |
        least-connections-node |
        least-sessions |
        observed-member | observed-node |
        predictive-member | predictive-node |
        ratio-least-connections-member |
        ratio-least-connections-node |
        ratio-member | ratio-node | ratio-session |
        round-robin | weighted-least-connections-member |
        weighted-least-connections-node]
    min_active_members
        [integer]
    min_up_members
        [integer]
    min_up_members_action
        [failover | reboot | restart-all]
    min_up_members_checking
        [enabled | disabled]
    monitor
        [name]
    profiles
        [none | profile_name]
    queue_on_connection_limit
        [enabled | disabled]
    queue_depth_limit
        [integer]
    queue_time_limit
        [integer]
    reselect_tries
        [integer]
    service_down_action
        [drop | none | reselect | reset]
    slow_ramp_time
        [integer]

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_pool bigip admin admin my-pool 10.1.1.1:80,10.1.1.2:80,10.1.1.3:80 min_active_members=1
    rjr�r�r�r�r�r�r�r�r�zmin-up_members-actionr�rmr�r�r�r�r�r8r�r�r0rNrzrON)r,r<rrqrSr#rrrrTr
rHrUr%r ) r$rrr0r�r�rjr�r�r�r�r�r�r�r�r�r�r�rmr�r�r�r�r�r�r�r(r;r)rVrrWrrr�modify_poolKspf��������	�
���
�������

����r�c
C�vt||�}z|�tj|d�d|���}Wntjjy.}zt||�WYd}~Sd}~wwt|�dkr7dSt|�S)a�
    A function to connect to a bigip device and delete a specific pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool which will be deleted

    CLI Example

    .. code-block:: bash

        salt '*' bigip.delete_node bigip admin admin my-pool
    rNrzNrvTrwr}rrr�delete_pool��
���r�c

Csi}||d<|durVt|t�r|�d�}g}|D]9}t|t�rDd|��vr,|�d�|d<|D]}|�dd�}	|�|�||	<q.|�|�q|�||�d�d	d
��q||d<t||�}
z|
j	t
j|d�d
|��tj
j�|�d�}Wt|�Stjjy�}zt||�WYd}~Sd}~ww)aY
    A function to connect to a bigip device and replace members of an existing pool with new members.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to modify
    members
        List of comma delimited pool members to replace existing members with.
        i.e. 10.1.1.1:80,10.1.1.2:80,10.1.1.3:80

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.replace_pool_members bigip admin admin my-pool 10.2.2.1:80,10.2.2.2:80,10.2.2.3:80
    r0Nr.�member_stater^�_�-r@r�r0rgr�rNrzrO)r1�strr3rC�keys�poprFr4rrqrSr#rrrrTr
rHrUr%r )
r$rrr0r�r)Zpool_members�member�key�new_keyrVrrWrrr�replace_pool_members
s6



����r�c
Cs�t|t�r'd|��vr|�d�|d<|D]}|�dd�}|�|�||<q|}n
||�d�dd�}t||�}z|jtj	|d�d	|�d
�t
jj�
|�d�}	Wt|	�Stjjyj}
zt||
�WYd}
~
Sd}
~
ww)
a�
    A function to connect to a bigip device and add a new member to an existing pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to modify
    member
        The name of the member to add
        i.e. 10.1.1.2:80

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.add_pool_members bigip admin admin my-pool 10.2.2.1:80
    r�r^r�r�r@rr�rNrzz/membersrON)r1rCr�r�rFr3rrRrSr#rrrrTr
rHrUr%r )r$rrr0r�r�r�r)rVrrWrrr�add_pool_memberOs&

����r�c
Cs�|||||	|
|||
|||d�}t||�}t|�}z|jtj|d�d|�d|��tjj�|�d�}Wt
|�St	j
jyN}zt||�WYd}~Sd}~ww)a�
    A function to connect to a bigip device and modify an existing member of a pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to modify
    member
        The name of the member to modify i.e. 10.1.1.2:80
    connection_limit
        [integer]
    description
        [string]
    dynamic_ratio
        [integer]
    inherit_profile
        [enabled | disabled]
    logging
        [enabled | disabled]
    monitor
        [name]
    priority_group
        [integer]
    profiles
        [none | profile_name]
    rate_limit
        [integer]
    ratio
        [integer]
    session
        [user-enabled | user-disabled]
    state
        [ user-up | user-down ]

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_pool_member bigip admin admin my-pool 10.2.2.1:80 state=use-down session=user-disabled
    )rirjrkzinherit-profilerlrmzpriority-groupr�rnrorr^rNrz�	/members/rONrp)r$rrr0r�rrrjrsZinherit_profilerlrmZpriority_groupr�rtrorr^r(rVr)rrWrrr�modify_pool_member�s6A�

�����r�c
C�|t||�}z|�tj|d�d|�d|���}Wntjjy1}zt||�WYd}~Sd}~wwt|�dkr:dSt|�S)a�
    A function to connect to a bigip device and delete a specific pool.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the pool to modify
    member
        The name of the pool member to delete

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_pool_member bigip admin admin my-pool 10.2.2.2:80
    rNrzr�NrvTrw)r$rrr0r�rVrrWrrr�delete_pool_member�s
���r�c
Cry)a�
    A function to connect to a bigip device and list all virtuals or a specific virtual.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the virtual to list. If no name is specified than all
        virtuals will be listed.

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_virtual bigip admin admin my-virtual
    rN�
/ltm/virtual/r{�/ltm/virtualNrdr}rrr�list_virtualrr�c+3
Cs�id|�d|�d|�d|
�d|�d|
�d|�d|�d	|�d
|�d|�d|�d
|�d|�d|�d|�d|�|||#|%|(|)d��}+d|d�d|	d�d|d�d|"d�d|d�d|d�d|d�d�},t||�}-t|+�}.||.d<||.d<t|.|,�}.|dur~t|d�|.d<|dur�t|d�|.d<|dur�t|d�|.d<| dur�t| d�|.d<|!dur�t|!d�|.d <|$dur�t|$t�r�|$|.d!<n7|$d"kr�d"d"d#�|.d!<n+|$d$kr�d"d$d#�|.d!<n|$d%kr�d"d%d#�|.d!<n|$�d&�r�|$�d'�d(}/|/d&d#�|.d!<|'dur�t|'d�|.d)<|*du�r�t|*t��r1z|*d*|.d+<|*d,�rd-|.d.<n	|*d/�rd-|.d0<Wnqt�y0d1j	|*d2�YSw|*d"k�r;d"|.d+<nW|*d3k�rEd3|.d+<nMt|*t
��r�|*�d,��sW|*�d/��r�z(|*�d'�d4}0|*�d'�d(�d5�|.d+<|0d/k�rud-|.d0<n	|0d,k�r~d-|.d.<Wnt�y�d6j	|*d2�YSwd7S|&du�r�|&d,k�r�d-|.d,<n	|&d/k�r�d-|.d/<z|-jtj	|d8�d9t
jj�|.�d:�}1Wt|1�Stjj�y�}2zt||2�WYd}2~2Sd}2~2ww);u=
    A function to connect to a bigip device and create a virtual server.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the virtual to create
    destination
        [ [virtual_address_name:port] | [ipv4:port] | [ipv6.port] ]
    pool
        [ [pool_name] | none]
    address_status
        [yes | no]
    auto_lasthop
        [default | enabled | disabled ]
    bwc_policy
        [none] | string]
    cmp_enabled
        [yes | no]
    dhcp_relay
        [yes | no]
    connection_limit
        [integer]
    description
        [string]
    state
        [disabled | enabled]
    fallback_persistence
        [none | [profile name] ]
    flow_eviction_policy
        [none | [eviction policy name] ]
    gtm_score
        [integer]
    ip_forward
        [yes | no]
    ip_protocol
        [any | protocol]
    internal
        [yes | no]
    twelve_forward
        (12-forward)
        [yes | no]
    last_hop-pool
        [ [pool_name] | none]
    mask
        { [ipv4] | [ipv6] }
    mirror
        { [disabled | enabled | none] }
    nat64
        [enabled | disabled]
    persist
        [none | profile1,profile2,profile3 ... ]
    profiles
        [none | default | profile1,profile2,profile3 ... ]
    policies
        [none | default | policy1,policy2,policy3 ... ]
    rate_class
        [name]
    rate_limit
        [integer]
    rate_limit_mode
        [destination | object | object-destination |
        object-source | object-source-destination |
        source | source-destination]
    rate_limit_dst
        [integer]
    rate_limitçsrc
        [integer]
    rules
        [none | [rule_one,rule_two ...] ]
    related_rules
        [none | [rule_one,rule_two ...] ]
    reject
        [yes | no]
    source
        { [ipv4[/prefixlen]] | [ipv6[/prefixlen]] }
    source_address_translation
        [none | snat:pool_name | lsn | automap ]
    source_port
        [change | preserve | preserve-strict]
    state
        [enabled | disabled]
    traffic_classes
        [none | default | class_one,class_two ... ]
    translate_address
        [enabled | disabled]
    translate_port
        [enabled | disabled]
    vlans
        [none | default | [enabled|disabled]:vlan1,vlan2,vlan3 ... ]

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.create_virtual bigip admin admin my-virtual-3 26.2.2.5:80 \
            pool=my-http-pool-http profiles=http,tcp

        salt '*' bigip.create_virtual bigip admin admin my-virtual-3 43.2.2.5:80 \
            pool=test-http-pool-http profiles=http,websecurity persist=cookie,hash \
            policies=asm_auto_l7_policy__http-virtual \
            rules=_sys_APM_ExchangeSupport_helper,_sys_https_redirect \
            related_rules=_sys_APM_activesync,_sys_APM_ExchangeSupport_helper \
            source_address_translation=snat:my-snat-pool \
            translate_address=enabled translate_port=enabled \
            traffic_classes=my-class,other-class \
            vlans=enabled:external,internal

    �pool�auto-lasthop�
bwc-policyrirj�fallback-persistence�flow-eviction-policy�	gtm-score�ip-protocol�
last-hop-pool�mask�mirror�nat64�persist�
rate-classrn�rate-limit-mode)�rate-limit-dst�rate-limit-src�source�source-port�translate-address�translate-portr8r�r:�zaddress-statuszcmp-enabledz
dhcp-relay�rejectz
12-forward�internalz
ip-forwardr0�destinationN�ltm:virtual:profiler��ltm:virtual:persist�ltm:virtual:policy�policies�rules�
related-rules�source-address-translationr-�r�r7�automap�lsn�snatr@rA�traffic-classes�vlan_ids�vlans�enabledT�
vlans-enabled�disabled�vlans-disabled�8Error: Unable to Parse vlans dictionary: 
	vlans={vlans}�r��defaultrr.�4Error: Unable to Parse vlans option: 
	vlans={vlans}z,Error: vlans must be a dictionary or string.rNr�rO)rr,r<r6r1rCrDr3rGr#r�rRrSrrrrTr
rHrUr%r �3r$rrr0r�r�Zaddress_statusZauto_lasthopZ
bwc_policyZcmp_enabledrrZ
dhcp_relayrjZfallback_persistenceZflow_eviction_policyZ	gtm_scoreZ
ip_forwardZip_protocolr�Ztwelve_forwardZ
last_hop_poolr�r�r�r�r�r�Z
rate_classrtZrate_limit_modeZrate_limit_dstZrate_limit_srcr�Z
related_rulesr�r�Zsource_address_translationZsource_portr^Ztraffic_classesZtranslate_addressZtranslate_portr�r(r;rVr)Z	snat_poolZ
vlans_settingrrWrrr�create_virtual9s
 ��������	�
���
�������








����



��


�
��



����r�c+3
Cs�id|�d|�d|�d|�d|
�d|�d|
�d|�d	|�d
|�d|�d|�d
|�d|�d|�d|�d|�||||#|%|(|)d��}+d|d�d|	d�d|d�d|"d�d|d�d|d�d|d�d�},t||�}-t|+�}.||.d<t|.|,�}.|dur{t|d�|.d<|dur�t|d�|.d<|dur�t|d�|.d<| dur�t| d�|.d<|!dur�t|!d�|.d<|$dur�|$d kr�d d d!�|.d"<n+|$d#kr�d d#d!�|.d"<n|$d$kr�d d$d!�|.d"<n|$�d%�r�|$�d&�d'}/|/d%d!�|.d"<|'dur�t|'d�|.d(<|*du�r}t|*t��r$z|*d)|.d*<|*d+�r	d,|.d-<n	|*d.�rd,|.d/<Wnit�y#d0j	|*d1�YSw|*d k�r.d |.d*<nO|*d2k�r8d2|.d*<nE|*�d+��sD|*�d.��r}z(|*�d&�d3}0|*�d&�d'�d4�|.d*<|0d.k�rbd,|.d/<n	|0d+k�rkd,|.d-<Wnt�y|d5j	|*d1�YSw|&du�r�|&d+k�r�d,|.d+<n	|&d.k�r�d,|.d.<z|-j
tj	|d6�d7|��tj
j�|.�d8�}1Wt|1�Stjj�y�}2zt||2�WYd}2~2Sd}2~2ww)9a-

    A function to connect to a bigip device and modify an existing virtual server.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the virtual to modify
    destination
        [ [virtual_address_name:port] | [ipv4:port] | [ipv6.port] ]
    pool
        [ [pool_name] | none]
    address_status
        [yes | no]
    auto_lasthop
        [default | enabled | disabled ]
    bwc_policy
        [none] | string]
    cmp_enabled
        [yes | no]
    dhcp_relay
        [yes | no}
    connection_limit
        [integer]
    description
        [string]
    state
        [disabled | enabled]
    fallback_persistence
        [none | [profile name] ]
    flow_eviction_policy
        [none | [eviction policy name] ]
    gtm_score
        [integer]
    ip_forward
        [yes | no]
    ip_protocol
        [any | protocol]
    internal
        [yes | no]
    twelve_forward
        (12-forward)
        [yes | no]
    last_hop-pool
        [ [pool_name] | none]
    mask
        { [ipv4] | [ipv6] }
    mirror
        { [disabled | enabled | none] }
    nat64
        [enabled | disabled]
    persist
        [none | profile1,profile2,profile3 ... ]
    profiles
        [none | default | profile1,profile2,profile3 ... ]
    policies
        [none | default | policy1,policy2,policy3 ... ]
    rate_class
        [name]
    rate_limit
        [integer]
    rate_limitr_mode
        [destination | object | object-destination |
        object-source | object-source-destination |
        source | source-destination]
    rate_limit_dst
        [integer]
    rate_limit_src
        [integer]
    rules
        [none | [rule_one,rule_two ...] ]
    related_rules
        [none | [rule_one,rule_two ...] ]
    reject
        [yes | no]
    source
        { [ipv4[/prefixlen]] | [ipv6[/prefixlen]] }
    source_address_translation
        [none | snat:pool_name | lsn | automap ]
    source_port
        [change | preserve | preserve-strict]
    state
        [enabled | disable]
    traffic_classes
        [none | default | class_one,class_two ... ]
    translate_address
        [enabled | disabled]
    translate_port
        [enabled | disabled]
    vlans
        [none | default | [enabled|disabled]:vlan1,vlan2,vlan3 ... ]

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_virtual bigip admin admin my-virtual source_address_translation=none
        salt '*' bigip.modify_virtual bigip admin admin my-virtual rules=my-rule,my-other-rule
    r�r�r�r�rirjr�r�r�r�r�r�r�r�r�r�rn)r�r�r�r�r�r�r�r8r�r:r�r0Nr�r�r�r�r�r�r�r-r�r�r�r�r�r@rAr�r�r�r�Tr�r�r�r�r�r�rr.r�rNr�rO)rr,r<r6rDr3r1rCrGr#rqrSrrrrTr
rHrUr%r r�rrr�modify_virtualjs���������	�
���
�������






����






�
��



����r�c
Cr�)a�
    A function to connect to a bigip device and delete a specific virtual.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    name
        The name of the virtual to delete

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_virtual bigip admin admin my-virtual
    rNr�NrvTrwr}rrr�delete_virtual�r�r�c
C�t||�}z+|r|�tj|d�dj||d��}n|�tj|d�d|���}Wt|�SWt|�StjjyI}zt||�WYd}~Sd}~ww)a 
    A function to connect to a bigip device and list an existing monitor.  If no name is provided than all
    monitors of the specified type will be listed.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    monitor_type
        The type of monitor(s) to list
    name
        The name of the monitor to list

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_monitor bigip admin admin http my-http-monitor

    rNz4/ltm/monitor/{type}/{name}?expandSubcollections=true�r7r0�
/ltm/monitor/Nrd�r$rr�monitor_typer0rVrrWrrr�list_monitor��(

�����
���r�c
Ks�t||�}i}||d<|��D]\}}	|�d�s&|dvr&|�dd�}|	||<qz|jtj|d�d|��tjj	�
|�d�}
Wt|
�Stjj
yZ}zt||�WYd	}~Sd	}~ww)
ac
    A function to connect to a bigip device and create a monitor.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    monitor_type
        The type of monitor to create
    name
        The name of the monitor to create
    kwargs
        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.create_monitor bigip admin admin http my-http-monitor timeout=10 interval=5
    r0�__)r$rrr7r�r�rNr�rON)rr'rDrFrRrSr#rrrrTr
rHrUr%r �r$rrr�r0�kwargsrVr)r�r+rrWrrr�create_monitor�s&

�����r�c
Ks�t||�}i}|��D]\}}	|�d�s"|dvr"|�dd�}|	||<qz|jtj|d�d|�d|��tjj	�
|�d�}
Wt|
�Stjj
yY}zt||�WYd	}~Sd	}~ww)
an
    A function to connect to a bigip device and modify an existing monitor.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    monitor_type
        The type of monitor to modify
    name
        The name of the monitor to modify
    kwargs
        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_monitor bigip admin admin http my-http-monitor  timout=16 interval=6

    r�)r$rrr7r0r�r�rNr��/rON)rr'rDrFrqrSr#rrrrTr
rHrUr%r r�rrr�modify_monitors(

�
�����r�c
Cr�)a�
    A function to connect to a bigip device and delete an existing monitor.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    monitor_type
        The type of monitor to delete
    name
        The name of the monitor to delete

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_monitor bigip admin admin http my-http-monitor

    rNr�r�NrvTrwr�rrr�delete_monitorI�

����r�c
Cr�)a 
    A function to connect to a bigip device and list an existing profile.  If no name is provided than all
    profiles of the specified type will be listed.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile(s) to list
    name
        The name of the profile to list

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.list_profile bigip admin admin http my-http-profile

    rNz4/ltm/profile/{type}/{name}?expandSubcollections=truer��
/ltm/profile/Nrd�r$rr�profile_typer0rVrrWrrr�list_profilerr�rc
Ks�t||�}i}||d<|��D]0\}}	|�d�s?|dvr?|�dd�}zt|	�||<Wqtjjy>dj||	d�YSwqz|j	t
j|d�d	|��tjj�
|�d
�}
Wt|
�Stjjys}zt||�WYd}~Sd}~ww)a
    A function to connect to a bigip device and create a profile.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile to create
    name
        The name of the profile to create
    kwargs
        ``[ arg=val ] ... [arg=key1:val1,key2:val2] ...``

        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    Creating Complex Args
        Profiles can get pretty complicated in terms of the amount of possible
        config options. Use the following shorthand to create complex arguments such
        as lists, dictionaries, and lists of dictionaries. An option is also
        provided to pass raw json as well.

        lists ``[i,i,i]``:
            ``param='item1,item2,item3'``

        Dictionary ``[k:v,k:v,k,v]``:
            ``param='key-1:val-1,key-2:val2,key-3:va-3'``

        List of Dictionaries ``[k:v,k:v|k:v,k:v|k:v,k:v]``:
           ``param='key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2'``

        JSON: ``'j{ ... }j'``:
           ``cert-key-chain='j{ "default": { "cert": "default.crt", "chain": "default.crt", "key": "default.key" } }j'``

        Escaping Delimiters:
            Use ``\,`` or ``\:`` or ``\|`` to escape characters which shouldn't
            be treated as delimiters i.e. ``ciphers='DEFAULT\:!SSLv3'``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http'
        salt '*' bigip.create_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http' \
            enforcement=maxHeaderCount:3200,maxRequests:10

    r0r��r$rrrr�r��=Error: Unable to Parse JSON data for parameter: {key}
{value}�r�r+rNr�rON)rr'rDrFrJrrHrIr#rRrSrrrTr
rUr%r �r$rrrr0r�rVr)r�r+rrWrrr�create_profile�s2
5
�������rc
Ks�t||�}i}||d<|��D]0\}}	|�d�s?|dvr?|�dd�}zt|	�||<Wqtjjy>dj||	d�YSwqz|j	t
j|d�d	|�d
|��tjj�
|�d�}
Wt|
�Stjjyv}zt||�WYd}~Sd}~ww)
ab
    A function to connect to a bigip device and create a profile.

    A function to connect to a bigip device and create a profile.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile to create
    name
        The name of the profile to create
    kwargs
        ``[ arg=val ] ... [arg=key1:val1,key2:val2] ...``

        Consult F5 BIGIP user guide for specific options for each monitor type.
        Typically, tmsh arg names are used.

    Creating Complex Args

        Profiles can get pretty complicated in terms of the amount of possible
        config options. Use the following shorthand to create complex arguments such
        as lists, dictionaries, and lists of dictionaries. An option is also
        provided to pass raw json as well.

        lists ``[i,i,i]``:
            ``param='item1,item2,item3'``

        Dictionary ``[k:v,k:v,k,v]``:
            ``param='key-1:val-1,key-2:val2,key-3:va-3'``

        List of Dictionaries ``[k:v,k:v|k:v,k:v|k:v,k:v]``:
           ``param='key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2|key-1:val-1,key-2:val-2'``

        JSON: ``'j{ ... }j'``:
           ``cert-key-chain='j{ "default": { "cert": "default.crt", "chain": "default.crt", "key": "default.key" } }j'``

        Escaping Delimiters:
            Use ``\,`` or ``\:`` or ``\|`` to escape characters which shouldn't
            be treated as delimiters i.e. ``ciphers='DEFAULT\:!SSLv3'``

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.modify_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http'

        salt '*' bigip.modify_profile bigip admin admin http my-http-profile defaultsFrom='/Common/http' \
            enforcement=maxHeaderCount:3200,maxRequests:10

        salt '*' bigip.modify_profile bigip admin admin client-ssl my-client-ssl-1 retainCertificate=false \
            ciphers='DEFAULT\:!SSLv3'
            cert_key_chain='j{ "default": { "cert": "default.crt", "chain": "default.crt", "key": "default.key" } }j'
    r0r�rr�r�rrrNr�r�rON)rr'rDrFrJrrHrIr#rqrSrrrTr
rUr%r rrrr�modify_profile�s6
<
���
�����rc
Cr�)a�
    A function to connect to a bigip device and delete an existing profile.

    hostname
        The host/address of the bigip device
    username
        The iControl REST username
    password
        The iControl REST password
    profile_type
        The type of profile to delete
    name
        The name of the profile to delete

    CLI Example:

    .. code-block:: bash

        salt '*' bigip.delete_profile bigip admin admin http my-http-profile

    rNr�r�NrvTrwr�rrr�delete_profileX	r�r)N)NN)
NNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNNNNN)NNNNNNNNNNNN)&NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN)'NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN).�__doc__Zsalt.exceptionsrZsalt.utils.jsonr
Zrequests.exceptionsr�ImportErrorrrrSrr r%r,r6r<rJrXr]r_rarfrhrurxr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr�<module>s��
 <5.0
,
,2
�
W
(.
�(
�%E>
�b
'/
�8
�*
�445.
�4U]