azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[BUG][JAVA SDK]We have observed that the listAvailablePrivateIPAddresses method, which we use to list the available IPs of a subnet, does not work when the subnet has only AddressPrefixes instead of a AddressPrefix.

Open abhishekpankaj54 opened this issue 1 year ago • 5 comments

Describe the bug [JAVA SDK]We have observed that the listAvailablePrivateIPAddresses method, which we use to list the available IPs of a subnet, does not work when the subnet has only AddressPrefixes instead of a AddressPrefix.

When you list the Vnet details via Azure SDK you will have all the subnet info of that Vnet and its value/parameters. We found when the subnet only has the AddressPrefix as a parameter it can get the AvailablePrivateIPAddresses using listAvailablePrivateIPAddresses method but when subnet only have the AddressPrefixes instead of addressPrefix this method( listAvailablePrivateIPAddresses) does not list the Available IP even we have the Free available IPs(Verified by azure cloud shell command).

Example of Vnet'subnet : "subnets": [ { "addressPrefixes": [ "10.0.0.0/29" ], "delegations": [], "etag": "W/"043b41c2-cdf2-45f6-a425-dfe908a9dd4e"", "id":

Here for this Subnet we can not get the free IPs as it has addressPrefixes as a parameter and addressPrefix parameter is missing.

Exception or Stack Trace DEBUG [2024-10-17 08:47:47,759] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:205]: Subnet name prismacloud-scan-1729154298905891729 DEBUG [2024-10-17 08:47:47,759] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:207]: Subnet addressPrefix 10.0.0.0/24 DEBUG [2024-10-17 08:47:47,885] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:210]: Subnet listAvailablePrivateIPAddresses [10.0.0.4, 10.0.0.5, 10.0.0.6, 10.0.0.7, 10.0.0.8] DEBUG [2024-10-17 08:47:47,885] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:205]: Subnet name default DEBUG [2024-10-17 08:47:47,885] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:209]: Subnet addressPrefixes 10.0.0.0/24

DEBUG [2024-10-17 08:47:47,886] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:210]: Subnet listAvailablePrivateIPAddresses []

DEBUG [2024-10-17 08:47:47,886] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:205]: Subnet name default DEBUG [2024-10-17 08:47:47,886] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:207]: Subnet addressPrefix 10.1.0.0/24 DEBUG [2024-10-17 08:47:48,020] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:210]: Subnet listAvailablePrivateIPAddresses [10.1.0.4, 10.1.0.5, 10.1.0.6, 10.1.0.7, 10.1.0.8] DEBUG [2024-10-17 08:47:48,020] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:205]: Subnet name defaultSubnet DEBUG [2024-10-17 08:47:48,020] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:207]: Subnet addressPrefix 10.15.0.0/24 DEBUG [2024-10-17 08:47:48,523] [main] [AzureClientFactory:getCloudTargetNetworksFromProvider:210]: Subnet listAvailablePrivateIPAddresses [10.15.0.4, 10.15.0.5, 10.15.0.6, 10.15.0.7, 10.15.0.8]

To Reproduce Just Create the Vnet and its subnet using Azure portal and list the Vnet details(Using CLI/or API calls) so you will have the addressPrefixes as a parameter of the subnet and try to build a simple java program as mentioned below.

Code Snippet

Sample code : public class AzureSubnetList { public static void main(String[] args) { // Create a NetworkManager instance with your Azure credentials NetworkManager networkManager = NetworkManager.authenticate( "", "", "", "" );

    // Get the network you want to list the subnets for
    Network network = networkManager.networks().getByResourceGroup("<your-resource-group>", "<your-network-name>");

    // Iterate over the subnets and print their parameters
    PagedIterable<Subnet> subnets = network.subnets().list();
    for (Subnet subnet : subnets) {
        System.out.println("Subnet ID: " + subnet.id());
        System.out.println("Subnet Name: " + subnet.name());
        if (subnet.inner().addressPrefix()!=null){

System.out.println("Subnet Address Prefix: " + subnet.addressPrefix()); } else{ System.out.println("Subnet Address Prefixes: " + subnet.inner().addressPrefixes().get(0)); }

           System.out.println("Subnet listAvailablePrivateIPAddresses: " + subnet.listAvailablePrivateIPAddresses());   ///  
        
       
        System.out.println();
    }
}

} Note that you'll need to replace the placeholders (, , , , , ) with your actual Azure subscription ID, client ID, client secret, tenant ID, resource group, and network name.

Also, make sure you have the Azure Java SDK added to your project's dependencies. You can find the Maven coordinates for the SDK here: https://mvnrepository.com/artifact/com.azure.resourcemanager/azure-resourcemanager-network

Expected behavior We should have the list of all private Available Ips.

Screenshots If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: [e.g. iOS]
  • IDE: [e.g. IntelliJ] Intellij
  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]
  • Java version: [e.g. 8] :java 17
  • App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special]
  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc]

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide: NO

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [ ] Bug Description Added
  • [ ] Repro Steps Added
  • [ ] Setup information Added

abhishekpankaj54 avatar Oct 18 '24 09:10 abhishekpankaj54

Thank you for your feedback. Tagging and routing to the team member best able to assist.

github-actions[bot] avatar Oct 18 '24 09:10 github-actions[bot]

@weidongxu-microsoft , Could you please have a look at it urgently? If you want more info please let me know.

abhishekpankaj54 avatar Oct 18 '24 14:10 abhishekpankaj54

@weidongxu-microsoft Did you check this?

abhishekpankaj54 avatar Oct 21 '24 07:10 abhishekpankaj54

@XiaofeiCao Could you take a look? If there is bug we'd like to fix it before Oct. release.

weidongxu-microsoft avatar Oct 21 '24 07:10 weidongxu-microsoft

@XiaofeiCao , Please update us as soon as possible, as our application is being impacted by this.

abhishekpankaj54 avatar Oct 21 '24 13:10 abhishekpankaj54

@XiaofeiCao , Did you get a chance to look into this?

abhishekpankaj54 avatar Oct 22 '24 07:10 abhishekpankaj54

@XiaofeiCao , Did you get a chance to look into this?

Yeah, I'm looking into this. This is an SDK bug and we've found the root cause. I'm working on a fix and should be able to release a new version this week.

XiaofeiCao avatar Oct 22 '24 07:10 XiaofeiCao

@XiaofeiCao , Thanks for the Update, please update me once it is released.

abhishekpankaj54 avatar Oct 22 '24 08:10 abhishekpankaj54

@XiaofeiCao , Will you be releasing a new version of the Azure Java SDK to address this fix? The latest version is 2.43.0 , so I assume a new version will be released by the end of October?

https://mvnrepository.com/artifact/com.azure.resourcemanager/azure-resourcemanager

abhishekpankaj54 avatar Oct 22 '24 11:10 abhishekpankaj54

@abhishekpankaj54 yes, target release date for 2.44.0 is 10/25

XiaofeiCao avatar Oct 23 '24 02:10 XiaofeiCao

@abhishekpankaj54 2.44.0 released with the fix.

XiaofeiCao avatar Oct 25 '24 09:10 XiaofeiCao

Hi @abhishekpankaj54. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar Oct 25 '24 09:10 github-actions[bot]

Hi @abhishekpankaj54, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

github-actions[bot] avatar Nov 01 '24 16:11 github-actions[bot]