Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/libcloud/common/__pycache__/abiquo.cpython-39.pyc
Ðазад
a q�hK( � @ s� d Z ddlZddlmZmZ ddlmZ ddlmZmZ ddl m Z ddl mZ ddl mZ dd l mZ d d� ZG dd � d e�ZG dd� dee�ZG dd� de�ZdS )zk Abiquo Utilities Module for the Abiquo Driver. Common utilities needed by the :class:`AbiquoNodeDriver`. � N)�ConnectionUserAndKey�PollingConnection)�XmlResponse)�InvalidCredsError� LibcloudError)�httplib)�urlparse)�b)� NodeStatec C sj | � d�}|D ]V}|jd |kr|jd }d}t�|�j}|�|�}||t|� d d� }| S qdS )aH Search a RESTLink element in the :class:`AbiquoResponse`. Abiquo, as a REST API, it offers self-discovering functionality. That means that you could walk through the whole API only navigating from the links offered by the entities. This is a basic method to find the 'relations' of an entity searching into its links. For instance, a Rack entity serialized as XML as the following:: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <rack> <link href="http://host/api/admin/datacenters/1" type="application/vnd.abiquo.datacenter+xml" rel="datacenter"/> <link href="http://host/api/admin/datacenters/1/racks/1" type="application/vnd.abiquo.rack+xml" rel="edit"/> <link href="http://host/api/admin/datacenters/1/racks/1/machines" type="application/vnd.abiquo.machines+xml" rel="machines"/> <haEnabled>false</haEnabled> <id>1</id> <longDescription></longDescription> <name>racacaca</name> <nrsq>10</nrsq> <shortDescription></shortDescription> <vlanIdMax>4094</vlanIdMax> <vlanIdMin>2</vlanIdMin> <vlanPerVdcReserved>1</vlanPerVdcReserved> <vlansIdAvoided></vlansIdAvoided> </rack> offers link to datacenters (rel='datacenter'), to itself (rel='edit') and to the machines defined in it (rel='machines') A call to this method with the 'rack' element using 'datacenter' as 'rel' will return: 'http://10.60.12.7:80/api/admin/datacenters/1' :type element: :class:`xml.etree.ElementTree` :param element: Xml Entity returned by Abiquo API (required) :type rel: ``str`` :param rel: relation link name :rtype: ``str`` :return: the 'href' value according to the 'rel' input parameter �link�rel�hrefz/api/� N)�findall�attribr �path�find�len) �elementr �linksr r �needleZurl_path�index�result� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/libcloud/common/abiquo.py�get_href s 0 r c @ sN e Zd ZdZejejejejejejejejd�Z dd� Z dd� Zdd� Zd S ) �AbiquoResponsezt Abiquo XML Response. Wraps the response in XML bodies or extract the error data in case of error. )Z NOT_ALLOCATEDZ ALLOCATEDZ CONFIGURED�ONZPAUSEDZOFF�LOCKED�UNKNOWNc C s� | j tjkrt| jjd��nv| j tjkr6t| jj��n\| j tjkrLt d��nF| � � }|dur�t|d�r�| � � �d�}t |d � d���n t | j��dS )a Parse the error messages. Response body can easily be handled by this class parent :class:`XmlResponse`, but there are use cases which Abiquo API does not respond an XML but an HTML. So we need to handle these special cases. )�driverzNot AcceptableNr �errorr �message)�statusr �UNAUTHORIZEDr � connectionr � FORBIDDEN�ForbiddenError�NOT_ACCEPTABLEr � parse_body�hasattrr �findtext�body)�selfZ parsebody�errorsr r r �parse_errors s zAbiquoResponse.parse_errorc C s | j tjtjtjtjfv S )z� Determine if the request was successful. Any of the 2XX HTTP response codes are accepted as successful requests :rtype: ``bool`` :return: successful request or not. )r# r �OK�CREATED� NO_CONTENT�ACCEPTED)r- r r r �success� s �zAbiquoResponse.successc C s&