Re: [libvirt] [PATCH] examples: Add script to parse topology from capabilities output

2013-09-03 Thread Peter Krempa
On 09/03/13 11:15, Martin Kletzander wrote:
> On 09/02/2013 04:57 PM, Peter Krempa wrote:
>> Add a demo script originally written by Amador Pahim to parse topology
>> of the host from data provided in the capabilities XML.
>> ---
>>  examples/python/topology.py | 45 
>> +
>>  1 file changed, 45 insertions(+)
>>  create mode 100755 examples/python/topology.py
>>
>> diff --git a/examples/python/topology.py b/examples/python/topology.py
>> new file mode 100755
>> index 000..1b678bc
>> --- /dev/null
>> +++ b/examples/python/topology.py

...

>> +
>> +print "Host topology"
>> +print "NUMA nodes:", cells.getAttribute('num')
>> +print "   Sockets:",len(set(socketIds))
>> +print " Cores:",len(set(siblingsIds))
>> +print "   Threads:",total_cpus
>>
> 
> I won't get into details like len() vs. .length, string formatting, etc.
> ;-)  But please add a space after these commas.

Hmmm, yeah. My python skills are very weak :/. But as an example, this
should be kind of okay :/

I've added the spaces

> 
> Even though I don't know how this will turn out on those weird
> multi-processor per core and similar architectures/processors, it should
> turn out OK since you're the one who should know how those will look in
> the capabilities XML.
> 
> It would be also worth adding it into specfile like other python
> examples (I'm guessing those are in libvirt-python).

and added the script to examples/python/Makefile.am. The specfile seems
to automatically add all the example python scripts.
> 
> ACK with those two things fixed,

Pushed; Thanks.

> Martin
> 

Peter




signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] examples: Add script to parse topology from capabilities output

2013-09-03 Thread Martin Kletzander
On 09/02/2013 04:57 PM, Peter Krempa wrote:
> Add a demo script originally written by Amador Pahim to parse topology
> of the host from data provided in the capabilities XML.
> ---
>  examples/python/topology.py | 45 
> +
>  1 file changed, 45 insertions(+)
>  create mode 100755 examples/python/topology.py
> 
> diff --git a/examples/python/topology.py b/examples/python/topology.py
> new file mode 100755
> index 000..1b678bc
> --- /dev/null
> +++ b/examples/python/topology.py
> @@ -0,0 +1,45 @@
> +#!/usr/bin/env python
> +# Parse topology information from the capabilities XML and use
> +# them to calculate host topology
> +#
> +# Authors:
> +#   Amador Pahim 
> +#   Peter Krempa 
> +
> +import libvirt
> +import sys
> +from xml.dom import minidom
> +
> +try:
> +conn = libvirt.openReadOnly(None)
> +except libvirt.libvirtError:
> +print 'Failed to connect to the hypervisor'
> +sys.exit(1)
> +
> +try:
> +capsXML = conn.getCapabilities()
> +except libvirt.libvirtError:
> +print 'Failed to request capabilities'
> +sys.exit(1)
> +
> +caps = minidom.parseString(capsXML)
> +host = caps.getElementsByTagName('host')[0]
> +cells = host.getElementsByTagName('cells')[0]
> +total_cpus = cells.getElementsByTagName('cpu').length
> +
> +socketIds = []
> +siblingsIds = []
> +
> +socketIds = [ proc.getAttribute('socket_id')
> +  for proc in cells.getElementsByTagName('cpu')
> +  if proc.getAttribute('socket_id') not in socketIds ]
> +
> +siblingsIds = [ proc.getAttribute('siblings')
> +for proc in cells.getElementsByTagName('cpu')
> +if proc.getAttribute('siblings') not in siblingsIds ]
> +
> +print "Host topology"
> +print "NUMA nodes:", cells.getAttribute('num')
> +print "   Sockets:",len(set(socketIds))
> +print " Cores:",len(set(siblingsIds))
> +print "   Threads:",total_cpus
> 

I won't get into details like len() vs. .length, string formatting, etc.
;-)  But please add a space after these commas.

Even though I don't know how this will turn out on those weird
multi-processor per core and similar architectures/processors, it should
turn out OK since you're the one who should know how those will look in
the capabilities XML.

It would be also worth adding it into specfile like other python
examples (I'm guessing those are in libvirt-python).

ACK with those two things fixed,
Martin

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] examples: Add script to parse topology from capabilities output

2013-09-02 Thread Peter Krempa
Add a demo script originally written by Amador Pahim to parse topology
of the host from data provided in the capabilities XML.
---
 examples/python/topology.py | 45 +
 1 file changed, 45 insertions(+)
 create mode 100755 examples/python/topology.py

diff --git a/examples/python/topology.py b/examples/python/topology.py
new file mode 100755
index 000..1b678bc
--- /dev/null
+++ b/examples/python/topology.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# Parse topology information from the capabilities XML and use
+# them to calculate host topology
+#
+# Authors:
+#   Amador Pahim 
+#   Peter Krempa 
+
+import libvirt
+import sys
+from xml.dom import minidom
+
+try:
+conn = libvirt.openReadOnly(None)
+except libvirt.libvirtError:
+print 'Failed to connect to the hypervisor'
+sys.exit(1)
+
+try:
+capsXML = conn.getCapabilities()
+except libvirt.libvirtError:
+print 'Failed to request capabilities'
+sys.exit(1)
+
+caps = minidom.parseString(capsXML)
+host = caps.getElementsByTagName('host')[0]
+cells = host.getElementsByTagName('cells')[0]
+total_cpus = cells.getElementsByTagName('cpu').length
+
+socketIds = []
+siblingsIds = []
+
+socketIds = [ proc.getAttribute('socket_id')
+  for proc in cells.getElementsByTagName('cpu')
+  if proc.getAttribute('socket_id') not in socketIds ]
+
+siblingsIds = [ proc.getAttribute('siblings')
+for proc in cells.getElementsByTagName('cpu')
+if proc.getAttribute('siblings') not in siblingsIds ]
+
+print "Host topology"
+print "NUMA nodes:", cells.getAttribute('num')
+print "   Sockets:",len(set(socketIds))
+print " Cores:",len(set(siblingsIds))
+print "   Threads:",total_cpus
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list