【问题标题】:Adding Application Security Group to Azure VM将应用程序安全组添加到 Azure VM
【发布时间】:2019-11-03 07:14:48
【问题描述】:

我需要将现有的 ASG(应用程序安全组)添加到现有的 NetworkInterface。

在下面的代码中,我可以找到我的 ASG 和 NetworkInterface...但我不知道如何将它们连接在一起。

public void AddASG(string servername, string ASGName)
{
    IAzure azure = ConnectAzure();
    var ASG = azure.ApplicationSecurityGroups.List().Where(y => y.Name == ASGName).First();

    var nic = azure.NetworkInterfaces.List()
        .Where(y => y.Name.ToUpper().Contains(servername))
        .Select(x => x).First();

    nic.IPConfigurations?????;
}

【问题讨论】:

    标签: c# azure azure-virtual-machine


    【解决方案1】:

    目前看来,这样的功能是不可能的。请看同一个feature request,它仍然开放。

    作为一种解决方法,您可以发出this REST API 请求,以便将所需的 ASG 关联到您的网络接口。

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}?api-version=2018-11-01
    

    发送 JSON 请求,格式为:

     {
      "location": "xxx",
      "properties": {
        "ipConfigurations": [
        {
          "name": "primary",
          "properties": 
          {
            "privateIPAllocationMethod": "Dynamic",
            "subnet": {
              "id": "/subscriptions/xxxxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworks/xxx/subnets/xxx"
          },
            "applicationSecurityGroups" : [
              { 
                "id": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/applicationSecurityGroups/xxx"
              }
            ]
          }
        }
        ]
     }
    }
    

    或者,您也可以execute PowerShell scripts from C#

    希望这对你有帮助。

    【讨论】:

    • 非常感谢,我会试试这个,但这看起来是个不错的选择
    猜你喜欢
    • 1970-01-01
    • 2016-10-22
    • 2023-03-24
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多