Search in sources :

Example 6 with Subnet

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);
            }
        }
    }
}
Also used : NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(com.microsoft.azure.management.network.Subnet)

Example 7 with Subnet

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);
    }
}
Also used : Subnet(com.microsoft.azure.management.network.Subnet)

Example 8 with Subnet

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());
}
Also used : Subnet(com.microsoft.azure.management.network.Subnet) Route(com.microsoft.azure.management.network.Route)

Example 9 with Subnet

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());
}
Also used : RouteTable(com.microsoft.azure.management.network.RouteTable) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) Subnet(com.microsoft.azure.management.network.Subnet)

Example 10 with Subnet

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);
}
Also used : VolumeParameterType.values(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.values) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Cacheable(org.springframework.cache.annotation.Cacheable) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Strings(com.google.common.base.Strings) Network(com.microsoft.azure.management.network.Network) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) Set(java.util.Set) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Objects(java.util.Objects) List(java.util.List) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Network(com.microsoft.azure.management.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Subnet(com.microsoft.azure.management.network.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

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