ó
½-'Nc           @   sŠ   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d	 „  Z d
 „  Z d S(   iÿÿÿÿN(   t   succeed(   t   gather_results(   t   ManagerPlugint   EucalyptusInfoc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sD   Provide utility methods to get information about a Eucalyptus cloud.c         C   s   | |  _  d  S(   N(   t   _tools(   t   selft   tools(    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   __init__   s    c         C   s   t  |  j j d d g ƒ ƒ S(   s	  Get information about the version of Eucalyptus in use.

        A string matching the following format is returned::

          Eucalyptus version: 1.6.2

        @return: A L{Deferred} firing with the string output of the
           C{--version} command.
        t	   euca_confs	   --version(   R    R   t   _runTool(   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_version_info   s    
c         C   s   t  |  j j d d g ƒ ƒ S(   s%  Get information about the registered walruses (S3).

        A string matching the following format is returned::

          registered walruses:
            walrus 10.0.1.113

        @return: A L{Deferred} firing with the string output of the
            C{--list-walruses} command.
        R   s   --list-walruses(   R    R   R	   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_walrus_info   s    c         C   s   t  |  j j d d g ƒ ƒ S(   s.  Get information about the registered cluster controllers..

        A string matching the following format is returned::

          registered clusters:
            dynamite 10.0.1.113

        @return: A L{Deferred} firing with the string output of the
            C{--list-clusters} command.
        R   s   --list-clusters(   R    R   R	   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_cluster_controller_info)   s    c         C   s   t  |  j j d d g ƒ ƒ S(   s9  Get information about the registered storage controllers (EBS).

        A string matching the following format is returned::

          registered storage controllers:
            dynamite 10.0.1.113

        @return: A L{Deferred} firing with the string output of the
            C{--list-scs} command.
        R   s
   --list-scs(   R    R   R	   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_storage_controller_info6   s    c         C   s   t  |  j j d d g ƒ ƒ S(   sÅ  Get information about the registered node controller.

        A string matching the following format is returned::

          registered nodes:
            10.1.1.71  canyonedge   i-2DC5056F i-5DE5176D
            10.1.1.72  canyonedge
            10.1.1.73  canyonedge
            10.1.1.74  canyonedge
            10.1.1.75  canyonedge

        @return: A L{Deferred} firing with the string output of the
            C{--list-nodes} command.
        R   s   --list-nodes(   R    R   R	   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_node_controller_infoC   s    c         C   s   t  |  j j d d g ƒ ƒ S(   sÉ  Get information about the capacity of the cloud.

        A string matching the following format is returned::

          AVAILABILITYZONE	bruterobe	10.0.1.113
          AVAILABILITYZONE	|- vm types	free / max   cpu   ram  disk
          AVAILABILITYZONE	|- m1.small	0008 / 0008   1    128     2
          AVAILABILITYZONE	|- c1.medium	0008 / 0008   1    256     5
          AVAILABILITYZONE	|- m1.large	0004 / 0004   2    512    10
          AVAILABILITYZONE	|- m1.xlarge	0004 / 0004   2   1024    20
          AVAILABILITYZONE	|- c1.xlarge	0002 / 0002   4   2048    20

        @return: A L{Deferred} firing with the string output of the
            C{euca-describe-availability-zones verbose} command.
        s    euca-describe-availability-zonest   verbose(   R    R   R	   (   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   get_capacity_infoT   s    (
   t   __name__t
   __module__t   __doc__R   R
   R   R   R   R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR   
   s   						t
   Eucalyptusc           B   sY   e  Z d  Z d Z d Z d Z d Z d d d „ Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   s+   A management plugin for a Eucalyptus cloud.s   eucalyptus-managers   eucalyptus-infos   eucalyptus-info-errori   i<   c         C   sh   t  t |  ƒ j ƒ  | |  _ |  j d  k r7 t |  _ n  | |  _ |  j d  k r[ t |  _ n  t |  _	 d  S(   N(
   t   superR   R   t   _service_hub_factoryt   Nonet   start_service_hubt   _eucalyptus_info_factoryt   get_eucalyptus_infot   Truet   enabled(   R   t   service_hub_factoryt   eucalyptus_info_factory(    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR   p   s    		c         C   s)   |  j  s d S|  j j j |  j |  j ƒ S(   s»  Run the plugin.

        A C{ServiceHub} runs services that provide information about
        Eucalyptus.  If a service hub can't be created the plugin assumes that
        Eucalyptus is not installed.  In such cases a message is written to
        the log and the plugin is disabled.

        @return: A C{Deferred} that will fire when the plugin has finished
            running, unless it's disabled in which case None is returned.
        N(   R   t   registryt   brokert   call_if_acceptedt   message_typet   send_message(   R   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   runz   s    	c            sÛ   |  j  j j } y |  j | ƒ ‰  Wn= t k
 ra } t j | ƒ t |  _ t j	 d |  j
 ƒ nv Xd d l m } ˆ  j | d ƒ ƒ } | j |  j ƒ | j |  j ƒ | j |  j  j j ƒ | j ‡  f d †  ƒ | Sd  S(   Ns;   Couldn't start service hub.  '%s' plugin has been disabled.iÿÿÿÿ(   t   GetEucaInfot   adminc            s
   ˆ  j  ƒ  S(   N(   t   stop(   t   ignored(   t   service_hub(    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   <lambda>š   s    (   R   t   configt	   data_pathR   t	   Exceptiont   loggingt   debugt   FalseR   t   infoR"   t   imagestore.eucaserviceR%   t   addTaskt   addCallbackt   _get_messaget
   addErrbackt   _get_error_messageR    R#   t   addBoth(   R   R,   t   eR%   t   deferred(    (   R)   s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR#   Š   s    		c            sv   g  } ˆ  j  ˆ ƒ } | j ƒ  | j ƒ  | j ƒ  | j ƒ  | j ƒ  | j ƒ  g } ‡  ‡ f d †  } t | ƒ j | ƒ S(   s#  Create a message with information about a Eucalyptus cloud.

        @param credentials: A C{EucaInfo} instance containing credentials for
            the Eucalyptus cloud being managed.
        @return: A message with information about Eucalyptus to send to the
            server.
        c   	         s³   |  \ } } } } } } | j  ƒ  d } i ˆ j d 6ˆ j d 6ˆ j d 6ˆ j d 6ˆ j d 6ˆ j d 6ˆ j d 6| d	 6} i ˆ  j d
 6| d 6| d 6| d 6| d 6| d 6| d 6S(   Niÿÿÿÿt
   access_keyt
   secret_keyt   private_key_patht   certificate_patht   cloud_certificate_patht
   url_for_s3t   url_for_ec2t   eucalyptus_versiont   typet
   basic_infot   walrus_infot   cluster_controller_infot   storage_controller_infot   node_controller_infot   capacity_info(	   t   splitt	   accessKeyt	   secretKeyt   privateKeyPatht   certificatePatht   cloudCertificatePatht   urlForS3t	   urlForEC2R"   (	   t   resultt   version_infoRE   RF   RG   RH   RI   t   versiont   data(   R   t   credentials(    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   create_message¯   s     






(	   R   R
   R   R   R   R   R   R   R4   (   R   RV   t   deferred_listR1   RW   (    (   R   RV   s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR5      s    					c         C   sL   d d l  m } | j | ƒ r+ t |  _ n  | j ƒ  } i |  j d 6| d 6S(   sï   Create an error message.

        @param failure: A C{Failure} instance containing information about an
            error that occurred while trying to retrieve credentials.
        @return: An error message to send to the server.
        iÿÿÿÿ(   t   EucaToolsErrorRC   t   error(   R2   RY   t   checkR0   R   t   getBriefTracebackt   error_message_type(   R   t   failureRY   RZ   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR7   Ä   s
    i„  N(   R   R   R   t   plugin_nameR"   R]   t   run_intervalR   R   R$   R#   R5   R7   (    (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR   h   s   
			'c         C   s”   d d l  m } d d l m } d d l m } t j j |  d ƒ } t j j	 | ƒ sg t j
 | ƒ n  | ƒ  } | j | | | ƒ ƒ | j ƒ  | S(   sú   Create and start a C{ServiceHub} to use when getting credentials.

    @param data_path: The path to Landscape's data directory.
    @return: A running C{ServiceHub} with a C{EucaService} service that
        can be used to retrieve credentials.
    iÿÿÿÿ(   t   reactor(   t
   ServiceHub(   t   EucaServicet
   eucalyptus(   t   twisted.internetRa   t   imagestore.lib.serviceRb   R2   Rc   t   ost   patht   joint   existst   makedirst
   addServicet   start(   R,   Ra   Rb   Rc   t	   base_pathR)   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR   Ó   s    	
c         C   s    d d l  m } t | |  ƒ ƒ S(   s   Create a L{EucalyptusInfo} instance.

    @param credentials: An C{imagestore.eucaservice.EucaInfo} instance.
    @return: A L{EucalyptusInfo} instance.
    iÿÿÿÿ(   t	   EucaTools(   R2   Ro   R   (   RV   Ro   (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyR   ç   s    (   Rg   R.   t   twisted.internet.deferR    t   landscape.lib.twisted_utilR   t   landscape.manager.pluginR   t   objectR   R   R   R   (    (    (    s@   /usr/lib/python2.7/dist-packages/landscape/manager/eucalyptus.pyt   <module>   s   ^k	