Search in sources :

Example 1 with NetworkInterfaceIPConfigurationInner

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

the class AzureInstanceService method newAzureNetworkInterface.

/**
 * Converts Photon model constructs to underlying Azure NetworkInterface model.
 */
private NetworkInterfaceInner newAzureNetworkInterface(AzureInstanceContext ctx, AzureNicContext nicCtx) {
    NetworkInterfaceDescription description = nicCtx.nicStateWithDesc.description;
    NetworkInterfaceIPConfigurationInner ipConfig = new NetworkInterfaceIPConfigurationInner();
    ipConfig.withName(AzureUtils.generateClusterCommonName(NICCONFIG_NAME_PREFIX, ctx));
    ipConfig.withSubnet(nicCtx.subnet);
    if (nicCtx.publicIP != null) {
        // Public IP is not auto-assigned so check for existence
        ipConfig.withPublicIPAddress(new SubResource().withId(nicCtx.publicIP.id()));
    }
    ipConfig.withPrivateIPAllocationMethod(new IPAllocationMethod(description.assignment.name()));
    if (description.assignment == IpAssignment.STATIC) {
        ipConfig.withPrivateIPAddress(description.address);
    }
    NetworkInterfaceInner nic = new NetworkInterfaceInner();
    nic.withLocation(ctx.resourceGroup.location());
    // Azure's custom serializers don't handle well collections constructed with
    // Collections.singletonList(), so initialize an ArrayList
    List<NetworkInterfaceIPConfigurationInner> ipConfigs = new ArrayList<>();
    ipConfigs.add(ipConfig);
    nic.withIpConfigurations(ipConfigs);
    if (nicCtx.securityGroup != null) {
        // Security group is optional so check for existence
        nic.withNetworkSecurityGroup(new SubResource().withId(nicCtx.securityGroup.id()));
    }
    return nic;
}
Also used : NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) IPAllocationMethod(com.microsoft.azure.management.network.IPAllocationMethod) SubResource(com.microsoft.azure.SubResource) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) ArrayList(java.util.ArrayList) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)

Example 2 with NetworkInterfaceIPConfigurationInner

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

the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.

/**
 * Processes request for creating and updating Network interface resources.
 */
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
    nic.name = remoteNic.name();
    nic.subnetLink = subnetPerNicId.get(remoteNic.id());
    NicMetadata nicMeta = new NicMetadata();
    nicMeta.state = nic;
    nicMeta.macAddress = remoteNic.macAddress();
    // else will default to original ID for PATCH requests
    if (isCreate) {
        nic.id = remoteNic.id();
        nic.endpointLink = ctx.request.endpointLink;
        AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
        nic.tenantLinks = ctx.parentCompute.tenantLinks;
        nic.regionId = remoteNic.location();
        nic.computeHostLink = ctx.parentCompute.documentSelfLink;
    } else {
        if (StringUtils.isEmpty(nic.endpointLink)) {
            nic.endpointLink = ctx.request.endpointLink;
        }
        nic.endpointLinks.add(ctx.request.endpointLink);
    }
    List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
    if (ipConfigurations == null || ipConfigurations.isEmpty()) {
        executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
        return;
    }
    NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
    nic.address = nicIPConf.privateIPAddress();
    if (nicIPConf.publicIPAddress() == null) {
        executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
        return;
    }
    // IP address is not directly available in NetworkInterfaceIPConfigurationInner.
    // It is available as a SubResource, We use the SubResource ID of IP address from
    // NetworkInterfaceIPConfigurationInner to obtain the IP address.
    Consumer<Throwable> failure = e -> {
        logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
        handleError(ctx, e);
    };
    PhotonModelUtils.runInExecutor(this.executorService, () -> {
        Azure azure = ctx.azureSdkClients.getAzureClient();
        azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {

            @Override
            public void call(PublicIPAddress publicIPAddress) {
                nicMeta.publicIp = publicIPAddress.ipAddress();
                if (publicIPAddress.inner().dnsSettings() != null) {
                    nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
                }
                executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
            }
        }));
    }, failure);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Pair(org.apache.commons.lang3.tuple.Pair) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) OSDisk(com.microsoft.azure.management.compute.OSDisk) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) VirtualMachinesInner(com.microsoft.azure.management.compute.implementation.VirtualMachinesInner) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) BiConsumer(java.util.function.BiConsumer) AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK) AZURE_STORAGE_ACCOUNT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_URI) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DataDisk(com.microsoft.azure.management.compute.DataDisk) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ENVIRONMENT_NAME_AZURE(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AZURE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) AZURE_RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_RESOURCE_GROUP_NAME) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) AzureUtils.injectOperationContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.injectOperationContext) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureUtils.isDiskManaged(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.isDiskManaged) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashMap(java.util.HashMap) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Operation(com.vmware.xenon.common.Operation) Page(com.microsoft.azure.Page) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) Azure(com.microsoft.azure.management.Azure) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Action1(rx.functions.Action1) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress)

Aggregations

NetworkInterfaceIPConfigurationInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner)2 NetworkInterfaceInner (com.microsoft.azure.management.network.implementation.NetworkInterfaceInner)2 Page (com.microsoft.azure.Page)1 SubResource (com.microsoft.azure.SubResource)1 Azure (com.microsoft.azure.management.Azure)1 DataDisk (com.microsoft.azure.management.compute.DataDisk)1 InstanceViewStatus (com.microsoft.azure.management.compute.InstanceViewStatus)1 InstanceViewTypes (com.microsoft.azure.management.compute.InstanceViewTypes)1 OSDisk (com.microsoft.azure.management.compute.OSDisk)1 OperatingSystemTypes (com.microsoft.azure.management.compute.OperatingSystemTypes)1 StorageAccountTypes (com.microsoft.azure.management.compute.StorageAccountTypes)1 ImageReferenceInner (com.microsoft.azure.management.compute.implementation.ImageReferenceInner)1 NetworkInterfaceReferenceInner (com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner)1 VirtualMachineInner (com.microsoft.azure.management.compute.implementation.VirtualMachineInner)1 VirtualMachinesInner (com.microsoft.azure.management.compute.implementation.VirtualMachinesInner)1 IPAllocationMethod (com.microsoft.azure.management.network.IPAllocationMethod)1 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)1 NetworkInterfacesInner (com.microsoft.azure.management.network.implementation.NetworkInterfacesInner)1 CUSTOM_OS_TYPE (com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE)1 OSType (com.vmware.photon.controller.model.ComputeProperties.OSType)1