§
    ÎÑßjsw  ã                   ó�   — d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
mZmZmZ ddlmZmZ  G d„ de¦  «        Z G d„ d	¦  «        Zd
S )zí
Abiquo Compute Driver

The driver implements the compute Abiquo functionality for the Abiquo API.
This version is compatible with the following versions of Abiquo:

    * Abiquo 3.4 (http://wiki.abiquo.com/display/ABI34/The+Abiquo+API)
é    )ÚETÚtostring)ÚNodeÚNodeSizeÚ	NodeImageÚ
NodeDriverÚNodeLocation)ÚAbiquoResponseÚAbiquoConnectionÚget_href)ÚProviderÚLibcloudErrorc                   ó  ‡ — e Zd ZdZej        ZdZdZe	Z
dZdZdZdZdZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZˆ fd„Zd.d„Zd„ Zd„ Z d„ Z!d/d„Z"d„ Z#d/d„Z$d/d„Z%d „ Z&d/d!„Z'd/d"„Z(d#„ Z)d$„ Z*d%„ Z+d&„ Z,d'„ Z-d(„ Z.d/d)„Z/d*„ Z0d+„ Z1d/d,„Z2d0d-„Z3ˆ xZ4S )1ÚAbiquoNodeDriverzN
    Implements the :class:`NodeDriver`'s for the Abiquo Compute Provider
    ÚAbiquozhttp://www.abiquo.com/iÐ  z*application/vnd.abiquo.virtualmachines+xmlz)application/vnd.abiquo.virtualmachine+xmlz,application/vnd.abiquo.virtualappliances+xmlz+application/vnd.abiquo.virtualappliance+xmlz-application/vnd.abiquo.virtualmachinetask+xmlzapplication/vnd.abiquo.user+xmlz%application/vnd.abiquo.enterprise+xmlz-application/vnd.abiquo.virtualdatacenters+xmlz,application/vnd.abiquo.virtualdatacenter+xmlz&application/vnd.abiquo.datacenters+xmlz2application/vnd.abiquo.virtualmachinetemplates+xmlz1application/vnd.abiquo.virtualmachinetemplate+xmlzapplication/vnd.abiquo.nics+xmlz1application/vnd.abiquo.datacenterrepositories+xmlz/application/vnd.abiquo.datacenterrepository+xmlz*application/vnd.abiquo.acceptedrequest+xmli   @c           	      ó|   •— || _          t          ¦   «         j        d||ddddœ|¤Ž |                      ¦   «          dS )aÉ  
        Initializes Abiquo Driver

        Initializes the :class:`NodeDriver` object and populate the cache.

        :param       user_id: identifier of Abiquo user (required)
        :type        user_id: ``str``
        :param       secret: password of the Abiquo user (required)
        :type        secret: ``str``
        :param       endpoint: Abiquo API endpoint (required)
        :type        endpoint: ``str`` that can be parsed as URL
        FN)ÚkeyÚsecretÚsecureÚhostÚport© )ÚendpointÚsuperÚ__init__Úex_populate_cache)ÚselfÚuser_idr   r   ÚkwargsÚ	__class__s        €úS/opt/saltstack/salt/lib/python3.11/site-packages/libcloud/compute/drivers/abiquo.pyr   zAbiquoNodeDriver.__init__>   sP   ø€ ð !ˆŒØ�‰ŒÔÐb˜W¨V¸EÈÐSWÐbÐbÐ[aÐbÐbÐbØ×ÒÑ Ô Ð Ð Ð ó    Nc                 ó`  — |                       ||¬¦  «        \  }}|                      |||¦  «        }|                      ||||¬¦  «        }	|                      |	¦  «         t	          |	d¦  «        }
d| j        i}| j                             |
|¬¦  «        j        }	|  	                    |	| ¦  «        S )a?  
        Create a new node instance in Abiquo

        All the :class:`Node`s need to be defined inside a VirtualAppliance
        (called :class:`NodeGroup` here). If there is no group name defined,
        'libcloud' name will be used instead.

        This method wraps these Abiquo actions:

            1. Create a group if it does not exist.
            2. Register a new node in the group.
            3. Deploy the node and boot it.
            4. Retrieves it again to get schedule-time attributes (such as ips
               and vnc ports).

        The rest of the driver methods has been created in a way that, if any
        of these actions fail, the user can not reach an inconsistent state

        :keyword    name:   The name for this new node (required)
        :type       name:   ``str``

        :keyword    size:   The size of resources allocated to this node.
        :type       size:   :class:`NodeSize`

        :keyword    image:  OS Image to boot on node. (required)
        :type       image:  :class:`NodeImage`

        :keyword    location: Which data center to create a node in. If empty,
                              undefined behavior will be selected. (optional)
        :type       location: :class:`NodeLocation`

        :keyword   ex_group_name:  Which group this node belongs to. If empty,
                                   it will be created into 'libcloud' group. If
                                   it does not found any group in the target
                                   location (random location if you have not
                                   set the parameter), then it will create a
                                   new group with this name.
        :type     ex_group_name:  c{str}

        :return:               The newly created node.
        :rtype:                :class:`Node`
        )ÚimageÚlocation)ÚnameÚsizer$   ÚeditÚAccept©Úheaders)
Ú_define_create_node_locationÚ_define_create_node_groupÚ_define_create_node_nodeÚ_deploy_remoter   ÚNODE_MIME_TYPEÚ
connectionÚrequestÚobjectÚ_to_node)r   r$   r&   r'   r%   Úex_group_nameÚxml_locÚlocÚgroupÚvmÚedit_vmr+   s               r!   Úcreate_nodezAbiquoNodeDriver.create_nodeO   s½   € ð^ ×8Ò8¸uÈxÐ8ÑXÔX‰ˆ�ð ×.Ò.¨w¸¸]ÑKÔKˆð ×*Ò*¨5°tÀ$ÈeÐ*ÑTÔTˆð 	×Ò˜BÑÔÐõ ˜2˜vÑ&Ô&ˆØ˜TÔ0Ð1ˆØŒ_×$Ò$ W°gÐ$Ñ>Ô>ÔEˆà�}Š}˜R Ñ&Ô&Ð&r"   c                 óP  — d| j         i}| j                             |j        d         |¬¦  «        j        }|                     d¦  «        }|dv rt          d| ¦  «        ‚d}|dk    rzt          j        d	¦  «        }t          j	        |d
¦  «        }d|_
        |j        d         dz   }| j        | j        dœ}| j                             |dt          |¦  «        |¬¦  «        }|dk    s|r=|                     ¦   «         r)| j                             |j        d         d¬¦  «         dS dS )aC  
        Destroy a node

        Depending on the provider, this may destroy all data associated with
        the node, including backups.

        :param node: The node to be destroyed
        :type node: :class:`Node`

        :return: True if the destroy was successful, otherwise False
        :rtype: ``bool``
        r)   Úuri_idr*   Ústate)Ú	ALLOCATEDÚ
CONFIGUREDÚLOCKEDÚUNKNOWNúInvalid Node stateNÚNOT_ALLOCATEDÚvirtualmachinetaskÚforceUndeployÚTrueú/action/undeploy©r)   zContent-typeÚPOST©ÚactionÚmethodÚdatar+   ÚDELETE©rL   rM   TF)r0   r1   r2   Úextrar3   Úfindtextr   r   ÚElementÚ
SubElementÚtextÚAR_MIME_TYPEÚVM_TASK_MIME_TYPEÚasync_requestr   Úasync_success)	r   Únoder+   Úe_vmr>   ÚresÚvm_taskÚforce_undeployÚdestroy_uris	            r!   Údestroy_nodezAbiquoNodeDriver.destroy_node�   sI  € ð ˜TÔ0Ð1ˆØŒ×&Ò& t¤z°(Ô';ÀWÐ&ÑMÔMÔTˆà—’˜gÑ&Ô&ˆàÐDÐDÐDÝÐ 4°dÑ;Ô;Ð;àˆà�OÒ#Ð#å”jÐ!5Ñ6Ô6ˆGÝœ]¨7°OÑDÔDˆNØ"(ˆNÔàœ* XÔ.Ð1CÑCˆKð Ô+Ø $Ô 6ðð ˆGð ”/×/Ò/Ø"ØÝ˜gÑ&Ô&Øð	 0ñ ô ˆCð �OÒ#Ð#¨Ð#°×0AÒ0AÑ0CÔ0CÐ#àŒO×#Ò#¨4¬:°hÔ+?ÈÐ#ÑQÔQÐQà�4à�5r"   c                 óv  — | j                              |j        d         ¦  «        j        }|                     d¦  «        }|dk    rt          d| ¦  «        ‚|                      |¦  «         t          |d¦  «        }d| j        i}| j                              ||¬¦  «        j        }|  	                    || ¦  «        S )a‡  
        Runs a node

        Here there is a bit difference between Abiquo states and libcloud
        states, so this method is created to have better compatibility. In
        libcloud, if the node is not running, then it does not exist (avoiding
        UNKNOWN and temporal states). In Abiquo, you can define a node, and
        then deploy it.

        If the node is in :class:`NodeState.TERMINATED` libcloud's state and in
        'NOT_DEPLOYED' Abiquo state, there is a way to run and recover it
        for libcloud using this method. There is no way to reach this state
        if you are using only libcloud, but you may have used another Abiquo
        client and now you want to recover your node to be used by libcloud.

        :param node: The node to run
        :type node: :class:`Node`

        :return: The node itself, but with the new state
        :rtype: :class:`Node`
        r=   r>   rD   rC   r(   r)   r*   )
r1   r2   rQ   r3   rR   r   r/   r   r0   r4   )r   rZ   r[   r>   r:   r+   s         r!   Úex_run_nodezAbiquoNodeDriver.ex_run_nodeÆ   sµ   € ð. Œ×&Ò& t¤z°(Ô';Ñ<Ô<ÔCˆØ—’˜gÑ&Ô&ˆà�OÒ#Ð#ÝÐ 4°dÑ;Ô;Ð;ð
 	×Ò˜DÑ!Ô!Ð!õ ˜4 Ñ(Ô(ˆØ˜TÔ0Ð1ˆØŒ×&Ò& w¸Ð&Ñ@Ô@ÔGˆà�}Š}˜T 4Ñ(Ô(Ð(r"   c                 ó  — d| j         i}| j                             d|¬¦  «        j        }|| j        j        d<   t          | j        j        d         d¦  «        }d| j        i}| j                             ||¬¦  «        j        }|| j        j        d<   d| j        i}d}| j                             ||¬¦  «        j        }d|                      ¦   «         i}	d| j	        i}
| j                             d|
|	¬	¦  «        j        }i }| 
                    d
¦  «        D ]}t          |d¦  «        }|||<   Œi | j        j        d<   | 
                    d¦  «        D ]7}t          |d¦  «        }|�#t          |d¦  «        | j        j        d         |<   Œ8dS )aˆ  
        Populate the cache.

        For each connection, it is good to store some objects that will be
        useful for further requests, such as the 'user' and the 'enterprise'
        objects.

        Executes the 'login' resource after setting the connection parameters
        and, if the execution is successful, it sets the 'user' object into
        cache. After that, it also requests for the 'enterprise' and
        'locations' data.

        List of locations should remain the same for a single libcloud
        connection. However, this method is public and you are able to
        refresh the list of locations any time.
        r)   z/loginr*   ÚuserÚ
enterprisez/cloud/virtualdatacentersÚidEnterprisez/admin/datacenters)r+   ÚparamsÚ
datacenterr   Ú	locationsÚvirtualDatacenterr%   Nr(   )ÚUSER_MIME_TYPEr1   r2   r3   Úcacher   ÚENT_MIME_TYPEÚVDCS_MIME_TYPEÚ_get_enterprise_idÚDCS_MIME_TYPEÚfindall)r   Úuser_headersrd   Úe_entÚent_headersÚentÚvdcs_headersÚuri_vdcsÚe_vdcsrg   Údcs_headersÚe_dcsÚdc_dictÚdcr   Úe_vdcr7   s                    r!   r   z"AbiquoNodeDriver.ex_populate_cacheò   s´  € ð$ ! $Ô"5Ð6ˆØŒ×&Ò& x¸Ð&ÑFÔFÔMˆØ(,ˆŒÔ˜fÑ%Ý˜œÔ.¨vÔ6¸ÑEÔEˆØ Ô!3Ð4ˆØŒo×%Ò% e°[Ð%ÑAÔAÔHˆØ.1ˆŒÔ˜lÑ+à  $Ô"5Ð6ˆØ.ˆØ”×(Ò(¨¸<Ð(ÑHÔHÔOˆà  $×"9Ò"9Ñ";Ô";Ð<ˆà Ô!3Ð4ˆØ”×'Ò'Ø ¨+¸fð (ñ 
ô 
ä
ð 	ð ˆà—-’- Ñ-Ô-ð 	ð 	ˆBÝ˜2˜vÑ&Ô&ˆCØˆG�C‰LˆLð .0ˆŒÔ˜kÑ*à—^’^Ð$7Ñ8Ô8ð 	Rð 	RˆEÝ˜5 *Ñ-Ô-ˆCàˆÝ:BÀ5È&Ñ:QÔ:Q�”Ô% kÔ2°3Ñ7øð		Rð 	Rr"   c                 ór  — t          j        d¦  «        }t          j        |d¦  «        }||_        |€|                      ¦   «         d         }n%||                      ¦   «         vrt          d¦  «        ‚| j        j        d         |         }d| j        i}| j         	                    ||¬¦  «        j
        }t          |d	¦  «        }| j        | j        d
œ}	| j         	                    |t          |¦  «        |	d¬¦  «        j
        }t          |d¦  «        }
t          | |                     d¦  «        |
¬¦  «        S )aŒ  
        Create an empty group.

        You can specify the location as well.

        :param     group:     name of the group (required)
        :type      group:     ``str``

        :param     location: location were to create the group
        :type      location: :class:`NodeLocation`

        :returns:            the created group
        :rtype:              :class:`NodeGroup`
        ÚvirtualAppliancer&   Nr   úLocation does not existri   r)   r*   ÚvirtualappliancesrI   rJ   ©rN   r+   rM   r(   ©Úuri)r   rS   rT   rU   Úlist_locationsr   r1   rl   ÚVDC_MIME_TYPEr2   r3   r   ÚVAPP_MIME_TYPEr   Ú	NodeGrouprR   )r   r&   r%   ÚvappÚ	vapp_nameÚlink_vdcÚhdr_vdcr}   Úcreation_linkr+   Úuri_vapps              r!   Úex_create_groupz AbiquoNodeDriver.ex_create_group%  s4  € õ  ŒzÐ,Ñ-Ô-ˆÝ”M $¨Ñ/Ô/ˆ	Øˆ	ŒàÐØ×*Ò*Ñ,Ô,¨QÔ/ˆHˆHØ˜T×0Ò0Ñ2Ô2Ð2Ð2ÝÐ 9Ñ:Ô:Ð:à”?Ô(¨Ô5°hÔ?ˆØ˜TÔ/Ð0ˆØ”×'Ò'¨¸'Ð'ÑBÔBÔIˆå  Ð(;Ñ<Ô<ˆØ!Ô0À$ÔBUÐVÐVˆØŒ×&Ò&Ø¥¨¡¤¸Èð 'ñ 
ô 
ä
ð 	õ ˜D &Ñ)Ô)ˆå˜˜tŸ}š}¨VÑ4Ô4¸(ÐCÑCÔCÐCr"   c                 ó  — | j                              |j        ¦  «        j        }|                     d¦  «        }|dvrd}t          || ¦  «        ‚d}|dk    rtt          j        d¦  «        }t          j        |d¦  «        }d|_	        |j        d	z   }| j
        | j        d
œ}	| j                              |dt          |¦  «        |	¬¦  «        }|dk    s|r7|                     ¦   «         r#| j                              |j        d¬¦  «         dS dS )aë  
        Destroy a group.

        Be careful! Destroying a group means destroying all the :class:`Node`
        instances there and the group itself!

        If there is currently any action over any :class:`Node` of the
        :class:`NodeGroup`, then the method will raise an exception.

        :param     name: The group (required)
        :type      name: :class:`NodeGroup`

        :return:         If the group was destroyed successfully
        :rtype:          ``bool``
        r>   )ÚNOT_DEPLOYEDÚDEPLOYEDz.Can not destroy group because of current stateNr’   rE   rF   rG   rH   rI   rJ   rK   r‘   rO   rP   TF)r1   r2   r„   r3   rR   r   r   rS   rT   rU   rV   rW   rX   r   rY   )
r   r8   Úe_groupr>   Úerrorr\   r]   r^   Úundeploy_urir+   s
             r!   Úex_destroy_groupz!AbiquoNodeDriver.ex_destroy_groupL  s2  € ð" ”/×)Ò)¨%¬)Ñ4Ô4Ô;ˆØ× Ò  Ñ)Ô)ˆàÐ4Ð4Ð4ØDˆEÝ  tÑ,Ô,Ð,àˆà�JÒÐå”jÐ!5Ñ6Ô6ˆGÝœ]¨7°OÑDÔDˆNØ"(ˆNÔð !œ9Ð'9Ñ9ˆLð Ô+Ø $Ô 6ðð ˆGð ”/×/Ò/Ø#ØÝ˜gÑ&Ô&Øð	 0ñ ô ˆCð �NÒ"Ð" sÐ"¨s×/@Ò/@Ñ/BÔ/BÐ"ð ŒO×#Ò#¨5¬9¸XÐ#ÑFÔFÐFà�4à�5r"   c                 óð  — g }|                       |¦  «        D �]\}| j        j        d         |         }d| j        i}| j                             ||¬¦  «        j        }t          |d¦  «        }d| j        i}| j                             ||¬¦  «        j        }	|	                     d¦  «        D ]Ç}
g }t          |
d¦  «        }d| j	        i}| j                             ||¬¦  «        j        }|                     d¦  «        D ]+}| 
                    |                      || ¦  «        ¦  «         Œ,t          | |
                     d¦  «        |t          |
d	¦  «        ¦  «        }| 
                    |¦  «         ŒÈ�Œ^|S )
zÙ
        List all groups.

        :param location: filter the groups by location (optional)
        :type  location: a :class:`NodeLocation` instance.

        :return:         the list of :class:`NodeGroup`
        ri   r)   r*   r�   r   ÚvirtualmachinesÚvirtualMachiner&   r(   )Ú_get_locationsr1   rl   r†   r2   r3   r   ÚVAPPS_MIME_TYPErq   ÚNODES_MIME_TYPEÚappendr4   rˆ   rR   )r   r%   ÚgroupsÚvdcr‹   rŒ   r}   Ú	apps_linkÚ	hdr_vappsÚvappsr‰   ÚnodesÚvms_linkr+   Úvmsr9   r8   s                    r!   Úex_list_groupszAbiquoNodeDriver.ex_list_groups†  sƒ  € ð ˆà×&Ò& xÑ0Ô0ð 	%ñ 	%ˆCØ”Ô,¨[Ô9¸#Ô>ˆHØ Ô!3Ð4ˆGØ”O×+Ò+¨H¸gÐ+ÑFÔFÔMˆEÝ  Ð(;Ñ<Ô<ˆIØ! 4Ô#7Ð8ˆIØ”O×+Ò+¨I¸yÐ+ÑIÔIÔPˆEàŸšÐ&8Ñ9Ô9ð 	%ð 	%�Ø�Ý# DÐ*;Ñ<Ô<�Ø# TÔ%9Ð:�Ø”o×-Ò-¨hÀÐ-ÑHÔHÔO�àŸ+š+Ð&6Ñ7Ô7ð :ð :�BØ—L’L §¢¨r°4Ñ!8Ô!8Ñ9Ô9Ð9Ð9Ý! $¨¯ª°fÑ(=Ô(=¸uÅhÈtÐU[ÑF\ÔF\Ñ]Ô]�Ø—’˜eÑ$Ô$Ð$Ð$ñ	%ð ˆr"   c                 ó¾  — |                       ¦   «         }d|z  }d| j        i}| j                             ||¬¦  «        j        }g }|                     d¦  «        D �]€}|                      |¦  «        D �]f}| j        j        d         |         }	d| j        i}
| j                             |	|
¬¦  «        j        }t          |d¦  «        }t          |d¦  «        }| 
                    d¦  «        d	         | 
                    d¦  «        d	         k    rÉt          |d
¦  «        }|                     d¦  «        }d|i}d| j        i}| j                             |||¬¦  «        j        }|                     d¦  «        D ]_}|                     d¦  «        }d„ |D ¦   «         }||vr8|                     |                      || t          |d¦  «        ¦  «        ¦  «         Œ`�Œh�Œ‚|S )a  
        List images on Abiquo Repositories

        :keyword location: The location to list images for.
        :type    location: :class:`NodeLocation`

        :return:           list of node image objects
        :rtype:            ``list`` of :class:`NodeImage`
        z-/admin/enterprises/%s/datacenterrepositories/r)   r*   ÚdatacenterRepositoryri   r%   rh   ú/éÿÿÿÿÚvirtualmachinetemplatesÚhypervisorTypeÚhypervisorTypeNameÚvirtualMachineTemplateÚidc                 ó   — g | ]	}|j         ‘Œ
S r   )r¯   )Ú.0r$   s     r!   ú
<listcomp>z0AbiquoNodeDriver.list_images.<locals>.<listcomp>Ð  s   € Ð<Ð<Ð<¨E˜uœxÐ<Ð<Ð<r"   r(   )ro   ÚDCRS_MIME_TYPEr1   r2   r3   rq   rš   rl   r†   r   ÚsplitrR   ÚVMTPLS_MIME_TYPEr�   Ú_to_nodeimage)r   r%   Úenterprise_idr„   Ú	repos_hdrÚreposÚimagesÚreporŸ   r‹   rŒ   r}   Údc_link_vdcÚdc_link_repoÚurl_templatesÚhypervisor_typerg   r+   Ú	templatesÚtemplÚid_templateÚidss                         r!   Úlist_imageszAbiquoNodeDriver.list_images¦  s  € ð ×/Ò/Ñ1Ô1ˆØ=ÀÑOˆØ˜tÔ2Ð3ˆ	Ø”×'Ò'¨°YÐ'Ñ?Ô?ÔFˆàˆà—M’MÐ"8Ñ9Ô9ð 	cñ 	cˆDð ×*Ò*¨8Ñ4Ô4ð cñ c�àœ?Ô0°Ô=¸cÔB�Ø# TÔ%7Ð8�Øœ×/Ò/°À'Ð/ÑJÔJÔQ�Ý& u¨jÑ9Ô9�Ý'¨¨lÑ;Ô;�à×$Ò$ SÑ)Ô)¨"Ô-°×1CÒ1CÀCÑ1HÔ1HÈÔ1LÒLÐLå$,¨TÐ3LÑ$MÔ$M�MØ&+§n¢nÐ5EÑ&FÔ&F�OØ2°OÐD�FØ'¨Ô)>Ð?�GØ $¤× 7Ò 7Ø% v°wð !8ñ !ô !äð ð "+×!2Ò!2Ð3KÑ!LÔ!Lð cð c˜à&+§n¢n°TÑ&:Ô&:˜Ø<Ð<°VÐ<Ñ<Ô<˜à&¨cÐ1Ð1Ø"ŸMšM¨$×*<Ò*<¸UÀDÍ(ÐSWÐY_ÑJ`ÔJ`Ñ*aÔ*aÑbÔbÐbøùñ1cð4 ˆr"   c                 ód   — t          | j        j        d                              ¦   «         ¦  «        S )zß
        Return list of locations where the user has access to.

        :return: the list of :class:`NodeLocation` available for the current
                 user
        :rtype:  ``list`` of :class:`NodeLocation`
        ri   )Úlistr1   rl   Úkeys©r   s    r!   r…   zAbiquoNodeDriver.list_locations×  s(   € õ �D”OÔ)¨+Ô6×;Ò;Ñ=Ô=Ñ>Ô>Ð>r"   c                 ón   — g }|                       |¦  «        D ]}|                     |j        ¦  «         Œ|S )zñ
        List all nodes.

        :param location: Filter the groups by location (optional)
        :type  location: a :class:`NodeLocation` instance.

        :return:  List of node objects
        :rtype: ``list`` of :class:`Node`
        )r¦   Úextendr£   )r   r%   r£   r8   s       r!   Ú
list_nodeszAbiquoNodeDriver.list_nodesâ  sB   € ð ˆà×(Ò(¨Ñ2Ô2ð 	&ð 	&ˆEØ�LŠL˜œÑ%Ô%Ð%Ð%àˆr"   c                 ó®   — t          dddddd| ¬¦  «        t          ddd	d
dd| ¬¦  «        t          dddddd| ¬¦  «        t          dddddd| ¬¦  «        gS )aF  
        List sizes on a provider.

        Abiquo does not work with sizes. However, this method
        returns a list of predefined ones (copied from :class:`DummyNodeDriver`
        but without price neither bandwidth) to help the users to create their
        own.

        If you call the method :class:`AbiquoNodeDriver.create_node` with the
        size informed, it will just override the 'ram' value of the 'image'
        template. So it is no too much useful work with sizes...

        :return: The list of sizes
        :rtype:  ``list`` of :class:`NodeSizes`
        é   ÚSmallé€   é   N)r¯   r&   ÚramÚdiskÚ	bandwidthÚpriceÚdriveré   ÚMediumi   é   é   ÚBigi   é    zXXL Bigi    )r   ©r   r%   s     r!   Ú
list_sizeszAbiquoNodeDriver.list_sizesó  s°   € õ$ ØØØØØØØðñ ô õ ØØØØØØØðñ ô õ ØØØØØØØðñ ô õ ØØØØØØØðñ ô ð9%
ð %	
r"   c                 ó–   — |j         d         dz   }d| j        i}| j                             |d|¬¦  «        }|                     ¦   «         S )zÎ
        Reboot a node.

        :param node: The node to be rebooted
        :type node: :class:`Node`

        :return: True if the reboot was successful, otherwise False
        :rtype: ``bool``
        r=   z/action/resetr)   rJ   )rL   rM   r+   )rQ   rV   r1   rX   rY   )r   rZ   Ú
reboot_uriÚ
reboot_hdrr\   s        r!   Úreboot_nodezAbiquoNodeDriver.reboot_node+  sQ   € ð ”Z Ô)¨OÑ;ˆ
Ø Ô 1Ð2ˆ
ØŒo×+Ò+°:ÀfÐV`Ð+ÑaÔaˆà× Ò Ñ"Ô"Ð"r"   c                 ó   — d| j         iS )a  
        Set the endpoint as an extra :class:`AbiquoConnection` argument.

        According to Connection code, the "url" argument should be
        parsed properly to connection.

        :return: ``dict`` of :class:`AbiquoConnection` input arguments
        Úurl)r   rÈ   s    r!   Ú_ex_connection_class_kwargsz,AbiquoNodeDriver._ex_connection_class_kwargs?  s   € ð �t”}Ð%Ð%r"   c                 óB  — t          j        d¦  «        }t          j        |d¦  «        }d|_        | j        | j        dœ}t          |d¦  «        }| j                             |dt          |¦  «        |¬¦  «        }| 
                    ¦   «         st          d| ¦  «        ‚d	S )
z7
        Asynchronous call to create the node.
        rE   ÚforceEnterpriseSoftLimitsrG   rI   ÚdeployrJ   rK   zCould not run the nodeN)r   rS   rT   rU   rV   rW   r   r1   rX   r   rY   r   )r   r[   r]   Úforce_deployr+   Úlink_deployr\   s          r!   r/   zAbiquoNodeDriver._deploy_remoteK  s³   € õ ”*Ð1Ñ2Ô2ˆÝ”} WÐ.IÑJÔJˆØ"ˆÔð "Ô.ÀÔ@VÐWÐWˆÝ˜t XÑ.Ô.ˆØŒo×+Ò+Ø vµH¸WÑ4EÔ4EÈwð ,ñ 
ô 
ˆð × Ò Ñ"Ô"ð 	@ÝÐ 8¸$Ñ?Ô?Ð?ð	@ð 	@r"   c                 ó¤   — |                      d¦  «        }|                      d¦  «        }|                      d¦  «        }t          ||||¦  «        S )z<
        Generates the :class:`NodeLocation` class.
        r¯   r&   )rR   r	   )r   rŸ   r|   rÕ   Ú
identifierr&   Úcountrys          r!   Ú_to_locationzAbiquoNodeDriver._to_locationa  sK   € ð —\’\ $Ñ'Ô'ˆ
Ø�|Š|˜FÑ#Ô#ˆØ—+’+˜fÑ%Ô%ˆå˜J¨¨g°vÑ>Ô>Ð>r"   c           
      óÄ  — |                      d¦  «        }|                      d¦  «        }t          j        |                      d¦  «                 }t          |d¦  «        }d| j        i}| j                             ||¬¦  «        j        }t          |d¦  «        }	|                      || |	¦  «        }
g }g }d| j	        i}| j                             t          |d¦  «        |¬¦  «        j        }| 
                    d	¦  «        D ]q}|                      d
¦  «        }| 
                    d¦  «        D ]D}|j        d         }|dk    r|                     |¦  «         Œ+|dv r|                     |¦  «         ŒEŒrdt          |d¦  «        i}|                     d¦  «        �0|                      d¦  «        |d<   |                      d¦  «        |d<   t          |||||||
|¬¦  «        S )z4
        Generates the :class:`Node` class.
        r¯   Úlabelr>   Úvirtualmachinetemplater)   r*   ÚdatacenterrepositoryÚnicsÚnicÚipÚlinkÚrelÚprivatenetwork)ÚpublicnetworkÚexternalnetworkÚunmanagednetworkr=   r(   ÚvdrpIpNÚvdrpIPÚvdrp_ipÚvdrpPortÚ	vdrp_port)r$   rQ   )rR   r
   ÚNODE_STATE_MAPr   ÚVMTPL_MIME_TYPEr1   r2   r3   r¶   ÚNICS_MIME_TYPErq   Úattribr�   Úfindr   )r   r9   rÕ   rë   r&   r>   Ú
link_imageÚlink_hdrÚimage_elementÚ	repo_linkr$   Úprivate_ipsÚ
public_ipsÚnics_hdrÚnics_elementró   rô   rõ   rö   rQ   s                       r!   r4   zAbiquoNodeDriver._to_nodek  s  € ð —[’[ Ñ&Ô&ˆ
Ø�{Š{˜7Ñ#Ô#ˆÝÔ-¨b¯kªk¸'Ñ.BÔ.BÔCˆå˜bÐ":Ñ;Ô;ˆ
Ø˜dÔ2Ð3ˆØœ×/Ò/°
ÀHÐ/ÑMÔMÔTˆÝ˜]Ð,BÑCÔCˆ	Ø×"Ò" =°$¸	ÑBÔBˆð ˆØˆ
Ø˜dÔ1Ð2ˆØ”×.Ò.­x¸¸FÑ/CÔ/CÈXÐ.ÑVÔVÔ]ˆà×'Ò'¨Ñ.Ô.ð 		*ð 		*ˆCØ—’˜dÑ#Ô#ˆBàŸš FÑ+Ô+ð *ð *�Ø”k %Ô(�àÐ*Ò*Ð*Ø×&Ò& rÑ*Ô*Ð*Ð*ØÐTÐTÐTØ×%Ò% bÑ)Ô)Ð)øð*ð �8 B¨Ñ/Ô/Ð0ˆà�7Š7�8ÑÔÐ(Ø!Ÿ{š{¨8Ñ4Ô4ˆE�)ÑØ!#§¢¨ZÑ!8Ô!8ˆE�+ÑåØØØØØØØØð	
ñ 	
ô 	
ð 		
r"   c                 óÐ   — |                      d¦  «        }|                      d¦  «        }t          |d¦  «        }|                      d¦  «        }|||dœ}t          ||||¦  «        S )z9
        Generates the :class:`NodeImage` class.
        r¯   r&   r(   Ú
hdRequired)r»   rã   Ú
hdrequired)rR   r   r   )	r   ÚtemplaterÕ   r»   rë   r&   rã   ÚhdreqdrQ   s	            r!   r¶   zAbiquoNodeDriver._to_nodeimage›  so   € ð ×&Ò& tÑ,Ô,ˆ
Ø× Ò  Ñ(Ô(ˆÝ�x Ñ(Ô(ˆØ×"Ò" <Ñ0Ô0ˆØ c¸Ð@Ð@ˆå˜ T¨6°5Ñ9Ô9Ð9r"   c              #   óN   K  — |�|V — dS |                       ¦   «         E d{V —† dS )z7
        Returns the locations as a generator.
        N)r…   rÜ   s     r!   rš   zAbiquoNodeDriver._get_locations§  sE   è è € ð
 ÐØˆNˆNˆNˆNˆNà×*Ò*Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,r"   c                 óL   — | j         j        d                              d¦  «        S )zI
        Returns the identifier of the logged user's enterprise.
        re   r¯   )r1   rl   rR   rÈ   s    r!   ro   z#AbiquoNodeDriver._get_enterprise_id±  s"   € ð
 ŒÔ$ \Ô2×;Ò;¸DÑAÔAÐAr"   c                 óÀ  — |sd}t          || ¦  «        ‚|r%||                      ¦   «         vrt          d¦  «        ‚d}d}|                      |¦  «        D ]r}| j        j        d         |         }d| j        i}| j                             ||¬¦  «        j        }	|                      |¦  «        D ]}
|
j	        |j	        k    r|	}|} nŒŒs|€d}t          || ¦  «        ‚||fS )z¦
        Search for a location where to create the node.

        Based on 'create_node' **kwargs argument, decide in which
        location will be created.
        z'image' parameter is mandatoryr€   Nri   r)   r*   z)The image can not be used in any location)
r   r…   rš   r1   rl   r†   r2   r3   rÄ   r¯   )r   r$   r%   r”   r7   Ú
target_locÚcandidate_locr‹   rŒ   r}   Úimgs              r!   r,   z-AbiquoNodeDriver._define_create_node_location¸  s  € ð ð 	-Ø4ˆEÝ  tÑ,Ô,Ð,ð ð 	?Ø˜t×2Ò2Ñ4Ô4Ð4Ð4Ý#Ð$=Ñ>Ô>Ð>ð ˆØˆ
à!×0Ò0°Ñ:Ô:ð 
	ð 
	ˆMØ”Ô,¨[Ô9¸-ÔHˆHØ Ô!3Ð4ˆGØ”O×+Ò+¨H¸gÐ+ÑFÔFÔMˆEà×'Ò'¨Ñ6Ô6ð ð �Ø”6˜UœXÒ%Ð%Ø�CØ!.�Jà�Eð	 &øð ˆ;Ø?ˆEÝ  tÑ,Ô,Ð,à�JˆÐr"   c                 óš  — |st           j        }t          |d¦  «        }d| j        i}| j                             ||¬¦  «        j        }d}|                     d¦  «        D ]R}|                     d¦  «        |k    r7t          |d¦  «        }	t          | |                     d¦  «        |	¬¦  «        c S ŒS|€|  	                    ||¦  «        S dS )	zˆ
        Search for a group where to create the node.

        If we can not find any group, create it into argument 'location'
        r�   r)   r*   Nr   r&   r(   rƒ   )
rˆ   ÚDEFAULT_GROUP_NAMEr   r›   r1   r2   r3   rq   rR   r�   )
r   r6   r7   Ú
group_nameÚgroups_linkÚ
groups_hdrÚvapps_elementÚtarget_groupr‰   rŽ   s
             r!   r-   z*AbiquoNodeDriver._define_create_node_groupâ  sí   € ð ð 	6Ý"Ô5ˆJõ ˜wÐ(;Ñ<Ô<ˆØ Ô 4Ð5ˆ
Øœ×/Ò/°ÀZÐ/ÑPÔPÔWˆØˆà!×)Ò)Ð*<Ñ=Ô=ð 	Lð 	LˆDØ�}Š}˜VÑ$Ô$¨
Ò2Ð2Ý# D¨&Ñ1Ô1�å   t§}¢}°VÑ'<Ô'<À(ÐKÑKÔKÐKÐKÐKð 3ð ÐØ×'Ò'¨
°CÑ8Ô8Ð8ð  Ðr"   c                 ó&  — t          j        d¦  «        }|rt          j        |d¦  «        }||_        | j        d|j        d         dœ}t          j        |d|¬¦  «         | j        | j        dœ}|r.t          j        |d	¦  «        }	t          |j        ¦  «        |	_        |j	        d
z   }
| j
                             |
t          |¦  «        |d¬¦  «        j        }t          |d¦  «        }d| j        i}| j
                             ||¬¦  «        j        S )z½
        Defines the node before to create.

        In Abiquo, you first need to 'register' or 'define' the node in
        the API before to create it into the target hypervisor.
        r™   rï   rð   rã   )Útyperö   Úhrefrõ   )r  rI   rÑ   z/virtualmachinesrJ   r‚   r(   r)   r*   )r   rS   rT   rU   r  rQ   r0   ÚstrrÑ   r„   r1   r2   r   r3   r   )r   r8   r&   r'   r$   r9   Úvmnamer  r+   rÑ   Ú
nodes_linkr:   s               r!   r.   z)AbiquoNodeDriver._define_create_node_nodeÿ  s#  € õ ŒZÐ(Ñ)Ô)ˆàð 	Ý”] 2 wÑ/Ô/ˆFØˆFŒKàÔ(Ø+Ø”K Ô&ð
ð 
ˆõ
 	Œ�b˜&¨Ð0Ñ0Ô0Ð0Ø!Ô0À$ÔBUÐVÐVˆàð 	%å”-  EÑ*Ô*ˆCÝ˜4œ8‘}”}ˆCŒHð ”YÐ!3Ñ3ˆ
ØŒ_×$Ò$Ø�X b™\œ\°7À6ð %ñ 
ô 
ä
ð 	õ ˜2˜vÑ&Ô&ˆØ˜TÔ0Ð1ˆàŒ×&Ò& w¸Ð&Ñ@Ô@ÔGÐGr"   )NNNN)N)NNN)5Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚABIQUOr   r&   Úwebsiter   ÚconnectionClsÚtimeoutrœ   r0   r›   r‡   rW   rk   rm   rn   r†   rp   rµ   r  r  r³   ÚDCR_MIME_TYPErV   ÚGIGABYTEr   r;   r`   rb   r   r�   r–   r¦   rÄ   r…   rË   rÝ   rá   rä   r/   rí   r4   r¶   rš   ro   r,   r-   r.   Ú__classcell__)r    s   @r!   r   r      sR  ø€ € € € € ðð ð Œ?€DØ€DØ&€GØ$€MØ€Gð C€OØ@€NØD€OØB€NØGÐØ6€NØ;€MØD€NØB€MØ<€MØKÐØI€OØ6€NØH€NØE€MØ?€Lð €Hð!ð !ð !ð !ð !ð"?'ð ?'ð ?'ð ?'ðB4ð 4ð 4ðl*)ð *)ð *)ðX1Rð 1Rð 1Rðf%Dð %Dð %Dð %DðN8ð 8ð 8ðtð ð ð ð@/ð /ð /ð /ðb	?ð 	?ð 	?ðð ð ð ð"6
ð 6
ð 6
ð 6
ðp#ð #ð #ð(
&ð 
&ð 
&ð@ð @ð @ð,?ð ?ð ?ð.
ð .
ð .
ð`
:ð 
:ð 
:ð-ð -ð -ð -ðBð Bð Bð(ð (ð (ðT9ð 9ð 9ð 9ð:!Hð !Hð !Hð !Hð !Hð !Hð !Hð !Hr"   r   c                   ó0   — e Zd ZdZdZeg dfd„Zd„ Zd„ ZdS )rˆ   aë  
    Group of virtual machines that can be managed together

    All :class:`Node`s in Abiquo must be defined inside a Virtual Appliance.
    We offer a way to handle virtual appliances (called NodeGroup to
    maintain some kind of name conventions here) inside the
    :class:`AbiquoNodeDriver` without breaking compatibility of the rest of
    libcloud API.

    If the user does not want to handle groups, all the virtual machines
    will be created inside a group named 'libcloud'
    ÚlibcloudÚ c                 ó>   — || _         || _        || _        || _        dS )z0
        Initialize a new group object.
        N)rÕ   r&   r£   r„   )r   rÕ   r&   r£   r„   s        r!   r   zNodeGroup.__init__3  s$   € ð ˆŒØˆŒ	ØˆŒ
ØˆŒˆˆr"   c           	      ót   — d| j         ›dd                     t          t          | j        ¦  «        ¦  «        ›d�S )Nz<NodeGroup: name=z	, nodes=[ú,z] >)r&   ÚjoinÚmapr"  r£   rÈ   s    r!   Ú__repr__zNodeGroup.__repr__<  s8   € € àŒIˆIˆIØ�HŠH•S�˜dœjÑ)Ô)Ñ*Ô*Ð*Ð*ð
ð 	
r"   c                 ó6   — | j                              | ¦  «        S )zc
        Destroys the group delegating the execution to
        :class:`AbiquoNodeDriver`.
        )rÕ   r–   rÈ   s    r!   ÚdestroyzNodeGroup.destroyB  s   € ð Œ{×+Ò+¨DÑ1Ô1Ð1r"   N)r%  r&  r'  r(  r  r   r8  r:  r   r"   r!   rˆ   rˆ   #  s_   € € € € € ðð ð $Ðà$6¸bÀbð ð ð ð ð
ð 
ð 
ð2ð 2ð 2ð 2ð 2r"   rˆ   N)r(  Úlibcloud.utils.py3r   r   Úlibcloud.compute.baser   r   r   r   r	   Úlibcloud.common.abiquor
   r   r   Úlibcloud.compute.typesr   r   r   rˆ   r   r"   r!   ú<module>r?     sö   ððð ð ,Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ø UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UÐ UØ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ :Ð :Ð :Ð :Ð :Ð :Ð :Ð :ðBHð BHð BHð BHð BH�zñ BHô BHð BHðJ%2ð %2ð %2ð %2ð %2ñ %2ô %2ð %2ð %2ð %2r"   