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