o
    b                     @   s,   d dl mZ ddlmZ G dd deZdS )   )Device   )XMLPropertyc                   @   s$  e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zedd Zedd Zg 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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ddZedddZed ddZed!ddZ ed"ddZ!d#d$ Z"d%d& Z#d'd( Z$d)S )*DeviceController
controlleridefdcscsisatavirtio-serialusbpciccidxenbusc                 C   s   g }t | }d|_d|_|| t | }d|_d|_d|_|| t | }d|_d|_d|_|| t | }d|_d|_d|_|| |S )	Nr   z
ich9-ehci1z
ich9-uhci1    z
ich9-uhci2r   z
ich9-uhci3   )r   typemodelappendmaster_startport)connretctrl r   6/usr/share/virt-manager/virtinst/devices/controller.pyget_usb2_controllers   s*   



z%DeviceController.get_usb2_controllersc                 C   s<   |}t | }d|_d|_| j rd|_| j rd|_|S )Nr   znec-xhciz	qemu-xhci   )r   r   r   supportconn_qemu_xhciconn_usb3_portsports)r   guestignorer   r   r   r   get_usb3_controller3   s   

z$DeviceController.get_usb3_controller)r   indexr   r   driver_queuesmaxGrantFramesz./@typez./@modelz
./@vectorsT)is_intz./@portsz./@maxGrantFramesz./@indexz./driver/@iothreadz./driver/@queuesz./master/@startportz./target/@chassisNrz./target/@chassisz./target/@portz./target/@hotplug)is_onoffz./target/@busNrz./target/@indexz./target/nodec                 C   s:   g }|j jD ]}| j|jkr| j|jjkr|| q|S )N)devicesdiskr   busr$   addressr   r   )selfr!   r   r*   r   r   r   _get_attached_disk_devicesY   s   
z+DeviceController._get_attached_disk_devicesc                 C   sh   g }|j jD ]}| j|jjkr| j|jjkr|| q|j jD ]}| jdkr1|jdkr1|| q |S )Nr   virtio)	r)   channelr   r,   r$   r   r   consoletarget_type)r-   r!   r   devr   r   r   "_get_attached_virtioserial_devicesa   s   

z3DeviceController._get_attached_virtioserial_devicesc                 C   s4   g }| j dkr| |}|S | j dv r| |}|S )zr
        Return all the Device objects from the passed Guest that are attached
        to this controller
        r   )r	   r
   r   r   )r   r4   r.   )r-   r!   r   r   r   r   get_attached_devicesm   s   



z%DeviceController.get_attached_devicesN)%__name__
__module____qualname__XML_NAMETYPE_IDETYPE_FDC	TYPE_SCSI	TYPE_SATATYPE_VIRTIOSERIALTYPE_USBTYPE_PCI	TYPE_CCIDTYPE_XENBUSstaticmethodr   r#   _XML_PROP_ORDERr   r   r   vectorsr    r&   r$   driver_iothreadr%   r   target_chassisNrtarget_chassistarget_porttarget_hotplugtarget_busNrtarget_indextarget_noder.   r4   r5   r   r   r   r   r      sF    

r   N)devicer   
xmlbuilderr   r   r   r   r   r   <module>   s   