Search in sources :

Example 6 with StorageDomain

use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.

the class ListGlanceImages method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the root of the services tree:
    SystemService systemService = connection.systemService();
    // Find the Glance storage domain that is available for default in any oVirt installation:
    StorageDomainsService sdsService = systemService.storageDomainsService();
    StorageDomain sd = sdsService.list().search("name=ovirt-image-repository").send().storageDomains().get(0);
    // Find the service that manages the Glance storage domain:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    // Find the service that manages the images available in that storage domain:
    ImagesService imagesService = sdService.imagesService();
    // List the images available in the storage domain:
    List<Image> images = imagesService.list().send().images();
    for (Image image : images) {
        System.out.println(image.name());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) Connection(org.ovirt.engine.sdk4.Connection) ImagesService(org.ovirt.engine.sdk4.services.ImagesService) Image(org.ovirt.engine.sdk4.types.Image)

Example 7 with StorageDomain

use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.

the class AddNfsDataStorageDomain method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the storage domains service:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    // Create a new NFS storage domain:
    StorageDomain sd = sdsService.add().storageDomain(storageDomain().name("mydata").description("My data").type(StorageDomainType.DATA).host(host().name("myhost")).storage(hostStorage().type(StorageType.NFS).address("server0.example.com").path("/nfs/ovirt/40/mydata"))).send().storageDomain();
    // Wait till the storage domain is unattached:
    StorageDomainService sdService = sdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = sdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.UNATTACHED) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Connection(org.ovirt.engine.sdk4.Connection)

Example 8 with StorageDomain

use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.

the class StorageDomainsServiceTest method testGetObjectFromStorageDomainService.

/**
 * Test we don't get null storage service for existing storage id and correct object
 */
@Test
public void testGetObjectFromStorageDomainService() {
    StorageDomainService sdService = storageDomainsService.storageDomainService("123");
    StorageDomain sd = sdService.get().send().storageDomain();
    assertEquals("123", sd.id());
    assertEquals("testsd", sd.name());
    assertNull(sd.description());
}
Also used : StorageDomainService(org.ovirt.engine.sdk4.services.StorageDomainService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Test(org.junit.Test)

Example 9 with StorageDomain

use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.

the class AddFloatingDisk method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the disks service:
    DisksService disksService = connection.systemService().disksService();
    // Add the disk. Note that the size of the disk, the `provisionedSize` attribute, is specified in bytes,
    // so to create a disk of 10 GiB the value should be 10 * 2^30.
    Disk disk = disksService.add().disk(disk().name("mydisk").description("My disk").format(DiskFormat.COW).provisionedSize(BigInteger.valueOf(10).multiply(BigInteger.valueOf(2).pow(30))).storageDomains(storageDomain().name("mydata"))).send().disk();
    // Wait till the disk is completely created:
    DiskService diskService = disksService.diskService(disk.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        disk = diskService.get().send().disk();
        if (disk.status() == DiskStatus.OK) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : DisksService(org.ovirt.engine.sdk4.services.DisksService) Connection(org.ovirt.engine.sdk4.Connection) Disk(org.ovirt.engine.sdk4.types.Disk) DiskService(org.ovirt.engine.sdk4.services.DiskService)

Example 10 with StorageDomain

use of org.ovirt.engine.sdk4.types.StorageDomain in project ovirt-engine-sdk-java by oVirt.

the class AttachNfsIsoStorageDomain method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Locate the service that manages the storage domains, and use it to search for the storage domain:
    StorageDomainsService sdsService = connection.systemService().storageDomainsService();
    StorageDomain sd = sdsService.list().search("name=myiso").send().storageDomains().get(0);
    // Locate the service that manages the data centers and use it to search for the data center:
    DataCentersService dcsService = connection.systemService().dataCentersService();
    DataCenter dc = dcsService.list().search("name=mydc").send().dataCenters().get(0);
    // Locate the service that manages the data center where we want to attach the storage domain:
    DataCenterService dcService = dcsService.dataCenterService(dc.id());
    // Locate the service that manages the storage domains that are attached to the data center:
    AttachedStorageDomainsService attachedSdsService = dcService.storageDomainsService();
    // Use the "add" method of the service that manages the attached storage domains to attach it:
    attachedSdsService.add().storageDomain(storageDomain().id(sd.id())).send();
    // Wait till the storage domain is active:
    AttachedStorageDomainService attachedSdService = attachedSdsService.storageDomainService(sd.id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        sd = attachedSdService.get().send().storageDomain();
        if (sd.status() == StorageDomainStatus.ACTIVE) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : AttachedStorageDomainsService(org.ovirt.engine.sdk4.services.AttachedStorageDomainsService) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) DataCentersService(org.ovirt.engine.sdk4.services.DataCentersService) DataCenter(org.ovirt.engine.sdk4.types.DataCenter) AttachedStorageDomainService(org.ovirt.engine.sdk4.services.AttachedStorageDomainService) Connection(org.ovirt.engine.sdk4.Connection) DataCenterService(org.ovirt.engine.sdk4.services.DataCenterService) AttachedStorageDomainsService(org.ovirt.engine.sdk4.services.AttachedStorageDomainsService)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)15 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)13 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)12 StorageDomainService (org.ovirt.engine.sdk4.services.StorageDomainService)7 SystemService (org.ovirt.engine.sdk4.services.SystemService)7 Vm (org.ovirt.engine.sdk4.types.Vm)6 VmsService (org.ovirt.engine.sdk4.services.VmsService)5 Disk (org.ovirt.engine.sdk4.types.Disk)4 DataCenterService (org.ovirt.engine.sdk4.services.DataCenterService)3 DataCentersService (org.ovirt.engine.sdk4.services.DataCentersService)3 VmService (org.ovirt.engine.sdk4.services.VmService)3 DataCenter (org.ovirt.engine.sdk4.types.DataCenter)3 AttachedStorageDomainService (org.ovirt.engine.sdk4.services.AttachedStorageDomainService)2 AttachedStorageDomainsService (org.ovirt.engine.sdk4.services.AttachedStorageDomainsService)2 DiskService (org.ovirt.engine.sdk4.services.DiskService)2 DisksService (org.ovirt.engine.sdk4.services.DisksService)2 ImagesService (org.ovirt.engine.sdk4.services.ImagesService)2 StorageDomainVmsService (org.ovirt.engine.sdk4.services.StorageDomainVmsService)2 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)2 Image (org.ovirt.engine.sdk4.types.Image)2