B
    `                 @   sr   d dl mZ d dlmZmZmZmZmZmZm	Z	 G dd deZ
G dd dZG dd deZG d	d
 d
eZdS )    )UnexpectedResponseError)BaseDerivedBasePropertyRegionTypeInstanceMappedObjectc               @   s"   e Zd ZdZdZdeddiZdS )KubeVersionzO
    A KubeVersion is a version of Kubernetes that can be deployed on LKE.
    z/lke/versions/{id}idT)
identifierN)__name__
__module____qualname____doc__api_endpointr   
properties r   r   F/home/dcms/DCMS/lib/python3.7/site-packages/linode_api4/objects/lke.pyr
      s   r
   c               @   s   e Zd ZdZdd ZdS )LKENodePoolNodez
    AN LKE Node Pool Node is a helper class that is used to populate the "nodes"
    array of an LKE Node Pool, and set up an automatic relationship with the
    Linode Instance the Node represented.
    c             C   s6   | d| _| d| _t|| j| _| d| _dS )z+
        Creates this NodePoolNode
        r   instance_idstatusN)getr   r   r   instancer   )selfclientjsonr   r   r   __init__   s    zLKENodePoolNode.__init__N)r   r   r   r   r   r   r   r   r   r      s   r   c                   sf   e Zd ZdZdZdZdZeddeddeede eddedd	d
Z	 fddZ
dd Z  ZS )LKENodePoolze
    An LKE Node Pool describes a pool of Linode Instances that exist within an
    LKE Cluster.
    z%/lke/clusters/{cluster_id}/pools/{id}poolsZ	linode_idT)r   )slug_relationship)mutable)Zvolatile)r   Z
cluster_idtypediskscountnodesc                s6   |dk	r& fdd|d D }||d< t  | dS )zF
        Parse Nodes into more useful LKENodePoolNode objects
        Nc                s   g | ]}t  j|qS r   )r   _client).0c)r   r   r   
<listcomp>?   s    z)LKENodePool._populate.<locals>.<listcomp>r%   )super	_populate)r   r   Z	new_nodes)	__class__)r   r   r+   9   s    zLKENodePool._populatec             C   s$   | j jdtj| d |   dS )z
        Deleted and recreates all Linodes in this Node Pool in a rolling fashion.
        Completing this operation may take several minutes.  This operation will
        cause all local data on Linode Instances in this pool to be lost.
        z
{}/recycle)modelN)r&   postformatr   r   
invalidate)r   r   r   r   recycleE   s    zLKENodePool.recycle)r   r   r   r   r   Zderived_url_pathZ	parent_idr   r   r   r+   r1   __classcell__r   r   )r,   r   r   '   s   r   c            
   @   sz   e Zd ZdZdZeddeddeddeddeddeedeedeedd	Z	e
d
d Ze
dd Zdd ZdS )
LKEClusterzW
    An LKE Cluster is a single k8s cluster deployed via Linode Kubernetes Engine.
    z/lke/clusters/{id}T)r   )Zis_datetime)r!   )r    )Zderived_class)r   createdlabeltagsupdatedZregionZk8s_versionr   c             C   s<   t | ds6| jjdtj| d}dd |d D | _| jS )z;
        A list of API Endpoints for this Cluster.
        _api_endpointsz{}/api-endpoints)r-   c             S   s   g | ]}t f |qS r   )r	   )r'   r(   r   r   r   r)   k   s    z,LKECluster.api_endpoints.<locals>.<listcomp>data)hasattrr&   r   r/   r3   r   r8   )r   resultsr   r   r   api_endpoints`   s    
zLKECluster.api_endpointsc             C   s2   t | ds,| jjdtj| d}|d | _| jS )a  
        The administrative Kubernetes Config used to access this cluster, encoded
        in base64.  Note that this config contains sensitive credentials to your
        cluster.

        To convert this config into a readable form, use python's `base64` module::

           import base64

           config = my_cluster.kubeconfig
           yaml_config = base64.b64decode(config)

           # write this config out to disk
           with open("/path/to/target/kubeconfig.yaml", "w") as f:
               f.write(yaml_config.decode())

        It may take a few minutes for a config to be ready when creating a new
        cluster; during that time this request may fail.
        _kubeconfigz{}/kubeconfig)r-   
kubeconfig)r:   r&   r   r/   r3   r   r=   )r   resultr   r   r   r>   o   s    

zLKECluster.kubeconfigc             K   s`   ||d}| | | jjdtj| |d}|   d|krJtd|dt| j|d | j	|S )a  
        Creates a new :any:`LKENodePool` for this cluster.

        :param node_type: The type of nodes to create in this pool.
        :type node_type: :any:`Type` or str
        :param node_count: The number of nodes to create in this pool.
        :type node_count: int
        :param kwargs: Any other arguments to pass to the API.  See the API docs
                       for possible values.

        :returns: The new Node Pool
        :rtype: LKENodePool
        )r"   r$   z{}/pools)r-   r9   r   z'Unexpected response creating node pool!)r   )
updater&   r.   r/   r3   r   r0   r   r   r   )r   Z	node_typeZ
node_countkwargsparamsr?   r   r   r   node_pool_create   s    
zLKECluster.node_pool_createN)r   r   r   r   r   r   r   r
   r   r   propertyr<   r>   rC   r   r   r   r   r3   O   s   r3   N)Zlinode_api4.errorsr   Zlinode_api4.objectsr   r   r   r   r   r   r	   r
   r   r   r3   r   r   r   r   <module>   s
   $(