�
�Udac @` s� d Z d d l m Z m Z m Z e Z d d l m Z d d l m
Z
d d l m Z d d l
m Z m Z d d l
m Z m Z d d l
m Z m Z d e f d
� � YZ d S( s�
The iosxr_interfaces class
It is in this file where the current configuration (as dict)
is compared to the provided configuration (as dict) and the command set
necessary to bring the current configuration to it's desired end-state is
created
i ( t absolute_importt divisiont print_function( t
ConfigBase( t to_list( t Facts( t get_interface_typet dict_to_set( t remove_command_from_config_listt add_command_to_config_list( t filter_dict_having_none_valuet remove_duplicate_interfacet
Interfacesc B` s� e Z d Z d d g Z d g Z d Z d � Z d � Z d
� Z d � Z d � Z
d
� Z d � Z d � Z
d � Z d � Z d � Z RS( s$
The iosxr_interfaces class
s !alls !mint
interfacest descriptiont mtut speedt duplexc C` s t t | � j | � d S( N( t superR t __init__( t selft module( ( sc /usr/lib/python2.7/site-packages/ansible/module_utils/network/iosxr/config/interfaces/interfaces.pyR ( s c C` sH t | j � j | j | j � \ } } | d j d � } | sD g S| S( s� Get the 'facts' (the current configuration)
:rtype: A dictionary
:returns: The current configuration as a dictionary
t ansible_network_resourcesR
( R t _modulet get_factst
gather_subsett gather_network_resourcest get( R t factst _warningst interfaces_facts( ( sc /usr/lib/python2.7/site-packages/ansible/module_utils/network/iosxr/config/interfaces/interfaces.pyt get_interfaces_facts+ s
'c C` s� i t d 6} t � } t � } | j � } | j | j | � � | rs | j j sf | j j | � n t | d <n | | d <| j � } | | d <| d r� | | d <n | | d <| S( sl Execute the module
:rtype: A dictionary
:returns: The result from module execution
t changedt commandst beforet aftert warnings(
t Falset listR t extendt
set_configR t
check_modet _connectiont edit_configt True( R t resultR! R$ t existing_interfaces_factst changed_interfaces_facts( ( sc /usr/lib/python2.7/site-packages/ansible/module_utils/network/iosxr/config/interfaces/interfaces.pyt execute_module6 s
c C` s2 | j j d } | } | j | | � } t | � S( s Collect the configuration from the args passed to the module,
collect the current configuration (as a dict from facts)
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
t config( R t paramst set_stateR ( R R. t wantt havet resp( ( sc /usr/lib/python2.7/site-packages/ansible/module_utils/network/iosxr/config/interfaces/interfaces.pyR( P s c C` s� g } | j j d } | d k rH | rH | j j d d j | � � n | d k ri | j | | � } nc | d k r� | j | | � } nB | d k r� | j | | � } n! | d k r� | j | | � } n | S( sW Select the appropriate function based on the state provided
:param want: the desired configuration as a dictionary
:param have: the current configuration as a dictionary
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
t statet
overriddent mergedt replacedt msgs9 value of config parameter must not be empty for state {0}t deleted( R8 R9 R: ( R R2 t fail_jsont formatt _state_overriddent _state_deletedt
_state_mergedt _state_replaced( R R4 R5 R! R7 ( ( sc /usr/lib/python2.7/site-packages/ansible/module_utils/network/iosxr/config/interfaces/interfaces.pyR3 ] s c C` s� g } x� | D]� } xA | D]6 } | d | d k r8 Pq | d | d k r Pq q Wq
t | | � } t � } | j | j | | � � | j | j | | � � q
Wt | � } | S( s� The command generator when state is replaced
:rtype: A list
:returns: the commands necessary to migrate the current configuration
to the desired configuration
t name( R
t dictR'