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;
}
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;
}
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);
}
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));
}
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;
}
Aggregations