コード例 #1
0
        // Get public IP addresses out of a resource group in Azure
        public static List <ARM.IpAddress> GetPublicIps(string customerId, string subscriptionId, string groupName)
        {
            // Initialize
            List <IpAddress> output = new List <IpAddress>();

            // Get token from ARM API
            string token      = REST.getArmTokenSync(customerId, UserAuth: true);
            var    credential = new TokenCredentials(token);
            var    armClient  = new Microsoft.Azure.Management.ResourceManager.ResourceManagementClient(credential)
            {
                SubscriptionId = subscriptionId
            };

            // Get resources in resource group
            var resourceList = armClient.Resources.ListByResourceGroup(groupName).ToList();

            foreach (var resource in resourceList)
            {
                if (resource.Type == "Microsoft.Network/publicIPAddresses")
                {
                    //var thisresource = armClient.Resources.GetById(resource.Id);
                    var    thisresource = armClient.Resources.GetById(resource.Id, "2018-02-01");
                    string jsonstring   = thisresource.Properties.ToString();
                    JToken jtoken       = JObject.Parse(jsonstring);
                    string ipAddress    = (string)jtoken.SelectToken("ipAddress");
                    if (!thisresource.Name.Contains("slb"))
                    {
                        ARM.IpAddress newIp = new ARM.IpAddress();
                        newIp.Address = ipAddress;
                        newIp.Name    = thisresource.Name.Replace("-pip", "");
                        output.Add(newIp);
                    }
                }
            }

            // Return everything
            return(output);
        }