Search in sources :

Example 1 with SubnetRangeState

use of com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState 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 2 with SubnetRangeState

use of com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState in project photon-model by vmware.

the class ModelUtils method createSubnetRange.

public static SubnetRangeState createSubnetRange(BaseModelTest test, SubnetState subnetState, String startIpAddr, String endIPAddr) throws Throwable {
    SubnetRangeState subnetRangeState = new SubnetRangeService.SubnetRangeState();
    subnetRangeState.startIPAddress = startIpAddr;
    subnetRangeState.endIPAddress = endIPAddr;
    subnetRangeState.ipVersion = IPVersion.IPv4;
    subnetRangeState.subnetLink = subnetState.documentSelfLink;
    subnetRangeState = test.postServiceSynchronously(SubnetRangeService.FACTORY_LINK, subnetRangeState, SubnetRangeState.class);
    return subnetRangeState;
}
Also used : SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState)

Example 3 with SubnetRangeState

use of com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState 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 SubnetRangeState

use of com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState 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 SubnetRangeState

use of com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState in project photon-model by vmware.

the class IPAddressAllocationTaskService method setMaxPossibleIpCountInSubnet.

private void setMaxPossibleIpCountInSubnet(IPAddressAllocationContext context) {
    List<SubnetRangeState> subnetRangeStates = context.subnetRangeStates;
    int maxIps = 0;
    for (SubnetRangeState subnetRangeState : subnetRangeStates) {
        Long startIP = IpHelper.ipStringToLong(subnetRangeState.startIPAddress);
        Long endIP = IpHelper.ipStringToLong(subnetRangeState.endIPAddress);
        maxIps = maxIps + (int) (endIP - startIP) + 1;
    }
    context.maxPossibleIpsCount = maxIps;
}
Also used : SubnetRangeState(com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState)

Aggregations

SubnetRangeState (com.vmware.photon.controller.model.resources.SubnetRangeService.SubnetRangeState)5 IPAddressState (com.vmware.photon.controller.model.resources.IPAddressService.IPAddressState)3 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 NetworkInterfaceState (com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1 SubnetState (com.vmware.photon.controller.model.resources.SubnetService.SubnetState)1 ArrayList (java.util.ArrayList)1