Search in sources :

Example 1 with DiskService

use of org.ovirt.engine.sdk4.services.DiskService in project ovirt-engine-sdk-java by oVirt.

the class AddVmDisk 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 virtual machines service and use it to find the virtual machine:
    VmsService vmsService = connection.systemService().vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Locate the service that manages the disk attachments of the virtual machine:
    DiskAttachmentsService diskAttachmentsService = vmsService.vmService(vm.id()).diskAttachmentsService();
    // Use the `add` method of the disk attachments service to add the disk. Note that the size of the disk,
    // the `provionedSize` attribute, is specified in bytes, so to create a disk of 10 GiB the value should
    // be 10 * 2^30.
    DiskAttachment diskAttachment = diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("mydisk").description("My disk").format(DiskFormat.COW).provisionedSize(BigInteger.valueOf(10).multiply(BigInteger.valueOf(2).pow(30))).storageDomains(storageDomain().name("mydata"))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
    // Wait till the disk is OK:
    DisksService disksService = connection.systemService().disksService();
    DiskService diskService = disksService.diskService(diskAttachment.disk().id());
    for (; ; ) {
        Thread.sleep(5 * 1000);
        Disk disk = diskService.get().send().disk();
        if (disk.status() == DiskStatus.OK) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) Vm(org.ovirt.engine.sdk4.types.Vm) DisksService(org.ovirt.engine.sdk4.services.DisksService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) Disk(org.ovirt.engine.sdk4.types.Disk) DiskService(org.ovirt.engine.sdk4.services.DiskService) DiskAttachmentsService(org.ovirt.engine.sdk4.services.DiskAttachmentsService)

Example 2 with DiskService

use of org.ovirt.engine.sdk4.services.DiskService 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)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)2 DiskService (org.ovirt.engine.sdk4.services.DiskService)2 DisksService (org.ovirt.engine.sdk4.services.DisksService)2 Disk (org.ovirt.engine.sdk4.types.Disk)2 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)1 VmsService (org.ovirt.engine.sdk4.services.VmsService)1 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)1 Vm (org.ovirt.engine.sdk4.types.Vm)1