summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java
blob: dc5fbd099b1406d965ccc0a13ce19e4b42c29099 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package org.openslx.libvirt.capabilities.cpu;

import java.util.ArrayList;
import java.util.List;

import org.openslx.libvirt.xml.LibvirtXmlNode;
import org.w3c.dom.NodeList;

/**
 * Implementation of the host CPU capabilities as part of the Libvirt capabilities XML document.
 * 
 * @author Manuel Bentele
 * @version 1.0
 */
public class Cpu extends LibvirtXmlNode
{
	/**
	 * Creates an empty host CPU capabilities instance.
	 */
	public Cpu()
	{
		super();
	}

	/**
	 * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU
	 * capabilities element.
	 * 
	 * @param xmlNode existing Libvirt XML host CPU capabilities element.
	 */
	public Cpu( LibvirtXmlNode xmlNode )
	{
		super( xmlNode );
	}

	/**
	 * Returns the architecture name of the host CPU.
	 * 
	 * @return architecture name of the host CPU.
	 */
	public String getArch()
	{
		return this.getXmlElementValue( "arch" );
	}

	/**
	 * Returns the model name of the host CPU.
	 * 
	 * @return model name of the host CPU.
	 */
	public String getModel()
	{
		return this.getXmlElementValue( "model" );
	}

	/**
	 * Returns the vendor name of the host CPU.
	 * 
	 * @return vendor name of the host CPU.
	 */
	public String getVendor()
	{
		return this.getXmlElementValue( "vendor" );
	}

	/**
	 * Returns the number of sockets of the host CPU.
	 * 
	 * @return number of sockets of the host CPU.
	 */
	public int getTopologySockets()
	{
		final String numSockets = this.getXmlElementAttributeValue( "topology", "sockets" );
		return Integer.parseInt( numSockets );
	}

	/**
	 * Returns the number of dies of the host CPU.
	 * 
	 * @return number of dies of the host CPU.
	 */
	public int getTopologyDies()
	{
		final String numDies = this.getXmlElementAttributeValue( "topology", "dies" );
		return Integer.parseInt( numDies );
	}

	/**
	 * Returns the number of cores of the host CPU.
	 * 
	 * @return number of cores of the host CPU.
	 */
	public int getTopologyCores()
	{
		final String numCores = this.getXmlElementAttributeValue( "topology", "cores" );
		return Integer.parseInt( numCores );
	}

	/**
	 * Returns the number of threads of the host CPU.
	 * 
	 * @return number of threads of the host CPU.
	 */
	public int getTopologyThreads()
	{
		final String numThreads = this.getXmlElementAttributeValue( "topology", "threads" );
		return Integer.parseInt( numThreads );
	}

	/**
	 * Returns the supported features of the host CPU.
	 * 
	 * @return supported features of the host CPU.
	 */
	public List<Feature> getFeatures()
	{
		final List<Feature> featureList = new ArrayList<Feature>();
		final NodeList featureNodes = this.getXmlNodes( "feature" );

		for ( int i = 0; i < featureNodes.getLength(); i++ ) {
			final LibvirtXmlNode featureNode = new LibvirtXmlNode( this.getXmlDocument(), featureNodes.item( i ) );
			final Feature feature = Feature.newInstance( featureNode );

			if ( feature != null ) {
				featureList.add( feature );
			}
		}

		return featureList;
	}

	/**
	 * Returns the supported memory pages of the host CPU.
	 * 
	 * @return supported memory pages of the host CPU.
	 */
	public List<Pages> getPages()
	{
		final List<Pages> pagesList = new ArrayList<Pages>();
		final NodeList pagesNodes = this.getXmlNodes( "pages" );

		for ( int i = 0; i < pagesNodes.getLength(); i++ ) {
			final LibvirtXmlNode pagesNode = new LibvirtXmlNode( this.getXmlDocument(), pagesNodes.item( i ) );
			final Pages pages = Pages.newInstance( pagesNode );

			if ( pages != null ) {
				pagesList.add( pages );
			}
		}

		return pagesList;
	}

	/**
	 * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU
	 * capabilities element.
	 * 
	 * @param xmlNode existing Libvirt XML host CPU capabilities element.
	 * @return host CPU capabilities instance.
	 */
	public static Cpu newInstance( LibvirtXmlNode xmlNode )
	{
		return new Cpu( xmlNode );
	}
}