Search in sources :

Example 1 with ResourceGroups

use of com.microsoft.azure.management.resources.ResourceGroups in project azure-sdk-for-java by Azure.

the class NetworkInterfaceOperationsTests method canCreateBatchOfNetworkInterfaces.

@Test
public void canCreateBatchOfNetworkInterfaces() throws Exception {
    ResourceGroups resourceGroups = resourceManager.resourceGroups();
    Networks networks = networkManager.networks();
    NetworkInterfaces networkInterfaces = networkManager.networkInterfaces();
    Creatable<ResourceGroup> resourceGroupCreatable = resourceGroups.define(RG_NAME).withRegion(Region.US_EAST);
    final String vnetName = "vnet1212";
    Creatable<Network> networkCreatable = networks.define(vnetName).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withAddressSpace("10.0.0.0/28");
    // Prepare a batch of nics
    //
    final String nic1Name = "nic1";
    Creatable<NetworkInterface> networkInterface1Creatable = networkInterfaces.define(nic1Name).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.5");
    final String nic2Name = "nic2";
    Creatable<NetworkInterface> networkInterface2Creatable = networkInterfaces.define(nic2Name).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.6");
    final String nic3Name = "nic3";
    Creatable<NetworkInterface> networkInterface3Creatable = networkInterfaces.define(nic3Name).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.7");
    final String nic4Name = "nic4";
    Creatable<NetworkInterface> networkInterface4Creatable = networkInterfaces.define(nic4Name).withRegion(Region.US_EAST).withNewResourceGroup(resourceGroupCreatable).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressStatic("10.0.0.8");
    @SuppressWarnings("unchecked") Collection<NetworkInterface> batchNics = networkInterfaces.create(networkInterface1Creatable, networkInterface2Creatable, networkInterface3Creatable, networkInterface4Creatable).values();
    Assert.assertTrue(batchNics.size() == 4);
    HashMap<String, Boolean> found = new LinkedHashMap<>();
    for (NetworkInterface nic : batchNics) {
        if (nic.name().equalsIgnoreCase(nic1Name)) {
            found.put(nic1Name, true);
        }
        if (nic.name().equalsIgnoreCase(nic2Name)) {
            found.put(nic2Name, true);
        }
        if (nic.name().equalsIgnoreCase(nic3Name)) {
            found.put(nic3Name, true);
        }
        if (nic.name().equalsIgnoreCase(nic4Name)) {
            found.put(nic4Name, true);
        }
    }
    Assert.assertTrue(found.size() == 4);
}
Also used : ResourceGroups(com.microsoft.azure.management.resources.ResourceGroups) LinkedHashMap(java.util.LinkedHashMap) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Test(org.junit.Test)

Example 2 with ResourceGroups

use of com.microsoft.azure.management.resources.ResourceGroups in project azure-tools-for-java by Microsoft.

the class Program method printResourceGroups.

@SuppressWarnings("unused")
private static void printResourceGroups(AzureManager manager) throws Exception {
    Set<String> sidList = manager.getSubscriptionManager().getAccountSidList();
    for (String sid : sidList) {
        Azure azure = manager.getAzure(sid);
        System.out.println("==> Resource groups / " + sid);
        ResourceGroups rgs = azure.resourceGroups();
        for (ResourceGroup rg : rgs.list()) {
            System.out.println("    " + rg.name());
        }
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) ResourceGroups(com.microsoft.azure.management.resources.ResourceGroups) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Aggregations

ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 ResourceGroups (com.microsoft.azure.management.resources.ResourceGroups)2 Azure (com.microsoft.azure.management.Azure)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1