
    Vh9                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ g dZg dZg d	Zd
dgZ G d de      Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionu
  
---
module: flowadm
deprecated:
  removed_in: 6.0.0
  why: This collection and all content in it is unmaintained and deprecated.
  alternative: Unknown.
short_description: Manage bandwidth resource control and priority for protocols, services and zones on Solaris/illumos systems
description:
    - Create/modify/remove networking bandwidth and associated resources for a type of traffic on a particular link.
author: Adam Števko (@xen0l)
options:
    name:
        description: >
            - A flow is defined as a set of attributes based on Layer 3 and Layer 4
            headers, which can be used to identify a protocol, service, or a zone.
        required: true
        aliases: [ 'flow' ]
    link:
        description:
            - Specifiies a link to configure flow on.
        required: false
    local_ip:
        description:
            - Identifies a network flow by the local IP address.
        required: false
    remote_ip:
        description:
            - Identifies a network flow by the remote IP address.
        required: false
    transport:
        description: >
            - Specifies a Layer 4 protocol to be used. It is typically used in combination with I(local_port) to
            identify the service that needs special attention.
        required: false
    local_port:
        description:
            - Identifies a service specified by the local port.
        required: false
    dsfield:
        description: >
            - Identifies the 8-bit differentiated services field (as defined in
            RFC 2474). The optional dsfield_mask is used to state the bits of interest in
            the differentiated services field when comparing with the dsfield
            value. Both values must be in hexadecimal.
        required: false
    maxbw:
        description: >
            - Sets the full duplex bandwidth for the flow. The bandwidth is
            specified as an integer with one of the scale suffixes(K, M, or G
            for Kbps, Mbps, and Gbps). If no units are specified, the input
            value will be read as Mbps.
        required: false
    priority:
        description:
            - Sets the relative priority for the flow.
        required: false
        default: 'medium'
        choices: [ 'low', 'medium', 'high' ]
    temporary:
        description:
            - Specifies that the configured flow is temporary. Temporary
              flows do not persist across reboots.
        required: false
        default: false
        type: bool
    state:
        description:
            - Create/delete/enable/disable an IP address on the network interface.
        required: false
        default: present
        choices: [ 'absent', 'present', 'resetted' ]
a(  
- name: Limit SSH traffic to 100M via vnic0 interface
  community.network.flowadm:
    link: vnic0
    flow: ssh_out
    transport: tcp
    local_port: 22
    maxbw: 100M
    state: present

- name: Reset flow properties
  community.network.flowadm:
    name: dns
    state: resetted

- name: Configure policy for EF PHB (DSCP value of 101110 from RFC 2598) with a bandwidth of 500 Mbps and a high priority
  community.network.flowadm:
    link: bge0
    dsfield: '0x2e:0xfc'
    maxbw: 500M
    priority: high
    flow: efphb-flow
    state: present
a  
name:
    description: flow name
    returned: always
    type: str
    sample: "http_drop"
link:
    description: flow's link
    returned: if link is defined
    type: str
    sample: "vnic0"
state:
    description: state of the target
    returned: always
    type: str
    sample: "present"
temporary:
    description: flow's persistence
    returned: always
    type: bool
    sample: "True"
priority:
    description: flow's priority
    returned: if priority is defined
    type: str
    sample: "low"
transport:
    description: flow's transport
    returned: if transport is defined
    type: str
    sample: "tcp"
maxbw:
    description: flow's maximum bandwidth
    returned: if maxbw is defined
    type: str
    sample: "100M"
local_Ip:
    description: flow's local IP address
    returned: if local_ip is defined
    type: str
    sample: "10.0.0.42"
local_port:
    description: flow's local port
    returned: if local_port is defined
    type: int
    sample: 1337
remote_Ip:
    description: flow's remote IP address
    returned: if remote_ip is defined
    type: str
    sample: "10.0.0.42"
dsfield:
    description: flow's differentiated services value
    returned: if dsfield is defined
    type: str
    sample: "0x2e:0xfc"
N)AnsibleModule)tcpudpsctpicmpicmpv6)lowmediumhigh)local_ip	remote_ip	transport
local_portdsfieldmaxbwpriorityc                   v    e Zd Zd Zed        Zed        Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zy)Flowc                    || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _	        |j                  d	   | _
        |j                  d
   | _        |j                  d   | _        ddd| _        y )Nnamelinkr   r   r   r   r   r   r   	temporarystateF)r   r   )moduleparamsr   r   r   r   r   r   r   r   r   r   r   _needs_updating)selfr   s     m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/network/plugins/modules/flowadm.py__init__zFlow.__init__   s    MM&)	MM&)	j1{3{3 --5}}Y/]]7+
j1{3]]7+
  
    c                 4    dt        |      cxk  xr dk  S c S )N   i  )int)clsports     r!   is_valid_portzFlow.is_valid_port   s    CI&&&&&r#   c                    |j                  d      dk(  r|j                  d      \  }}n|}t        |j                  d            dk(  r4	 t        j                  t        j
                  |       dcxk  rdk  sy yy		 t        j                  t        j                  |       dcxk  rdk  sy yy	# t        j                  $ r Y yw xY w# t        j                  $ r Y yw xY w)
N/r%   .   Fr          T)countsplitlensocket	inet_ptonAF_INETerrorAF_INET6)r'   ip
ip_addressnetmasks       r!   is_valid_addresszFlow.is_valid_address   s     88C=A"$((3-JJz$%*  < %2% &   *= &3& ' <<  << s$   
$B1 >$C
 1CC
C C c                 <    	 t        |d       y# t        $ r Y yw xY w)N   FT)r&   
ValueError)r'   numbers     r!   is_hexzFlow.is_hex   s)    	O   		s    	c                    d }|j                  d      dk(  r|j                  d      d   }n|j                  d      \  }}|r/dt        |d      cxk  rdk  sn dt        |d      cxk  rdk  sy ydt        |d      cxk  rdk  sy yy)N:r%   r   r=      FT)r0   r1   r&   )r'   r   dsmaskdsvals       r!   is_valid_dsfieldzFlow.is_valid_dsfield   s     =="MM#&q)E#MM#.ME6$#fb/9T9$#eUW.B`\`B` CaUB/4/ 0r#   c                     | j                   j                  d      g}|j                  d       |j                  | j                         | j                   j	                  |      \  }}}|dk(  ryy)Nflowadmz	show-flowr   TFr   get_bin_pathappendr   run_command)r    cmdrcdummys       r!   flow_existszFlow.flow_exists  s]    {{''	23

;

499![[44S9UE7r#   c                    | j                   j                  d      g}|j                  d       | j                  r|j                  d       |j                  | j                         | j                   j                  |      S )NrH   zremove-flow-t)r   rJ   rK   r   r   rL   r    rM   s     r!   delete_flowzFlow.delete_flow  s]    {{''	23

=!>>JJt

499{{&&s++r#   c                    | j                   j                  d      g}|j                  d       |j                  d       |j                  | j                         | j                  r/|j                  d       |j                  d| j                  z          | j
                  r/|j                  d       |j                  d| j
                  z          | j                  r/|j                  d       |j                  d| j                  z          | j                  r/|j                  d       |j                  d| j                  z          | j                  r/|j                  d       |j                  d	| j                  z          | j                  r/|j                  d
       |j                  d| j                  z          | j                  r/|j                  d
       |j                  d| j                  z          | j                  r|j                  d       |j                  | j                         | j                   j                  |      S )NrH   zadd-flowz-lz-az	local_ip=z
remote_ip=z
transport=zlocal_port=zdsfield=-pmaxbw=	priority=rR   )r   rJ   rK   r   r   r   r   r   r   r   r   r   r   rL   rS   s     r!   create_flowzFlow.create_flow  s   {{''	23

:

4

499==JJtJJ{T]]23>>JJtJJ|dnn45>>JJtJJ|dnn45??JJtJJ}t67<<JJtJJzDLL01::JJtJJx$**,-==JJtJJ{T]]23>>JJt

499{{&&s++r#   c                 .   | j                   j                  d      g}|j                  d       |j                  d       |j                  d       |j                  d       |j                  | j                         | j                   j	                  |      S )NrH   zshow-flowpropz-cz-ozproperty,possiblerI   rS   s     r!   _query_flow_propszFlow._query_flow_propsD  so    {{''	23

?#

4

4

&'

499{{&&s++r#   c                    | j                         \  }}}d}|dk(  rd |j                         j                  d      D        }|D ]n  \  }}|dk(  r/| j                  |k7  r | j                  j                  |di       d}:|dk(  s@| j                  |k7  sP| j                  j                  |di       d}p |S | j                  j                  d|z  ||	       y )
NFr   c              3   >   K   | ]  }|j                  d         yw)rB   N)r1   ).0lines     r!   	<genexpr>z+Flow.flow_needs_udpating.<locals>.<genexpr>U  s     Od$**S/Os   
r   Tr   z(Error while checking flow properties: %s)msgstderrrN   )	r[   rstripr1   r   r   updater   r   	fail_json)r    rN   outerrNEEDS_UPDATING
propertiespropvalues           r!   flow_needs_udpatingzFlow.flow_needs_udpatingO  s    //1S#7Ocjjl6H6H6NOJ) *e7?tzzU':((//t=%)NZ'DMMU,B((//t=%)N* "!KK!!&PSV&V),%' " )r#   c                 *   | j                   j                  d      g}|j                  d       | j                  r>| j                  d   r/|j                  d       |j                  d| j                  z          | j
                  r>| j                  d   r/|j                  d       |j                  d| j
                  z          | j                  r|j                  d       |j                  | j                         | j                   j                  |      S )	NrH   zset-flowpropr   rV   rW   r   rX   rR   )	r   rJ   rK   r   r   r   r   r   rL   rS   s     r!   update_flowzFlow.update_flowe  s    {{''	23

>"::$..w7JJtJJx$**,-==T11*=JJtJJ{T]]23>>JJt

499{{&&s++r#   N)__name__
__module____qualname__r"   classmethodr)   r;   r@   rF   rP   rT   rY   r[   rm   ro    r#   r!   r   r      sv    
( ' '  4     ,',R	,),,r#   r   c                     t        t        t        ddg      t        d      t        d      t        d      t        dt              t        d      t        d      t        d      t        ddt              t        dd	
      t        ddg d            g dd      } t	        |       }d }d}d}i }|j
                  |d<   |j                  |d<   |j                  |d<   |j                  r|j                  |d<   |j                  r|j                  |d<   |j                  r|j                  |d<   |j                  r*|j                  |j                        r|j                  |d<   |j                  r*|j                  |j                        r|j                  |d<   |j                  r|j                  |d<   |j                  rK|j!                  |j                        r|j                  |d<   n | j#                  d|j                  z  d       |j$                  rK|j'                  |j$                        r|j$                  |d<   n | j#                  d|j$                  z  d       |j                  d k(  rm|j)                         r| j*                  r| j-                  d!       |j/                         \  }}}|d"k7  ra| j#                  d#|z  |j
                  ||$       n=|j                  dk(  r|j)                         sZ| j*                  r| j-                  d!       |j1                         \  }}}|d"k7  r| j#                  d%|z  |j
                  ||$       n|j3                         r|j5                         \  }}}|d"k7  r| j#                  d&|z  |j
                  ||$       nx|j                  d'k(  ri|j)                         rY| j*                  r| j-                  d!       |j7                         \  }}}|d"k7  r"| j#                  d(|z  |j
                  ||$       |d|d)<   nd|d)<   |r||d*<   |r||d+<    | j,                  d,i | y )-NTflow)requiredaliasesF)rw   )rw   choicesr   )rw   defaultry   bool)rz   typepresent)absentr}   resetted)r   r   r   r   r   r   r   r   r   r   r   )	)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )argument_specmutually_exclusivesupports_check_mode r   r   r   r   r   r   r   r   r   r   zInvalid port: %sr%   )rb   rN   r   zInvalid dsfield: %sr~   )changedr   zError while deleting flow: "%s")rb   r   rc   rN   zError while creating flow: "%s"zError while updating flow: "%s"r   z Error while resetting flow: "%s"r   stdoutrc   rt   )r   dictSUPPORTED_TRANSPORTSSUPPORTED_PRIORITIESr   r   r   r   r   r   r   r   r;   r   r   r   r)   rf   r   rF   rP   
check_mode	exit_jsonrT   rY   rm   ro   
reset_flow)r   rv   rN   rg   rh   results         r!   mainr   y  s
   tfX6u%5)E*E3GHU+%(&5"*"68 5v6(@B
"

 !;F@ <D	B
C
CFYYF6NjjF7O..F;yyvzz**w}}!]]z}}  /!%F:~~  0"&..F;~~"nn{doo.#'??F< !3doo!E !  # ||  . $F9!6!E !  # zzX     .!--/NRcQw  %F%L&*ii(+$& ! (
 
y	 !     .!--/NRcQw  %F%L&*ii(+$& ! (
 '')!%!1!1!3S#7$$)JS)P*.)),/(* % ,
 
z	!     .!__.NRcQw  %G#%M&*ii(+$& ! (
 
z!y y
x
xFvr#   __main__)
__future__r   r   r   r|   __metaclass__DOCUMENTATIONEXAMPLESRETURNr3   ansible.module_utils.basicr   r   r   SUPPORTED_ATTRIBUTESSUPPORTPED_PROPERTIESobjectr   r   rp   rt   r#   r!   <module>r      s}    A @HT28
v  4 @ 0 V  *- A,6 A,HCL zF r#   