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 TYPE_CHECKING 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 HttpRequest, HttpResponse 14from azure.mgmt.core.exceptions import ARMErrorFormat 15 16from .. import models as _models 17 18if TYPE_CHECKING: 19 # pylint: disable=unused-import,ungrouped-imports 20 from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar 21 22 T = TypeVar('T') 23 ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] 24 25class VirtualMachineImagesOperations(object): 26 """VirtualMachineImagesOperations operations. 27 28 You should not instantiate this class directly. Instead, you should create a Client instance that 29 instantiates it for you and attaches it as an attribute. 30 31 :ivar models: Alias to model classes used in this operation group. 32 :type models: ~azure.mgmt.compute.v2016_03_30.models 33 :param client: Client for service requests. 34 :param config: Configuration of service client. 35 :param serializer: An object model serializer. 36 :param deserializer: An object model deserializer. 37 """ 38 39 models = _models 40 41 def __init__(self, client, config, serializer, deserializer): 42 self._client = client 43 self._serialize = serializer 44 self._deserialize = deserializer 45 self._config = config 46 47 def get( 48 self, 49 location, # type: str 50 publisher_name, # type: str 51 offer, # type: str 52 skus, # type: str 53 version, # type: str 54 **kwargs # type: Any 55 ): 56 # type: (...) -> "_models.VirtualMachineImage" 57 """Gets a virtual machine image. 58 59 :param location: The name of a supported Azure region. 60 :type location: str 61 :param publisher_name: A valid image publisher. 62 :type publisher_name: str 63 :param offer: A valid image publisher offer. 64 :type offer: str 65 :param skus: A valid image SKU. 66 :type skus: str 67 :param version: A valid image SKU version. 68 :type version: str 69 :keyword callable cls: A custom type or function that will be passed the direct response 70 :return: VirtualMachineImage, or the result of cls(response) 71 :rtype: ~azure.mgmt.compute.v2016_03_30.models.VirtualMachineImage 72 :raises: ~azure.core.exceptions.HttpResponseError 73 """ 74 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineImage"] 75 error_map = { 76 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 77 } 78 error_map.update(kwargs.pop('error_map', {})) 79 api_version = "2016-03-30" 80 accept = "application/json" 81 82 # Construct URL 83 url = self.get.metadata['url'] # type: ignore 84 path_format_arguments = { 85 'location': self._serialize.url("location", location, 'str'), 86 'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'), 87 'offer': self._serialize.url("offer", offer, 'str'), 88 'skus': self._serialize.url("skus", skus, 'str'), 89 'version': self._serialize.url("version", version, 'str'), 90 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 91 } 92 url = self._client.format_url(url, **path_format_arguments) 93 94 # Construct parameters 95 query_parameters = {} # type: Dict[str, Any] 96 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 97 98 # Construct headers 99 header_parameters = {} # type: Dict[str, Any] 100 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 101 102 request = self._client.get(url, query_parameters, header_parameters) 103 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 104 response = pipeline_response.http_response 105 106 if response.status_code not in [200]: 107 map_error(status_code=response.status_code, response=response, error_map=error_map) 108 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 109 110 deserialized = self._deserialize('VirtualMachineImage', pipeline_response) 111 112 if cls: 113 return cls(pipeline_response, deserialized, {}) 114 115 return deserialized 116 get.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions/{version}'} # type: ignore 117 118 def list( 119 self, 120 location, # type: str 121 publisher_name, # type: str 122 offer, # type: str 123 skus, # type: str 124 expand=None, # type: Optional[str] 125 top=None, # type: Optional[int] 126 orderby=None, # type: Optional[str] 127 **kwargs # type: Any 128 ): 129 # type: (...) -> List["_models.VirtualMachineImageResource"] 130 """Gets a list of all virtual machine image versions for the specified location, publisher, offer, 131 and SKU. 132 133 :param location: The name of a supported Azure region. 134 :type location: str 135 :param publisher_name: A valid image publisher. 136 :type publisher_name: str 137 :param offer: A valid image publisher offer. 138 :type offer: str 139 :param skus: A valid image SKU. 140 :type skus: str 141 :param expand: The expand expression to apply on the operation. 142 :type expand: str 143 :param top: 144 :type top: int 145 :param orderby: 146 :type orderby: str 147 :keyword callable cls: A custom type or function that will be passed the direct response 148 :return: list of VirtualMachineImageResource, or the result of cls(response) 149 :rtype: list[~azure.mgmt.compute.v2016_03_30.models.VirtualMachineImageResource] 150 :raises: ~azure.core.exceptions.HttpResponseError 151 """ 152 cls = kwargs.pop('cls', None) # type: ClsType[List["_models.VirtualMachineImageResource"]] 153 error_map = { 154 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 155 } 156 error_map.update(kwargs.pop('error_map', {})) 157 api_version = "2016-03-30" 158 accept = "application/json" 159 160 # Construct URL 161 url = self.list.metadata['url'] # type: ignore 162 path_format_arguments = { 163 'location': self._serialize.url("location", location, 'str'), 164 'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'), 165 'offer': self._serialize.url("offer", offer, 'str'), 166 'skus': self._serialize.url("skus", skus, 'str'), 167 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 168 } 169 url = self._client.format_url(url, **path_format_arguments) 170 171 # Construct parameters 172 query_parameters = {} # type: Dict[str, Any] 173 if expand is not None: 174 query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') 175 if top is not None: 176 query_parameters['$top'] = self._serialize.query("top", top, 'int') 177 if orderby is not None: 178 query_parameters['$orderby'] = self._serialize.query("orderby", orderby, 'str') 179 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 180 181 # Construct headers 182 header_parameters = {} # type: Dict[str, Any] 183 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 184 185 request = self._client.get(url, query_parameters, header_parameters) 186 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 187 response = pipeline_response.http_response 188 189 if response.status_code not in [200]: 190 map_error(status_code=response.status_code, response=response, error_map=error_map) 191 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 192 193 deserialized = self._deserialize('[VirtualMachineImageResource]', pipeline_response) 194 195 if cls: 196 return cls(pipeline_response, deserialized, {}) 197 198 return deserialized 199 list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions'} # type: ignore 200 201 def list_offers( 202 self, 203 location, # type: str 204 publisher_name, # type: str 205 **kwargs # type: Any 206 ): 207 # type: (...) -> List["_models.VirtualMachineImageResource"] 208 """Gets a list of virtual machine image offers for the specified location and publisher. 209 210 :param location: The name of a supported Azure region. 211 :type location: str 212 :param publisher_name: A valid image publisher. 213 :type publisher_name: str 214 :keyword callable cls: A custom type or function that will be passed the direct response 215 :return: list of VirtualMachineImageResource, or the result of cls(response) 216 :rtype: list[~azure.mgmt.compute.v2016_03_30.models.VirtualMachineImageResource] 217 :raises: ~azure.core.exceptions.HttpResponseError 218 """ 219 cls = kwargs.pop('cls', None) # type: ClsType[List["_models.VirtualMachineImageResource"]] 220 error_map = { 221 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 222 } 223 error_map.update(kwargs.pop('error_map', {})) 224 api_version = "2016-03-30" 225 accept = "application/json" 226 227 # Construct URL 228 url = self.list_offers.metadata['url'] # type: ignore 229 path_format_arguments = { 230 'location': self._serialize.url("location", location, 'str'), 231 'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'), 232 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 233 } 234 url = self._client.format_url(url, **path_format_arguments) 235 236 # Construct parameters 237 query_parameters = {} # type: Dict[str, Any] 238 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 239 240 # Construct headers 241 header_parameters = {} # type: Dict[str, Any] 242 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 243 244 request = self._client.get(url, query_parameters, header_parameters) 245 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 246 response = pipeline_response.http_response 247 248 if response.status_code not in [200]: 249 map_error(status_code=response.status_code, response=response, error_map=error_map) 250 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 251 252 deserialized = self._deserialize('[VirtualMachineImageResource]', pipeline_response) 253 254 if cls: 255 return cls(pipeline_response, deserialized, {}) 256 257 return deserialized 258 list_offers.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers'} # type: ignore 259 260 def list_publishers( 261 self, 262 location, # type: str 263 **kwargs # type: Any 264 ): 265 # type: (...) -> List["_models.VirtualMachineImageResource"] 266 """Gets a list of virtual machine image publishers for the specified Azure location. 267 268 :param location: The name of a supported Azure region. 269 :type location: str 270 :keyword callable cls: A custom type or function that will be passed the direct response 271 :return: list of VirtualMachineImageResource, or the result of cls(response) 272 :rtype: list[~azure.mgmt.compute.v2016_03_30.models.VirtualMachineImageResource] 273 :raises: ~azure.core.exceptions.HttpResponseError 274 """ 275 cls = kwargs.pop('cls', None) # type: ClsType[List["_models.VirtualMachineImageResource"]] 276 error_map = { 277 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 278 } 279 error_map.update(kwargs.pop('error_map', {})) 280 api_version = "2016-03-30" 281 accept = "application/json" 282 283 # Construct URL 284 url = self.list_publishers.metadata['url'] # type: ignore 285 path_format_arguments = { 286 'location': self._serialize.url("location", location, 'str'), 287 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 288 } 289 url = self._client.format_url(url, **path_format_arguments) 290 291 # Construct parameters 292 query_parameters = {} # type: Dict[str, Any] 293 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 294 295 # Construct headers 296 header_parameters = {} # type: Dict[str, Any] 297 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 298 299 request = self._client.get(url, query_parameters, header_parameters) 300 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 301 response = pipeline_response.http_response 302 303 if response.status_code not in [200]: 304 map_error(status_code=response.status_code, response=response, error_map=error_map) 305 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 306 307 deserialized = self._deserialize('[VirtualMachineImageResource]', pipeline_response) 308 309 if cls: 310 return cls(pipeline_response, deserialized, {}) 311 312 return deserialized 313 list_publishers.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers'} # type: ignore 314 315 def list_skus( 316 self, 317 location, # type: str 318 publisher_name, # type: str 319 offer, # type: str 320 **kwargs # type: Any 321 ): 322 # type: (...) -> List["_models.VirtualMachineImageResource"] 323 """Gets a list of virtual machine image SKUs for the specified location, publisher, and offer. 324 325 :param location: The name of a supported Azure region. 326 :type location: str 327 :param publisher_name: A valid image publisher. 328 :type publisher_name: str 329 :param offer: A valid image publisher offer. 330 :type offer: str 331 :keyword callable cls: A custom type or function that will be passed the direct response 332 :return: list of VirtualMachineImageResource, or the result of cls(response) 333 :rtype: list[~azure.mgmt.compute.v2016_03_30.models.VirtualMachineImageResource] 334 :raises: ~azure.core.exceptions.HttpResponseError 335 """ 336 cls = kwargs.pop('cls', None) # type: ClsType[List["_models.VirtualMachineImageResource"]] 337 error_map = { 338 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 339 } 340 error_map.update(kwargs.pop('error_map', {})) 341 api_version = "2016-03-30" 342 accept = "application/json" 343 344 # Construct URL 345 url = self.list_skus.metadata['url'] # type: ignore 346 path_format_arguments = { 347 'location': self._serialize.url("location", location, 'str'), 348 'publisherName': self._serialize.url("publisher_name", publisher_name, 'str'), 349 'offer': self._serialize.url("offer", offer, 'str'), 350 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 351 } 352 url = self._client.format_url(url, **path_format_arguments) 353 354 # Construct parameters 355 query_parameters = {} # type: Dict[str, Any] 356 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 357 358 # Construct headers 359 header_parameters = {} # type: Dict[str, Any] 360 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 361 362 request = self._client.get(url, query_parameters, header_parameters) 363 pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) 364 response = pipeline_response.http_response 365 366 if response.status_code not in [200]: 367 map_error(status_code=response.status_code, response=response, error_map=error_map) 368 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 369 370 deserialized = self._deserialize('[VirtualMachineImageResource]', pipeline_response) 371 372 if cls: 373 return cls(pipeline_response, deserialized, {}) 374 375 return deserialized 376 list_skus.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus'} # type: ignore 377