blob: 1848d975f2193608cdced22f0b26291a971b73c4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.openslx.runvirt.viewer;
import org.openslx.runvirt.virtualization.LibvirtHypervisor;
import org.openslx.runvirt.virtualization.LibvirtHypervisorException;
import org.openslx.runvirt.virtualization.LibvirtVirtualMachine;
import org.openslx.virtualization.Version;
/**
* Virtual Machine Manager (virt-manager) to control and view a display of a virtual machine.
*
* @author Manuel Bentele
* @version 1.0
*/
public class ViewerVirtManager extends Viewer
{
/**
* Name of the Virtual Machine Manager program.
*/
private final static String NAME = "virt-manager";
/**
* Maximum number of supported displays by the Virtual Machine Manager.
*/
private final static int NUM_SUPPORTED_DISPLAYS = 1;
/**
* Creates a new Virtual Machine Manager for a virtual machine running on a hypervisor.
*
* @param machine virtual machine to display.
* @param hypervisor remote (hypervisor) endpoint for the viewer to connect to.
*/
public ViewerVirtManager( LibvirtVirtualMachine machine, LibvirtHypervisor hypervisor )
{
super( ViewerVirtManager.NAME, ViewerVirtManager.NUM_SUPPORTED_DISPLAYS, machine, hypervisor );
}
@Override
public Version getVersion() throws ViewerException
{
// execute viewer process with arguments:
// "virt-manager --version"
final String versionOutput = ViewerUtils.executeViewer( ViewerVirtManager.NAME,
new String[] { "--version" } );
return Version.valueOf( versionOutput );
}
@Override
public void render() throws ViewerException
{
String connectionUri = null;
String machineUuid = null;
// get URI of the hypervisor connection and UUID of the machine
try {
connectionUri = this.getHypervisor().getConnectionUri();
machineUuid = this.getMachine().getConfiguration().getUuid();
} catch ( LibvirtHypervisorException e ) {
throw new ViewerException(
"Failed to retrieve the URI of the hypervisor backend or the UUID of the machine to display: "
+ e.getLocalizedMessage() );
}
// check if URI of the hypervisor connection and UUID of the machine is specified, otherwise abort
if ( connectionUri == null || connectionUri.isEmpty() || machineUuid == null || machineUuid.isEmpty() ) {
throw new ViewerException(
"The URI of the hypervisor backend or the UUID of the machine to display is missing!" );
}
// execute viewer process with arguments:
// "virt-viewer --connect=<URI> --show-domain-console <DOMAIN-UUID>"
ViewerUtils.executeViewer( ViewerVirtManager.NAME,
new String[] { "--connect=" + connectionUri, "--show-domain-console", machineUuid } );
}
}
|