
    Vh                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
---
module: edit_ipv4
version_added: "1.0.0"
author:
    - WangBaoshan (@ieisystem)
short_description: Set ipv4 information
description:
   - Set ipv4 information on kaytus Server.
notes:
   - Does not support C(check_mode).
options:
    interface_name:
        description:
            - Set interface name. Select the LAN interface to be configured.
        choices: ['eth0', 'eth1', 'bond0']
        required: true
        type: str
    ipv4_status:
        description:
            - Enable or disable IPV4.
        choices: ['enable', 'disable']
        type: str
    ipv4_dhcp_enable:
        description:
            - Enable 'Enable DHCP' to dynamically configure IPv4 address using Dynamic Host Configuration Protocol (DHCP).
        choices: ['dhcp', 'static']
        type: str
    ipv4_address:
        description:
            - If DHCP is disabled, specify a static IPv4 address to be configured for the selected interface.
            - Required when I(ipv4_dhcp_enable=static).
        type: str
    ipv4_subnet:
        description:
            - If DHCP is disabled, specify a static Subnet Mask to be configured for the selected interface.
            - Required when I(ipv4_dhcp_enable=static).
        type: str
    ipv4_gateway:
        description:
            - If DHCP is disabled, specify a static Default Gateway to be configured for the selected interface.
            - Required when I(ipv4_dhcp_enable=static).
        type: str
extends_documentation_fragment:
    - kaytus.ksmanage.ksmanage
aN  
- name: Ipv4 test
  hosts: ksmanage
  connection: local
  gather_facts: false
  vars:
    ksmanage:
      host: "{{ ansible_ssh_host }}"
      username: "{{ username }}"
      password: "{{ password }}"

  tasks:

  - name: "Set ipv4 information"
    kaytus.ksmanage.edit_ipv4:
      interface_name: "eth0"
      ipv4_status: "disable"
      provider: "{{ ksmanage }}"

  - name: "Set ipv4 information"
    kaytus.ksmanage.edit_ipv4:
      interface_name: "eth0"
      ipv4_status: "enable"
      ipv4_dhcp_enable: "dhcp"
      provider: "{{ ksmanage }}"

  - name: "Set ipv4 information"
    kaytus.ksmanage.edit_ipv4:
      interface_name: "eth0"
      ipv4_status: "enable"
      ipv4_dhcp_enable: "static"
      ipv4_address: "100.2.36.10"
      ipv4_subnet: "255.255.255.0"
      ipv4_gateway: "100.2.36.1"
      provider: "{{ ksmanage }}"
a1  
message:
    description: Messages returned after module execution.
    returned: always
    type: str
state:
    description: Status after module execution.
    returned: always
    type: str
changed:
    description: Check to see if a change was made on the device.
    returned: always
    type: bool
)AnsibleModule)ksmanage_argument_specget_connectionc                   *    e Zd Zd Zd Zd Zd Zd Zy)Networkc                 ^    || _         d | _        | j                          t               | _        y )N)specmoduleinit_moduledictresults)selfargument_specs     m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/kaytus/ksmanage/plugins/modules/edit_ipv4.py__init__zNetwork.__init__s   s%    !	v    c                 <    t        | j                  d      | _        y)zInit module objectF)r   supports_check_modeN)r   r   r   r   s    r   r   zNetwork.init_moduley   s     $))@r   c                     d| j                   j                  d<   t        | j                         | _        | j                  d   dk(  rd| j                  d<   y y )Nsetipv4
subcommandStateSuccessTchanged)r   paramsr   r   r   s    r   run_commandzNetwork.run_command   sJ    +4<(%dkk2<< I-&*DLL# .r   c                 P     | j                   j                  di | j                   y)zShow resultN )r   	exit_jsonr   r   s    r   show_resultzNetwork.show_result   s    --r   c                 D    | j                          | j                          y)WorkerN)r    r$   r   s    r   workzNetwork.work   s    r   N)__name__
__module____qualname__r   r   r    r$   r'   r"   r   r   r
   r
   r   s    @+.r   r
   c                     t        t        ddg d      t        ddddg      t        dddd	g      t        dd
      t        dd
      t        dd
            } | j                  t               t        |       }|j	                          y )NstrT)eth0eth1bond0)typerequiredchoicesFenabledisabledhcpstatic)r0   r1   )interface_nameipv4_statusipv4_dhcp_enableipv4_addressipv4_subnetipv4_gateway)r   updater   r
   r'   )r   net_objs     r   mainr?      s}    ?XYeeh	=RS5568BTUuu5ee4uu5M /0m$GLLNr   __main__N)
__future__r   r   r   r0   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Aansible_collections.kaytus.ksmanage.plugins.module_utils.ksmanager   r   objectr
   r?   r(   r"   r   r   <module>rI      sW    C B-^#J
 5 vf : zF r   