如何在运行时查找将服务结构部署到哪个Azure群集

时间:2019-01-08 09:32:05

标签: azure azure-deployment azure-service-fabric

我有一个.Net Service Fabric应用程序,该应用程序已部署到不同的Azure群集。 在运行时是否有一些API可以知道我的代码在哪个Azure群集区域中运行?

这样做的动机是我想根据代码在哪个区域运行来更改代码行为。

1 个答案:

答案 0 :(得分:0)

天蓝色,您可以使用Instance Metadada Service来查询有关运行应用程序的VM的详细信息。

类似这样的东西:

curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-12-01"

将使用location属性返回计算信息:

{
  "compute": {
    "location": "westus",
    "name": "avset2",
    "offer": "UbuntuServer",
    "osType": "Linux",
    "placementGroupId": "",
    "platformFaultDomain": "1",
    "platformUpdateDomain": "1",
    "publisher": "Canonical",
    "resourceGroupName": "myrg",
    "sku": "16.04-LTS",
    "subscriptionId": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
    "tags": "",
    "version": "16.04.201708030",
    "vmId": "13f56399-bd52-4150-9748-7190aae1ff21",
    "vmScaleSetName": "",
    "vmSize": "Standard_D1",
    "zone": "1"
  },
  "network": {
    "interface": [
      {
        "ipv4": {
          "ipAddress": [
            {
              "privateIpAddress": "10.1.2.5",
              "publicIpAddress": "X.X.X.X"
            }
          ],
          "subnet": [
            {
              "address": "10.1.2.0",
              "prefix": "24"
            }
          ]
        },
        "ipv6": {
          "ipAddress": []
        },
        "macAddress": "000D3A36DDED"
      }
    ]
  }
}