Viewing File: /opt/hc_python/lib/python3.12/site-packages/pyone/__pycache__/__init__.cpython-312.pyc

�

d��g�+���dZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
Gd�d	e�ZGd
�de�ZGd�d
e�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Ze	ddd��Ze	ddd��Ze	ddd��Ze	ddd��Ze	dd d��Ze	d!d"d��Ze	d#d$d��Ze	d%d&d��Ze	d'd(d��Ze	d)d*d��Ze	d+d,d��Z e	d-d.d��Z!e	d/d0d��Z"e	d1d2d��Z#dd3l$m%Z%Gd4�d5ejLjN�Z(Gd6�d7ejLjR�Z*y)8z=
PyONE is an implementation of Open Nebula XML-RPC bindings.
�N)�string_types)�IntEnum)�bindings�)�cast2onec��eZdZy)�OneExceptionN��__name__�
__module__�__qualname__���=/opt/hc_python/lib/python3.12/site-packages/pyone/__init__.pyr	r	!���rr	c��eZdZy)�OneAuthenticationExceptionNr
rrrrr%rrrc��eZdZy)�OneAuthorizationExceptionNr
rrrrr)rrrc��eZdZy)�OneNoExistsExceptionNr
rrrrr-rrrc��eZdZy)�OneActionExceptionNr
rrrrr1rrrc��eZdZy)�OneApiExceptionNr
rrrrr5rrrc��eZdZy)�OneInternalExceptionNr
rrrrr9rrr�DATASTORE_TYPESzIMAGE SYSTEM FILE)�start�DATASTORE_STATESzREADY DISABLED�
DISK_TYPESzFILE CD_ROM BLOCK RBD�HISTORY_ACTIONanone migrate live-migrate
        shutdown shutdown-hard undeploy undeploy-hard hold release stop
        suspend resume boot delete delete-recreate reboot reboot-hard resched
        unresched poweroff poweroff-hard disk-attach disk-detach nic-attach
        nic-detach disk-snapshot-create disk-snapshot-delete terminate
        terminate-hard disk-resize deploy chown chmod updateconf rename resize
        update snapshot-resize snapshot-delete snapshot-revert disk-saveas
        disk-snapshot-revert recover retry monitor�HOST_STATESzINIT MONITORING_MONITORED MONITORED
        ERROR DISABLED MONITORING_ERROR MONITORING_INIT MONITORING_DISABLED
        OFFLINE�HOST_STATUSzENABLED DISABLED OFFLINE�IMAGE_STATESzaINIT READY USED DISABLED LOCKED ERROR
        CLONE DELETE USED_PERS LOCKED_USED LOCKED_USED_PERS�IMAGE_TYPESz1OS CDROM DATABLOCK KERNEL RAMDISK
        CONTEXT�	LCM_STATEa
            LCM_INIT
            PROLOG
            BOOT
            RUNNING
            MIGRATE
            SAVE_STOP
            SAVE_SUSPEND
            SAVE_MIGRATE
            PROLOG_MIGRATE
            PROLOG_RESUME
            EPILOG_STOP
            EPILOG
            SHUTDOWN
            CANCEL
            FAILURE
            CLEANUP_RESUBMIT
            UNKNOWN
            HOTPLUG
            SHUTDOWN_POWEROFF
            BOOT_UNKNOWN
            BOOT_POWEROFF
            BOOT_SUSPENDED
            BOOT_STOPPED
            CLEANUP_DELETE
            HOTPLUG_SNAPSHOT
            HOTPLUG_NIC
            HOTPLUG_SAVEAS
            HOTPLUG_SAVEAS_POWEROFF
            HOTPLUG_SAVEAS_SUSPENDED
            SHUTDOWN_UNDEPLOY
            EPILOG_UNDEPLOY
            PROLOG_UNDEPLOY
            BOOT_UNDEPLOY
            HOTPLUG_PROLOG_POWEROFF
            HOTPLUG_EPILOG_POWEROFF
            BOOT_MIGRATE
            BOOT_FAILURE
            BOOT_MIGRATE_FAILURE
            PROLOG_MIGRATE_FAILURE
            PROLOG_FAILURE
            EPILOG_FAILURE
            EPILOG_STOP_FAILURE
            EPILOG_UNDEPLOY_FAILURE
            PROLOG_MIGRATE_POWEROFF
            PROLOG_MIGRATE_POWEROFF_FAILURE
            PROLOG_MIGRATE_SUSPEND
            PROLOG_MIGRATE_SUSPEND_FAILURE
            BOOT_UNDEPLOY_FAILURE
            BOOT_STOPPED_FAILURE
            PROLOG_RESUME_FAILURE
            PROLOG_UNDEPLOY_FAILURE
            DISK_SNAPSHOT_POWEROFF
            DISK_SNAPSHOT_REVERT_POWEROFF
            DISK_SNAPSHOT_DELETE_POWEROFF
            DISK_SNAPSHOT_SUSPENDED
            DISK_SNAPSHOT_REVERT_SUSPENDED
            DISK_SNAPSHOT_DELETE_SUSPENDED
            DISK_SNAPSHOT
            DISK_SNAPSHOT_REVERT
            DISK_SNAPSHOT_DELETE
            PROLOG_MIGRATE_UNKNOWN
            PROLOG_MIGRATE_UNKNOWN_FAILURE
            DISK_RESIZE
            DISK_RESIZE_POWEROFF
            DISK_RESIZE_UNDEPLOYED
            HOTPLUG_NIC_POWEROFF
            HOTPLUG_RESIZE
            HOTPLUG_SAVEAS_UNDEPLOYED
            HOTPLUG_SAVEAS_STOPPED�MARKETPLACEAPP_STATESz(INIT READY LOCKED
        ERROR DISABLED�MARKETPLACEAPP_TYPESz1UNKNOWN IMAGE
        VMTEMPLATE SERVICE_TEMPLATE�PAGINATED_POOLSzLVM_POOL IMAGE_POOL
        TEMPLATE_POOL VN_POOL DOCUMENT_POOL SECGROUP_POOL�REMOVE_VNET_ATTRSzgAR_ID BRIDGE CLUSTER_ID
        IP MAC TARGET NIC_ID NETWORK_ID VN_MAD SECURITY_GROUPS VLAN_ID
        �VM_STATEzjINIT PENDING HOLD ACTIVE STOPPED SUSPENDED
        DONE FAILED POWEROFF UNDEPLOYED CLONING CLONING_FAILURE)�marketapp_exportc�<�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
y)�	OneServerzB
    XML-RPC OpenNebula Server
    Slightly tuned ServerProxy
    Nc�*�||_|rtj|�dti|_t�}|j
|jd��|j|�tjjj||fd|i|��y)a�
        Override the constructor to take the authentication or session
        Will also configure the socket timeout
        :param uri: OpenNebula endpoint
        :param session: OpenNebula authentication session
        :param timeout: Socket timetout
        :param https_verify: if https cert should be verified
        :param options: additional options for ServerProxy
        zmarketapp.export�https�	transportN)
�_OneServer__session�socket�setdefaulttimeoutr-�_OneServer__helpers�RequestsTransport�	set_https�
startswith�set_https_verify�xmlrpc�client�ServerProxy�__init__)�self�uri�session�timeout�https_verify�optionsr2s       rr>zOneServer.__init__�s���!�����$�$�W�-�
� 0�
���&�'�	����C�N�N�7�3�4��"�"�<�0��
�
�!�!�*�*���	� �	��		rc��||jvr|j||g|���S|jd|z|j|��}|j|�S)a�
        Override/patch the (private) request method to:
          - structured parameters will be casted to attribute=value or XML
          - automatically prefix all methodnames with "one."
          - automatically add the authentication info as first parameter
          - process the response

        :param methodname: XMLRPC method name
        :param params: XMLRPC parameters
        :return: opennebula object or XMLRPC returned value
        zone.)r6�_do_request�_cast_parms�_OneServer__response)r?�
methodname�params�rets    r�_ServerProxy__requestzOneServer._ServerProxy__request�s\������'�-�4�>�>�*�-�d�<�V�<�<����v�j�0�$�2B�2B�6�2J�K�����s�#�#rc���	tjjj|||�S#tjj$r}tt
|���d}~wwxYw�N)r;r<r=rL�Faultr	�str)r?�methodrJ�es    rrFzOneServer._do_request�sT��	'��=�=�,�,�B�B��f�f�&�
&���}�}�"�"�	'��s�1�v�&�&��	'�s�*-�A#�
A�A#c��t|�}t|�D]\}}t|�||<�t|�}|jf|z}|S)za
        cast parameters, make them one-friendly
        :param params:
        :return:
        )�list�	enumerater�tupler3)r?rJ�lparams�i�params     rrGzOneServer._cast_parms�sL���v�,��!�'�*�H�A�u�!�%��G�A�J�+��w����.�.�"�V�+���
rc��|d}|d}|rC|d}t|t�r,|ddk(r$tj|j	d��S|S|d}|dk(rt|��|dk(rt
|��|dk(rt|��|d	k(rt|��|d
k(rt|��|dk(rt|��t|��)Nr�r�<zutf-8�iiiii )�
isinstancerr�parseString�encoderrrrrrr	)r?�raw_response�sucess�coderK�messages      r�
__responsezOneServer.__responses����a����A�����q�/�C��#�|�,��q�6�S�=�#�/�/��
�
�7�0C�D�D��J��q�/���6�>�,�W�5�5��6�>�+�G�4�4��6�>�&�w�/�/��6�>�$�W�-�-��6�>�!�'�*�*��6�>�&�w�/�/��7�#�#rc��y)z�returns the recommended wait time between attempts to check if
        the opennebula platform has reached a desired state, in secondsrr�r?s r�server_retry_intervalzOneServer.server_retry_interval's��rc��yrNrrgs r�server_closezOneServer.server_close,s��r)NT)rrr
�__doc__r>rLrFrGrHrhrjrrrr/r/�s+���
�B$�*'��"$�6�

rr/c�:�eZdZdZdZdZd
d�Zd�Zd
d�Zd�Z	d�Z
y	)r7zO
    Drop in Transport for xmlrpclib that uses Requests instead of httplib
    z1Python XMLRPC with Requests (python-requests.org)Fc��||_yrN)�	use_https)r?r1s  rr8zRequestsTransport.set_https8s	����rc��||_yrN)rC)r?rCs  rr:z"RequestsTransport.set_https_verify;s
��(��rc��|jddd�}|j||�}d|ji}tj|f||d�|��}	|j�|j
|�S#tj$rD}	tjj||jt|	�|j��d}	~	wwxYw)z)
        Make an xmlrpc request.
        ztext/xmlz*/*)z
User-AgentzContent-Type�Accept�verify)�data�headersN)�
user_agent�
_build_urlrC�requests�post�raise_for_status�parse_response�RequestExceptionr;r<�
ProtocolError�status_coderPrt)
r?�host�handler�request_body�verbosert�url�kwargs�resprRs
          r�requestzRequestsTransport.request>s���"&���#-�"���
�o�o�d�G�,���D�-�-�/���}�}�S�'�|�W�'�%�'��	-��!�!�#�
�&�&�t�,�,��	�(�(�	D��-�-�-�-�c�4�3C�3C�.1�!�f�d�l�l�D�
D��	D�s�A,�,C�??B>�>Cc��|j�\}}|j|j�|j�|j�S)z,
        Parse the xmlrpc response.
        )�	getparser�feed�content�close)r?�response�p�us    rrzz RequestsTransport.parse_responseUs;���~�~����1�	���x��� �	���	��w�w�y�rc�X�|jrdnd}|jd�}|�d|�d|��S)zf
        Build a url for our request based on the host, handler and use_http
        property
        r1�http�/z://)rn�lstrip)r?r~r�schemes    rrvzRequestsTransport._build_url`s,��
!�N�N�����.�.��%��%�t�W�5�5rN)F)rrr
rkrurnr8r:r�rzrvrrrr7r70s-���E�J��I��)�-�.	�6rr7)+rk�
xmlrpc.clientr;r4rw�requests.utils�sixr�enumr�pyoner�utilr�	Exceptionr	rrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,�helpersr-r<r=r/�	Transportr7rrr�<module>r�s�����
�������	�9�	�	��	�	��	�	�<�	�	��	�	�l�	�	�<�	��+�-@��J���-�/?�q�I��
�\�#:�!�
D�
��)�,6�>?�@���m�&�����m�%?�q�I���~�(?�FG�I���m�&����
�K�E"&�J./�KE
0�	�N � 7�:�!"�$���5�8'�./�1���+�.=�DE�G���/�2�����:� C�JK�M��&�u
��
�
�)�)�u
�p86��
�
�/�/�86r
Back to Directory File Manager