Azure / azure-libraries-for-java

Azure Management Libraries for Java
https://docs.microsoft.com/en-us/java/azure/
MIT License
94 stars 98 forks source link

Get the Public IP of an instance within a VMSS #1393

Closed renutz closed 3 years ago

renutz commented 3 years ago

We are trying to get the public IP of an instance within a VMSS.

https://docs.microsoft.com/en-us/rest/api/virtualnetwork/publicipaddress%20in%20vmss/getvirtualmachinescalesetpublicipaddress

Apparently it's not implemented of the SDK.

When calling the NetworkInterface:

nic = myvmss.listNetworkInterfacesByInstanceId("1");

https://management.azure.com/subscriptions/xxxxx/resourceGroups/myrg/providers/microsoft.Compute/virtualMachineScaleSets/myvmss/virtualMachines/1/networkInterfaces?api-version=2018-10-01

... "ipConfigurations": [ { "name": "xxx", "id": "xxx", "etag": "xx", "properties": { "provisioningState": "Succeeded", "privateIPAddress": "xx", "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "id" }, "subnet": ....

It only brings the ID. There is no method to call further and get the publicIPAddress details based on this ID.

Thanks.

weidongxu-microsoft commented 3 years ago

Would azure.publicIpAddresses().getById(id) get it?

weidongxu-microsoft commented 3 years ago

Or you can do this if you really wanted to azure.networkInterfaces().manager().inner().publicIPAddresses().getVirtualMachineScaleSetPublicIPAddress()

renutz commented 3 years ago

Hi,

Thanks for promptness.

azure.publicIpAddresses().getById(id) -> it does not work. It gets 404.

azure.networkInterfaces().manager().inner().publicIPAddresses().getVirtualMachineScaleSetPublicIPAddress() -> it worked! (I guess I don't need to tell, but this is really obscure....)

weidongxu-microsoft commented 3 years ago

The method in the inner() is kind of less exposed because the API could be less stable (it is auto-generated from REST API spec). Though the API there would be complete.

BTW, next gen SDK is here. If you just start on new project, you might want to switch to this SDK. https://aka.ms/azsdk/java/mgmt Similar the API is azure.networkInterfaces().manager().serviceClient().getPublicIpAddresses().getVirtualMachineScaleSetPublicIpAddress(), and we can update the SDK to better expose it.