Search in sources :

Example 1 with DiskAttachment

use of org.ovirt.engine.sdk4.types.DiskAttachment 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 DiskAttachment

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

the class AddVmFromTemplateVersion 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 root of the tree of services:
    SystemService systemService = connection.systemService();
    // Get the reference to the service that manages the storage domains:
    StorageDomainsService storageDomainsService = systemService.storageDomainsService();
    // Find the storage domain we want to be used for virtual machine disks:
    StorageDomain storageDomain = storageDomainsService.list().search("name=mydata").send().storageDomains().get(0);
    // Get the reference to the service that manages the templates:
    TemplatesService templatesService = systemService.templatesService();
    // When a template has multiple versions they all have the same name, so we need to explicitly find the one that
    // has the version name or version number that we want to use. In this case we want to use version 3 of the
    // template.
    List<Template> templates = templatesService.list().search("name=mytemplate").send().templates();
    String templateId = null;
    for (Template template : templates) {
        if (template.version().versionNumber().equals(BigInteger.valueOf(3))) {
            templateId = template.id();
            break;
        }
    }
    // Find the template disk we want be created on specific storage domain
    // for our virtual machine:
    TemplateService templateService = templatesService.templateService(templateId);
    List<DiskAttachment> diskAttachments = connection.followLink(templateService.get().send().template().diskAttachments());
    Disk disk = diskAttachments.get(0).disk();
    // Get the reference to the service that manages the virtual machines:
    VmsService vmsService = connection.systemService().vmsService();
    // Add a new virtual machine explicitly indicating the identifier of the template version that we want to use:
    vmsService.add().vm(vm().name("myvm").cluster(cluster().name("mycluster")).template(template().id(templateId)).diskAttachments(diskAttachment().disk(disk().id(disk.id()).format(DiskFormat.COW).storageDomains(storageDomain().id(storageDomain.id()))))).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) TemplatesService(org.ovirt.engine.sdk4.services.TemplatesService) Template(org.ovirt.engine.sdk4.types.Template) StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) SystemService(org.ovirt.engine.sdk4.services.SystemService) DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) TemplateService(org.ovirt.engine.sdk4.services.TemplateService) Disk(org.ovirt.engine.sdk4.types.Disk)

Example 3 with DiskAttachment

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

the class ListVmDisks 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 "vms" service:
    VmsService vmsService = connection.systemService().vmsService();
    // Find the virtual machine:
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Locate the service that manages the virtual machine:
    VmService vmService = vmsService.vmService(vm.id());
    // Locate the service that manages the disk attachments of the virtual machine:
    DiskAttachmentsService diskAttachmentsService = vmService.diskAttachmentsService();
    // Retrieve the list of disks attachments, and print the disk details. Note that each attachment contains a link
    // to the corresponding disk, but not the actual disk data. In order to retrieve the actual disk data we use the
    // `follow_link` method.
    List<DiskAttachment> diskAttachments = diskAttachmentsService.list().send().attachments();
    for (DiskAttachment diskAttachment : diskAttachments) {
        Disk disk = connection.followLink(diskAttachment.disk());
        System.out.printf("name: %s\n", disk.name());
        System.out.printf("id: %s\n", disk.id());
        System.out.printf("status: %s\n", disk.status());
        System.out.printf("provisioned_size: %s\n", disk.provisionedSize());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) Vm(org.ovirt.engine.sdk4.types.Vm) VmService(org.ovirt.engine.sdk4.services.VmService) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) Disk(org.ovirt.engine.sdk4.types.Disk) DiskAttachmentsService(org.ovirt.engine.sdk4.services.DiskAttachmentsService)

Example 4 with DiskAttachment

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

the class AddLunDiskToVm method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine/ovirt-engine/api").user("admin@internal").password("123456").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 LUN disk.
    diskAttachmentsService.add().attachment(diskAttachment().disk(disk().name("myiscsidisk").lunStorage(hostStorage().type(StorageType.ISCSI).logicalUnits(logicalUnit().address("192.168.200.3").port(3260).target("iqn.2014-07.org.ovirt:storage").id("36001405e793bf9c57a840f58c9a8a220").username("username").password("password")))).interface_(DiskInterface.VIRTIO).bootable(false).active(true)).send().attachment();
    // Close the connection to the server:
    connection.close();
}
Also used : Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) VmsService(org.ovirt.engine.sdk4.services.VmsService) DiskAttachmentsService(org.ovirt.engine.sdk4.services.DiskAttachmentsService)

Example 5 with DiskAttachment

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

the class VmTest method testVmDiskWithValues.

/**
 * Check when creating list of vm disks it creates that list
 */
@Test
public void testVmDiskWithValues() {
    VmContainer vm = new VmContainer();
    vm.diskAttachments(Arrays.asList((DiskAttachment) new DiskAttachmentContainer()));
    assertNotNull(vm.diskAttachments());
    assertEquals(1, vm.diskAttachments().size());
    assertNotNull(vm.diskAttachments().get(0));
}
Also used : DiskAttachment(org.ovirt.engine.sdk4.types.DiskAttachment) VmContainer(org.ovirt.engine.sdk4.internal.containers.VmContainer) DiskAttachmentContainer(org.ovirt.engine.sdk4.internal.containers.DiskAttachmentContainer) Test(org.junit.Test)

Aggregations

VmsService (org.ovirt.engine.sdk4.services.VmsService)6 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)6 Connection (org.ovirt.engine.sdk4.Connection)5 Vm (org.ovirt.engine.sdk4.types.Vm)5 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)4 Disk (org.ovirt.engine.sdk4.types.Disk)4 ArrayList (java.util.ArrayList)2 SystemService (org.ovirt.engine.sdk4.services.SystemService)2 TemplateService (org.ovirt.engine.sdk4.services.TemplateService)2 TemplatesService (org.ovirt.engine.sdk4.services.TemplatesService)2 VmService (org.ovirt.engine.sdk4.services.VmService)2 Template (org.ovirt.engine.sdk4.types.Template)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Test (org.junit.Test)1 DiskAttachmentContainer (org.ovirt.engine.sdk4.internal.containers.DiskAttachmentContainer)1 VmContainer (org.ovirt.engine.sdk4.internal.containers.VmContainer)1 DiskAttachmentService (org.ovirt.engine.sdk4.services.DiskAttachmentService)1 DiskService (org.ovirt.engine.sdk4.services.DiskService)1