Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.34k stars 1.98k forks source link

[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. #42457

Open abhishekpankaj54 opened 5 days ago

abhishekpankaj54 commented 5 days ago

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):

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

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

github-actions[bot] commented 5 days ago

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

abhishekpankaj54 commented 4 days ago

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

abhishekpankaj54 commented 2 days ago

@weidongxu-microsoft Did you check this?

weidongxu-microsoft commented 2 days ago

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

abhishekpankaj54 commented 2 days ago

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

abhishekpankaj54 commented 1 day ago

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

XiaofeiCao commented 1 day ago

@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.

abhishekpankaj54 commented 1 day ago

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

abhishekpankaj54 commented 1 day ago

@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

XiaofeiCao commented 11 hours ago

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