azure python sdk 方法中的 custom_headers 是什么?
What is custom_headers in azure python sdk methods?
我正在尝试查找附加到 运行 Azure VM 的 public IP 地址。
我已经根据 尝试了两个答案,但我没有得到所需的输出。
正在获取 Public IP:None
...: 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 的完整列表?
- 也有人可以分享一些列出和获取 running/stopped VM 的所有详细信息的示例吗?
简短版:您的问题已在 Github 上得到解决:
https://github.com/Azure/azure-sdk-for-python/issues/897
一些评论:
custom_headers
是定义 HTTP headers,这对您的情况没有帮助:
- 根据设计,当您创建
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-
- 您的第一个代码很好,但是您需要将 re-inject 的 public IP id 转换为
public_ip_addresses.get
。由于计算原因,NIC 不会扩展到实际的 Public IP 值。
(我在 MS Python SDK 团队工作)
我正在尝试查找附加到 运行 Azure VM 的 public 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 的完整列表?
- 也有人可以分享一些列出和获取 running/stopped VM 的所有详细信息的示例吗?
简短版:您的问题已在 Github 上得到解决: https://github.com/Azure/azure-sdk-for-python/issues/897
一些评论:
custom_headers
是定义 HTTP headers,这对您的情况没有帮助:- 根据设计,当您创建
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-- 您的第一个代码很好,但是您需要将 re-inject 的 public IP id 转换为
public_ip_addresses.get
。由于计算原因,NIC 不会扩展到实际的 Public IP 值。
(我在 MS Python SDK 团队工作)