【问题标题】:how to get resource cost with azure python sdk?如何使用 azure python sdk 获取资源成本?
【发布时间】:2021-08-09 15:09:56
【问题描述】:

我正在努力弄清楚如何使用 python sdk 获取 azure 资源的成本

我创建了一个客户端“BillingManagementClient” 但我不知道如何开始使用它并找到有关资源的成本信息, 谁能分享他的知识?

【问题讨论】:

    标签: azure azure-sdk-python cost-management


    【解决方案1】:

    要使用 Azure Python SDK 获取资源成本,计费可作为 SDK 提供。 azure-mgmt-billing 6.0.0azure-mgmt-consumption 8.0.0

    _billing_management_client.py

     def _send_request(self, http_request, **kwargs):
            # type: (HttpRequest, Any) -> HttpResponse
            """Runs the network request through the client's chained policies.
            :param http_request: The network request you want to make. Required.
            :type http_request: ~azure.core.pipeline.transport.HttpRequest
            :keyword bool stream: Whether the response payload will be streamed. Defaults to True.
            :return: The response of your network call. Does not do error handling on your response.
            :rtype: ~azure.core.pipeline.transport.HttpResponse
            """
            path_format_arguments = {
                'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
            }
            http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
            stream = kwargs.pop("stream", True)
            pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
            return pipeline_response.http_response
    

    您可以参考Show azure cost analysis data using Azure billing API/SDKGetting started - Managing Resource using Azure Python SDK

    【讨论】:

      相关资源