Last active
December 12, 2015 00:29
-
-
Save amadorpahim/4684551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 class CpuTopology(object): | |
87 def __init__(self, capabilities=None): | |
88 self._topology = _getCpuTopology(capabilities) | |
89 | |
90 def threads(self): | |
91 return self._topology['threads'] | |
92 | |
93 def cores(self): | |
94 return self._topology['cores'] | |
95 | |
96 def sockets(self): | |
97 return self._topology['sockets'] | |
98 | |
99 | |
100 @utils.memoized | |
101 def _getCapsXMLStr(): | |
102 return libvirtconnection.get().getCapabilities() | |
103 | |
104 | |
105 @utils.memoized | |
106 def _getCpuTopology(capabilities): | |
107 if capabilities is None: | |
108 capabilities = _getCapsXMLStr() | |
109 caps = minidom.parseString(capabilities) | |
110 host = caps.getElementsByTagName('host')[0] | |
111 cells = host.getElementsByTagName('cells')[0] | |
112 cpus = cells.getElementsByTagName('cpu').length | |
113 | |
114 socketList = [] | |
115 siblingsList = [] | |
116 for line in cells.getElementsByTagName('cpu'): | |
117 socket_id = line.getAttribute('socket_id') | |
118 siblings = line.getAttribute('siblings') | |
119 socketList.extend(socket_id) | |
120 siblingsList.extend([siblings]) | |
121 topology = {'sockets': len(set(socketList)), | |
122 'cores': len(set(siblingsList)), | |
123 'threads': cpus} | |
124 return topology |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment