Search in sources :

Example 1 with AddressSpace

use of com.vmware.photon.controller.model.adapters.azure.model.network.AddressSpace in project photon-model by vmware.

the class AzureNetworkEnumerationAdapterService method buildNetworkState.

/**
 * @param localNetworkState
 *            null to do a create, non null to update an existing network state
 */
private NetworkState buildNetworkState(NetworkEnumContext context, VirtualNetwork azureVirtualNetwork, NetworkState localNetworkState) {
    NetworkState resultNetworkState = new NetworkState();
    if (localNetworkState != null) {
        resultNetworkState.id = localNetworkState.id;
        resultNetworkState.authCredentialsLink = localNetworkState.authCredentialsLink;
        resultNetworkState.documentSelfLink = localNetworkState.documentSelfLink;
        resultNetworkState.groupLinks = localNetworkState.groupLinks;
        resultNetworkState.resourcePoolLink = localNetworkState.resourcePoolLink;
        resultNetworkState.tagLinks = localNetworkState.tagLinks;
        resultNetworkState.endpointLinks = localNetworkState.endpointLinks;
    } else {
        resultNetworkState.id = azureVirtualNetwork.id;
        resultNetworkState.authCredentialsLink = context.endpointAuth.documentSelfLink;
        resultNetworkState.resourcePoolLink = context.request.resourcePoolLink;
    }
    resultNetworkState.name = azureVirtualNetwork.name;
    resultNetworkState.regionId = azureVirtualNetwork.location;
    if (StringUtils.isEmpty(resultNetworkState.endpointLink)) {
        resultNetworkState.endpointLink = context.request.endpointLink;
    }
    resultNetworkState.computeHostLink = context.parentCompute.documentSelfLink;
    AdapterUtils.addToEndpointLinks(resultNetworkState, context.request.endpointLink);
    AddressSpace addressSpace = azureVirtualNetwork.properties.addressSpace;
    if (addressSpace != null && addressSpace.addressPrefixes != null && addressSpace.addressPrefixes.size() > 0) {
        // TODO: Get the first address prefix for now.
        // Trim any whitespaces that might be presented (VSYM-4132).
        resultNetworkState.subnetCIDR = addressSpace.addressPrefixes.get(0).trim();
    }
    // Add gateway as custom property in case gateway is defined
    String gatewayId = AzureUtils.getVirtualNetworkGatewayId(azureVirtualNetwork);
    if (gatewayId != null) {
        resultNetworkState.customProperties = Collections.singletonMap(ComputeProperties.FIELD_VIRTUAL_GATEWAY, gatewayId);
        logFine(() -> String.format("Added Gateway %s for Network State %s.", gatewayId, resultNetworkState.name));
    }
    // TODO: There is no Azure Network Adapter Service. Add a default reference since this is
    // required field.
    resultNetworkState.instanceAdapterReference = AdapterUriUtil.buildAdapterUri(getHost().getPort(), DEFAULT_INSTANCE_ADAPTER_REFERENCE);
    String resourceGroupId = AzureUtils.getResourceGroupId(azureVirtualNetwork.id);
    String resourceGroupStateLink = context.resourceGroupStates.get(resourceGroupId);
    if (resourceGroupStateLink != null) {
        if (resultNetworkState.groupLinks == null) {
            resultNetworkState.groupLinks = new HashSet<>();
        }
        // Add if a resource group state with this name exists.
        // If not then the resource group was not enumerated yet. The groupLink will be filled
        // during the next enumeration cycle.
        resultNetworkState.groupLinks.add(resourceGroupStateLink);
    }
    resultNetworkState.tenantLinks = context.parentCompute.tenantLinks;
    return resultNetworkState;
}
Also used : AddressSpace(com.vmware.photon.controller.model.adapters.azure.model.network.AddressSpace) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState)

Aggregations

AddressSpace (com.vmware.photon.controller.model.adapters.azure.model.network.AddressSpace)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1