
    Vh                         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 d dlmZ d dlmZ d d	lmZmZmZmZmZ  e       Zd
 Z G d de      Zy)    )absolute_importdivisionprint_functionaV  
deprecated:
  removed_in: 6.0.0
  why: This collection and all content in it is unmaintained and deprecated.
  alternative: Unknown.
name: avi
author: Sandeep Bandi (@sabandi) <sandeepb@avinetworks.com>
short_description: Look up ``Avi`` objects.
description:
    - Given an object_type, fetch all the objects of that type or fetch
      the specific object that matches the name/uuid given via options.
    - For single object lookup. If you want the output to be a list, you may
      want to pass option wantlist=True to the plugin.

options:
    obj_type:
        description:
            - type of object to query
        required: true
    obj_name:
        description:
            - name of the object to query
    obj_uuid:
        description:
            - UUID of the object to query
extends_documentation_fragment:
- community.network.avi

a  
# Lookup query for all the objects of a specific type.
- ansible.builtin.debug: msg="{{ lookup('community.network.avi', avi_credentials=avi_credentials, obj_type='virtualservice') }}"
# Lookup query for an object with the given name and type.
- ansible.builtin.debug: msg="{{ lookup('community.network.avi', avi_credentials=avi_credentials, obj_name='vs1', obj_type='virtualservice', wantlist=True) }}"
# Lookup query for an object with the given UUID and type.
- ansible.builtin.debug: msg="{{ lookup('community.network.avi', obj_uuid='virtualservice-5c0e183a-690a-45d8-8d6f-88c30a52550d', obj_type='virtualservice') }}"
# We can replace lookup with query function to always the get the output as list.
# This is helpful for looping.
- ansible.builtin.debug: msg="{{ query('community.network.avi', obj_uuid='virtualservice-5c0e183a-690a-45d8-8d6f-88c30a52550d', obj_type='virtualservice') }}"
z
 _raw:
     description:
         - One ore more objects returned from ``Avi`` API.
     type: list
     elements: dictionary
)	to_native)AnsibleErrorAnsibleParserError)
LookupBase)Display)
ApiSessionAviCredentialsAviServerErrorObjectNotFoundAPIErrorc                    g }	  | j                   |fi |j                         }d|v r|d   }|S |j                  |       	 |S # t        $ r>}t        j                  d       t        j                  t        |             Y d}~|S d}~wt        t        f$ r}t        t        |            d}~wt        $ r}t        dt        |      z        d}~ww xY w)zl
    Generic function to handle both /<obj_type>/<obj_uuid> and /<obj_type>
    API resource endpoints.
    resultszRResource not found. Please check obj_name/obj_uuid/obj_type are spelled correctly.Nz5Unable to communicate with controllerdue to error: %s)getjsonappendr   displaywarningvr   r   r   r   	Exception)avi_sessionpathkwargsrsprsp_dataes         h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/network/plugins/lookup/avi.py_apir    F   s    
 C>";??4262779 9%C J JJx  J    C 	D		)A, J H% )9Q<(( > .09!= > 	>>s4   *A A 	C3BCB,,C8CCc                       e Zd ZddZy)LookupModuleNc                    t        d
i |}	 t        |      }g }	 |j                  d      }	|j                  dd       rV|j                  d      }
	 t        j                  d|
d|	        |j                  |	|
fi |}|r|j                  |       |S |j                  dd       rB|j                  d      }|	d|}t        j                  d|d|	       t        ||fi |}|S t        j                  d	|	z         t        ||	fi |}|S # t        $ r}t        t	        |            d }~ww xY w# t        $ r t        d      w xY w# t        $ r}t        t	        |            d }~ww xY w)N)avi_credentialsobj_typez#Please pass the obj_type for lookupobj_namezFetching obj: z
 of type: obj_uuid/z Fetching all objects of type: %s )r   r   r   r   r   popKeyErrorr   r   r   get_object_by_namer   r   r    )selfterms	variablesr$   r   	api_credsavir   r   r   namer   r'   obj_paths                 r   runzLookupModule.runa   sx   "5_5		-Y7C
 	F::j)D ::j$'::j)D1		D$GH1311$GG JJx( 
 ZZ
D)zz*-H"&1HII$GHsH//C
 
 II84?@sD+F+C
=  	-y|,,	-  	FDEE	F " 1"9Q<001s;   D D5 AE 	D2D--D25E
	E/E**E/)NN)__name__
__module____qualname__r4   r)       r   r"   r"   `   s    $r8   r"   N)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils._textr   ansible.errorsr   r   ansible.plugins.lookupr	   ansible.utils.displayr
   Nansible_collections.community.network.plugins.module_utils.network.avi.avi_apir   r   r   r   r   r   r    r"   r)   r8   r   <module>rD      s\    C B<

 1 ; - )f f )4%: %r8   