
    Vhl/                         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 d dlmZ d dlmZmZ dad	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: eos_system
author: Peter Sprygada (@privateip)
short_description: Manage the system attributes on Arista EOS devices
description:
- This module provides declarative management of node system attributes on Arista
  EOS devices.  It provides an option to configure host system parameters or remove
  those parameters from the device active configuration.
version_added: 1.0.0
notes:
- Tested against Arista EOS 4.24.6F
options:
  hostname:
    description:
    - Configure the device hostname parameter. This option takes an ASCII string value.
    type: str
  domain_name:
    description:
    - Configure the IP domain name on the remote device to the provided value. Value
      should be in the dotted name form and will be appended to the C(hostname) to
      create a fully-qualified domain name.
    type: str
  domain_list:
    description:
    - Provides the list of domain suffixes to append to the hostname for the purpose
      of doing name resolution. This argument accepts a list of names and will be
      reconciled with the current active configuration on the running node.
    aliases:
    - domain_search
    type: list
    elements: str
  lookup_source:
    description:
    - Provides one or more source interfaces to use for performing DNS lookups.  The
      interface provided in C(lookup_source) can only exist in a single VRF.  This
      argument accepts either a list of interface names or a list of hashes that configure
      the interface name and VRF name.  See examples.
    elements: raw
    type: list
  name_servers:
    description:
    - List of DNS name servers by IP address to use to perform name resolution lookups.  This
      argument accepts either a list of DNS servers or a list of hashes that configure
      the name server and VRF name.  See examples.
    type: list
    elements: raw
  state:
    description:
    - State of the configuration values in the device's current active configuration.  When
      set to I(present), the values should be configured in the device active configuration
      and when set to I(absent) the values should not be in the device active configuration
    default: present
    type: str
    choices:
    - present
    - absent
a  
- name: configure hostname and domain-name
  arista.eos.eos_system:
    hostname: eos01
    domain_name: test.example.com

- name: remove configuration
  arista.eos.eos_system:
    state: absent

- name: configure DNS lookup sources
  arista.eos.eos_system:
    lookup_source: Management1

- name: configure DNS lookup sources with VRF support
  arista.eos.eos_system:
    lookup_source:
      - interface: Management1
        vrf: mgmt
      - interface: Ethernet1
        vrf: myvrf

- name: configure name servers
  arista.eos.eos_system:
    name_servers:
      - 8.8.8.8
      - 8.8.4.4

- name: configure name servers with VRF support
  arista.eos.eos_system:
    name_servers:
      - {server: 8.8.8.8, vrf: mgmt}
      - {server: 8.8.4.4, vrf: mgmt}
aN  
commands:
  description: The list of configuration mode commands to send to the device
  returned: always
  type: list
  sample:
    - hostname eos01
    - dns domain test.example.com
session_name:
  description: The EOS config session name used to load the configuration
  returned: changed
  type: str
  sample: ansible_1479315771
N)AnsibleModule)ComplexList)
get_configload_configc                     t         |t         v S t        |       }t        j                  d|      a t         j	                  d       |t         v S )Nzvrf instance (\S+)default)_CONFIGURED_VRFSr   refindallappend)modulevrfconfigs      i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/arista/eos/plugins/modules/eos_system.pyhas_vrfr      sJ    #&&&Fzz"7@I&"""    c                     t               }|j                  d   } fd}|dk(  r/d   r|j                  d       d   dk7  r|j                  d       |d	k(  r |d      r|j                  d
 d   z          |d      r|j                  d d   z          d   rrt        d         j	                   d         D ]  }|j                  d|z          t         d         j	                  d         D ]  }|j                  d|z           d   rd   D ]l  }| d   vs|d   rFt        ||d         s|j                  d|d   z         |d   |d   f}|j                  d|z         V|j                  d|d   z         n  d   D ]l  }|d   vs|d   rFt        ||d         s|j                  d|d   z         |d   |d   f}|j                  d|z         V|j                  d|d   z         n  d   rd   D ]n  }| d   vst        ||d         s|j                  d|d   z         |d   dvr|d   |d   f}|j                  d|z         X|j                  d|d   z         p  d   D ]n  }|d   vst        ||d         s|j                  d|d   z         |d   dvr|d   |d   f}|j                  d|z         X|j                  d|d   z         p |S )Nstatec                 p    j                  |       xr# j                  |       j                  |       k7  S )N)get)xhavewants    r   needs_updatez)map_obj_to_commands.<locals>.needs_update   s+    xx{;txx{ :;r   absentdomain_namezno dns domainhostname	localhostzno hostnamepresentzhostname %szdns domain %sdomain_listzno ip domain-list %szip domain-list %slookup_sourcer   zvrf %s is not configured)msg	interfacez.no ip domain lookup vrf %s source-interface %sz'no ip domain lookup source-interface %sz+ip domain lookup vrf %s source-interface %sz$ip domain lookup source-interface %sname_servers)r   Nserverzno ip name-server vrf %s %szno ip name-server %szip name-server vrf %s %szip name-server %s)listparamsr   set
differencer   	fail_json)r   r   r   commandsr   r   itemvaluess   ``      r   map_obj_to_commandsr1      s   vHMM'"E< OOO,
{*OOM*	
#OOMD,<<=&OOOd=.AABD/0;;]# ?  6 =>? D/0;;]# <  3d :;<
  _- tO44E{&vtE{;",,$>e$L -  #'u+tK/@!A LvU !E[HYY" _- tO44E{&vtE{;",,$>e$L -  #'u+tK/@!A IFR !BT+EVV   ^, tN33"64;7(( :T%[ H )  E{*;;"&u+tH~!> (E(NO 2T(^C ^, 
NtN33"64;7(( :T%[ H )  E{*;;"&u+tH~!> (BV(KL (;d8n(LM
N Or   c                 t    t        j                  d| t         j                        }|r|j                  d      S y )Nz^hostname (\S+)   r   searchMgroupr   matchs     r   parse_hostnamer:     s/    II(&"$$7E{{1~ r   c                 t    t        j                  d| t         j                        }|r|j                  d      S y )Nz^dns domain (\S+)r3   r4   r8   s     r   parse_domain_namer<   	  s/    II*FBDD9E{{1~ r   c                     t               }d}t        j                  || t        j                        D ])  \  }}t	        |      dk(  rd }|j                  ||d       + |S )Nz6ip domain lookup (?:vrf (\S+) )*source-interface (\S+)r   r&   r   )r)   r   r   r6   lenr   )r   objectsregexr   intfs        r   parse_lookup_sourcerC     sZ    fGEEZZvrtt4 8	Ts8q=CT#678 Nr   c                     t               }t        j                  d| t        j                        D ]  \  }}|j	                  ||d        |S )Nzip name-server vrf (\S+) (\S+)r(   r   )r)   r   r   r6   r   )r   r@   r   addrs       r   parse_name_serversrG     sL    fGZZ)
 5	T
 	$s345 Nr   c                     t        |       }t        |      t        |      t        j                  d|t        j
                        t        |      t        |      dS )Nz^ip domain-list (\S+))r    r   r#   r$   r'   )r   r:   r<   r   r   r6   rC   rG   )r   r   s     r   map_config_to_objrI   $  sK    F"6*(0zz":FBDDI,V4*62 r   c                    | j                   d   | j                   d   | j                   d   d}t        t        t        d      t                     |       }t        t        t        d      t        d	      
      |       }d|fd|ffD ]2  \  }}| j                   |    || j                   |         ||<   .d ||<   4 |S )Nr    r   r#   )r    r   r#   T)keyr>   r   )r   rE   r$   r'   )r*   r   dict)r   objr$   r'   argcasts         r   map_params_to_objrP   /  s    MM*-}}]3}}]3C  t~462M
 DTNY(?@L 
-(	& 	T ==)FMM#./CHCH Jr   c                     t        t               t               t        ddgd      t        dd      t        dd      t        dddg	      
      } t        | d      }ddi}t        |      }t        |      }t	        |||      }||d<   |rg|j
                   }t        |||      }|j                  d      r"|j                  rd|j                  d      i|d<   |j                  d      |d<   d|d<    |j                  di | y)z%main entry point for module executionr)   domain_searchstr)typealiaseselementsraw)rT   rV   r"   r   )r   choices)r    r   r#   r$   r'   r   T)argument_specsupports_check_modechangedFr.   )commitdiffpreparedsessionsession_nameN )
rL   r   rP   rI   r1   
check_moder	   r   _diff	exit_json)rY   r   resultr   r   r.   r\   responses           r   mainrg   L  s   F$%
 7v69y(.CDM # F
 FV$DV$D"4v6H!F:&&&vx?<<FLL((,,v*>?F6N!)i!8~ yFvr   __main__)
__future__r   r   r   rT   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   ansible.module_utils.basicr   Oansible_collections.ansible.netcommon.plugins.module_utils.network.common.utilsr   Cansible_collections.arista.eos.plugins.module_utils.network.eos.eosr   r	   r   r   r1   r:   r<   rC   rG   rI   rP   rg   __name__ra   r   r   <module>rr      s   $ A @ 8t!F
 
 4  #cL:&R zF r   