Search in sources :

Example 1 with VirtualNetworkGatewayIPConfigurationInner

use of com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayIPConfigurationInner in project photon-model by vmware.

the class AzureTestUtil method addAzureGatewayToVirtualNetwork.

/**
 * Adds Gateway to Virtual Network in Azure
 */
private static void addAzureGatewayToVirtualNetwork(String resourceGroupName, AzureNicSpecs nicSpecs, NetworkManagementClientImpl networkManagementClient) throws CloudException, IOException, InterruptedException {
    // create Gateway Subnet
    SubnetInner gatewaySubnetParams = new SubnetInner();
    gatewaySubnetParams.withName(nicSpecs.gateway.name);
    gatewaySubnetParams.withAddressPrefix(nicSpecs.gateway.cidr);
    SubnetInner gatewaySubnet = networkManagementClient.subnets().createOrUpdate(resourceGroupName, nicSpecs.network.name, AzureConstants.GATEWAY_SUBNET_NAME, gatewaySubnetParams);
    // create Public IP
    PublicIPAddressInner publicIPAddressParams = new PublicIPAddressInner();
    publicIPAddressParams.withPublicIPAllocationMethod(IPAllocationMethod.DYNAMIC);
    publicIPAddressParams.withLocation(nicSpecs.gateway.zoneId);
    PublicIPAddressInner publicIPAddress = networkManagementClient.publicIPAddresses().createOrUpdate(resourceGroupName, nicSpecs.gateway.publicIpName, publicIPAddressParams);
    SubResource publicIPSubResource = new SubResource();
    publicIPSubResource.withId(publicIPAddress.id());
    // create IP Configuration
    VirtualNetworkGatewayIPConfigurationInner ipConfiguration = new VirtualNetworkGatewayIPConfigurationInner();
    ipConfiguration.withName(nicSpecs.gateway.ipConfigurationName);
    ipConfiguration.withSubnet(gatewaySubnet);
    ipConfiguration.withPrivateIPAllocationMethod(IPAllocationMethod.DYNAMIC);
    ipConfiguration.withPublicIPAddress(publicIPSubResource);
    // create Virtual Network Gateway
    VirtualNetworkGatewayInner virtualNetworkGateway = new VirtualNetworkGatewayInner();
    virtualNetworkGateway.withGatewayType(VirtualNetworkGatewayType.VPN);
    virtualNetworkGateway.withVpnType(VpnType.ROUTE_BASED);
    VirtualNetworkGatewaySku vNetGatewaySku = new VirtualNetworkGatewaySku();
    vNetGatewaySku.withName(VirtualNetworkGatewaySkuName.STANDARD);
    vNetGatewaySku.withTier(VirtualNetworkGatewaySkuTier.STANDARD);
    vNetGatewaySku.withCapacity(2);
    virtualNetworkGateway.withSku(vNetGatewaySku);
    virtualNetworkGateway.withLocation(AZURE_RESOURCE_GROUP_LOCATION);
    List<VirtualNetworkGatewayIPConfigurationInner> ipConfigurations = new ArrayList<>();
    ipConfigurations.add(ipConfiguration);
    virtualNetworkGateway.withIpConfigurations(ipConfigurations);
    // Call the async variant because the virtual network gateway provisioning depends on
    // the public IP address assignment which is time-consuming operation
    networkManagementClient.virtualNetworkGateways().createOrUpdateAsync(resourceGroupName, nicSpecs.gateway.name, virtualNetworkGateway, new ServiceCallback<VirtualNetworkGatewayInner>() {

        @Override
        public void failure(Throwable throwable) {
            throw new RuntimeException("Error creating Azure Virtual Network Gateway.", throwable);
        }

        @Override
        public void success(VirtualNetworkGatewayInner response) {
        }
    });
}
Also used : SubResource(com.microsoft.azure.SubResource) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) VirtualNetworkGatewaySku(com.microsoft.azure.management.network.VirtualNetworkGatewaySku) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) ArrayList(java.util.ArrayList) VirtualNetworkGatewayIPConfigurationInner(com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayIPConfigurationInner) VirtualNetworkGatewayInner(com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayInner)

Aggregations

SubResource (com.microsoft.azure.SubResource)1 VirtualNetworkGatewaySku (com.microsoft.azure.management.network.VirtualNetworkGatewaySku)1 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)1 SubnetInner (com.microsoft.azure.management.network.implementation.SubnetInner)1 VirtualNetworkGatewayIPConfigurationInner (com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayIPConfigurationInner)1 VirtualNetworkGatewayInner (com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayInner)1 ArrayList (java.util.ArrayList)1