U
    3dDy                     @   sX   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 G dd deZdS )	    N)json)AWSQueryConnection)
RegionInfo)JSONResponseError)
exceptionsc                       s  e Zd ZdZdZdZdZeZe	j
e	jdZ fddZdd	 Zd5ddZdd Zd6ddZdd Zd7ddZd8ddZdd Zd9ddZd:ddZd;ddZd<dd Zd=d!d"Zd>d#d$Zd?d%d&Zd'd( Zd@d)d*ZdAd+d,ZdBd-d.Z dCd/d0Z!dDd1d2Z"d3d4 Z#  Z$S )EEC2ContainerServiceConnectionaz  
    Amazon EC2 Container Service (Amazon ECS) is a highly scalable,
    fast, container management service that makes it easy to run,
    stop, and manage Docker containers on a cluster of Amazon EC2
    instances. Amazon ECS lets you launch and stop container-enabled
    applications with simple API calls, allows you to get the state of
    your cluster from a centralized service, and gives you access to
    many familiar Amazon EC2 features like security groups, Amazon EBS
    volumes, and IAM roles.

    You can use Amazon ECS to schedule the placement of containers
    across your cluster based on your resource needs, isolation
    policies, and availability requirements. Amazon EC2 Container
    Service eliminates the need for you to operate your own cluster
    management and configuration management systems or worry about
    scaling your management infrastructure.
    z
2014-11-13z	us-east-1zecs.us-east-1.amazonaws.com)ServerExceptionClientExceptionc                    sZ   | dd }|s t| | j| j}d|ks4|d d kr>|j|d< tt| jf | || _d S )Nregionhost)	popr   DefaultRegionNameDefaultRegionEndpointZendpointsuperr   __init__r
   )selfkwargsr
   	__class__ C/tmp/pip-unpacked-wheel-d7dsrkjd/boto/ec2containerservice/layer1.pyr   <   s    
z&EC2ContainerServiceConnection.__init__c                 C   s   dgS )Nzhmac-v4r   )r   r   r   r   _required_auth_capabilityH   s    z7EC2ContainerServiceConnection._required_auth_capabilityNc                 C   s&   i }|dk	r||d< | j ddd|dS )a  
        Creates a new Amazon ECS cluster. By default, your account
        will receive a `default` cluster when you launch your first
        container instance. However, you can create your own cluster
        with a unique name with the `CreateCluster` action.

        During the preview, each account is limited to two clusters.

        :type cluster_name: string
        :param cluster_name: The name of your cluster. If you do not specify a
            name for your cluster, you will create a cluster named `default`.

        NZclusterNameZCreateClusterPOST/actionverbpathparams_make_request)r   Zcluster_namer   r   r   r   create_clusterK   s     z,EC2ContainerServiceConnection.create_clusterc                 C   s   d|i}| j ddd|dS )a  
        Deletes the specified cluster. You must deregister all
        container instances from this cluster before you may delete
        it. You can list the container instances in a cluster with
        ListContainerInstances and deregister them with
        DeregisterContainerInstance.

        :type cluster: string
        :param cluster: The cluster you want to delete.

        clusterZDeleteClusterr   r   r   r   )r   r"   r   r   r   r   delete_clustera   s     z,EC2ContainerServiceConnection.delete_clusterc                 C   sB   d|i}|dk	r||d< |dk	r0t | |d< | jddd|dS )	aG  
        Deregisters an Amazon ECS container instance from the
        specified cluster. This instance will no longer be available
        to run tasks.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the container instance you want to
            deregister. If you do not specify a cluster, the default cluster is
            assumed.

        :type container_instance: string
        :param container_instance: The container instance UUID or full Amazon
            Resource Name (ARN) of the container instance you want to
            deregister. The ARN contains the `arn:aws:ecs` namespace, followed
            by the region of the container instance, the AWS account ID of the
            container instance owner, the `container-instance` namespace, and
            then the container instance UUID. For example, arn:aws:ecs: region
            : aws_account_id :container-instance/ container_instance_UUID .

        :type force: boolean
        :param force: Force the deregistration of the container instance. You
            can use the `force` parameter if you have several tasks running on
            a container instance and you don't want to run `StopTask` for each
            task before deregistering the container instance.

        containerInstanceNr"   forceZDeregisterContainerInstancer   r   r   )strlowerr    )r   container_instancer"   r%   r   r   r   r   deregister_container_instances   s     z;EC2ContainerServiceConnection.deregister_container_instancec                 C   s   d|i}| j ddd|dS )a  
        Deregisters the specified task definition. You will no longer
        be able to run tasks from this definition after
        deregistration.

        :type task_definition: string
        :param task_definition: The `family` and `revision` (
            `family:revision`) or full Amazon Resource Name (ARN) of the task
            definition that you want to deregister.

        taskDefinitionZDeregisterTaskDefinitionr   r   r   r   r   task_definitionr   r   r   r   deregister_task_definition   s     z8EC2ContainerServiceConnection.deregister_task_definitionc                 C   s,   i }|dk	r|  ||d | jddd|dS )a&  
        Describes one or more of your clusters.

        :type clusters: list
        :param clusters: A space-separated list of cluster names or full
            cluster Amazon Resource Name (ARN) entries. If you do not specify a
            cluster, the default cluster is assumed.

        Nzclusters.memberZDescribeClustersr   r   r   Zbuild_list_paramsr    )r   Zclustersr   r   r   r   describe_clusters   s    
 z/EC2ContainerServiceConnection.describe_clustersc                 C   s4   i }|  ||d |dk	r"||d< | jddd|dS )a  
        Describes Amazon EC2 Container Service container instances.
        Returns metadata about registered and remaining resources on
        each container instance requested.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the container instances you want to
            describe. If you do not specify a cluster, the default cluster is
            assumed.

        :type container_instances: list
        :param container_instances: A space-separated list of container
            instance UUIDs or full Amazon Resource Name (ARN) entries.

        containerInstances.memberNr"   ZDescribeContainerInstancesr   r   r   r.   )r   container_instancesr"   r   r   r   r   describe_container_instances   s     z:EC2ContainerServiceConnection.describe_container_instancesc                 C   s   d|i}| j ddd|dS )a  
        Describes a task definition.

        :type task_definition: string
        :param task_definition: The `family` and `revision` (
            `family:revision`) or full Amazon Resource Name (ARN) of the task
            definition that you want to describe.

        r*   ZDescribeTaskDefinitionr   r   r   r   r+   r   r   r   describe_task_definition   s    
 z6EC2ContainerServiceConnection.describe_task_definitionc                 C   s4   i }|  ||d |dk	r"||d< | jddd|dS )a  
        Describes a specified task or tasks.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the task you want to describe. If you do not
            specify a cluster, the default cluster is assumed.

        :type tasks: list
        :param tasks: A space-separated list of task UUIDs or full Amazon
            Resource Name (ARN) entries.

        ztasks.memberNr"   ZDescribeTasksr   r   r   r.   )r   Ztasksr"   r   r   r   r   describe_tasks   s     z,EC2ContainerServiceConnection.describe_tasksc                 C   s&   i }|dk	r||d< | j ddd|dS )a(  
        This action is only used by the Amazon EC2 Container Service
        agent, and it is not intended for use outside of the agent.


        Returns an endpoint for the Amazon EC2 Container Service agent
        to poll for updates.

        :type container_instance: string
        :param container_instance: The container instance UUID or full Amazon
            Resource Name (ARN) of the container instance. The ARN contains the
            `arn:aws:ecs` namespace, followed by the region of the container
            instance, the AWS account ID of the container instance owner, the
            `container-instance` namespace, and then the container instance
            UUID. For example, arn:aws:ecs: region : aws_account_id :container-
            instance/ container_instance_UUID .

        Nr$   ZDiscoverPollEndpointr   r   r   r   )r   r(   r   r   r   r   discover_poll_endpoint  s     z4EC2ContainerServiceConnection.discover_poll_endpointc                 C   s6   i }|dk	r||d< |dk	r$||d< | j ddd|dS )a  
        Returns a list of existing clusters.

        :type next_token: string
        :param next_token: The `nextToken` value returned from a previous
            paginated `ListClusters` request where `maxResults` was used and
            the results exceeded the value of that parameter. Pagination
            continues from the end of the previous results that returned the
            `nextToken` value. This value is `null` when there are no more
            results to return.

        :type max_results: integer
        :param max_results: The maximum number of cluster results returned by
            `ListClusters` in paginated output. When this parameter is used,
            `ListClusters` only returns `maxResults` results in a single page
            along with a `nextToken` response element. The remaining results of
            the initial request can be seen by sending another `ListClusters`
            request with the returned `nextToken` value. This value can be
            between 1 and 100. If this parameter is not used, then
            `ListClusters` returns up to 100 results and a `nextToken` value if
            applicable.

        N	nextToken
maxResultsZListClustersr   r   r   r   )r   
next_tokenmax_resultsr   r   r   r   list_clusters!  s     z+EC2ContainerServiceConnection.list_clustersc                 C   sF   i }|dk	r||d< |dk	r$||d< |dk	r4||d< | j ddd|dS )	a  
        Returns a list of container instances in a specified cluster.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the container instances you want to list. If
            you do not specify a cluster, the default cluster is assumed..

        :type next_token: string
        :param next_token: The `nextToken` value returned from a previous
            paginated `ListContainerInstances` request where `maxResults` was
            used and the results exceeded the value of that parameter.
            Pagination continues from the end of the previous results that
            returned the `nextToken` value. This value is `null` when there are
            no more results to return.

        :type max_results: integer
        :param max_results: The maximum number of container instance results
            returned by `ListContainerInstances` in paginated output. When this
            parameter is used, `ListContainerInstances` only returns
            `maxResults` results in a single page along with a `nextToken`
            response element. The remaining results of the initial request can
            be seen by sending another `ListContainerInstances` request with
            the returned `nextToken` value. This value can be between 1 and
            100. If this parameter is not used, then `ListContainerInstances`
            returns up to 100 results and a `nextToken` value if applicable.

        Nr"   r6   r7   ZListContainerInstancesr   r   r   r   )r   r"   r8   r9   r   r   r   r   list_container_instancesC  s     z6EC2ContainerServiceConnection.list_container_instancesc                 C   sF   i }|dk	r||d< |dk	r$||d< |dk	r4||d< | j ddd|dS )	ah  
        Returns a list of task definitions that are registered to your
        account. You can filter the results by family name with the
        `familyPrefix` parameter.

        :type family_prefix: string
        :param family_prefix: The name of the family that you want to filter
            the `ListTaskDefinitions` results with. Specifying a `familyPrefix`
            will limit the listed task definitions to definitions that belong
            to that family.

        :type next_token: string
        :param next_token: The `nextToken` value returned from a previous
            paginated `ListTaskDefinitions` request where `maxResults` was used
            and the results exceeded the value of that parameter. Pagination
            continues from the end of the previous results that returned the
            `nextToken` value. This value is `null` when there are no more
            results to return.

        :type max_results: integer
        :param max_results: The maximum number of task definition results
            returned by `ListTaskDefinitions` in paginated output. When this
            parameter is used, `ListTaskDefinitions` only returns `maxResults`
            results in a single page along with a `nextToken` response element.
            The remaining results of the initial request can be seen by sending
            another `ListTaskDefinitions` request with the returned `nextToken`
            value. This value can be between 1 and 100. If this parameter is
            not used, then `ListTaskDefinitions` returns up to 100 results and
            a `nextToken` value if applicable.

        NZfamilyPrefixr6   r7   ZListTaskDefinitionsr   r   r   r   )r   Zfamily_prefixr8   r9   r   r   r   r   list_task_definitionsm  s    ! z3EC2ContainerServiceConnection.list_task_definitionsc                 C   sf   i }|dk	r||d< |dk	r$||d< |dk	r4||d< |dk	rD||d< |dk	rT||d< | j ddd	|d
S )ao  
        Returns a list of tasks for a specified cluster. You can
        filter the results by family name or by a particular container
        instance with the `family` and `containerInstance` parameters.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the tasks you want to list. If you do not
            specify a cluster, the default cluster is assumed..

        :type container_instance: string
        :param container_instance: The container instance UUID or full Amazon
            Resource Name (ARN) of the container instance that you want to
            filter the `ListTasks` results with. Specifying a
            `containerInstance` will limit the results to tasks that belong to
            that container instance.

        :type family: string
        :param family: The name of the family that you want to filter the
            `ListTasks` results with. Specifying a `family` will limit the
            results to tasks that belong to that family.

        :type next_token: string
        :param next_token: The `nextToken` value returned from a previous
            paginated `ListTasks` request where `maxResults` was used and the
            results exceeded the value of that parameter. Pagination continues
            from the end of the previous results that returned the `nextToken`
            value. This value is `null` when there are no more results to
            return.

        :type max_results: integer
        :param max_results: The maximum number of task results returned by
            `ListTasks` in paginated output. When this parameter is used,
            `ListTasks` only returns `maxResults` results in a single page
            along with a `nextToken` response element. The remaining results of
            the initial request can be seen by sending another `ListTasks`
            request with the returned `nextToken` value. This value can be
            between 1 and 100. If this parameter is not used, then `ListTasks`
            returns up to 100 results and a `nextToken` value if applicable.

        Nr"   r$   familyr6   r7   Z	ListTasksr   r   r   r   )r   r"   r(   r=   r8   r9   r   r   r   r   
list_tasks  s"    + z(EC2ContainerServiceConnection.list_tasksc                 C   s^   i }|dk	r||d< |dk	r$||d< |dk	r4||d< |dk	rL|  ||dd | jddd	|d
S )a;  
        This action is only used by the Amazon EC2 Container Service
        agent, and it is not intended for use outside of the agent.


        Registers an Amazon EC2 instance into the specified cluster.
        This instance will become available to place containers on.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that you want to register your container instance with.
            If you do not specify a cluster, the default cluster is assumed..

        :type instance_identity_document: string
        :param instance_identity_document:

        :type instance_identity_document_signature: string
        :param instance_identity_document_signature:

        :type total_resources: list
        :param total_resources:

        Nr"   ZinstanceIdentityDocumentZ!instanceIdentityDocumentSignatureztotalResources.member)nametypeZdoubleValueZ	longValueZintegerValueZstringSetValueZRegisterContainerInstancer   r   r   Zbuild_complex_list_paramsr    )r   r"   Zinstance_identity_documentZ$instance_identity_document_signatureZtotal_resourcesr   r   r   r   register_container_instance  s(      z9EC2ContainerServiceConnection.register_container_instancec                 C   s*   d|i}|  ||dd | jddd|dS )aR  
        Registers a new task definition from the supplied `family` and
        `containerDefinitions`.

        :type family: string
        :param family: You can specify a `family` for a task definition, which
            allows you to track multiple versions of the same task definition.
            You can think of the `family` as a name for your task definition.

        :type container_definitions: list
        :param container_definitions: A list of container definitions in JSON
            format that describe the different containers that make up your
            task.

        r=   zcontainerDefinitions.member)
r?   imagecpuZmemorylinksZportMappingsZ	essentialZ
entryPointcommandenvironmentZRegisterTaskDefinitionr   r   r   rA   )r   r=   Zcontainer_definitionsr   r   r   r   register_task_definition  s      z6EC2ContainerServiceConnection.register_task_definitionc                 C   sJ   d|i}|dk	r||d< |dk	r(||d< |dk	r8||d< | j ddd|d	S )
a  
        Start a task using random placement and the default Amazon ECS
        scheduler. If you want to use your own scheduler or place a
        task on a specific container instance, use `StartTask`
        instead.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that you want to run your task on. If you do not
            specify a cluster, the default cluster is assumed..

        :type task_definition: string
        :param task_definition: The `family` and `revision` (
            `family:revision`) or full Amazon Resource Name (ARN) of the task
            definition that you want to run.

        :type overrides: dict
        :param overrides:

        :type count: integer
        :param count: The number of instances of the specified task that you
            would like to place on your cluster.

        r*   Nr"   	overridescountZRunTaskr   r   r   r   )r   r,   r"   rI   rJ   r   r   r   r   run_task  s     z&EC2ContainerServiceConnection.run_taskc                 C   sH   d|i}|  ||d |dk	r&||d< |dk	r6||d< | jddd|d	S )
a  
        Starts a new task from the specified task definition on the
        specified container instance or instances. If you want to use
        the default Amazon ECS scheduler to place your task, use
        `RunTask` instead.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that you want to start your task on. If you do not
            specify a cluster, the default cluster is assumed..

        :type task_definition: string
        :param task_definition: The `family` and `revision` (
            `family:revision`) or full Amazon Resource Name (ARN) of the task
            definition that you want to start.

        :type overrides: dict
        :param overrides:

        :type container_instances: list
        :param container_instances: The container instance UUIDs or full Amazon
            Resource Name (ARN) entries for the container instances on which
            you would like to place your task.

        r*   r0   Nr"   rI   Z	StartTaskr   r   r   r.   )r   r,   r1   r"   rI   r   r   r   r   
start_taskA  s     z(EC2ContainerServiceConnection.start_taskc                 C   s*   d|i}|dk	r||d< | j ddd|dS )a  
        Stops a running task.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the task you want to stop. If you do not
            specify a cluster, the default cluster is assumed..

        :type task: string
        :param task: The task UUIDs or full Amazon Resource Name (ARN) entry of
            the task you would like to stop.

        taskNr"   ZStopTaskr   r   r   r   )r   rM   r"   r   r   r   r   	stop_taski  s     z'EC2ContainerServiceConnection.stop_taskc           	      C   s   i }|dk	r||d< |dk	r$||d< |dk	r4||d< |dk	rD||d< |dk	rT||d< |dk	rd||d< |dk	r||  ||dd	 | jd
dd|dS )a  
        This action is only used by the Amazon EC2 Container Service
        agent, and it is not intended for use outside of the agent.


        Sent to acknowledge that a container changed states.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the container.

        :type task: string
        :param task: The task UUID or full Amazon Resource Name (ARN) of the
            task that hosts the container.

        :type container_name: string
        :param container_name: The name of the container.

        :type status: string
        :param status: The status of the state change request.

        :type exit_code: integer
        :param exit_code: The exit code returned for the state change request.

        :type reason: string
        :param reason: The reason for the state change request.

        :type network_bindings: list
        :param network_bindings: The network bindings of the container.

        Nr"   rM   ZcontainerNamestatusZexitCodereasonznetworkBindings.member)ZbindIPZcontainerPortZhostPortZSubmitContainerStateChanger   r   r   rA   )	r   r"   rM   Zcontainer_namerO   Z	exit_coderP   Znetwork_bindingsr   r   r   r   submit_container_state_change  s4    #  z;EC2ContainerServiceConnection.submit_container_state_changec                 C   sV   i }|dk	r||d< |dk	r$||d< |dk	r4||d< |dk	rD||d< | j ddd|d	S )
a  
        This action is only used by the Amazon EC2 Container Service
        agent, and it is not intended for use outside of the agent.


        Sent to acknowledge that a task changed states.

        :type cluster: string
        :param cluster: The short name or full Amazon Resource Name (ARN) of
            the cluster that hosts the task.

        :type task: string
        :param task: The task UUID or full Amazon Resource Name (ARN) of the
            task in the state change request.

        :type status: string
        :param status: The status of the state change request.

        :type reason: string
        :param reason: The reason for the state change request.

        Nr"   rM   rO   rP   ZSubmitTaskStateChanger   r   r   r   )r   r"   rM   rO   rP   r   r   r   r   submit_task_state_change  s     z6EC2ContainerServiceConnection.submit_task_state_changec           
      C   s   d|d< | j |dd|d}| d}tj| |jdkrHt|S t|}|	di 	d	d }| j
	|| j}	|	|j|j|d
d S )NZJSONZContentTyper   r   r   zutf-8   ErrorZCode)body)Zmake_requestreaddecodebotologdebugrO   r   loadsget_faultsResponseErrorrP   )
r   r   r   r   r   responserU   Z	json_bodyZ
fault_nameZexception_classr   r   r   r      s     



z+EC2ContainerServiceConnection._make_request)N)NN)N)N)N)N)NN)NNN)NNN)NNNNN)NNNN)NNN)NN)N)NNNNNNN)NNNN)%__name__
__module____qualname____doc__Z
APIVersionr   r   r   r^   r   r   r	   r]   r   r   r!   r#   r)   r-   r/   r2   r3   r4   r5   r:   r;   r<   r>   rB   rH   rK   rL   rN   rQ   rR   r    __classcell__r   r   r   r   r      sp   
  
(




"  
*  
-    
;    
,  
&  
(
        
:  
&r   )rX   Zboto.compatr   Zboto.connectionr   Zboto.regioninfor   Zboto.exceptionr   Zboto.ec2containerservicer   r   r   r   r   r   <module>   s   