Search in sources :

Example 41 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class BaseVSphereAdapterTest method constructDiskState.

protected DiskState constructDiskState(String alias, DiskService.DiskType type, int bootOrder, URI sourceImageReference, long capacityMBytes, HashMap<String, String> customProperties) {
    DiskState res = new DiskState();
    res.capacityMBytes = capacityMBytes;
    if (bootOrder > 0) {
        res.bootOrder = bootOrder;
    }
    res.type = type;
    res.id = res.name = "disk-" + alias;
    res.sourceImageReference = sourceImageReference;
    res.customProperties = customProperties;
    return res;
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Example 42 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createDiskWithStoragePolicy.

/**
 * Create a new disk state to attach it to the virual machine.
 */
protected DiskState createDiskWithStoragePolicy(String alias, DiskService.DiskType type, int bootOrder, URI sourceImageReference, long capacityMBytes, HashMap<String, String> customProperties) throws Throwable {
    DiskState diskState = constructDiskState(alias, type, bootOrder, sourceImageReference, capacityMBytes, customProperties);
    diskState.groupLinks = new HashSet<>();
    diskState.groupLinks.add(createResourceGroupState().documentSelfLink);
    return doPost(this.host, diskState, DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Example 43 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method createBootDisk.

private DiskState createBootDisk(String imageLink) throws Throwable {
    DiskService.DiskState res = new DiskService.DiskState();
    res.name = nextName("disk");
    res.id = res.name;
    res.capacityMBytes = 1;
    res.bootOrder = 1;
    res.type = DiskType.HDD;
    res.imageLink = imageLink;
    return doPost(this.host, res, DiskService.DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) DiskService(com.vmware.photon.controller.model.resources.DiskService)

Example 44 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class TestVSphereDiskService method testDiskCreateAndDeleteWithDatastore.

@Test
public void testDiskCreateAndDeleteWithDatastore() throws Throwable {
    prepareEnvironment();
    DiskState diskState = createDiskWithDatastore("AdditionalDisk1", DiskService.DiskType.HDD, ADDITIONAL_DISK_SIZE, buildCustomProperties());
    testDiskCreateAndDelete(diskState);
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test)

Example 45 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class TestVSphereDiskService method testDiskAvailabilityInVSphereAndDeleteIfAbsent.

@Test
public void testDiskAvailabilityInVSphereAndDeleteIfAbsent() throws Throwable {
    if (isMock()) {
        return;
    }
    prepareEnvironment();
    // Create a sample disk
    DiskState diskState = createDiskWithDatastore("AdditionalDisk1", DiskService.DiskType.HDD, ADDITIONAL_DISK_SIZE, buildCustomProperties());
    String documentSelfLink = performDiskRequest(diskState, SubStage.CREATING_DISK);
    this.host.waitForFinishedTask(ProvisionDiskTaskService.ProvisionDiskTaskState.class, documentSelfLink);
    ServiceDocumentQueryResult result = ProvisioningUtils.queryDiskInstances(this.host, 1);
    diskState = Utils.fromJson(result.documents.get(diskState.documentSelfLink), DiskState.class);
    // refresh enumeration before delete disk
    this.enumerateComputes(this.computeHost, this.endpointState);
    // delete disk in vSphere
    deleteDiskFromVSphere(diskState);
    // refresh enumeration after delete disk, this refresh will sync the deleted disk
    this.enumerateComputes(this.computeHost, this.endpointState);
    // disk state should be 0
    ProvisioningUtils.queryDiskInstances(this.host, 0);
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Aggregations

DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)77 ArrayList (java.util.ArrayList)24 Operation (com.vmware.xenon.common.Operation)23 DiskService (com.vmware.photon.controller.model.resources.DiskService)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)16 List (java.util.List)15 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)13 UriUtils (com.vmware.xenon.common.UriUtils)13 Utils (com.vmware.xenon.common.Utils)13 HashMap (java.util.HashMap)13 TimeUnit (java.util.concurrent.TimeUnit)13 QueryTask (com.vmware.xenon.services.common.QueryTask)12 Query (com.vmware.xenon.services.common.QueryTask.Query)12 HashSet (java.util.HashSet)12 Test (org.junit.Test)11 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)10 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)10 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)10 AuthCredentialsService (com.vmware.xenon.services.common.AuthCredentialsService)10 Map (java.util.Map)10