[libvirt] [libvirt-python PATCH v12] Expose virDomainInterfacesAddresses to python binding
by Pavel Hrdina
From: Nehal J Wani <nehaljw.kkd1(a)gmail.com>
examples/Makefile.am:
* Add new file domipaddrs.py
examples/README:
* Add documentation for the python example
libvirt-override-api.xml:
* Add new symbol for virDomainInterfacesAddresses
libvirt-override.c:
* Hand written python api
Example:
$ python examples/domipaddrs.py qemu:///system f18
Interface MAC address Protocol Address
vnet0 52:54:00:20:70:3d ipv4 192.168.105.240/16
In v11:
- Cope with hwaddr being NULL by filling in PY_NONE
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
MANIFEST.in | 1 +
examples/README | 1 +
examples/domipaddrs.py | 57 +++++++++++++++++++++
generator.py | 2 +
libvirt-override-api.xml | 7 +++
libvirt-override.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++
sanitytest.py | 3 ++
7 files changed, 199 insertions(+)
create mode 100755 examples/domipaddrs.py
diff --git a/MANIFEST.in b/MANIFEST.in
index d7bc545..dd05221 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -4,6 +4,7 @@ include COPYING
include COPYING.LESSER
include ChangeLog
include examples/consolecallback.py
+include examples/domipaddrs.py
include examples/dominfo.py
include examples/domrestore.py
include examples/domsave.py
diff --git a/examples/README b/examples/README
index 5b5d405..1d4b425 100644
--- a/examples/README
+++ b/examples/README
@@ -11,6 +11,7 @@ domrestore.py - restore domU's from their saved files in a directory
esxlist.py - list active domains of an VMware ESX host and print some info.
also demonstrates how to use the libvirt.openAuth() method
dhcpleases.py - list dhcp leases for a given virtual network
+domipaddrs.py - list IP addresses for guest domains
The XML files in this directory are examples of the XML format that libvirt
expects, and will have to be adapted for your setup. They are only needed
diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py
new file mode 100755
index 0000000..d6d5cac
--- /dev/null
+++ b/examples/domipaddrs.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# domipaddrs - print domain interfaces along with their MAC and IP addresses
+
+import libvirt
+import sys
+
+def usage():
+ print "Usage: %s [URI] DOMAIN" % sys.argv[0]
+ print " Print domain interfaces along with their MAC and IP addresses"
+
+uri = None
+name = None
+args = len(sys.argv)
+
+if args == 2:
+ name = sys.argv[1]
+elif args == 3:
+ uri = sys.argv[1]
+ name = sys.argv[2]
+else:
+ usage()
+ sys.exit(2)
+
+conn = libvirt.open(uri)
+if conn == None:
+ print "Unable to open connection to libvirt"
+ sys.exit(1)
+
+try:
+ dom = conn.lookupByName(name)
+except libvirt.libvirtError:
+ print "Domain %s not found" % name
+ sys.exit(0)
+
+ifaces = dom.interfaceAddresses(libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE);
+if (ifaces == None):
+ print "Failed to get domain interfaces"
+ sys.exit(0)
+
+print " {0:10} {1:20} {2:12} {3}".format("Interface", "MAC address", "Protocol", "Address")
+
+def toIPAddrType(addrType):
+ if addrType == libvirt.VIR_IP_ADDR_TYPE_IPV4:
+ return "ipv4"
+ elif addrType == libvirt.VIR_IP_ADDR_TYPE_IPV6:
+ return "ipv6"
+
+for (name, val) in ifaces.iteritems():
+ if val['addrs']:
+ for addr in val['addrs']:
+ print " {0:10} {1:19}".format(name, val['hwaddr']),
+ print " {0:12} {1}/{2} ".format(toIPAddrType(addr['type']), addr['addr'], addr['prefix']),
+ print
+ else:
+ print " {0:10} {1:19}".format(name, val['hwaddr']),
+ print " {0:12} {1}".format("N/A", "N/A"),
+ print
diff --git a/generator.py b/generator.py
index df7a74d..8c1c48e 100755
--- a/generator.py
+++ b/generator.py
@@ -483,6 +483,7 @@ skip_impl = (
'virDomainBlockCopy',
'virNodeAllocPages',
'virDomainGetFSInfo',
+ 'virDomainInterfaceAddresses',
)
lxc_skip_impl = (
@@ -595,6 +596,7 @@ skip_function = (
'virDomainStatsRecordListFree', # only useful in C, python uses dict
'virDomainFSInfoFree', # only useful in C, python code uses list
'virDomainIOThreadsInfoFree', # only useful in C, python code uses list
+ 'virDomainInterfaceFree', # only useful in C, python code uses list
)
lxc_skip_function = (
diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
index 4660c9f..40ad602 100644
--- a/libvirt-override-api.xml
+++ b/libvirt-override-api.xml
@@ -678,5 +678,12 @@
<arg name='flags' type='unsigned int' info='unused, pass 0'/>
<return type='char *' info="list of mounted filesystems information"/>
</function>
+ <function name='virDomainInterfaceAddresses' file='python'>
+ <info>returns a dictionary of domain interfaces along with their MAC and IP addresses</info>
+ <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
+ <arg name='source' type='unsigned int' info='the data source'/>
+ <arg name='flags' type='unsigned int' info='extra flags; not used yet, so callers should always pass 0'/>
+ <return type='char *' info="dictionary of domain interfaces along with their MAC and IP addresses"/>
+ </function>
</symbols>
</api>
diff --git a/libvirt-override.c b/libvirt-override.c
index 1241305..b64c101 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -5120,6 +5120,131 @@ cleanup:
return py_retval;
}
+
+#if LIBVIR_CHECK_VERSION(1, 2, 14)
+static PyObject *
+libvirt_virDomainInterfaceAddresses(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *py_retval = VIR_PY_NONE;
+ PyObject *pyobj_domain;
+ virDomainPtr domain;
+ virDomainInterfacePtr *ifaces = NULL;
+ unsigned int source;
+ unsigned int flags;
+ int ifaces_count = 0;
+ size_t i, j;
+
+ if (!PyArg_ParseTuple(args, (char *) "Oii:virDomainInterfaceAddresses",
+ &pyobj_domain, &source, &flags))
+ goto error;
+
+ domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ ifaces_count = virDomainInterfaceAddresses(domain, &ifaces, source, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (ifaces_count < 0)
+ goto cleanup;
+
+ if (!(py_retval = PyDict_New()))
+ goto error;
+
+ for (i = 0; i < ifaces_count; i++) {
+ virDomainInterfacePtr iface = ifaces[i];
+ PyObject *py_addrs = NULL;
+ PyObject *py_iface = NULL;
+ PyObject *py_iname = NULL;
+ PyObject *py_ivalue = NULL;
+
+ if (!(py_iface = PyDict_New()))
+ goto error;
+
+ if ((py_iname = libvirt_charPtrWrap(iface->name)) == NULL ||
+ PyDict_SetItem(py_retval, py_iname, py_iface) < 0) {
+ Py_XDECREF(py_iname);
+ Py_DECREF(py_iface);
+ goto error;
+ }
+
+ if (iface->naddrs) {
+ if (!(py_addrs = PyList_New(iface->naddrs))) {
+ goto error;
+ }
+ } else {
+ py_addrs = VIR_PY_NONE;
+ }
+
+ if ((py_iname = libvirt_constcharPtrWrap("addrs")) == NULL ||
+ PyDict_SetItem(py_iface, py_iname, py_addrs) < 0) {
+ Py_XDECREF(py_iname);
+ Py_DECREF(py_addrs);
+ goto error;
+ }
+
+ if ((py_iname = libvirt_constcharPtrWrap("hwaddr")) == NULL ||
+ (py_ivalue = libvirt_constcharPtrWrap(iface->hwaddr)) == NULL ||
+ PyDict_SetItem(py_iface, py_iname, py_ivalue) < 0) {
+ Py_XDECREF(py_iname);
+ Py_XDECREF(py_ivalue);
+ goto error;
+ }
+
+ for (j = 0; j < iface->naddrs; j++) {
+ virDomainIPAddressPtr addr = &(iface->addrs[j]);
+ PyObject *py_addr = PyDict_New();
+
+ if (!py_addr)
+ goto error;
+
+ if (PyList_SetItem(py_addrs, j, py_addr) < 0) {
+ Py_DECREF(py_addr);
+ goto error;
+ }
+
+ if ((py_iname = libvirt_constcharPtrWrap("addr")) == NULL ||
+ (py_ivalue = libvirt_constcharPtrWrap(addr->addr)) == NULL ||
+ PyDict_SetItem(py_addr, py_iname, py_ivalue) < 0) {
+ Py_XDECREF(py_iname);
+ Py_XDECREF(py_ivalue);
+ goto error;
+ }
+ if ((py_iname = libvirt_constcharPtrWrap("prefix")) == NULL ||
+ (py_ivalue = libvirt_intWrap(addr->prefix)) == NULL ||
+ PyDict_SetItem(py_addr, py_iname, py_ivalue) < 0) {
+ Py_XDECREF(py_iname);
+ Py_XDECREF(py_ivalue);
+ goto error;
+ }
+ if ((py_iname = libvirt_constcharPtrWrap("type")) == NULL ||
+ (py_ivalue = libvirt_intWrap(addr->type)) == NULL ||
+ PyDict_SetItem(py_addr, py_iname, py_ivalue) < 0) {
+ Py_XDECREF(py_iname);
+ Py_XDECREF(py_ivalue);
+ goto error;
+ }
+ }
+ }
+
+cleanup:
+ if (ifaces && ifaces_count > 0) {
+ for (i = 0; i < ifaces_count; i++) {
+ virDomainInterfaceFree(ifaces[i]);
+ }
+ }
+ VIR_FREE(ifaces);
+
+ return py_retval;
+
+error:
+ Py_XDECREF(py_retval);
+ py_retval = NULL;
+ goto cleanup;
+}
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
+
+
/*******************************************
* Helper functions to avoid importing modules
* for every callback
@@ -8750,6 +8875,9 @@ static PyMethodDef libvirtMethods[] = {
#if LIBVIR_CHECK_VERSION(1, 2, 11)
{(char *) "virDomainGetFSInfo", libvirt_virDomainGetFSInfo, METH_VARARGS, NULL},
#endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
+#if LIBVIR_CHECK_VERSION(1, 2, 14)
+ {(char *) "virDomainInterfaceAddresses", libvirt_virDomainInterfaceAddresses, METH_VARARGS, NULL},
+#endif /* LIBVIR_CHECK_VERSION(1, 2, 14) */
{NULL, NULL, 0, NULL}
};
diff --git a/sanitytest.py b/sanitytest.py
index 0e6e0e5..cae234a 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -145,6 +145,9 @@ for cname in wantfunctions:
if name[0:26] == "virDomainIOThreadsInfoFree":
continue
+ if name[0:22] == "virDomainInterfaceFree":
+ continue
+
if name[0:21] == "virDomainListGetStats":
name = "virConnectDomainListGetStats"
--
2.0.5
9 years, 8 months
[libvirt] [PATCH] vircgroup: Fix build issue on mingw
by John Ferlan
Commit id 'ba1dfc5' added virCgroupSetCpusetMemoryMigrate and
virCgroupGetCpusetMemoryMigrate, but did not add the corresponding
entry points into the "#else /* !VIR_CGROUP_SUPPORTED */" section
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Not pushing as a build break since I'm not 100% it fixes the issue
eblake mentions in his review of a recent cgroup series.
src/util/vircgroup.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0a2e729..093a146 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4420,6 +4420,26 @@ virCgroupGetCpusetMems(virCgroupPtr group ATTRIBUTE_UNUSED,
int
+virCgroupSetCpusetMemoryMigrate(virCgroupPtr group ATTRIBUTE_UNUSED,
+ bool migrate ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Control groups not supported on this platform"));
+ return -1;
+}
+
+
+int
+virCgroupGetCpusetMemoryMigrate(virCgroupPtr group ATTRIBUTE_UNUSED,
+ bool *migrate ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Control groups not supported on this platform"));
+ return -1;
+}
+
+
+int
virCgroupSetCpusetCpus(virCgroupPtr group ATTRIBUTE_UNUSED,
const char *cpus ATTRIBUTE_UNUSED)
{
--
2.1.0
9 years, 8 months
Re: [libvirt] bug#20082: new warning from ar on rawhide systems
by Eric Blake
[redirecting to libvirt; a continuation of
https://www.redhat.com/archives/libvir-list/2015-February/msg01227.html]
On 03/27/2015 02:43 PM, Pavel Raiskup wrote:
> [+cc back libtool bug; as fixing automake does not seem to be enough]
>
>>
>> Hmm. How hard is it to change ARFLAGS to 'cr' instead of the default of
>> 'cru', so that projects that want to silence the warning now can do so
>> without waiting on automake to catch up? (Remember, the warning is live
>> on rawhide systems now, and even if we release a new automake with a
>> patch to change the default, there are TONS of packages built with older
>> automake that will still warn until such time as autoreconf is run on
>> those packages to update them to the newer automake)
>
> Agreed here, while trying to look at possible patch, I found that libtool
> historically does not respect automake's ARFLAGS, it has its own AR_FLAGS:
> http://lists.gnu.org/archive/html/libtool/2008-05/msg00050.html
> So fixing automake does not help for libtool-enabled projects, and, in some
> situations users could need AR_FLAGS=X ARFLAGS=X, but yes - still easy to
> define on per-project basis.
>
> FTR, Libtool uses AR_FLAGS from ~2000 (commit 8300de4c54e6f04f0d), automake
> ARFLAGS from ~2003 (commit a71b3490639831ca).
>
Given the discussion on automake/libtool lists, I'm going to play with a
patch that just sets AR[_]FLAGS to 'cr' to shut up the compilation
warnings on rawhide. Anyone see a problem with that plan?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
9 years, 8 months
[libvirt] [PATCH 0/2] really fix qemucaps2xmltest
by Pavel Hrdina
Pavel Hrdina (2):
Revert "qemucaps2xmltest: fix test to successfully run without kvm
support"
tests: introduce qemucaps2xmlmock
tests/Makefile.am | 7 +++++++
tests/qemucaps2xmlmock.c | 33 +++++++++++++++++++++++++++++++++
tests/qemucaps2xmltest.c | 6 +++---
3 files changed, 43 insertions(+), 3 deletions(-)
create mode 100644 tests/qemucaps2xmlmock.c
--
2.0.5
9 years, 8 months
[libvirt] [PATCH] virnetlink: fix build error
by Pavel Hrdina
Commint 0473b45cc introduced new function virNetlinkDelLink, but in
it's counterpart for non-linux platform there should be ATTRIBUTE_UNUSED
instead of ATTRIBUTE_UNSUPPORTED.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
Pushed under build-breaker rule.
src/util/virnetlink.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index 86c9c9c..0052ef9 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -886,7 +886,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
int
-virNetlinkDelLink(const char *ifname ATTRIBUTE_UNSUPPORTED)
+virNetlinkDelLink(const char *ifname ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
--
2.0.5
9 years, 8 months
[libvirt] [PATCH 0/2] vshPrintPinInfo cleanups
by Ján Tomko
Ján Tomko (2):
Fix indentation in cmdVcpuPin
Rewrite vshPrintPinInfo
tools/virsh-domain.c | 55 ++++++++++++++++------------------------------------
1 file changed, 17 insertions(+), 38 deletions(-)
--
2.0.5
9 years, 8 months
[libvirt] [PATCH v4 0/3] Parallels disk device attach
by Alexander Burluka
This patchset implements disk device attachment and allows
OpenStack to attach volumes to Parallels-driven instances.
Parallels Cloud Server SDK supports live attachment of disk devices
and virtual interfaces cards.
Alexander Burluka (3):
Parallels: remove disk serial number check
Parallels: implement domainAttachDeviceFlags
Parallels: implemented domainAttachDevice
9 years, 8 months
Re: [libvirt] iscsi multipath failure with "libvirtError: Failed to open file '/dev/mapper/Mar': No such file or directory"
by Stefan Hajnoczi
On Mon, Mar 23, 2015 at 10:14:31PM +0530, mad Engineer wrote:
> hello All,
> I know the issue is related to libvirt,but i dont know
> where to ask.
The libvirt mailing list is the place to ask libvirt questions. I have
CCed it.
> i have centos 6.6 running KVM as compute node in openstack icehouse
>
> when i try to attach volume to instance it shows
>
> 2596: error : virStorageFileGetMetadataRecurse:952 : Failed to open
> file '/dev/mapper/Mar': No such file or directory
>
> in libvirt log
>
> This does not always happen when it happens no one will be able to
> attach volume to instance
>
>
> using EMC VNX as storage backend.
>
>
> multipath.conf
>
>
> # Skip the files uner /dev that are definitely not FC/iSCSI devices
> # Different system may need different customization
> devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
> devnode "^hd[a-z][0-9]*"
> devnode "^cciss!c[0-9]d[0-9]*[p[0-9]*]"
>
> # Skip LUNZ device from VNX
> device {
> vendor "DGC"
> product "LUNZ"
> }
> }
>
> defaults {
> user_friendly_names no
> flush_on_last_del yes
> }
>
> devices {
> # Device attributed for EMC CLARiiON and VNX series ALUA
> device {
> vendor "DGC"
> product ".*"
> product_blacklist "LUNZ"
> path_grouping_policy group_by_prio
> path_selector "round-robin 0"
> path_checker emc_clariion
> features "1 queue_if_no_path"
> hardware_handler "1 alua"
> prio alua
> failback immediate
> }
> }
>
>
> Can any one help me with this issue
You may need to check dmesg or logs related to the EMC storage. In
particular, check for LUNs going offline, coming online, or the
multipath device changing state.
Stefan
9 years, 8 months