Search in sources :

Example 1 with GraphicsConsole

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

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

the class AddVncConsole 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:
    VmsService vmsService = connection.systemService().vmsService();
    Vm vm = vmsService.list().search("name=myvm").send().vms().get(0);
    VmService vmService = vmsService.vmService(vm.id());
    // Find the graphics consoles of the virtual machine:
    VmGraphicsConsolesService consolesService = vmService.graphicsConsolesService();
    List<GraphicsConsole> consoles = consolesService.list().send().consoles();
    // Add a VNC console if it doesn't exist:
    GraphicsConsole console = null;
    for (GraphicsConsole c : consoles) {
        if (c.protocol() == GraphicsType.VNC) {
            console = c;
            break;
        }
    }
    if (console == null) {
        consolesService.add().console(graphicsConsole().protocol(GraphicsType.VNC)).send();
    }
    // Close the connection to the server:
    connection.close();
}
Also used : VmGraphicsConsolesService(org.ovirt.engine.sdk4.services.VmGraphicsConsolesService) 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)

Aggregations

Connection (org.ovirt.engine.sdk4.Connection)2 VmGraphicsConsolesService (org.ovirt.engine.sdk4.services.VmGraphicsConsolesService)2 VmService (org.ovirt.engine.sdk4.services.VmService)2 VmsService (org.ovirt.engine.sdk4.services.VmsService)2 GraphicsConsole (org.ovirt.engine.sdk4.types.GraphicsConsole)2 Vm (org.ovirt.engine.sdk4.types.Vm)2 SystemService (org.ovirt.engine.sdk4.services.SystemService)1 VmGraphicsConsoleService (org.ovirt.engine.sdk4.services.VmGraphicsConsoleService)1 Ticket (org.ovirt.engine.sdk4.types.Ticket)1