azure - azure python sdk方法中的custom_headers是什么?
问题描述
我正在尝试查找附加到运行 Azure VM 的公共 IP 地址。
我已经按照Get IP from VM object using azure sdk in python尝试了这两个答案,但我没有得到所需的输出。获取公共 IP:无
...: for interface in vm.network_profile.network_interfaces:
...: name=" ".join(interface.id.split('/')[-1:])
...: print (name)
...: sub="".join(interface.id.split('/')[4])
...: print (sub)
...: thing = network_client.network_interfaces.get(sub, name).ip_configurations
...: for x in thing:
...: print (x.public_ip_address)
...:
xxx
xxx
{'additional_properties': {}, 'id': '/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/publicIPAddresses/Test-ip', 'name': None, 'type': None, 'location': None, 'tags': None, 'sku': None, 'public_ip_allocation_method': None, 'public_ip_address_version': None, 'ip_configuration': None, 'dns_settings': None, 'ddos_settings': None, 'ip_tags': None, 'ip_address': None, 'public_ip_prefix': None, 'idle_timeout_in_minutes': None, 'resource_guid': None, 'provisioning_state': None, 'etag': None, 'zones': None}
而使用 network_client 我得到输出
In [6]: from azure.mgmt.network import NetworkManagementClient
In [21]: for i in network_client.public_ip_addresses.list("xxx"):
...: print (i)
但是在这里我得到了所有订阅的输出,所有基本上我想要过滤的资源组。因此,我认为使用 custom_headers 我们可以过滤,但我没有得到我为 custom_headers 创建的 dict 的确切命名约定。
- 如何获得可用 custom_headers 的完整列表?
- 也有人可以分享一些列出和获取正在运行/停止的 VM 的所有详细信息的示例吗?
解决方案
简短版:您的问题已在 Github 上得到解决: https ://github.com/Azure/azure-sdk-for-python/issues/897
不过有几点评论:
custom_headers
是定义 HTTP 标头,这对您的方案没有帮助:- 按照设计,当您创建一个订阅时
NetworkManagementClient
,您已经按订阅过滤,因为订阅是它的一个参数。 - 的参数
public_ip_addresses.list
是资源组名称,因此您已经按资源组名称过滤:请参阅https://docs.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2019_04_01 .operations.publicipaddressesoperations?view=azure-python#list-resource-group-name--custom-headers-none--raw-false----operation-config- - 您的第一个代码很好,但您需要将公共 IP id 重新注入
public_ip_addresses.get
. 出于计算原因,NIC 不会扩展到实际的公共 IP 值。
(我在 Python SDK 团队的 MS 工作)
推荐阅读
- python - 如何根据Django中数据库中的当前数据禁用表单选项?
- angular - Angular CDK 虚拟滚动从列表中删除项目
- mongodb - 有没有办法在mongo中按字母顺序投影/检索文档字段?
- mysql - 如何将json字符串作为存储过程参数处理
- mongodb - MongoDB:比较 ArrayFilter 中的两个字段
- javascript - 为什么内联元素在底部有额外的边距?
- r - 对数似然函数给出 NaN 值
- spring - 更新到 Srping Boot 2.2 后如何修复 mongo 索引创建?
- google-cloud-platform - 使用 DL 时无法接收来自 GCP 堆栈驱动程序监控的电子邮件通知?
- c - 格式字符串“%g”需要“double”类型的参数,但可变参数 1 的类型为“long”