use of com.microsoft.azure.management.network.Subnet in project cloudbreak by hortonworks.
the class AzureUtils method validateSubnetRules.
public void validateSubnetRules(AzureClient client, Network network) {
if (isExistingNetwork(network)) {
String resourceGroupName = getCustomResourceGroupName(network);
String networkId = getCustomNetworkId(network);
Collection<String> subnetIds = getCustomSubnetIds(network);
for (String subnetId : subnetIds) {
try {
Subnet subnet = client.getSubnetProperties(resourceGroupName, networkId, subnetId);
if (subnet == null) {
throw new CloudConnectorException(String.format("Subnet [%s] does not found with resourceGroupName [%s] and network [%s]", subnetId, resourceGroupName, networkId));
}
NetworkSecurityGroup networkSecurityGroup = subnet.getNetworkSecurityGroup();
if (networkSecurityGroup != null) {
validateSecurityGroup(client, networkSecurityGroup);
}
} catch (RuntimeException e) {
throw new CloudConnectorException("Subnet validation failed, cause: " + e.getMessage(), e);
}
}
}
}
use of com.microsoft.azure.management.network.Subnet in project cloudbreak by hortonworks.
the class AzureClient method collectAndSaveNetworkAndSubnet.
public void collectAndSaveNetworkAndSubnet(String resourceGroupName, String virtualNetwork, PersistenceNotifier notifier, CloudContext cloudContext) {
Optional<Subnet> first = getSubnets(resourceGroupName, virtualNetwork).values().stream().findFirst();
if (first.isPresent()) {
Subnet subnet = first.get();
String subnetName = subnet.name();
String networkName = subnet.parent().name();
notifier.notifyAllocation(CloudResource.builder().name(networkName).type(ResourceType.AZURE_NETWORK).build(), cloudContext);
notifier.notifyAllocation(CloudResource.builder().name(subnetName).type(ResourceType.AZURE_SUBNET).build(), cloudContext);
}
}
use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.
the class TestRouteTables method printRouteTable.
/**
* Outputs info about a route table
* @param resource a route table
*/
public static void printRouteTable(RouteTable resource) {
StringBuilder info = new StringBuilder();
info.append("Route table: ").append(resource.id()).append("\n\tName: ").append(resource.name()).append("\n\tResource group: ").append(resource.resourceGroupName()).append("\n\tRegion: ").append(resource.region()).append("\n\tTags: ").append(resource.tags());
// Output routes
Map<String, Route> routes = resource.routes();
info.append("\n\tRoutes: ").append(routes.values().size());
for (Route route : routes.values()) {
info.append("\n\t\tName: ").append(route.name()).append("\n\t\t\tDestination address prefix: ").append(route.destinationAddressPrefix()).append("\n\t\t\tNext hop type: ").append(route.nextHopType().toString()).append("\n\t\t\tNext hop IP address: ").append(route.nextHopIPAddress());
}
// Output associated subnets
List<Subnet> subnets = resource.listAssociatedSubnets();
info.append("\n\tAssociated subnets: ").append(subnets.size());
for (Subnet subnet : subnets) {
info.append("\n\t\tResource group: ").append(subnet.parent().resourceGroupName()).append("\n\t\tNetwork name: ").append(subnet.parent().name()).append("\n\t\tSubnet name: ").append(subnet.name()).append("\n\tSubnet's route table ID: ").append(subnet.routeTableId());
}
System.out.println(info.toString());
}
use of com.microsoft.azure.management.network.Subnet in project azure-sdk-for-java by Azure.
the class TestNetwork method printNetwork.
/**
* Outputs info about a network
* @param resource a network
*/
public static void printNetwork(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());
// Show associated NSG
info.append("\n\tAssociated NSG: ");
NetworkSecurityGroup nsg;
try {
nsg = subnet.getNetworkSecurityGroup();
} catch (Exception e) {
nsg = null;
}
info.append((null == nsg) ? "(None)" : nsg.resourceGroupName() + "/" + nsg.name());
// Show associated route table
info.append("\n\tAssociated route table: ");
RouteTable routeTable;
try {
routeTable = subnet.getRouteTable();
} catch (Exception e) {
routeTable = null;
}
info.append((null == routeTable) ? "(None)" : routeTable.resourceGroupName() + "/" + routeTable.name());
}
System.out.println(info.toString());
}
use of com.microsoft.azure.management.network.Subnet in project cloudbreak by hortonworks.
the class AzurePlatformResources method networks.
@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Map<String, Set<CloudNetwork>> result = new HashMap<>();
for (Network network : client.getNetworks()) {
String actualRegion = network.region().label();
if (regionMatch(actualRegion, region)) {
Map<String, String> subnets = new HashMap<>();
for (Entry<String, Subnet> subnet : network.subnets().entrySet()) {
subnets.put(subnet.getKey(), subnet.getKey());
}
Map<String, Object> properties = new HashMap<>();
properties.put("addressSpaces", network.addressSpaces());
properties.put("dnsServerIPs", network.dnsServerIPs());
properties.put("resourceGroupName", network.resourceGroupName());
CloudNetwork cloudNetwork = new CloudNetwork(network.name(), network.id(), subnets, properties);
result.computeIfAbsent(actualRegion, s -> new HashSet<>()).add(cloudNetwork);
}
}
if (result.isEmpty() && Objects.nonNull(region)) {
result.put(region.value(), new HashSet<>());
}
return new CloudNetworks(result);
}
Aggregations