Search in sources :

Example 1 with IPAddressState

use of com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState in project photon-model by vmware.

the class ModelUtils method createIpAddress.

public static IPAddressState createIpAddress(BaseModelTest test, String IPAddress, IPAddressState.IPAddressStatus ipAddressStatus, SubnetRangeState subnetRangeState, String connectedResourceLink) throws Throwable {
    IPAddressState ipAddressState = new IPAddressState();
    ipAddressState.ipAddress = IPAddress;
    ipAddressState.ipVersion = IPVersion.IPv4;
    ipAddressState.ipAddressStatus = ipAddressStatus;
    ipAddressState.subnetRangeLink = subnetRangeState.documentSelfLink;
    ipAddressState.connectedResourceLink = connectedResourceLink;
    ipAddressState = test.postServiceSynchronously(IPAddressService.FACTORY_LINK, ipAddressState, IPAddressState.class);
    return ipAddressState;
}
Also used : IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState)

Example 2 with IPAddressState

use of com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState in project photon-model by vmware.

the class ModelUtils method createSubnetRangeWithIpAddresses.

public static List<IPAddressState> createSubnetRangeWithIpAddresses(BaseModelTest test, String subnetLink, String connectedResourceLink, int ipAddressCount) throws Throwable {
    SubnetRangeState subnetRange = new SubnetRangeService.SubnetRangeState();
    subnetRange.startIPAddress = "12.12.12.2";
    subnetRange.endIPAddress = "12.12.12.120";
    subnetRange.ipVersion = IPVersion.IPv4;
    subnetRange.subnetLink = subnetLink;
    SubnetRangeState subnetRangeState = test.postServiceSynchronously(SubnetRangeService.FACTORY_LINK, subnetRange, SubnetRangeState.class);
    List<IPAddressState> returnStates = new ArrayList<>();
    String prefix = "12.12.12.";
    int initialValue = 3;
    for (int i = 0; i < ipAddressCount; i++) {
        IPAddressState ipAddressState = new IPAddressState();
        ipAddressState.ipAddress = prefix + (initialValue + i);
        ipAddressState.ipVersion = IPVersion.IPv4;
        ipAddressState.ipAddressStatus = IPAddressState.IPAddressStatus.ALLOCATED;
        ipAddressState.subnetRangeLink = subnetRangeState.documentSelfLink;
        ipAddressState.connectedResourceLink = connectedResourceLink;
        returnStates.add(test.postServiceSynchronously(IPAddressService.FACTORY_LINK, ipAddressState, IPAddressState.class));
    }
    return returnStates;
}
Also used : SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState) IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState) ArrayList(java.util.ArrayList)

Example 3 with IPAddressState

use of com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState in project photon-model by vmware.

the class ModelUtils method createCompute.

public static ComputeService.ComputeStateWithDescription createCompute(BaseModelTest test, ComputeDescriptionService.ComputeDescription cd) throws Throwable {
    ComputeService.ComputeState cs = new ComputeService.ComputeStateWithDescription();
    cs.id = UUID.randomUUID().toString();
    cs.name = cd.name;
    cs.descriptionLink = cd.documentSelfLink;
    cs.resourcePoolLink = null;
    cs.address = "10.0.0.1";
    cs.primaryMAC = "01:23:45:67:89:ab";
    cs.powerState = ComputeService.PowerState.ON;
    cs.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
    cs.diskLinks = new ArrayList<>();
    cs.diskLinks.add(createDiskState(test, cs.name).documentSelfLink);
    cs.networkInterfaceLinks = new ArrayList<>();
    EndpointState endpointState = createEndpoint(test);
    NetworkState networkState = createNetwork(test, endpointState);
    SubnetState subnetState = createSubnet(test, networkState, endpointState);
    SubnetRangeState subnetRangeState = createSubnetRange(test, subnetState, "12.12.12.2", "12.12.12.120");
    NetworkInterfaceState networkInterfaceState1 = createNetworkInterface(test, "nic-1", subnetState, networkState);
    IPAddressState ipAddressState1 = createIpAddress(test, "12.12.12.2", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState1.documentSelfLink);
    NetworkInterfaceState networkInterfaceState2 = createNetworkInterface(test, "nic-2", subnetState, networkState);
    IPAddressState ipAddressState2 = createIpAddress(test, "12.12.12.3", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState2.documentSelfLink);
    NetworkInterfaceState networkInterfaceState3 = createNetworkInterface(test, "nic-3", subnetState, networkState);
    IPAddressState ipAddressState3 = createIpAddress(test, "12.12.12.4", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState3.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState1.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState2.documentSelfLink);
    cs.networkInterfaceLinks.add(networkInterfaceState3.documentSelfLink);
    cs.customProperties = new HashMap<>();
    cs.customProperties.put(TEST_DESC_PROPERTY_NAME, TEST_DESC_PROPERTY_VALUE);
    cs.tenantLinks = new ArrayList<>();
    cs.tenantLinks.add("http://tenant");
    ComputeService.ComputeState returnState = test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
    return ComputeService.ComputeStateWithDescription.create(cd, returnState);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState) IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState)

Example 4 with IPAddressState

use of com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState in project photon-model by vmware.

the class IPAddressAllocationTaskService method createNewIpForSingleResource.

private DeferredResult<IPAddressState> createNewIpForSingleResource(IPAddressAllocationContext context, String connectedResourceLink) {
    List<SubnetRangeState> subnetRangeStates = context.subnetRangeStates;
    DeferredResult<IPAddressState> deferredIpAddr;
    for (SubnetRangeState subnetRangeState : subnetRangeStates) {
        if (!subnetRangeState.ipVersion.equals(IPVersion.IPv4)) {
            // If IPV6 then skip to next IP range.
            logWarning("Skipping allocation from IP address range %s. Currently, only IPV4 is supported", subnetRangeState.documentSelfLink);
            continue;
        }
        deferredIpAddr = createIpInRange(context, connectedResourceLink, subnetRangeState);
        if (deferredIpAddr != null) {
            return deferredIpAddr;
        }
    }
    String msg = String.format("Couldn't allocate an IP address for resource %s. No IP " + "addresses were remaining", connectedResourceLink);
    return DeferredResult.failed(new IllegalArgumentException(msg));
}
Also used : SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState) IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState)

Example 5 with IPAddressState

use of com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState in project photon-model by vmware.

the class IPAddressAllocationTaskService method assignExistingIpToResource.

/**
 * The context has all the existing IP address documents owned by the subnet.
 * We go through each of those IP address docs and check if it's status is available.
 * If it is, we allocate it to the passed in, connected resource.
 *
 * @param context IPAddressAllocationContext
 * @param connectedResourceLink The resource that needs an IP address
 * @return A DeferredResult of an IPAddressState
 */
private DeferredResult<IPAddressState> assignExistingIpToResource(IPAddressAllocationContext context, String connectedResourceLink) {
    List<IPAddressState> existingIpAddressStates = context.ipAddressStates;
    DeferredResult<IPAddressState> returnIp = new DeferredResult<>();
    for (IPAddressState addressState : existingIpAddressStates) {
        Long longIp = IpHelper.ipStringToLong(addressState.ipAddress);
        if (addressState.ipAddressStatus == IPAddressState.IPAddressStatus.AVAILABLE && (!context.unavailableIpAddresses.contains(longIp))) {
            context.unavailableIpAddresses.add(longIp);
            addressState.ipAddressStatus = IPAddressState.IPAddressStatus.ALLOCATED;
            addressState.connectedResourceLink = connectedResourceLink;
            logInfo("Picking an existing IP %s for resource %s", addressState.ipAddress, connectedResourceLink);
            return updateExistingIpAddressResource(addressState, context);
        } else {
            context.unavailableIpAddresses.add(longIp);
        }
    }
    returnIp.complete(null);
    return returnIp;
}
Also used : IPAddressState(com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

IPAddressState (com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState)10 SubnetRangeState (com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState)7 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)5 DeferredResult (com.vmware.xenon.common.DeferredResult)5 ArrayList (java.util.ArrayList)5 Since (com.esotericsoftware.kryo.serializers.VersionFieldSerializer.Since)4 UriPaths (com.vmware.photon.controller.model.UriPaths)4 ReleaseConstants (com.vmware.photon.controller.model.constants.ReleaseConstants)4 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 IPAddressService (com.vmware.photon.controller.model.resources.IPAddressService)4 IPAddressStatus (com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState.IPAddressStatus)4 PhotonModelUtils (com.vmware.photon.controller.model.resources.util.PhotonModelUtils)4 IPVersion (com.vmware.photon.controller.model.support.IPVersion)4 ServiceTaskCallbackResponse (com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse)4 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)4 IpHelper (com.vmware.photon.controller.model.util.IpHelper)4 SubnetValidator (com.vmware.photon.controller.model.util.SubnetValidator)4 Operation (com.vmware.xenon.common.Operation)4 Service (com.vmware.xenon.common.Service)4 ServiceDocument (com.vmware.xenon.common.ServiceDocument)4