Search in sources :

Example 6 with VmsService

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

the class ChangeVmCd 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 virtual machines:
    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 CDROM devices of the virtual machine:
    VmCdromsService cdromsService = vmService.cdromsService();
    // Get the first CDROM:
    Cdrom cdrom = cdromsService.list().send().cdroms().get(0);
    // Locate the service that manages the CDROM device found in the previous step:
    VmCdromService cdromService = cdromsService.cdromService(cdrom.id());
    // Change the CDROM disk of the virtual machine to 'my_iso_file.iso'. By default the below operation changes
    // permanently the disk that will be visible to the virtual machine after the next boot, but it doesn't have
    // any effect on the currently running virtual machine. If you want to change the disk that is visible to the
    // current running virtual machine, change the value of the 'current' parameter to 'true'.
    cdromService.update().cdrom(cdrom().file(file().id("my_iso_file.iso"))).current(false).send();
    // Close the connection to the server:
    connection.close();
}
Also used : VmCdromsService(org.ovirt.engine.sdk4.services.VmCdromsService) Cdrom(org.ovirt.engine.sdk4.types.Cdrom) VmCdromService(org.ovirt.engine.sdk4.services.VmCdromService) 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)

Example 7 with VmsService

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

the class CloneVmFromSnapshot 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();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Find the service that manages the virtual machine:
    VmService vmService = vmsService.vmService(vm.id());
    // Find the snapshot. Note that the snapshots collection doesn't support search, so we need to retrieve the
    // complete list and the look for the snapshot that has the description that we are looking for.
    SnapshotsService snapsService = vmService.snapshotsService();
    List<Snapshot> snaps = snapsService.list().send().snapshots();
    Snapshot snap = null;
    for (Snapshot s : snaps) {
        if (Objects.equals(s.description(), "mysnap")) {
            snap = s;
            break;
        }
    }
    // Create a new virtual machine, cloning it from the snapshot:
    Vm clonedVm = vmsService.add().vm(vm().name("myclonedvm").snapshots(snapshot().id(snap.id())).cluster(cluster().name("mycluster"))).send().vm();
    // Find the service that manages the cloned virtual machine:
    VmService clonedVmService = vmsService.vmService(clonedVm.id());
    // Wait till the virtual machine is down, as that means that the creation of the disks has been completed:
    for (; ; ) {
        Thread.sleep(5 * 1000);
        clonedVm = clonedVmService.get().send().vm();
        if (clonedVm.status() == VmStatus.DOWN) {
            break;
        }
    }
    // Close the connection to the server:
    connection.close();
}
Also used : Snapshot(org.ovirt.engine.sdk4.types.Snapshot) SystemService(org.ovirt.engine.sdk4.services.SystemService) SnapshotsService(org.ovirt.engine.sdk4.services.SnapshotsService) 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)

Example 8 with VmsService

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

the class EnableSerialConsole 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();
    // Find the virtual machine. Note the use of the  `all_content` parameter, it is required in order to obtain
    // additional information that isn't retrieved by default, like the configuration of the serial console.
    VmsService vmsService = connection.systemService().vmsService();
    Vm vm = vmsService.list().search("name=myvm").allContent(true).send().vms().get(0);
    // Check if the serial console is enabled, and if it isn't then update the virtual machine to enable it:
    if (!vm.console().enabled()) {
        VmService vmService = vmsService.vmService(vm.id());
        vmService.update().vm(vm().console(console().enabled(true))).send();
    }
    // Close the connection to the server:
    connection.close();
}
Also used : 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)

Example 9 with VmsService

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

the class GetDisplayTicket 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();
    // Find the virtual machine:
    VmsService vmsService = systemService.vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    // Find the service that manages the graphics consoles of the virtual machine:
    VmService vmService = vmsService.vmService(vm.id());
    VmGraphicsConsolesService consolesService = vmService.graphicsConsolesService();
    // The method that lists the graphics consoles doesn't support search, so in order to find the console
    // corresponding to the access protocol that we are interested on (SPICE in this example) we need to get all of
    // them and filter explicitly. In addition the `current` parameter must be `true`, as otherwise you will *not*
    // get important values like the `address` and `port` where the console is available.
    List<GraphicsConsole> consoles = consolesService.list().current(true).send().consoles();
    GraphicsConsole console = null;
    for (GraphicsConsole c : consoles) {
        if (c.protocol() == GraphicsType.SPICE) {
            console = c;
            break;
        }
    }
    // Find the service that manages the graphics console that was selected in the previous step:
    VmGraphicsConsoleService consoleService = consolesService.consoleService(console.id());
    // Request the ticket. The virtual machine must be up and running, as it doesn't make sense to get a console
    // ticket for a virtual machine that is down. If you try that, the request will fail.
    Ticket ticket = consoleService.ticket().send().ticket();
    // Print the details needed to connect to the console (the ticket value is the password):
    System.out.printf("address: %s\n", console.address());
    System.out.printf("port: %d\n", console.port());
    System.out.printf("tls_port: %d\n", console.tlsPort());
    System.out.printf("password: %s\n", ticket.value());
    // Close the connection to the server:
    connection.close();
}
Also used : Ticket(org.ovirt.engine.sdk4.types.Ticket) SystemService(org.ovirt.engine.sdk4.services.SystemService) VmGraphicsConsolesService(org.ovirt.engine.sdk4.services.VmGraphicsConsolesService) VmGraphicsConsoleService(org.ovirt.engine.sdk4.services.VmGraphicsConsoleService) 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) GraphicsConsole(org.ovirt.engine.sdk4.types.GraphicsConsole)

Example 10 with VmsService

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

the class ImportVm method main.

public static void main(String[] args) throws Exception {
    // Create connection to the oVirt engine server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get storage domains service
    StorageDomainsService storageDomainsService = connection.systemService().storageDomainsService();
    // Get export storage domain
    StorageDomain exportDomain = storageDomainsService.list().search("name=myexport").send().storageDomains().get(0);
    // Get target storage domain
    StorageDomain targetStorageDomain = storageDomainsService.list().search("name=mydata").send().storageDomains().get(0);
    // Get cluster service
    ClustersService clustersService = connection.systemService().clustersService();
    // Get the cluster we import the VM to
    Cluster cluster = clustersService.list().search("name=mycluster").send().clusters().get(0);
    // Get VM service for export storage domain
    StorageDomainVmsService vmsService = storageDomainsService.storageDomainService(exportDomain.id()).vmsService();
    // Get the first exported VM, assuming we have one
    Vm exportedVm = vmsService.list().send().vm().get(0);
    // Import the exported VM into target storage domain, 'mydata'
    vmsService.vmService(exportedVm.id()).import_().storageDomain(storageDomain().id(targetStorageDomain.id())).cluster(cluster().id(cluster.id())).vm(vm().id(exportedVm.id())).send();
    // Close the connection
    connection.close();
}
Also used : StorageDomainsService(org.ovirt.engine.sdk4.services.StorageDomainsService) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) Vm(org.ovirt.engine.sdk4.types.Vm) Connection(org.ovirt.engine.sdk4.Connection) ClustersService(org.ovirt.engine.sdk4.services.ClustersService) Cluster(org.ovirt.engine.sdk4.types.Cluster) StorageDomainVmsService(org.ovirt.engine.sdk4.services.StorageDomainVmsService)

Aggregations

VmsService (org.ovirt.engine.sdk4.services.VmsService)34 Connection (org.ovirt.engine.sdk4.Connection)31 Vm (org.ovirt.engine.sdk4.types.Vm)29 VmService (org.ovirt.engine.sdk4.services.VmService)19 SystemService (org.ovirt.engine.sdk4.services.SystemService)8 Disk (org.ovirt.engine.sdk4.types.Disk)5 DiskAttachment (org.ovirt.engine.sdk4.types.DiskAttachment)5 DiskAttachmentsService (org.ovirt.engine.sdk4.services.DiskAttachmentsService)4 SnapshotsService (org.ovirt.engine.sdk4.services.SnapshotsService)4 StorageDomainsService (org.ovirt.engine.sdk4.services.StorageDomainsService)4 StorageDomain (org.ovirt.engine.sdk4.types.StorageDomain)4 Test (org.junit.Test)3 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 SnapshotDisksService (org.ovirt.engine.sdk4.services.SnapshotDisksService)2 SnapshotService (org.ovirt.engine.sdk4.services.SnapshotService)2 TemplateService (org.ovirt.engine.sdk4.services.TemplateService)2 TemplatesService (org.ovirt.engine.sdk4.services.TemplatesService)2