question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Public IP of VM in ScaleSet

See original GitHub issue

Query/Question How can I get the public IP of each VM in a scale set?

var _azure = Azure
            .Configure()
            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            .Authenticate(GetCredentials(credentials))
            .WithSubscription(credentials.Subscription);

var scaleSets = await _azure.VirtualMachineScaleSets.ListAsync(true, cancellationToken);

// example of how to get the private ip:
var privateIp = scaleSets.First().VirtualMachines.List().First().ListNetworkInterfaces().First().PrimaryPrivateIP;

// PrimaryPublicIp does not exist:
var publicIp = scaleSets.First().VirtualMachines.List().First().ListNetworkInterfaces().First().PrimaryPublicIP;

Setup (please complete the following information if applicable):

  • OS: Windows
  • IDE : JetBrains Rider
  • Version of the Library used:
    • Microsoft.Azure.Management.Fluent Version=“1.36.1”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
avirishuvcommented, Feb 4, 2021

@weidongxu-microsoft the API is documented in the NW spec here: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/network/resource-manager/Microsoft.Network/stable/2020-08-01/vmssPublicIpAddress.json

Hope this clarifies the question. Closing the issue, feel free to reopen if there are additional questions on this.

1reaction
klysecommented, Dec 18, 2020

Here is a workaround in c#:

Types:

public sealed record PublicIpConfiguration(IList<IpConfiguration> Value);

public sealed record IpConfiguration(string Name, string Id, string Etag, Properties Properties);

public sealed record Properties(string ProvisioningState, string ResourceGuid, string IpAddress, string PublicIPAddressVersion, string PublicIPAllocationMethod, string IdleTimeoutInMinutes, IpConfigurationId IpConfiguration);

public sealed record IpConfigurationId(string Id);

Call:

var client = RestClient
    .Configure()
    .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
    .WithCredentials(_credentials)
    .Build();

var url = $"https://management.azure.com/subscriptions/{_azure.SubscriptionId}/resourceGroups/{scaleSet.ResourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{scaleSet.Name}/publicipaddresses?api-version=2017-03-30";

var request = new HttpRequestMessage(HttpMethod.Get, url);

client.Credentials.ProcessHttpRequestAsync(request, cancellationToken).GetAwaiter().GetResult();
var httpClient = new HttpClient();
var response = httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).GetAwaiter().GetResult();

var stream = await response.Content.ReadAsStringAsync(cancellationToken);
var output = JsonConvert.DeserializeObject<PublicIpConfiguration>(stream);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to assign public ip to Virtual machine scale set instance
To create a scale set that assigns a public IP address to each virtual machine with the CLI, add the --public-ip-per-vm parameter to...
Read more >
How to assign public IP to VM in VM-scaleset in Azure
1 Answer. But probably it is a better idea to assign a Public IP to the load balancer and then create Inbound NAT...
Read more >
Adding public IP for existing virtual machine scale set
You can create a load balancer with the public IP, then add the virtual machine scale set into the backend pool of the...
Read more >
How to assign public ip to Virtual machine scale set instance
Hi I created a VSS and under this there are 2 instances. I want to assign public ip to these instances - https://prnt.sc/qhVd9zChzQiN...
Read more >
How To RDP/SSH Into Azure VMSS VM Instances
In this post we will review how to connect to Virtual Machine Scale Set instances using RDP for Windows and SSH for Linux....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found