use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestVSphereProvisionFromImageLink method provisionVMAndGetState.
private ComputeState provisionVMAndGetState() throws Throwable {
if (isMock()) {
return null;
}
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
enumerateComputes(this.computeHost, this.endpoint);
doRefresh();
snapshotFactoryState("images", ImageService.class);
String imageLink = findImage();
ComputeDescription desc = createVmDescription();
ComputeState vm = createVmState(desc, imageLink);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskState outTask = createProvisionTask(vm);
awaitTaskEnd(outTask);
return getComputeState(vm);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestVSphereEnumerationTask method testRefresh.
@Test
public void testRefresh() throws Throwable {
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
// Always create endpoint, so that there is no bogus
// endpointLink. This enumeration task is started on a real
// endpoint. This will also help tango based adapters
// as the existence of endpoint is more critical there to
// extract data collector identifier.
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
refreshAndRetire();
if (!isMock()) {
ComputeState vm = findRandomVm();
assertInternalPropertiesSet(vm);
assertNotNull(vm.endpointLink);
assertNotNull(vm.tenantLinks);
}
captureFactoryState("initial");
String aComputeLink = null;
String anUsedHostLink = null;
String anUnusedHostLink = null;
if (!isMock()) {
// clone a random compute and save it under different id
ComputeState randVm = findRandomVm();
ComputeState vm = Utils.clone(randVm);
vm.documentSelfLink = null;
vm.id = "fake-vm-" + vm.id;
vm.documentSelfLink = null;
vm = TestUtils.doPost(this.host, vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
aComputeLink = vm.documentSelfLink;
ComputeState randomHost = findRandomHost();
{
ComputeState host = Utils.clone(randomHost);
host.documentSelfLink = null;
host.powerState = PowerState.ON;
host.id = "fake-host-" + host.id;
host.documentSelfLink = null;
host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
anUsedHostLink = host.documentSelfLink;
ComputeState update = new ComputeState();
update.customProperties = new HashMap<>();
update.customProperties.put(ComputeProperties.PLACEMENT_LINK, host.documentSelfLink);
TestUtils.doPatch(this.host, update, ComputeState.class, UriUtils.buildUri(this.host, randVm.documentSelfLink));
}
{
ComputeState host = Utils.clone(randomHost);
host.documentSelfLink = null;
host.powerState = PowerState.ON;
host.id = "fake-host-unused" + host.id;
host.documentSelfLink = null;
host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
anUnusedHostLink = host.documentSelfLink;
}
}
// do a second refresh to test update path
refreshAndRetire();
captureFactoryState("updated");
snapshotFactoryState("metrics", ResourceMetricsService.class);
if (aComputeLink != null) {
// the second enumeration marked the fake vm as retired
Operation op = Operation.createGet(this.host, aComputeLink);
op = this.host.waitForResponse(op);
ComputeState compute = op.getBody(ComputeState.class);
assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
assertEquals(PowerState.OFF, compute.powerState);
}
if (anUsedHostLink != null) {
// the second enumeration marked the fake vm as retired
Operation op = Operation.createGet(this.host, anUsedHostLink);
op = this.host.waitForResponse(op);
ComputeState compute = op.getBody(ComputeState.class);
assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
assertEquals(PowerState.OFF, compute.powerState);
}
if (anUnusedHostLink != null) {
// the unused host is wiped out unconditionally
Operation op = Operation.createGet(this.host, anUnusedHostLink);
op = this.host.waitForResponse(op);
assertEquals(op.getStatusCode(), 404);
}
verifyDatastoreAndStoragePolicy();
if (!isMock()) {
verifyCIGapForComputeResourcesAndVMs();
verifyCIGapForDatacenterOrFolder(VimNames.TYPE_DATACENTER);
verifyCIGapForDatacenterOrFolder(VimNames.TYPE_FOLDER);
verifyCIGapForDatastore();
verifyCIGapForComputeResource();
}
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestVSphereCloneTaskBase method createInstanceFromTemplate.
protected void createInstanceFromTemplate(boolean withAdditionalDisks) throws Throwable {
ComputeService.ComputeState vm = null;
ComputeService.ComputeState clonedVm = null;
try {
this.auth = createAuth();
this.resourcePool = createResourcePool();
if (isMock()) {
createNetwork(networkId);
}
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
doRefresh();
snapshotFactoryState("clone-refresh", NetworkService.class);
ComputeDescriptionService.ComputeDescription vmDescription = createVmDescription();
vm = createVmState(vmDescription, false, null, withAdditionalDisks);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskService.ProvisionComputeTaskState provisionTask = createProvisionTask(vm);
awaitTaskEnd(provisionTask);
vm = getComputeState(vm);
// put fake moref in the vm
if (isMock()) {
ManagedObjectReference moref = new ManagedObjectReference();
moref.setValue("vm-0");
moref.setType(VimNames.TYPE_VM);
CustomProperties.of(vm).put(MOREF, moref);
vm = doPost(this.host, vm, ComputeService.ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
}
// create state & desc of the clone
ComputeDescriptionService.ComputeDescription cloneDescription = createCloneDescription(vm.documentSelfLink);
clonedVm = createCloneVmState(cloneDescription, false, withAdditionalDisks);
provisionTask = createProvisionTask(clonedVm);
awaitTaskEnd(provisionTask);
clonedVm = getComputeState(clonedVm);
if (!isMock()) {
// Verify that the disk is resized
BasicConnection connection = createConnection();
GetMoRef get = new GetMoRef(connection);
if (withAdditionalDisks) {
List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
assertEquals(3, virtualDisks.size());
} else {
verifyDiskSize(clonedVm, get, CLONE_HDD_DISK_SIZE);
}
}
} finally {
if (!isMock()) {
cleanUpVm(vm, clonedVm);
}
}
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestVSphereImageEnumerationTask method testRefresh.
@Test
public void testRefresh() throws Throwable {
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
doRefresh();
captureFactoryState("initial");
Query q = Query.Builder.create().addKindFieldClause(ImageState.class).build();
ImageState anImage = null;
try {
anImage = findFirstMatching(q, ImageState.class);
} catch (Exception ignore) {
}
if (anImage != null) {
assertFalse(anImage.tenantLinks.isEmpty());
}
doRefresh();
captureFactoryState("updated");
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class ModelUtils method createEndpoint.
public static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
EndpointState endpointState = new EndpointState();
endpointState.endpointType = "vsphere";
endpointState.computeLink = "/resources/compute/fakeGuidA";
endpointState.computeDescriptionLink = "/resources/compute-descriptions/fakeGuidB";
endpointState.resourcePoolLink = "/resources/pools/fakeGuidC";
endpointState.endpointProperties = new HashMap<>();
endpointState.endpointProperties.put("hostName", "sqa-nsxt2-vc.sqa.local");
endpointState.endpointProperties.put("regionId", "Datacenter:datacenter-2");
endpointState.endpointProperties.put("privateKeyId", "install.admin@sqa.local");
endpointState.endpointProperties.put("supportDatastores", "true");
endpointState.name = "vCenter";
endpointState = test.postServiceSynchronously(EndpointService.FACTORY_LINK, endpointState, EndpointState.class);
return endpointState;
}
Aggregations