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 license information.
5# Code generated by Microsoft (R) AutoRest Code Generator.
6# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7# --------------------------------------------------------------------------
8from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar
9import warnings
10
11from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
12from azure.core.pipeline import PipelineResponse
13from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
14from azure.mgmt.core.exceptions import ARMErrorFormat
15
16from ... import models as _models
17
18T = TypeVar('T')
19ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
20
21class VirtualMachineExtensionImagesOperations:
22    """VirtualMachineExtensionImagesOperations async operations.
23
24    You should not instantiate this class directly. Instead, you should create a Client instance that
25    instantiates it for you and attaches it as an attribute.
26
27    :ivar models: Alias to model classes used in this operation group.
28    :type models: ~azure.mgmt.compute.v2019_12_01.models
29    :param client: Client for service requests.
30    :param config: Configuration of service client.
31    :param serializer: An object model serializer.
32    :param deserializer: An object model deserializer.
33    """
34
35    models = _models
36
37    def __init__(self, client, config, serializer, deserializer) -> None:
38        self._client = client
39        self._serialize = serializer
40        self._deserialize = deserializer
41        self._config = config
42
43    async def get(
44        self,
45        location: str,
46        publisher_name: str,
47        type: str,
48        version: str,
49        **kwargs: Any
50    ) -> "_models.VirtualMachineExtensionImage":
51        """Gets a virtual machine extension image.
52
53        :param location: The name of a supported Azure region.
54        :type location: str
55        :param publisher_name:
56        :type publisher_name: str
57        :param type:
58        :type type: str
59        :param version:
60        :type version: str
61        :keyword callable cls: A custom type or function that will be passed the direct response
62        :return: VirtualMachineExtensionImage, or the result of cls(response)
63        :rtype: ~azure.mgmt.compute.v2019_12_01.models.VirtualMachineExtensionImage
64        :raises: ~azure.core.exceptions.HttpResponseError
65        """
66        cls = kwargs.pop('cls', None)  # type: ClsType["_models.VirtualMachineExtensionImage"]
67        error_map = {
68            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
69        }
70        error_map.update(kwargs.pop('error_map', {}))
71        api_version = "2019-12-01"
72        accept = "application/json"
73
74        # Construct URL
75        url = self.get.metadata['url']  # type: ignore
76        path_format_arguments = {
77            'location': self._serialize.url("location", location, 'str'),
78            'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'),
79            'type': self._serialize.url("type", type, 'str'),
80            'version': self._serialize.url("version", version, 'str'),
81            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
82        }
83        url = self._client.format_url(url, **path_format_arguments)
84
85        # Construct parameters
86        query_parameters = {}  # type: Dict[str, Any]
87        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
88
89        # Construct headers
90        header_parameters = {}  # type: Dict[str, Any]
91        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
92
93        request = self._client.get(url, query_parameters, header_parameters)
94        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
95        response = pipeline_response.http_response
96
97        if response.status_code not in [200]:
98            map_error(status_code=response.status_code, response=response, error_map=error_map)
99            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
100
101        deserialized = self._deserialize('VirtualMachineExtensionImage', pipeline_response)
102
103        if cls:
104            return cls(pipeline_response, deserialized, {})
105
106        return deserialized
107    get.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types/{type}/versions/{version}'}  # type: ignore
108
109    async def list_types(
110        self,
111        location: str,
112        publisher_name: str,
113        **kwargs: Any
114    ) -> List["_models.VirtualMachineExtensionImage"]:
115        """Gets a list of virtual machine extension image types.
116
117        :param location: The name of a supported Azure region.
118        :type location: str
119        :param publisher_name:
120        :type publisher_name: str
121        :keyword callable cls: A custom type or function that will be passed the direct response
122        :return: list of VirtualMachineExtensionImage, or the result of cls(response)
123        :rtype: list[~azure.mgmt.compute.v2019_12_01.models.VirtualMachineExtensionImage]
124        :raises: ~azure.core.exceptions.HttpResponseError
125        """
126        cls = kwargs.pop('cls', None)  # type: ClsType[List["_models.VirtualMachineExtensionImage"]]
127        error_map = {
128            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
129        }
130        error_map.update(kwargs.pop('error_map', {}))
131        api_version = "2019-12-01"
132        accept = "application/json"
133
134        # Construct URL
135        url = self.list_types.metadata['url']  # type: ignore
136        path_format_arguments = {
137            'location': self._serialize.url("location", location, 'str'),
138            'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'),
139            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
140        }
141        url = self._client.format_url(url, **path_format_arguments)
142
143        # Construct parameters
144        query_parameters = {}  # type: Dict[str, Any]
145        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
146
147        # Construct headers
148        header_parameters = {}  # type: Dict[str, Any]
149        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
150
151        request = self._client.get(url, query_parameters, header_parameters)
152        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
153        response = pipeline_response.http_response
154
155        if response.status_code not in [200]:
156            map_error(status_code=response.status_code, response=response, error_map=error_map)
157            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
158
159        deserialized = self._deserialize('[VirtualMachineExtensionImage]', pipeline_response)
160
161        if cls:
162            return cls(pipeline_response, deserialized, {})
163
164        return deserialized
165    list_types.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types'}  # type: ignore
166
167    async def list_versions(
168        self,
169        location: str,
170        publisher_name: str,
171        type: str,
172        filter: Optional[str] = None,
173        top: Optional[int] = None,
174        orderby: Optional[str] = None,
175        **kwargs: Any
176    ) -> List["_models.VirtualMachineExtensionImage"]:
177        """Gets a list of virtual machine extension image versions.
178
179        :param location: The name of a supported Azure region.
180        :type location: str
181        :param publisher_name:
182        :type publisher_name: str
183        :param type:
184        :type type: str
185        :param filter: The filter to apply on the operation.
186        :type filter: str
187        :param top:
188        :type top: int
189        :param orderby:
190        :type orderby: str
191        :keyword callable cls: A custom type or function that will be passed the direct response
192        :return: list of VirtualMachineExtensionImage, or the result of cls(response)
193        :rtype: list[~azure.mgmt.compute.v2019_12_01.models.VirtualMachineExtensionImage]
194        :raises: ~azure.core.exceptions.HttpResponseError
195        """
196        cls = kwargs.pop('cls', None)  # type: ClsType[List["_models.VirtualMachineExtensionImage"]]
197        error_map = {
198            401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
199        }
200        error_map.update(kwargs.pop('error_map', {}))
201        api_version = "2019-12-01"
202        accept = "application/json"
203
204        # Construct URL
205        url = self.list_versions.metadata['url']  # type: ignore
206        path_format_arguments = {
207            'location': self._serialize.url("location", location, 'str'),
208            'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'),
209            'type': self._serialize.url("type", type, 'str'),
210            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
211        }
212        url = self._client.format_url(url, **path_format_arguments)
213
214        # Construct parameters
215        query_parameters = {}  # type: Dict[str, Any]
216        if filter is not None:
217            query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
218        if top is not None:
219            query_parameters['$top'] = self._serialize.query("top", top, 'int')
220        if orderby is not None:
221            query_parameters['$orderby'] = self._serialize.query("orderby", orderby, 'str')
222        query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
223
224        # Construct headers
225        header_parameters = {}  # type: Dict[str, Any]
226        header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
227
228        request = self._client.get(url, query_parameters, header_parameters)
229        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
230        response = pipeline_response.http_response
231
232        if response.status_code not in [200]:
233            map_error(status_code=response.status_code, response=response, error_map=error_map)
234            raise HttpResponseError(response=response, error_format=ARMErrorFormat)
235
236        deserialized = self._deserialize('[VirtualMachineExtensionImage]', pipeline_response)
237
238        if cls:
239            return cls(pipeline_response, deserialized, {})
240
241        return deserialized
242    list_versions.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types/{type}/versions'}  # type: ignore
243