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();
}
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();
}
Aggregations