blob: 247118086ea59494a7644605e55c5353fc1f323c (
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package org.openslx.libvirt.capabilities.guest;
import java.util.ArrayList;
import java.util.List;
import org.openslx.libvirt.domain.Domain.OsType;
import org.openslx.libvirt.xml.LibvirtXmlNode;
import org.w3c.dom.NodeList;
/**
* Implementation of the guest capabilities as part of the Libvirt capabilities XML document.
*
* @author Manuel Bentele
* @version 1.0
*/
public class Guest extends LibvirtXmlNode
{
/**
* Creates an empty guest instance.
*/
public Guest()
{
super();
}
/**
* Creates a guest representing an existing Libvirt XML guest capabilities element.
*
* @param xmlNode existing Libvirt XML guest capabilities element.
*/
public Guest( LibvirtXmlNode xmlNode )
{
super( xmlNode );
}
/**
* Return OS type of the guest.
*
* @return OS type of the guest.
*/
public OsType getOsType()
{
final String osType = this.getXmlElementValue( "os_type" );
return OsType.fromString( osType );
}
/**
* Returns the architecture name of the guest.
*
* @return architecture name of the guest.
*/
public String getArchName()
{
return this.getXmlElementAttributeValue( "arch", "name" );
}
/**
* Return word size of the guest's architecture.
*
* @return word size of the guest's architecture.
*/
public int getArchWordSize()
{
final String archWordSize = this.getXmlElementValue( "arch/wordsize" );
return Integer.parseInt( archWordSize );
}
public String getArchEmulator()
{
return this.getXmlElementValue( "arch/emulator" );
}
/**
* Returns the available machines of the guest's architecture.
*
* @return available machines of the guest's architecture.
*/
public List<Machine> getArchMachines()
{
final List<Machine> machinesList = new ArrayList<Machine>();
final NodeList machineNodes = this.getXmlNodes( "arch/machine" );
for ( int i = 0; i < machineNodes.getLength(); i++ ) {
final LibvirtXmlNode machineNode = new LibvirtXmlNode( this.getXmlDocument(), machineNodes.item( i ) );
final Machine machine = Machine.newInstance( machineNode );
if ( machine != null ) {
machinesList.add( machine );
}
}
return machinesList;
}
/**
* Returns the supported domains of the guest.
*
* @return supported domains of the guest.
*/
public List<Domain> getArchDomains()
{
final List<Domain> domainList = new ArrayList<Domain>();
final NodeList domainNodes = this.getXmlNodes( "arch/domain" );
for ( int i = 0; i < domainNodes.getLength(); i++ ) {
final LibvirtXmlNode domainNode = new LibvirtXmlNode( this.getXmlDocument(), domainNodes.item( i ) );
final Domain domain = Domain.newInstance( domainNode );
if ( domain != null ) {
domainList.add( domain );
}
}
return domainList;
}
/**
* Creates a guest representing an existing Libvirt XML guest capabilities element.
*
* @param xmlNode existing Libvirt XML guest capabilities element.
* @return guest capabilities instance.
*/
public static Guest newInstance( LibvirtXmlNode xmlNode )
{
return new Guest( xmlNode );
}
}
|