use of com.microsoft.azure.management.network.implementation.VirtualNetworkGatewayInner 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) {
}
});
}
Aggregations