
    Vh                         d dl mZmZmZ eZdZdZd dlm	Z	m
Z
 d dlmZ d dlmZ 	 d dlZdZg dZ G d	 d
e	e
      Zy# e$ rZeZY dZ[dZ[ww xY w)    )absolute_importdivisionprint_functionai  
name: libvirt
extends_documentation_fragment:
    - constructed
    - community.libvirt.requirements
short_description: Libvirt inventory source
description:
    - Get libvirt guests in an inventory source.
author:
    - Dave Olsthoorn (@daveol) <dave@bewaar.me>
version_added: "2.10.0"
options:
    plugin:
        description: Token that ensures this is a source file for the 'libvirt' plugin.
        required: True
        choices: ['libvirt', 'community.libvirt.libvirt']
    uri:
        description: Libvirt Connection URI
        required: True
        type: str
    inventory_hostname:
        description: |
            What to register as the inventory hostname.
            If set to 'uuid' the uuid of the server will be used and a
            group will be created for the server name.
            If set to 'name' the name of the server will be used unless
            there are more than one server with the same name in which
            case the 'uuid' logic will be used.
            Default is to do 'name'.
        type: string
        choices:
            - name
            - uuid
        default: "name"
z
# Connect to lxc host
plugin: community.libvirt.libvirt
uri: 'lxc:///'

# Connect to qemu
plugin: community.libvirt.libvirt
uri: 'qemu:///system'
)BaseInventoryPluginConstructable)AnsibleError)
raise_fromN)	nostaterunningblockedpausedshutdownshutoffcrashedpmsuspendedlastc                   $     e Zd ZdZd fd	Z xZS )InventoryModulezcommunity.libvirt.libvirtc           	      >	   t         rt        t        d      t                t        t        |   ||||       | j                  |      }| j                  |       | j                  d      }|st        d      t        j                  |      }|st        d      t        ddd      j                  |j                               }|j                         D ]  }	t        |	j                         |	j!                         d	      j                  | j                  d
            }
t        |	j                         |	j!                         d      j                  | j                  d
            }| j"                  j%                  |
       | j"                  j'                  |       | j"                  j)                  ||
       |:| j"                  j+                  |
d|       | j"                  j+                  |
d|       	 |j-                  |	j                               }|j/                         \  }}}}}|t0        |   ||||d}| j"                  j+                  |
d|       | j"                  j+                  |
d|j3                                d}	 |j5                  d      }| j"                  j+                  |
d|       d}	 |j;                  t        j<                        }| j"                  j+                  |
d|       | j"                  j>                  |
   jA                         }| jC                  | j                  d      ||
| j                  d             | jE                  | j                  d      ||
| j                  d             | jG                  | j                  d      ||
| j                  d              y # t        j6                  $ r}dt9        |      i}Y d }~Dd }~ww xY w# | j"                  j+                  |
d|       w xY w# t        j6                  $ r}dt9        |      i}Y d }~Td }~ww xY w# | j"                  j+                  |
d|       w xY w# t        j6                  $ r1}| j"                  j+                  |
dt9        |             Y d }~d }~ww xY w)Nz<libvirt python bindings must be installed to use this plugin)cacheurizhypervisor uri not givenzhypervisor connection failurezcommunity.libvirt.libvirt_lxczcommunity.libvirt.libvirt_qemu)LXCQEMU)uuidnameinventory_hostname)r   r   ansible_libvirt_uriansible_connection)state_numberstate	maxMem_kb	memory_kb	nrVirtCpu
cpuTime_nsinfoxml_desc r   )typeserror
guest_info)sourceinterface_addressesERRORcomposestrictgroupskeyed_groups)$LIBVIRT_IMPORT_ERRORr	   r   superr   parse_read_config_data_consume_options
get_optionlibvirtopendictgetgetTypelistAllDomains
UUIDStringr   	inventoryadd_host	add_group	add_childset_variablelookupByUUIDStringr%   VIRDOMAINSTATEXMLDesc	guestInfolibvirtErrorstrinterfaceAddresses(VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENThostsget_vars_set_composite_vars_add_host_to_composed_groups_add_host_to_keyed_groups)selfr?   loaderpathr   config_datar   
connectionconnection_pluginserverr   inventory_hostname_aliasdomain_domain_state_domain_maxmem_domain_mem_domain_cpus_domain_cputdomain_infodomain_guestInfoedomain_interfaceAddresses	variables	__class__s                          o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/libvirt/plugins/inventory/libvirt.pyr4   zInventoryModule.parseD   s|   [\$& 	ot*	 	+ 	
 ,,T2 	k*ooe$9::\\#&
>?? !24"
  3z!!#$ 	
 !//1 q	F!%))+' " s 45  (,))+- ( s 45 % NN##$67NN$$%=>NN$$%=?QR ,++&)
 ++&(%5#66v7H7H7JK Z`YdYdYfV~{L,/<(6}(E,:,7,8-9; ++& ++&NN$ $& 
'-'7'7a'7'@$ NN//*$( -/)	060I0IQX  RB  RB0I  1C- NN//*-1 ,,-?@IIKI $$	*")	 --)")	 **/")	Yq	D ++ 9(/Q'8$9 NN//*$( ++ B18#a&0A-B NN//*-1_ '' ++&F sl   8QN8: P8O#OO&O##O&&PP3P.(P6.P33P66QR+&RR)T)__name__
__module____qualname__NAMEr4   __classcell__)rd   s   @re   r   r   A   s    &DR R    r   )
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESansible.plugins.inventoryr   r   ansible.errorsr   ansible.module_utils.sixr	   r8   r2   ImportErrorimp_excrE   r    rk   re   <module>rw      si    B B"H I ' /   uU)= U  #"#s   = AA		A