Current File : //usr/lib/python3/dist-packages/landscape/lib/__pycache__/vm_info.cpython-312.pyc |
�
�~�ev � �T � d Z ddlZddlmZ ddlmZ dZdd�Zd
d�Zd� Zd � Z d
� Z
d� Zy)zG
Network introspection utilities using ioctl and the /proc filesystem.
� N)�read_binary_file)�read_text_file)�
sys_vendor�chassis_vendor�bios_vendor�product_namec �@ � t | � ryt | � ryt j j | d� }t
D ]S }t j j ||� }t j j
|� s�Ct |� }|s�Q|c S t | � S )a
Return a bytestring with the virtualization type if it's known, an empty
bytestring otherwise.
It loops through some possible configurations and return a bytestring with
the name of the technology being used or None if there's no match
s openvzs xenzsys/class/dmi/id) �
_is_vm_openvz�
_is_vm_xen�os�path�join� DMI_FILES�exists�_get_vm_by_vendor�_get_vm_legacy)� root_path�
dmi_info_path�
dmi_info_file�dmi_vendor_path�vendors �7/usr/lib/python3/dist-packages/landscape/lib/vm_info.py�get_vm_infor
s� � � �Y����)��� �G�G�L�L��,>�?�M�"� �
��'�'�,�,�}�m�D���w�w�~�~�o�.��"�?�3����M�
� �)�$�$� c �� � dD ]\ }t j j | |� }t j j |� s�Ct |� j � c S y)zu
Return a string with the type of container the client is running in, if
any, an empty string otherwise.
)�container_typezsystemd/container� )r r
r r r �strip)�run_path�filenamer
s r �get_container_infor! ( sP � �
<� 0���w�w�|�|�H�h�/��
�7�7�>�>�$��!�$�'�-�-�/�/�0� r c � � t j j | d� }t j j |� xr t j |� S )z*Check if the host is virtualized with Xen.zsys/bus/xen/devices)r r
r �isdir�listdir)r �sys_xen_paths r r r 4 s8 � ��7�7�<�<� �+@�A�L�
�7�7�=�=��&�C�2�:�:�l�+C�Cr c �| � t j j t j j | d� � S )z-Check if the host is virtualized with OpenVZ.zproc/vz)r r
r r )r s r r
r
; s$ � �
�7�7�>�>�"�'�'�,�,�y�)�<�=�=r c �b � t | d�� j � }d}|D ]
\ }}||v s�|c S y)zDReturn the VM type byte string (possibly empty) based on the vendor.i )�limit)
)s
amazon ec2� kvm)s bochsr) )s digitaloceanr) )s googles gce)s innoteks
virtualbox)s microsofts hyperv)s nutanixr) )s openstackr) )s qemur) )r) r) )� vmwarer* )s rhevr) )s parallelsr) r )r �lower)�sys_vendor_pathr �content_vendors_map�name�vm_types r r r @ sG � � �o�T�
:�
@�
@�
B�F��� -� �
��g��6�>��N�� r c � � t t j j | d� � }d|v ryy# t $ r Y yw xY w)zBCheck if the host is virtualized looking at /proc/cpuinfo content.zproc/cpuinfor �qemur) )r r r
r �OSError)r �cpuinfos r r r \ sD � �� ������i��!H�I�� ������
� ���s �)1 � =�=)�/)z/run)�__doc__r �landscape.lib.fsr r r r r! r r
r r � r r �<module>r8 s<