1# coding=utf-8
2# --------------------------------------------------------------------------
3# Copyright (c) Microsoft Corporation. All rights reserved.
4# Licensed under the MIT License. See License.txt in the project root for
5# license information.
6#
7# Code generated by Microsoft (R) AutoRest Code Generator.
8# Changes may cause incorrect behavior and will be lost if the code is
9# regenerated.
10# --------------------------------------------------------------------------
11
12import uuid
13from msrest.pipeline import ClientRawResponse
14from msrestazure.azure_exceptions import CloudError
15
16from .. import models
17
18
19class ArmTemplatesOperations(object):
20    """ArmTemplatesOperations operations.
21
22    You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
23
24    :param client: Client for service requests.
25    :param config: Configuration of service client.
26    :param serializer: An object model serializer.
27    :param deserializer: An object model deserializer.
28    :ivar api_version: Client API version. Constant value: "2018-09-15".
29    """
30
31    models = models
32
33    def __init__(self, client, config, serializer, deserializer):
34
35        self._client = client
36        self._serialize = serializer
37        self._deserialize = deserializer
38        self.api_version = "2018-09-15"
39
40        self.config = config
41
42    def list(
43            self, resource_group_name, lab_name, artifact_source_name, expand=None, filter=None, top=None, orderby=None, custom_headers=None, raw=False, **operation_config):
44        """List azure resource manager templates in a given artifact source.
45
46        :param resource_group_name: The name of the resource group.
47        :type resource_group_name: str
48        :param lab_name: The name of the lab.
49        :type lab_name: str
50        :param artifact_source_name: The name of the artifact source.
51        :type artifact_source_name: str
52        :param expand: Specify the $expand query. Example:
53         'properties($select=displayName)'
54        :type expand: str
55        :param filter: The filter to apply to the operation. Example:
56         '$filter=contains(name,'myName')
57        :type filter: str
58        :param top: The maximum number of resources to return from the
59         operation. Example: '$top=10'
60        :type top: int
61        :param orderby: The ordering expression for the results, using OData
62         notation. Example: '$orderby=name desc'
63        :type orderby: str
64        :param dict custom_headers: headers that will be added to the request
65        :param bool raw: returns the direct response alongside the
66         deserialized response
67        :param operation_config: :ref:`Operation configuration
68         overrides<msrest:optionsforoperations>`.
69        :return: An iterator like instance of ArmTemplate
70        :rtype:
71         ~azure.mgmt.devtestlabs.models.ArmTemplatePaged[~azure.mgmt.devtestlabs.models.ArmTemplate]
72        :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
73        """
74        def prepare_request(next_link=None):
75            if not next_link:
76                # Construct URL
77                url = self.list.metadata['url']
78                path_format_arguments = {
79                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
80                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
81                    'labName': self._serialize.url("lab_name", lab_name, 'str'),
82                    'artifactSourceName': self._serialize.url("artifact_source_name", artifact_source_name, 'str')
83                }
84                url = self._client.format_url(url, **path_format_arguments)
85
86                # Construct parameters
87                query_parameters = {}
88                if expand is not None:
89                    query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
90                if filter is not None:
91                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
92                if top is not None:
93                    query_parameters['$top'] = self._serialize.query("top", top, 'int')
94                if orderby is not None:
95                    query_parameters['$orderby'] = self._serialize.query("orderby", orderby, 'str')
96                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
97
98            else:
99                url = next_link
100                query_parameters = {}
101
102            # Construct headers
103            header_parameters = {}
104            header_parameters['Accept'] = 'application/json'
105            if self.config.generate_client_request_id:
106                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
107            if custom_headers:
108                header_parameters.update(custom_headers)
109            if self.config.accept_language is not None:
110                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
111
112            # Construct and send request
113            request = self._client.get(url, query_parameters, header_parameters)
114            return request
115
116        def internal_paging(next_link=None):
117            request = prepare_request(next_link)
118
119            response = self._client.send(request, stream=False, **operation_config)
120
121            if response.status_code not in [200]:
122                exp = CloudError(response)
123                exp.request_id = response.headers.get('x-ms-request-id')
124                raise exp
125
126            return response
127
128        # Deserialize response
129        header_dict = None
130        if raw:
131            header_dict = {}
132        deserialized = models.ArmTemplatePaged(internal_paging, self._deserialize.dependencies, header_dict)
133
134        return deserialized
135    list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates'}
136
137    def get(
138            self, resource_group_name, lab_name, artifact_source_name, name, expand=None, custom_headers=None, raw=False, **operation_config):
139        """Get azure resource manager template.
140
141        :param resource_group_name: The name of the resource group.
142        :type resource_group_name: str
143        :param lab_name: The name of the lab.
144        :type lab_name: str
145        :param artifact_source_name: The name of the artifact source.
146        :type artifact_source_name: str
147        :param name: The name of the azure resource manager template.
148        :type name: str
149        :param expand: Specify the $expand query. Example:
150         'properties($select=displayName)'
151        :type expand: str
152        :param dict custom_headers: headers that will be added to the request
153        :param bool raw: returns the direct response alongside the
154         deserialized response
155        :param operation_config: :ref:`Operation configuration
156         overrides<msrest:optionsforoperations>`.
157        :return: ArmTemplate or ClientRawResponse if raw=true
158        :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplate or
159         ~msrest.pipeline.ClientRawResponse
160        :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
161        """
162        # Construct URL
163        url = self.get.metadata['url']
164        path_format_arguments = {
165            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
166            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
167            'labName': self._serialize.url("lab_name", lab_name, 'str'),
168            'artifactSourceName': self._serialize.url("artifact_source_name", artifact_source_name, 'str'),
169            'name': self._serialize.url("name", name, 'str')
170        }
171        url = self._client.format_url(url, **path_format_arguments)
172
173        # Construct parameters
174        query_parameters = {}
175        if expand is not None:
176            query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
177        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
178
179        # Construct headers
180        header_parameters = {}
181        header_parameters['Accept'] = 'application/json'
182        if self.config.generate_client_request_id:
183            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
184        if custom_headers:
185            header_parameters.update(custom_headers)
186        if self.config.accept_language is not None:
187            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
188
189        # Construct and send request
190        request = self._client.get(url, query_parameters, header_parameters)
191        response = self._client.send(request, stream=False, **operation_config)
192
193        if response.status_code not in [200]:
194            exp = CloudError(response)
195            exp.request_id = response.headers.get('x-ms-request-id')
196            raise exp
197
198        deserialized = None
199        if response.status_code == 200:
200            deserialized = self._deserialize('ArmTemplate', response)
201
202        if raw:
203            client_raw_response = ClientRawResponse(deserialized, response)
204            return client_raw_response
205
206        return deserialized
207    get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates/{name}'}
208