o
    b;                     @   sx   d dl mZmZmZ G dd deZG dd deZG dd deZG dd	 d	eZG d
d deZG dd deZ	dS )   )
XMLBuilderXMLChildPropertyXMLPropertyc                   @   sD   e Zd ZdZdZedddZedddZedddZedddZ	d	S )
DeviceVirtioDriverz3
    Represents shared virtio <driver> options
    driverz./@atsTis_onoffz./@iommuz	./@packedz./@page_per_vqN)
__name__
__module____qualname____doc__XML_NAMEr   atsiommupackedpage_per_vq r   r   2/usr/share/virt-manager/virtinst/devices/device.pyr      s    r   c                   @   s0   e Zd ZdZdZedZedddZedZdS )	DeviceSeclabelz:
    Minimal seclabel that's used for device sources.
    seclabelz./@modelz
./@relabelT)is_yesnoz./labelN)	r	   r
   r   r   r   r   modelrelabellabelr   r   r   r   r      s    r   c                   @   s   e Zd ZdZedZdS )DeviceAliasaliasz./@nameN)r	   r
   r   r   r   namer   r   r   r   r   !   s    r   c                   @   s$   e Zd ZdZedddZedZdS )
DeviceBootbootz./@orderTis_intz./@loadparmN)r	   r
   r   r   r   orderloadparmr   r   r   r   r   &   s    r   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	g dZ
d	d
 ZedZedddZedddZedddZedddZedddZedZedZedddZedddZedddZedddZedZedZedZedZedZedZed Zd!S )"DeviceAddressa  
    Examples:
    <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    <address type='drive' controller='0' bus='0' unit='0'/>
    <address type='ccid' controller='0' slot='0'/>
    <address type='virtio-serial' controller='1' bus='0' port='4'/>
    pcidrivezvirtio-serialccidz	spapr-vioaddress)	typedomain
controllerbusslotfunctiontargetunitmultifunctionc                 C   s,   d }| j | jkrd| j| j| j| jf }|S )Nz%s:%s:%s:%s)r(   ADDRESS_TYPE_DRIVEr*   r+   r.   r/   )selfpretty_descr   r   r   r3   ?   s   zDeviceAddress.pretty_descz./@typez	./@domainTr   z./@busz./@slotz./@functionz./@multifunctionr   z./zpci/@uidz./zpci/@fidz./@controllerz./@unitz./@portz	./@targetz./@regz./@cssidz./@ssidz./@devnoz	./@iobasez./@irqz./@baseN) r	   r
   r   r   ADDRESS_TYPE_PCIr1   ADDRESS_TYPE_VIRTIO_SERIALADDRESS_TYPE_CCIDADDRESS_TYPE_SPAPR_VIOr   _XML_PROP_ORDERr3   r   r(   r)   r+   r,   r-   r0   zpci_uidzpci_fidr*   r/   portr.   regcssidssiddevnoiobaseirqbaser   r   r   r   r#   ,   s:    r#   c                   @   s\   e Zd ZdZdd ZeeddZeeddZ	ee
ddZeeddZedd Zdd	 Zd
S )Devicez7
    Base class for all domain xml device objects.
    c                 O   s,   t j| g|R i | | jg d | _dS )zm
        Initialize device state

        :param conn: libvirt connection to validate device against
        )virtio_driverr   r'   N)r   __init__r8   )r2   argskwargsr   r   r   rE   f   s   zDevice.__init__T)	is_singlec                 C   s   | j S )N)r   )r2   r   r   r   DEVICE_TYPEu   s   zDevice.DEVICE_TYPEc                 C   sv  i dddgdddgdg dd	d
dgdd
dgdd
dgdg ddddgdddgdg ddddgdddgdddgdddgdddgdg ddddgddgd
dgd dgd
dgd
dgd
dgd!}t | t |krvd"S t| t|sd#S | j|vrd#S d$| v od$|  v }|| j D ]!}|dkr|sq|  }|}n
t| |}t||}||kr d#S qd"S )%aw  
        Attempt to compare this device against the passed @newdev,
        using various heuristics. For example, when removing a device
        from both active and inactive XML, the device XML my be very
        different or the devices may appear in different orders, so
        we have to do some fuzzy matching to determine if the devices
        are a 'match'
        diskr.   r+   	interfacemacaddrxmlindexinput)r+   r(   rM   soundr   videowatchdoghostdev)r(   managedrM   productvendorr-   r)   r,   serialr(   target_portparallelconsole)r(   target_typerW   graphicsr*   indexchanneltarget_name
filesystem	smartcardmoderedirdevtpmbackend_modelr   )rngpanicshmemvsock
memballoonr   TFdevices)id
isinstancer(   rI   
get_xml_idget_xml_idxgetattr)r2   newdevidxdevpropscan_check_xmldevproporigvalnewvalr   r   r   compare_devicey   s~   	




zDevice.compare_deviceN)r	   r
   r   r   rE   r   r   r   r#   r'   r   r   r   rD   propertyrI   rw   r   r   r   r   rC   b   s    

rC   N)

xmlbuilderr   r   r   r   r   r   r   r#   rC   r   r   r   r   <module>   s   
6