Search in sources :

Example 11 with Vm

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

the class ListAffinityLabels 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 affinity labels service:
    AffinityLabelsService affinityLabelsService = connection.systemService().affinityLabelsService();
    // Use the "list" method of the affinity labels service
    // to list all the affinity labels of the system:
    List<AffinityLabel> affinityLabels = affinityLabelsService.list().send().labels();
    // which has assigned that affinity label:
    for (AffinityLabel affinityLabel : affinityLabels) {
        System.out.printf("%s:\n", affinityLabel.name());
        for (Vm vm_link : connection.followLink(affinityLabel.vms())) {
            System.out.printf(" - %s\n", connection.followLink(vm_link).name());
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : AffinityLabelsService(org.ovirt.engine.sdk4.services.AffinityLabelsService) AffinityLabel(org.ovirt.engine.sdk4.types.AffinityLabel) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection)

Example 12 with Vm

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

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

the class AddLogicalNetwork 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 "networks" service:
    NetworksService networksService = connection.systemService().networksService();
    // Use the "add" method to create new VM logical network in data center called "mydatacenter", with VLAN tag
    // 100 and MTU 1500.
    networksService.add().network(network().name("mynetwork").description("My logical network").dataCenter(dataCenter().name("mydatacenter")).vlan(vlan().id(100)).usages(Arrays.asList(NetworkUsage.DISPLAY)).mtu(1500)).send();
    // Close the connection to the server:
    connection.close();
}
Also used : Connection(org.ovirt.engine.sdk4.Connection) NetworksService(org.ovirt.engine.sdk4.services.NetworksService)

Example 14 with Vm

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

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

Connection (org.ovirt.engine.sdk4.Connection)34 VmsService (org.ovirt.engine.sdk4.services.VmsService)34 Vm (org.ovirt.engine.sdk4.types.Vm)32 VmService (org.ovirt.engine.sdk4.services.VmService)21 Test (org.junit.Test)8 SystemService (org.ovirt.engine.sdk4.services.SystemService)8 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)6 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)5 Disk (org.ovirt.engine.sdk4.types.Disk)5 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)5 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)4 SnapshotsService (org.ovirt.engine.sdk4.services.SnapshotsService)4 AssignedTagsService (org.ovirt.engine.sdk4.services.AssignedTagsService)3 Snapshot (org.ovirt.engine.sdk4.types.Snapshot)3 Template (org.ovirt.engine.sdk4.types.Template)3 ArrayList (java.util.ArrayList)2 VmContainer (org.ovirt.engine.sdk4.internal.containers.VmContainer)2 AffinityLabelsService (org.ovirt.engine.sdk4.services.AffinityLabelsService)2 SnapshotDisksService (org.ovirt.engine.sdk4.services.SnapshotDisksService)2 SnapshotService (org.ovirt.engine.sdk4.services.SnapshotService)2