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);
}
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());
}
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());
}
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;
}
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;
}
Aggregations