# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

import uuid
from msrest.pipeline import ClientRawResponse

from .. import models


class PoolOperations(object):
    """PoolOperations operations.

    :param client: Client for service requests.
    :param config: Configuration of service client.
    :param serializer: An object model serializer.
    :param deserializer: An objec model deserializer.
    :ivar api_version: Client API Version. Constant value: "2017-06-01.5.1".
    """

    def __init__(self, client, config, serializer, deserializer):

        self._client = client
        self._serialize = serializer
        self._deserialize = deserializer
        self.api_version = "2017-06-01.5.1"

        self.config = config

    def list_usage_metrics(
            self, pool_list_usage_metrics_options=None, custom_headers=None, raw=False, **operation_config):
        """Lists the usage metrics, aggregated by pool across individual time
        intervals, for the specified account.

        If you do not specify a $filter clause including a poolId, the response
        includes all pools that existed in the account in the time range of the
        returned aggregation intervals. If you do not specify a $filter clause
        including a startTime or endTime these filters default to the start and
        end times of the last aggregation interval currently available; that
        is, only the last aggregation interval is returned.

        :param pool_list_usage_metrics_options: Additional parameters for the
         operation
        :type pool_list_usage_metrics_options:
         :class:`PoolListUsageMetricsOptions
         <azure.batch.models.PoolListUsageMetricsOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: An iterator like instance of :class:`PoolUsageMetrics
         <azure.batch.models.PoolUsageMetrics>`
        :rtype: :class:`PoolUsageMetricsPaged
         <azure.batch.models.PoolUsageMetricsPaged>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        start_time = None
        if pool_list_usage_metrics_options is not None:
            start_time = pool_list_usage_metrics_options.start_time
        end_time = None
        if pool_list_usage_metrics_options is not None:
            end_time = pool_list_usage_metrics_options.end_time
        filter = None
        if pool_list_usage_metrics_options is not None:
            filter = pool_list_usage_metrics_options.filter
        max_results = None
        if pool_list_usage_metrics_options is not None:
            max_results = pool_list_usage_metrics_options.max_results
        timeout = None
        if pool_list_usage_metrics_options is not None:
            timeout = pool_list_usage_metrics_options.timeout
        client_request_id = None
        if pool_list_usage_metrics_options is not None:
            client_request_id = pool_list_usage_metrics_options.client_request_id
        return_client_request_id = None
        if pool_list_usage_metrics_options is not None:
            return_client_request_id = pool_list_usage_metrics_options.return_client_request_id
        ocp_date = None
        if pool_list_usage_metrics_options is not None:
            ocp_date = pool_list_usage_metrics_options.ocp_date

        def internal_paging(next_link=None, raw=False):

            if not next_link:
                # Construct URL
                url = '/poolusagemetrics'

                # Construct parameters
                query_parameters = {}
                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
                if start_time is not None:
                    query_parameters['starttime'] = self._serialize.query("start_time", start_time, 'iso-8601')
                if end_time is not None:
                    query_parameters['endtime'] = self._serialize.query("end_time", end_time, 'iso-8601')
                if filter is not None:
                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
                if max_results is not None:
                    query_parameters['maxresults'] = self._serialize.query("max_results", max_results, 'int', maximum=1000, minimum=1)
                if timeout is not None:
                    query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

            else:
                url = next_link
                query_parameters = {}

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
            if client_request_id is not None:
                header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
            if return_client_request_id is not None:
                header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
            if ocp_date is not None:
                header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(
                request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                raise models.BatchErrorException(self._deserialize, response)

            return response

        # Deserialize response
        deserialized = models.PoolUsageMetricsPaged(internal_paging, self._deserialize.dependencies)

        if raw:
            header_dict = {}
            client_raw_response = models.PoolUsageMetricsPaged(internal_paging, self._deserialize.dependencies, header_dict)
            return client_raw_response

        return deserialized

    def get_all_lifetime_statistics(
            self, pool_get_all_lifetime_statistics_options=None, custom_headers=None, raw=False, **operation_config):
        """Gets lifetime summary statistics for all of the pools in the specified
        account.

        Statistics are aggregated across all pools that have ever existed in
        the account, from account creation to the last update time of the
        statistics.

        :param pool_get_all_lifetime_statistics_options: Additional parameters
         for the operation
        :type pool_get_all_lifetime_statistics_options:
         :class:`PoolGetAllLifetimeStatisticsOptions
         <azure.batch.models.PoolGetAllLifetimeStatisticsOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: :class:`PoolStatistics <azure.batch.models.PoolStatistics>`
         or :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: :class:`PoolStatistics <azure.batch.models.PoolStatistics>` or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_get_all_lifetime_statistics_options is not None:
            timeout = pool_get_all_lifetime_statistics_options.timeout
        client_request_id = None
        if pool_get_all_lifetime_statistics_options is not None:
            client_request_id = pool_get_all_lifetime_statistics_options.client_request_id
        return_client_request_id = None
        if pool_get_all_lifetime_statistics_options is not None:
            return_client_request_id = pool_get_all_lifetime_statistics_options.return_client_request_id
        ocp_date = None
        if pool_get_all_lifetime_statistics_options is not None:
            ocp_date = pool_get_all_lifetime_statistics_options.ocp_date

        # Construct URL
        url = '/lifetimepoolstats'

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

        # Construct and send request
        request = self._client.get(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        deserialized = None
        header_dict = {}

        if response.status_code == 200:
            deserialized = self._deserialize('PoolStatistics', response)
            header_dict = {
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
            }

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            client_raw_response.add_headers(header_dict)
            return client_raw_response

        return deserialized

    def add(
            self, pool, pool_add_options=None, custom_headers=None, raw=False, **operation_config):
        """Adds a pool to the specified account.

        When naming pools, avoid including sensitive information such as user
        names or secret project names. This information may appear in telemetry
        logs accessible to Microsoft Support engineers.

        :param pool: The pool to be added.
        :type pool: :class:`PoolAddParameter
         <azure.batch.models.PoolAddParameter>`
        :param pool_add_options: Additional parameters for the operation
        :type pool_add_options: :class:`PoolAddOptions
         <azure.batch.models.PoolAddOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_add_options is not None:
            timeout = pool_add_options.timeout
        client_request_id = None
        if pool_add_options is not None:
            client_request_id = pool_add_options.client_request_id
        return_client_request_id = None
        if pool_add_options is not None:
            return_client_request_id = pool_add_options.return_client_request_id
        ocp_date = None
        if pool_add_options is not None:
            ocp_date = pool_add_options.ocp_date

        # Construct URL
        url = '/pools'

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool, 'PoolAddParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [201]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def list(
            self, pool_list_options=None, custom_headers=None, raw=False, **operation_config):
        """Lists all of the pools in the specified account.

        :param pool_list_options: Additional parameters for the operation
        :type pool_list_options: :class:`PoolListOptions
         <azure.batch.models.PoolListOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: An iterator like instance of :class:`CloudPool
         <azure.batch.models.CloudPool>`
        :rtype: :class:`CloudPoolPaged <azure.batch.models.CloudPoolPaged>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        filter = None
        if pool_list_options is not None:
            filter = pool_list_options.filter
        select = None
        if pool_list_options is not None:
            select = pool_list_options.select
        expand = None
        if pool_list_options is not None:
            expand = pool_list_options.expand
        max_results = None
        if pool_list_options is not None:
            max_results = pool_list_options.max_results
        timeout = None
        if pool_list_options is not None:
            timeout = pool_list_options.timeout
        client_request_id = None
        if pool_list_options is not None:
            client_request_id = pool_list_options.client_request_id
        return_client_request_id = None
        if pool_list_options is not None:
            return_client_request_id = pool_list_options.return_client_request_id
        ocp_date = None
        if pool_list_options is not None:
            ocp_date = pool_list_options.ocp_date

        def internal_paging(next_link=None, raw=False):

            if not next_link:
                # Construct URL
                url = '/pools'

                # Construct parameters
                query_parameters = {}
                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
                if filter is not None:
                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
                if select is not None:
                    query_parameters['$select'] = self._serialize.query("select", select, 'str')
                if expand is not None:
                    query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
                if max_results is not None:
                    query_parameters['maxresults'] = self._serialize.query("max_results", max_results, 'int', maximum=1000, minimum=1)
                if timeout is not None:
                    query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

            else:
                url = next_link
                query_parameters = {}

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
            if client_request_id is not None:
                header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
            if return_client_request_id is not None:
                header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
            if ocp_date is not None:
                header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(
                request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                raise models.BatchErrorException(self._deserialize, response)

            return response

        # Deserialize response
        deserialized = models.CloudPoolPaged(internal_paging, self._deserialize.dependencies)

        if raw:
            header_dict = {}
            client_raw_response = models.CloudPoolPaged(internal_paging, self._deserialize.dependencies, header_dict)
            return client_raw_response

        return deserialized

    def delete(
            self, pool_id, pool_delete_options=None, custom_headers=None, raw=False, **operation_config):
        """Deletes a pool from the specified account.

        When you request that a pool be deleted, the following actions occur:
        the pool state is set to deleting; any ongoing resize operation on the
        pool are stopped; the Batch service starts resizing the pool to zero
        nodes; any tasks running on existing nodes are terminated and requeued
        (as if a resize pool operation had been requested with the default
        requeue option); finally, the pool is removed from the system. Because
        running tasks are requeued, the user can rerun these tasks by updating
        their job to target a different pool. The tasks can then run on the new
        pool. If you want to override the requeue behavior, then you should
        call resize pool explicitly to shrink the pool to zero size before
        deleting the pool. If you call an Update, Patch or Delete API on a pool
        in the deleting state, it will fail with HTTP status code 409 with
        error code PoolBeingDeleted.

        :param pool_id: The ID of the pool to delete.
        :type pool_id: str
        :param pool_delete_options: Additional parameters for the operation
        :type pool_delete_options: :class:`PoolDeleteOptions
         <azure.batch.models.PoolDeleteOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_delete_options is not None:
            timeout = pool_delete_options.timeout
        client_request_id = None
        if pool_delete_options is not None:
            client_request_id = pool_delete_options.client_request_id
        return_client_request_id = None
        if pool_delete_options is not None:
            return_client_request_id = pool_delete_options.return_client_request_id
        ocp_date = None
        if pool_delete_options is not None:
            ocp_date = pool_delete_options.ocp_date
        if_match = None
        if pool_delete_options is not None:
            if_match = pool_delete_options.if_match
        if_none_match = None
        if pool_delete_options is not None:
            if_none_match = pool_delete_options.if_none_match
        if_modified_since = None
        if pool_delete_options is not None:
            if_modified_since = pool_delete_options.if_modified_since
        if_unmodified_since = None
        if pool_delete_options is not None:
            if_unmodified_since = pool_delete_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct and send request
        request = self._client.delete(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [202]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
            })
            return client_raw_response

    def exists(
            self, pool_id, pool_exists_options=None, custom_headers=None, raw=False, **operation_config):
        """Gets basic properties of a pool.

        :param pool_id: The ID of the pool to get.
        :type pool_id: str
        :param pool_exists_options: Additional parameters for the operation
        :type pool_exists_options: :class:`PoolExistsOptions
         <azure.batch.models.PoolExistsOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: bool or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: bool or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_exists_options is not None:
            timeout = pool_exists_options.timeout
        client_request_id = None
        if pool_exists_options is not None:
            client_request_id = pool_exists_options.client_request_id
        return_client_request_id = None
        if pool_exists_options is not None:
            return_client_request_id = pool_exists_options.return_client_request_id
        ocp_date = None
        if pool_exists_options is not None:
            ocp_date = pool_exists_options.ocp_date
        if_match = None
        if pool_exists_options is not None:
            if_match = pool_exists_options.if_match
        if_none_match = None
        if pool_exists_options is not None:
            if_none_match = pool_exists_options.if_none_match
        if_modified_since = None
        if pool_exists_options is not None:
            if_modified_since = pool_exists_options.if_modified_since
        if_unmodified_since = None
        if pool_exists_options is not None:
            if_unmodified_since = pool_exists_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct and send request
        request = self._client.head(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [200, 404]:
            raise models.BatchErrorException(self._deserialize, response)

        deserialized = (response.status_code == 200)
        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                })
            return client_raw_response
        return deserialized

    def get(
            self, pool_id, pool_get_options=None, custom_headers=None, raw=False, **operation_config):
        """Gets information about the specified pool.

        :param pool_id: The ID of the pool to get.
        :type pool_id: str
        :param pool_get_options: Additional parameters for the operation
        :type pool_get_options: :class:`PoolGetOptions
         <azure.batch.models.PoolGetOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: :class:`CloudPool <azure.batch.models.CloudPool>` or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: :class:`CloudPool <azure.batch.models.CloudPool>` or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        select = None
        if pool_get_options is not None:
            select = pool_get_options.select
        expand = None
        if pool_get_options is not None:
            expand = pool_get_options.expand
        timeout = None
        if pool_get_options is not None:
            timeout = pool_get_options.timeout
        client_request_id = None
        if pool_get_options is not None:
            client_request_id = pool_get_options.client_request_id
        return_client_request_id = None
        if pool_get_options is not None:
            return_client_request_id = pool_get_options.return_client_request_id
        ocp_date = None
        if pool_get_options is not None:
            ocp_date = pool_get_options.ocp_date
        if_match = None
        if pool_get_options is not None:
            if_match = pool_get_options.if_match
        if_none_match = None
        if pool_get_options is not None:
            if_none_match = pool_get_options.if_none_match
        if_modified_since = None
        if pool_get_options is not None:
            if_modified_since = pool_get_options.if_modified_since
        if_unmodified_since = None
        if pool_get_options is not None:
            if_unmodified_since = pool_get_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if select is not None:
            query_parameters['$select'] = self._serialize.query("select", select, 'str')
        if expand is not None:
            query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct and send request
        request = self._client.get(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        deserialized = None
        header_dict = {}

        if response.status_code == 200:
            deserialized = self._deserialize('CloudPool', response)
            header_dict = {
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
            }

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            client_raw_response.add_headers(header_dict)
            return client_raw_response

        return deserialized

    def patch(
            self, pool_id, pool_patch_parameter, pool_patch_options=None, custom_headers=None, raw=False, **operation_config):
        """Updates the properties of the specified pool.

        This only replaces the pool properties specified in the request. For
        example, if the pool has a start task associated with it, and a request
        does not specify a start task element, then the pool keeps the existing
        start task.

        :param pool_id: The ID of the pool to update.
        :type pool_id: str
        :param pool_patch_parameter: The parameters for the request.
        :type pool_patch_parameter: :class:`PoolPatchParameter
         <azure.batch.models.PoolPatchParameter>`
        :param pool_patch_options: Additional parameters for the operation
        :type pool_patch_options: :class:`PoolPatchOptions
         <azure.batch.models.PoolPatchOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_patch_options is not None:
            timeout = pool_patch_options.timeout
        client_request_id = None
        if pool_patch_options is not None:
            client_request_id = pool_patch_options.client_request_id
        return_client_request_id = None
        if pool_patch_options is not None:
            return_client_request_id = pool_patch_options.return_client_request_id
        ocp_date = None
        if pool_patch_options is not None:
            ocp_date = pool_patch_options.ocp_date
        if_match = None
        if pool_patch_options is not None:
            if_match = pool_patch_options.if_match
        if_none_match = None
        if pool_patch_options is not None:
            if_none_match = pool_patch_options.if_none_match
        if_modified_since = None
        if pool_patch_options is not None:
            if_modified_since = pool_patch_options.if_modified_since
        if_unmodified_since = None
        if pool_patch_options is not None:
            if_unmodified_since = pool_patch_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_patch_parameter, 'PoolPatchParameter')

        # Construct and send request
        request = self._client.patch(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def disable_auto_scale(
            self, pool_id, pool_disable_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
        """Disables automatic scaling for a pool.

        :param pool_id: The ID of the pool on which to disable automatic
         scaling.
        :type pool_id: str
        :param pool_disable_auto_scale_options: Additional parameters for the
         operation
        :type pool_disable_auto_scale_options:
         :class:`PoolDisableAutoScaleOptions
         <azure.batch.models.PoolDisableAutoScaleOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_disable_auto_scale_options is not None:
            timeout = pool_disable_auto_scale_options.timeout
        client_request_id = None
        if pool_disable_auto_scale_options is not None:
            client_request_id = pool_disable_auto_scale_options.client_request_id
        return_client_request_id = None
        if pool_disable_auto_scale_options is not None:
            return_client_request_id = pool_disable_auto_scale_options.return_client_request_id
        ocp_date = None
        if pool_disable_auto_scale_options is not None:
            ocp_date = pool_disable_auto_scale_options.ocp_date

        # Construct URL
        url = '/pools/{poolId}/disableautoscale'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def enable_auto_scale(
            self, pool_id, pool_enable_auto_scale_options=None, auto_scale_formula=None, auto_scale_evaluation_interval=None, custom_headers=None, raw=False, **operation_config):
        """Enables automatic scaling for a pool.

        You cannot enable automatic scaling on a pool if a resize operation is
        in progress on the pool. If automatic scaling of the pool is currently
        disabled, you must specify a valid autoscale formula as part of the
        request. If automatic scaling of the pool is already enabled, you may
        specify a new autoscale formula and/or a new evaluation interval. You
        cannot call this API for the same pool more than once every 30 seconds.

        :param pool_id: The ID of the pool on which to enable automatic
         scaling.
        :type pool_id: str
        :param pool_enable_auto_scale_options: Additional parameters for the
         operation
        :type pool_enable_auto_scale_options:
         :class:`PoolEnableAutoScaleOptions
         <azure.batch.models.PoolEnableAutoScaleOptions>`
        :param auto_scale_formula: The formula for the desired number of
         compute nodes in the pool. The formula is checked for validity before
         it is applied to the pool. If the formula is not valid, the Batch
         service rejects the request with detailed error information. For more
         information about specifying this formula, see Automatically scale
         compute nodes in an Azure Batch pool
         (https://azure.microsoft.com/en-us/documentation/articles/batch-automatic-scaling).
        :type auto_scale_formula: str
        :param auto_scale_evaluation_interval: The time interval at which to
         automatically adjust the pool size according to the autoscale formula.
         The default value is 15 minutes. The minimum and maximum value are 5
         minutes and 168 hours respectively. If you specify a value less than 5
         minutes or greater than 168 hours, the Batch service rejects the
         request with an invalid property value error; if you are calling the
         REST API directly, the HTTP status code is 400 (Bad Request). If you
         specify a new interval, then the existing autoscale evaluation
         schedule will be stopped and a new autoscale evaluation schedule will
         be started, with its starting time being the time when this request
         was issued.
        :type auto_scale_evaluation_interval: timedelta
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_enable_auto_scale_options is not None:
            timeout = pool_enable_auto_scale_options.timeout
        client_request_id = None
        if pool_enable_auto_scale_options is not None:
            client_request_id = pool_enable_auto_scale_options.client_request_id
        return_client_request_id = None
        if pool_enable_auto_scale_options is not None:
            return_client_request_id = pool_enable_auto_scale_options.return_client_request_id
        ocp_date = None
        if pool_enable_auto_scale_options is not None:
            ocp_date = pool_enable_auto_scale_options.ocp_date
        if_match = None
        if pool_enable_auto_scale_options is not None:
            if_match = pool_enable_auto_scale_options.if_match
        if_none_match = None
        if pool_enable_auto_scale_options is not None:
            if_none_match = pool_enable_auto_scale_options.if_none_match
        if_modified_since = None
        if pool_enable_auto_scale_options is not None:
            if_modified_since = pool_enable_auto_scale_options.if_modified_since
        if_unmodified_since = None
        if pool_enable_auto_scale_options is not None:
            if_unmodified_since = pool_enable_auto_scale_options.if_unmodified_since
        pool_enable_auto_scale_parameter = models.PoolEnableAutoScaleParameter(auto_scale_formula=auto_scale_formula, auto_scale_evaluation_interval=auto_scale_evaluation_interval)

        # Construct URL
        url = '/pools/{poolId}/enableautoscale'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_enable_auto_scale_parameter, 'PoolEnableAutoScaleParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def evaluate_auto_scale(
            self, pool_id, auto_scale_formula, pool_evaluate_auto_scale_options=None, custom_headers=None, raw=False, **operation_config):
        """Gets the result of evaluating an automatic scaling formula on the pool.

        This API is primarily for validating an autoscale formula, as it simply
        returns the result without applying the formula to the pool. The pool
        must have auto scaling enabled in order to evaluate a formula.

        :param pool_id: The ID of the pool on which to evaluate the automatic
         scaling formula.
        :type pool_id: str
        :param auto_scale_formula: The formula for the desired number of
         compute nodes in the pool. The formula is validated and its results
         calculated, but it is not applied to the pool. To apply the formula to
         the pool, 'Enable automatic scaling on a pool'. For more information
         about specifying this formula, see Automatically scale compute nodes
         in an Azure Batch pool
         (https://azure.microsoft.com/en-us/documentation/articles/batch-automatic-scaling).
        :type auto_scale_formula: str
        :param pool_evaluate_auto_scale_options: Additional parameters for the
         operation
        :type pool_evaluate_auto_scale_options:
         :class:`PoolEvaluateAutoScaleOptions
         <azure.batch.models.PoolEvaluateAutoScaleOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: :class:`AutoScaleRun <azure.batch.models.AutoScaleRun>` or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: :class:`AutoScaleRun <azure.batch.models.AutoScaleRun>` or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_evaluate_auto_scale_options is not None:
            timeout = pool_evaluate_auto_scale_options.timeout
        client_request_id = None
        if pool_evaluate_auto_scale_options is not None:
            client_request_id = pool_evaluate_auto_scale_options.client_request_id
        return_client_request_id = None
        if pool_evaluate_auto_scale_options is not None:
            return_client_request_id = pool_evaluate_auto_scale_options.return_client_request_id
        ocp_date = None
        if pool_evaluate_auto_scale_options is not None:
            ocp_date = pool_evaluate_auto_scale_options.ocp_date
        pool_evaluate_auto_scale_parameter = models.PoolEvaluateAutoScaleParameter(auto_scale_formula=auto_scale_formula)

        # Construct URL
        url = '/pools/{poolId}/evaluateautoscale'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_evaluate_auto_scale_parameter, 'PoolEvaluateAutoScaleParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [200]:
            raise models.BatchErrorException(self._deserialize, response)

        deserialized = None
        header_dict = {}

        if response.status_code == 200:
            deserialized = self._deserialize('AutoScaleRun', response)
            header_dict = {
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            }

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            client_raw_response.add_headers(header_dict)
            return client_raw_response

        return deserialized

    def resize(
            self, pool_id, pool_resize_parameter, pool_resize_options=None, custom_headers=None, raw=False, **operation_config):
        """Changes the number of compute nodes that are assigned to a pool.

        You can only resize a pool when its allocation state is steady. If the
        pool is already resizing, the request fails with status code 409. When
        you resize a pool, the pool's allocation state changes from steady to
        resizing. You cannot resize pools which are configured for automatic
        scaling. If you try to do this, the Batch service returns an error 409.
        If you resize a pool downwards, the Batch service chooses which nodes
        to remove. To remove specific nodes, use the pool remove nodes API
        instead.

        :param pool_id: The ID of the pool to resize.
        :type pool_id: str
        :param pool_resize_parameter: The parameters for the request.
        :type pool_resize_parameter: :class:`PoolResizeParameter
         <azure.batch.models.PoolResizeParameter>`
        :param pool_resize_options: Additional parameters for the operation
        :type pool_resize_options: :class:`PoolResizeOptions
         <azure.batch.models.PoolResizeOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_resize_options is not None:
            timeout = pool_resize_options.timeout
        client_request_id = None
        if pool_resize_options is not None:
            client_request_id = pool_resize_options.client_request_id
        return_client_request_id = None
        if pool_resize_options is not None:
            return_client_request_id = pool_resize_options.return_client_request_id
        ocp_date = None
        if pool_resize_options is not None:
            ocp_date = pool_resize_options.ocp_date
        if_match = None
        if pool_resize_options is not None:
            if_match = pool_resize_options.if_match
        if_none_match = None
        if pool_resize_options is not None:
            if_none_match = pool_resize_options.if_none_match
        if_modified_since = None
        if pool_resize_options is not None:
            if_modified_since = pool_resize_options.if_modified_since
        if_unmodified_since = None
        if pool_resize_options is not None:
            if_unmodified_since = pool_resize_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}/resize'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_resize_parameter, 'PoolResizeParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [202]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def stop_resize(
            self, pool_id, pool_stop_resize_options=None, custom_headers=None, raw=False, **operation_config):
        """Stops an ongoing resize operation on the pool.

        This does not restore the pool to its previous state before the resize
        operation: it only stops any further changes being made, and the pool
        maintains its current state. After stopping, the pool stabilizes at the
        number of nodes it was at when the stop operation was done. During the
        stop operation, the pool allocation state changes first to stopping and
        then to steady. A resize operation need not be an explicit resize pool
        request; this API can also be used to halt the initial sizing of the
        pool when it is created.

        :param pool_id: The ID of the pool whose resizing you want to stop.
        :type pool_id: str
        :param pool_stop_resize_options: Additional parameters for the
         operation
        :type pool_stop_resize_options: :class:`PoolStopResizeOptions
         <azure.batch.models.PoolStopResizeOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_stop_resize_options is not None:
            timeout = pool_stop_resize_options.timeout
        client_request_id = None
        if pool_stop_resize_options is not None:
            client_request_id = pool_stop_resize_options.client_request_id
        return_client_request_id = None
        if pool_stop_resize_options is not None:
            return_client_request_id = pool_stop_resize_options.return_client_request_id
        ocp_date = None
        if pool_stop_resize_options is not None:
            ocp_date = pool_stop_resize_options.ocp_date
        if_match = None
        if pool_stop_resize_options is not None:
            if_match = pool_stop_resize_options.if_match
        if_none_match = None
        if pool_stop_resize_options is not None:
            if_none_match = pool_stop_resize_options.if_none_match
        if_modified_since = None
        if pool_stop_resize_options is not None:
            if_modified_since = pool_stop_resize_options.if_modified_since
        if_unmodified_since = None
        if pool_stop_resize_options is not None:
            if_unmodified_since = pool_stop_resize_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}/stopresize'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(request, header_parameters, **operation_config)

        if response.status_code not in [202]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def update_properties(
            self, pool_id, pool_update_properties_parameter, pool_update_properties_options=None, custom_headers=None, raw=False, **operation_config):
        """Updates the properties of the specified pool.

        This fully replaces all the updateable properties of the pool. For
        example, if the pool has a start task associated with it and if start
        task is not specified with this request, then the Batch service will
        remove the existing start task.

        :param pool_id: The ID of the pool to update.
        :type pool_id: str
        :param pool_update_properties_parameter: The parameters for the
         request.
        :type pool_update_properties_parameter:
         :class:`PoolUpdatePropertiesParameter
         <azure.batch.models.PoolUpdatePropertiesParameter>`
        :param pool_update_properties_options: Additional parameters for the
         operation
        :type pool_update_properties_options:
         :class:`PoolUpdatePropertiesOptions
         <azure.batch.models.PoolUpdatePropertiesOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_update_properties_options is not None:
            timeout = pool_update_properties_options.timeout
        client_request_id = None
        if pool_update_properties_options is not None:
            client_request_id = pool_update_properties_options.client_request_id
        return_client_request_id = None
        if pool_update_properties_options is not None:
            return_client_request_id = pool_update_properties_options.return_client_request_id
        ocp_date = None
        if pool_update_properties_options is not None:
            ocp_date = pool_update_properties_options.ocp_date

        # Construct URL
        url = '/pools/{poolId}/updateproperties'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_update_properties_parameter, 'PoolUpdatePropertiesParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [204]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def upgrade_os(
            self, pool_id, target_os_version, pool_upgrade_os_options=None, custom_headers=None, raw=False, **operation_config):
        """Upgrades the operating system of the specified pool.

        During an upgrade, the Batch service upgrades each compute node in the
        pool. When a compute node is chosen for upgrade, any tasks running on
        that node are removed from the node and returned to the queue to be
        rerun later (or on a different compute node). The node will be
        unavailable until the upgrade is complete. This operation results in
        temporarily reduced pool capacity as nodes are taken out of service to
        be upgraded. Although the Batch service tries to avoid upgrading all
        compute nodes at the same time, it does not guarantee to do this
        (particularly on small pools); therefore, the pool may be temporarily
        unavailable to run tasks. When this operation runs, the pool state
        changes to upgrading. When all compute nodes have finished upgrading,
        the pool state returns to active. While the upgrade is in progress, the
        pool's currentOSVersion reflects the OS version that nodes are
        upgrading from, and targetOSVersion reflects the OS version that nodes
        are upgrading to. Once the upgrade is complete, currentOSVersion is
        updated to reflect the OS version now running on all nodes. This
        operation can only be invoked on pools created with the
        cloudServiceConfiguration property.

        :param pool_id: The ID of the pool to upgrade.
        :type pool_id: str
        :param target_os_version: The Azure Guest OS version to be installed
         on the virtual machines in the pool.
        :type target_os_version: str
        :param pool_upgrade_os_options: Additional parameters for the
         operation
        :type pool_upgrade_os_options: :class:`PoolUpgradeOsOptions
         <azure.batch.models.PoolUpgradeOsOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_upgrade_os_options is not None:
            timeout = pool_upgrade_os_options.timeout
        client_request_id = None
        if pool_upgrade_os_options is not None:
            client_request_id = pool_upgrade_os_options.client_request_id
        return_client_request_id = None
        if pool_upgrade_os_options is not None:
            return_client_request_id = pool_upgrade_os_options.return_client_request_id
        ocp_date = None
        if pool_upgrade_os_options is not None:
            ocp_date = pool_upgrade_os_options.ocp_date
        if_match = None
        if pool_upgrade_os_options is not None:
            if_match = pool_upgrade_os_options.if_match
        if_none_match = None
        if pool_upgrade_os_options is not None:
            if_none_match = pool_upgrade_os_options.if_none_match
        if_modified_since = None
        if pool_upgrade_os_options is not None:
            if_modified_since = pool_upgrade_os_options.if_modified_since
        if_unmodified_since = None
        if pool_upgrade_os_options is not None:
            if_unmodified_since = pool_upgrade_os_options.if_unmodified_since
        pool_upgrade_os_parameter = models.PoolUpgradeOSParameter(target_os_version=target_os_version)

        # Construct URL
        url = '/pools/{poolId}/upgradeos'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(pool_upgrade_os_parameter, 'PoolUpgradeOSParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [202]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response

    def remove_nodes(
            self, pool_id, node_remove_parameter, pool_remove_nodes_options=None, custom_headers=None, raw=False, **operation_config):
        """Removes compute nodes from the specified pool.

        This operation can only run when the allocation state of the pool is
        steady. When this operation runs, the allocation state changes from
        steady to resizing.

        :param pool_id: The ID of the pool from which you want to remove
         nodes.
        :type pool_id: str
        :param node_remove_parameter: The parameters for the request.
        :type node_remove_parameter: :class:`NodeRemoveParameter
         <azure.batch.models.NodeRemoveParameter>`
        :param pool_remove_nodes_options: Additional parameters for the
         operation
        :type pool_remove_nodes_options: :class:`PoolRemoveNodesOptions
         <azure.batch.models.PoolRemoveNodesOptions>`
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
         raw=true
        :rtype: None or
         :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
        :raises:
         :class:`BatchErrorException<azure.batch.models.BatchErrorException>`
        """
        timeout = None
        if pool_remove_nodes_options is not None:
            timeout = pool_remove_nodes_options.timeout
        client_request_id = None
        if pool_remove_nodes_options is not None:
            client_request_id = pool_remove_nodes_options.client_request_id
        return_client_request_id = None
        if pool_remove_nodes_options is not None:
            return_client_request_id = pool_remove_nodes_options.return_client_request_id
        ocp_date = None
        if pool_remove_nodes_options is not None:
            ocp_date = pool_remove_nodes_options.ocp_date
        if_match = None
        if pool_remove_nodes_options is not None:
            if_match = pool_remove_nodes_options.if_match
        if_none_match = None
        if pool_remove_nodes_options is not None:
            if_none_match = pool_remove_nodes_options.if_none_match
        if_modified_since = None
        if pool_remove_nodes_options is not None:
            if_modified_since = pool_remove_nodes_options.if_modified_since
        if_unmodified_since = None
        if pool_remove_nodes_options is not None:
            if_unmodified_since = pool_remove_nodes_options.if_unmodified_since

        # Construct URL
        url = '/pools/{poolId}/removenodes'
        path_format_arguments = {
            'poolId': self._serialize.url("pool_id", pool_id, 'str')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if timeout is not None:
            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int')

        # Construct headers
        header_parameters = {}
        header_parameters['Content-Type'] = 'application/json; odata=minimalmetadata; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
        if client_request_id is not None:
            header_parameters['client-request-id'] = self._serialize.header("client_request_id", client_request_id, 'str')
        if return_client_request_id is not None:
            header_parameters['return-client-request-id'] = self._serialize.header("return_client_request_id", return_client_request_id, 'bool')
        if ocp_date is not None:
            header_parameters['ocp-date'] = self._serialize.header("ocp_date", ocp_date, 'rfc-1123')
        if if_match is not None:
            header_parameters['If-Match'] = self._serialize.header("if_match", if_match, 'str')
        if if_none_match is not None:
            header_parameters['If-None-Match'] = self._serialize.header("if_none_match", if_none_match, 'str')
        if if_modified_since is not None:
            header_parameters['If-Modified-Since'] = self._serialize.header("if_modified_since", if_modified_since, 'rfc-1123')
        if if_unmodified_since is not None:
            header_parameters['If-Unmodified-Since'] = self._serialize.header("if_unmodified_since", if_unmodified_since, 'rfc-1123')

        # Construct body
        body_content = self._serialize.body(node_remove_parameter, 'NodeRemoveParameter')

        # Construct and send request
        request = self._client.post(url, query_parameters)
        response = self._client.send(
            request, header_parameters, body_content, **operation_config)

        if response.status_code not in [202]:
            raise models.BatchErrorException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            client_raw_response.add_headers({
                'client-request-id': 'str',
                'request-id': 'str',
                'ETag': 'str',
                'Last-Modified': 'rfc-1123',
                'DataServiceId': 'str',
            })
            return client_raw_response
