Search in sources :

Example 6 with PublicIPAddressInner

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

the class AzureLoadBalancerService method getPublicIPAddress.

/**
 * Fetch public IP address after an address has been assigned
 */
private DeferredResult<AzureLoadBalancerContext> getPublicIPAddress(AzureLoadBalancerContext ctx) {
    if (ctx.publicIPAddressInner == null) {
        // No public IP address created -> do nothing.
        return DeferredResult.completed(ctx);
    }
    NetworkManagementClientImpl client = ctx.azureSdkClients.getNetworkManagementClientImpl();
    String msg = "Get public IP address for resource group [" + ctx.resourceGroupName + "] and name [" + ctx.publicIPAddressInner.name() + "].";
    AzureDeferredResultServiceCallback<PublicIPAddressInner> callback = new AzureDeferredResultServiceCallback<PublicIPAddressInner>(ctx.service, msg) {

        @Override
        protected DeferredResult<PublicIPAddressInner> consumeSuccess(PublicIPAddressInner result) {
            ctx.publicIPAddressInner = result;
            ctx.loadBalancerStateExpanded.address = result.ipAddress();
            return DeferredResult.completed(result);
        }
    };
    client.publicIPAddresses().getByResourceGroupAsync(ctx.resourceGroupName, ctx.publicIPAddressInner.name(), null, callback);
    return callback.toDeferredResult().thenApply(ignored -> ctx);
}
Also used : NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner)

Example 7 with PublicIPAddressInner

use of com.microsoft.azure.management.network.implementation.PublicIPAddressInner 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

PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)7 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)3 SubResource (com.microsoft.azure.SubResource)2 IPAllocationMethod (com.microsoft.azure.management.network.IPAllocationMethod)2 SubnetInner (com.microsoft.azure.management.network.implementation.SubnetInner)2 ArrayList (java.util.ArrayList)2 CloudError (com.microsoft.azure.CloudError)1 CloudException (com.microsoft.azure.CloudException)1 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 AvailabilitySet (com.microsoft.azure.management.compute.AvailabilitySet)1 AvailabilitySetSkuTypes (com.microsoft.azure.management.compute.AvailabilitySetSkuTypes)1 CachingTypes (com.microsoft.azure.management.compute.CachingTypes)1 DataDisk (com.microsoft.azure.management.compute.DataDisk)1 Disk (com.microsoft.azure.management.compute.Disk)1 DiskCreateOptionTypes (com.microsoft.azure.management.compute.DiskCreateOptionTypes)1 HardwareProfile (com.microsoft.azure.management.compute.HardwareProfile)1 NetworkProfile (com.microsoft.azure.management.compute.NetworkProfile)1 OSDisk (com.microsoft.azure.management.compute.OSDisk)1 OSProfile (com.microsoft.azure.management.compute.OSProfile)1