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# --------------------------------------------------------------------------
8
9from typing import TYPE_CHECKING
10
11from azure.mgmt.core import ARMPipelineClient
12from msrest import Deserializer, Serializer
13
14if TYPE_CHECKING:
15    # pylint: disable=unused-import,ungrouped-imports
16    from typing import Any, Optional
17
18    from azure.core.credentials import TokenCredential
19    from azure.core.pipeline.transport import HttpRequest, HttpResponse
20
21from ._configuration import ComputeManagementClientConfiguration
22from .operations import AvailabilitySetsOperations
23from .operations import VirtualMachineExtensionImagesOperations
24from .operations import VirtualMachineExtensionsOperations
25from .operations import VirtualMachinesOperations
26from .operations import VirtualMachineImagesOperations
27from .operations import UsageOperations
28from .operations import VirtualMachineSizesOperations
29from .operations import ImagesOperations
30from .operations import VirtualMachineScaleSetsOperations
31from .operations import VirtualMachineScaleSetVMsOperations
32from .operations import DisksOperations
33from .operations import SnapshotsOperations
34from . import models
35
36
37class ComputeManagementClient(object):
38    """Compute Client.
39
40    :ivar availability_sets: AvailabilitySetsOperations operations
41    :vartype availability_sets: azure.mgmt.compute.v2016_04_30_preview.operations.AvailabilitySetsOperations
42    :ivar virtual_machine_extension_images: VirtualMachineExtensionImagesOperations operations
43    :vartype virtual_machine_extension_images: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineExtensionImagesOperations
44    :ivar virtual_machine_extensions: VirtualMachineExtensionsOperations operations
45    :vartype virtual_machine_extensions: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineExtensionsOperations
46    :ivar virtual_machines: VirtualMachinesOperations operations
47    :vartype virtual_machines: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachinesOperations
48    :ivar virtual_machine_images: VirtualMachineImagesOperations operations
49    :vartype virtual_machine_images: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineImagesOperations
50    :ivar usage: UsageOperations operations
51    :vartype usage: azure.mgmt.compute.v2016_04_30_preview.operations.UsageOperations
52    :ivar virtual_machine_sizes: VirtualMachineSizesOperations operations
53    :vartype virtual_machine_sizes: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineSizesOperations
54    :ivar images: ImagesOperations operations
55    :vartype images: azure.mgmt.compute.v2016_04_30_preview.operations.ImagesOperations
56    :ivar virtual_machine_scale_sets: VirtualMachineScaleSetsOperations operations
57    :vartype virtual_machine_scale_sets: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineScaleSetsOperations
58    :ivar virtual_machine_scale_set_vms: VirtualMachineScaleSetVMsOperations operations
59    :vartype virtual_machine_scale_set_vms: azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineScaleSetVMsOperations
60    :ivar disks: DisksOperations operations
61    :vartype disks: azure.mgmt.compute.v2016_04_30_preview.operations.DisksOperations
62    :ivar snapshots: SnapshotsOperations operations
63    :vartype snapshots: azure.mgmt.compute.v2016_04_30_preview.operations.SnapshotsOperations
64    :param credential: Credential needed for the client to connect to Azure.
65    :type credential: ~azure.core.credentials.TokenCredential
66    :param subscription_id: Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.
67    :type subscription_id: str
68    :param str base_url: Service URL
69    :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
70    """
71
72    def __init__(
73        self,
74        credential,  # type: "TokenCredential"
75        subscription_id,  # type: str
76        base_url=None,  # type: Optional[str]
77        **kwargs  # type: Any
78    ):
79        # type: (...) -> None
80        if not base_url:
81            base_url = 'https://management.azure.com'
82        self._config = ComputeManagementClientConfiguration(credential, subscription_id, **kwargs)
83        self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
84
85        client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
86        self._serialize = Serializer(client_models)
87        self._serialize.client_side_validation = False
88        self._deserialize = Deserializer(client_models)
89
90        self.availability_sets = AvailabilitySetsOperations(
91            self._client, self._config, self._serialize, self._deserialize)
92        self.virtual_machine_extension_images = VirtualMachineExtensionImagesOperations(
93            self._client, self._config, self._serialize, self._deserialize)
94        self.virtual_machine_extensions = VirtualMachineExtensionsOperations(
95            self._client, self._config, self._serialize, self._deserialize)
96        self.virtual_machines = VirtualMachinesOperations(
97            self._client, self._config, self._serialize, self._deserialize)
98        self.virtual_machine_images = VirtualMachineImagesOperations(
99            self._client, self._config, self._serialize, self._deserialize)
100        self.usage = UsageOperations(
101            self._client, self._config, self._serialize, self._deserialize)
102        self.virtual_machine_sizes = VirtualMachineSizesOperations(
103            self._client, self._config, self._serialize, self._deserialize)
104        self.images = ImagesOperations(
105            self._client, self._config, self._serialize, self._deserialize)
106        self.virtual_machine_scale_sets = VirtualMachineScaleSetsOperations(
107            self._client, self._config, self._serialize, self._deserialize)
108        self.virtual_machine_scale_set_vms = VirtualMachineScaleSetVMsOperations(
109            self._client, self._config, self._serialize, self._deserialize)
110        self.disks = DisksOperations(
111            self._client, self._config, self._serialize, self._deserialize)
112        self.snapshots = SnapshotsOperations(
113            self._client, self._config, self._serialize, self._deserialize)
114
115    def _send_request(self, http_request, **kwargs):
116        # type: (HttpRequest, Any) -> HttpResponse
117        """Runs the network request through the client's chained policies.
118
119        :param http_request: The network request you want to make. Required.
120        :type http_request: ~azure.core.pipeline.transport.HttpRequest
121        :keyword bool stream: Whether the response payload will be streamed. Defaults to True.
122        :return: The response of your network call. Does not do error handling on your response.
123        :rtype: ~azure.core.pipeline.transport.HttpResponse
124        """
125        path_format_arguments = {
126            'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
127        }
128        http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
129        stream = kwargs.pop("stream", True)
130        pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
131        return pipeline_response.http_response
132
133    def close(self):
134        # type: () -> None
135        self._client.close()
136
137    def __enter__(self):
138        # type: () -> ComputeManagementClient
139        self._client.__enter__()
140        return self
141
142    def __exit__(self, *exc_details):
143        # type: (Any) -> None
144        self._client.__exit__(*exc_details)
145