Search in sources :

Example 1 with Subnet

use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.

the class NetworkManager method listAssociatedSubnets.

// Internal utility function
List<Subnet> listAssociatedSubnets(List<SubnetInner> subnetRefs) {
    final Map<String, Network> networks = new HashMap<>();
    final List<Subnet> subnets = new ArrayList<>();
    if (subnetRefs != null) {
        for (SubnetInner subnetRef : subnetRefs) {
            String networkId = ResourceUtils.parentResourceIdFromResourceId(subnetRef.id());
            Network network = networks.get(networkId);
            if (network == null) {
                network = this.networks().getById(networkId);
                networks.put(networkId, network);
            }
            String subnetName = ResourceUtils.nameFromResourceId(subnetRef.id());
            subnets.add(network.subnets().get(subnetName));
        }
    }
    return Collections.unmodifiableList(subnets);
}
Also used : HashMap(java.util.HashMap) Network(com.microsoft.azure.management.network.Network) ArrayList(java.util.ArrayList) Subnet(com.microsoft.azure.management.network.Subnet)

Example 2 with Subnet

use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.

the class Utils method print.

/**
     * Print network info.
     * @param resource a network
     * @throws IOException IO errors
     * @throws CloudException Cloud errors
     */
public static void print(Network resource) {
    StringBuilder info = new StringBuilder();
    info.append("Network: ").append(resource.id()).append("Name: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags()).append("\n\tAddress spaces: ").append(resource.addressSpaces()).append("\n\tDNS server IPs: ").append(resource.dnsServerIPs());
    // Output subnets
    for (Subnet subnet : resource.subnets().values()) {
        info.append("\n\tSubnet: ").append(subnet.name()).append("\n\t\tAddress prefix: ").append(subnet.addressPrefix());
        NetworkSecurityGroup subnetNsg = subnet.getNetworkSecurityGroup();
        if (subnetNsg != null) {
            info.append("\n\t\tNetwork security group: ").append(subnetNsg.id());
        }
    }
    System.out.println(info.toString());
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) Subnet(com.microsoft.azure.management.network.Subnet)

Example 3 with Subnet

use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.

the class TestNSG method printNSG.

public static void printNSG(NetworkSecurityGroup resource) {
    StringBuilder info = new StringBuilder();
    info.append("NSG: ").append(resource.id()).append("Name: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags());
    // Output security rules
    info.append("\n\tCustom security rules:");
    for (NetworkSecurityRule rule : resource.securityRules().values()) {
        info = printRule(rule, info);
    }
    // Output default security rules
    info.append("\n\tDefault security rules:");
    for (NetworkSecurityRule rule : resource.defaultSecurityRules().values()) {
        info = printRule(rule, info);
    }
    // Output associated NIC IDs
    info.append("\n\tNICs: ").append(resource.networkInterfaceIds());
    // Output associated subnets
    info.append("\n\tAssociated subnets: ");
    List<Subnet> subnets = resource.listAssociatedSubnets();
    if (subnets == null || subnets.size() == 0) {
        info.append("(None)");
    } else {
        for (Subnet subnet : subnets) {
            info.append("\n\t\tNetwork ID: ").append(subnet.parent().id()).append("\n\t\tSubnet name: ").append(subnet.name());
        }
    }
    System.out.println(info.toString());
}
Also used : NetworkSecurityRule(com.microsoft.azure.management.network.NetworkSecurityRule) Subnet(com.microsoft.azure.management.network.Subnet)

Example 4 with Subnet

use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.

the class TestNetworkInterface method createResource.

@Override
public NetworkInterface createResource(NetworkInterfaces networkInterfaces) throws Exception {
    final String nicName = "nic" + this.testId;
    final String vnetName = "net" + this.testId;
    final String pipName = "pip" + this.testId;
    final Region region = Region.US_EAST;
    Network network = networkInterfaces.manager().networks().define(vnetName).withRegion(region).withNewResourceGroup().withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/29").withSubnet("subnet2", "10.0.0.8/29").create();
    NetworkInterface nic = networkInterfaces.define(nicName).withRegion(region).withExistingResourceGroup(network.resourceGroupName()).withExistingPrimaryNetwork(network).withSubnet("subnet1").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(pipName).withIPForwarding().create();
    // Verifications
    NicIPConfiguration ipConfig = nic.primaryIPConfiguration();
    Assert.assertNotNull(ipConfig);
    network = ipConfig.getNetwork();
    Assert.assertNotNull(network);
    Subnet subnet = network.subnets().get(ipConfig.subnetName());
    Assert.assertNotNull(subnet);
    Assert.assertEquals(1, subnet.networkInterfaceIPConfigurationCount());
    Set<NicIPConfiguration> ipConfigs = subnet.getNetworkInterfaceIPConfigurations();
    Assert.assertNotNull(ipConfigs);
    Assert.assertEquals(1, ipConfigs.size());
    NicIPConfiguration ipConfig2 = ipConfigs.iterator().next();
    Assert.assertEquals(ipConfig.name().toLowerCase(), ipConfig2.name().toLowerCase());
    return nic;
}
Also used : Network(com.microsoft.azure.management.network.Network) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) Subnet(com.microsoft.azure.management.network.Subnet) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration)

Example 5 with Subnet

use of com.microsoft.azure.management.network.Subnet in project azure-tools-for-java by Microsoft.

the class AzureDockerUtils method getVirtualNetworks.

public static List<AzureDockerVnet> getVirtualNetworks(Azure azureClient) {
    List<AzureDockerVnet> result = new ArrayList<>();
    if (azureClient != null) {
        for (Network net : azureClient.networks().list()) {
            AzureDockerVnet vnet = new AzureDockerVnet();
            vnet.name = net.name();
            vnet.addrSpace = net.addressSpaces().get(0);
            vnet.id = net.id();
            vnet.region = net.regionName().toLowerCase();
            vnet.resourceGroup = net.resourceGroupName();
            vnet.subnets = new ArrayList<>();
            for (Subnet subnet : net.subnets().values()) {
                vnet.subnets.add(subnet.name());
            }
            result.add(vnet);
        }
    }
    return result;
}
Also used : Network(com.microsoft.azure.management.network.Network) Subnet(com.microsoft.azure.management.network.Subnet)

Aggregations

Subnet (com.microsoft.azure.management.network.Subnet)11 Network (com.microsoft.azure.management.network.Network)4 NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Strings (com.google.common.base.Strings)1 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)1 NetworkSecurityRule (com.microsoft.azure.management.network.NetworkSecurityRule)1 NicIPConfiguration (com.microsoft.azure.management.network.NicIPConfiguration)1 Route (com.microsoft.azure.management.network.Route)1 RouteTable (com.microsoft.azure.management.network.RouteTable)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 PlatformResources (com.sequenceiq.cloudbreak.cloud.PlatformResources)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureClientService (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudAccessConfigs (com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1