Search in sources :

Example 1 with SubnetsInner

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

the class AzureSubnetService method createSubnet.

private DeferredResult<AzureSubnetContext> createSubnet(AzureSubnetContext context) {
    SubnetInner subnet = new SubnetInner();
    subnet.withName(context.subnetState.name);
    subnet.withAddressPrefix(context.subnetState.subnetCIDR);
    String rgName = context.parentNetworkResourceGroupName;
    String vNetName = context.parentNetwork.name;
    final String msg = "Creating Azure Subnet [" + subnet.name() + "] in vNet [" + vNetName + "] in resource group [" + rgName + "].";
    SubnetsInner subnetsInner = context.azureSdkClients.getNetworkManagementClientImpl().subnets();
    AzureProvisioningCallback<SubnetInner> handler = new AzureProvisioningCallback<SubnetInner>(this, msg) {

        @Override
        protected DeferredResult<SubnetInner> consumeProvisioningSuccess(SubnetInner subnet) {
            // Populate the subnet id with Azure Subnet ID
            context.subnetState.id = subnet.id();
            return DeferredResult.completed(subnet);
        }

        @Override
        protected String getProvisioningState(SubnetInner subnet) {
            return subnet.provisioningState();
        }

        @Override
        protected Runnable checkProvisioningStateCall(ServiceCallback<SubnetInner> checkProvisioningStateCallback) {
            return () -> subnetsInner.getAsync(rgName, vNetName, subnet.name(), null, /* expand */
            checkProvisioningStateCallback);
        }
    };
    subnetsInner.createOrUpdateAsync(rgName, vNetName, subnet.name(), subnet, handler);
    return handler.toDeferredResult().thenApply(ignore -> context);
}
Also used : SubnetsInner(com.microsoft.azure.management.network.implementation.SubnetsInner) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) AzureProvisioningCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)

Example 2 with SubnetsInner

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

the class AzureInstanceContext method getNetworks.

/**
 * For every NIC lookup associated Azure Subnets as specified by
 * {@code AzureNicContext.networkState.name} and {@code AzureNicContext.subnetState.name}. If
 * any of the subnets is not found leave the {@link AzureNicContext#subnet} as null and proceed
 * without an exception.
 */
private DeferredResult<AzureInstanceContext> getNetworks(AzureInstanceContext context) {
    if (context.nics.isEmpty()) {
        return DeferredResult.completed(context);
    }
    SubnetsInner azureClient = service().getNetworkManagementClientImpl(context).subnets();
    List<DeferredResult<SubnetInner>> getSubnetDRs = context.nics.stream().filter(nicCtx -> nicCtx.networkRGState != null).map(nicCtx -> {
        String msg = "Getting Azure Subnet [" + nicCtx.networkRGState.name + "/" + nicCtx.networkState.name + "/" + nicCtx.subnetState.name + "] for [" + nicCtx.nicStateWithDesc.name + "] NIC for [" + context.vmName + "] VM";
        AzureDeferredResultServiceCallback<SubnetInner> handler = new AzureDeferredResultServiceCallback<SubnetInner>(service(), msg) {

            @Override
            protected DeferredResult<SubnetInner> consumeSuccess(SubnetInner subnet) {
                nicCtx.subnet = subnet;
                return DeferredResult.completed(subnet);
            }
        };
        azureClient.getAsync(nicCtx.networkRGState.name, nicCtx.networkState.name, nicCtx.subnetState.name, null, /* expand */
        handler);
        return handler.toDeferredResult();
    }).collect(Collectors.toList());
    return DeferredResult.allOf(getSubnetDRs).handle((all, exc) -> {
        if (exc != null) {
            String msg = String.format("Error getting Subnets from Azure for [%s] VM.", context.child.name);
            throw new IllegalStateException(msg, exc);
        }
        return context;
    });
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Level(java.util.logging.Level) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) PublicIPAddressInner(com.microsoft.azure.management.network.implementation.PublicIPAddressInner) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) AvailabilitySetInner(com.microsoft.azure.management.compute.implementation.AvailabilitySetInner) Collectors(java.util.stream.Collectors) Disk(com.microsoft.azure.management.compute.Disk) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) AzureSecurityGroupUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureSecurityGroupUtils) SubnetsInner(com.microsoft.azure.management.network.implementation.SubnetsInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkSecurityGroupsInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner) DeferredResult(com.vmware.xenon.common.DeferredResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) DiskService(com.vmware.photon.controller.model.resources.DiskService) SubnetsInner(com.microsoft.azure.management.network.implementation.SubnetsInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) SubnetInner(com.microsoft.azure.management.network.implementation.SubnetInner) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

SubnetInner (com.microsoft.azure.management.network.implementation.SubnetInner)2 SubnetsInner (com.microsoft.azure.management.network.implementation.SubnetsInner)2 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)2 AvailabilitySet (com.microsoft.azure.management.compute.AvailabilitySet)1 Disk (com.microsoft.azure.management.compute.Disk)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 AvailabilitySetInner (com.microsoft.azure.management.compute.implementation.AvailabilitySetInner)1 ImageReferenceInner (com.microsoft.azure.management.compute.implementation.ImageReferenceInner)1 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)1 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)1 NetworkSecurityGroupInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner)1 NetworkSecurityGroupsInner (com.microsoft.azure.management.network.implementation.NetworkSecurityGroupsInner)1 PublicIPAddressInner (com.microsoft.azure.management.network.implementation.PublicIPAddressInner)1 ResourceGroupInner (com.microsoft.azure.management.resources.implementation.ResourceGroupInner)1 StorageAccountInner (com.microsoft.azure.management.storage.implementation.StorageAccountInner)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)1 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)1 AzureProvisioningCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureProvisioningCallback)1 AzureSdkClients (com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients)1