Devel
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- 12 participants
- 40091 discussions
[libvirt] [PATCH 0/7] qapi: add commands to remove the need to parse -help output
by Anthony Liguori 10 Aug '12
by Anthony Liguori 10 Aug '12
10 Aug '12
This series implements the necessary commands to implements danpb's idea to
remove -help parsing in libvirt. We would introduce all of these commands in
1.2 and then change the -help output starting in 1.3.
Here is Dan's plan from a previous thread:
<danpb>
Basically I'd sum up my new idea as "just use QMP".
* No new command line arguments like -capabilities
* libvirt invokes something like
$QEMUBINARY -qmp CHARDEV -nodefault -nodefconfig -nographics
* libvirt then runs a number of QMP commands to find out
what it needs to know. I'd expect the following existing
commands would be used
- query-version - already supported
- query-commands - already supported
- query-events - already supported
- query-kvm - already supported
- qom-{list,list-types,get} - already supported
- query-spice/vnc - already supported
And add the following new commands
- query-devices - new, -device ?, and/or -device NAME,? data
in QMP
- query-machines - new, -M ? in QMP
- query-cpu-types - new, -cpu ? in QMP
The above would take care of probably 50% of the current libvirt
capabilities probing, including a portion of the -help stuff. Then
there is all the rest of the crap we detect from the -help. We could
just take the view, that "as of 1.2", we assume everything we previously
detected is just available by default, and thus don't need to probe
it. For stuff that is QOM based, I expect we'll be able to detect new
features in the future using the qom-XXX monitor commands. For stuff
that is non-qdev, and non-qom, libvirt can just do a plain version
number check, unless we decide there is specific info worth exposing
via other new 'query-XXX' monitor commands.
Basically I'd sum up my new idea as "just use QMP".
* No new command line arguments like -capabilities
* libvirt invokes something like
$QEMUBINARY -qmp CHARDEV -nodefault -nodefconfig -nographics
* libvirt then runs a number of QMP commands to find out
what it needs to know. I'd expect the following existing
commands would be used
- query-version - already supported
- query-commands - already supported
- query-events - already supported
- query-kvm - already supported
- qom-{list,list-types,get} - already supported
- query-spice/vnc - already supported
And add the following new commands
- query-devices - new, -device ?, and/or -device NAME,? data
in QMP
- query-machines - new, -M ? in QMP
- query-cpu-types - new, -cpu ? in QMP
The above would take care of probably 50% of the current libvirt
capabilities probing, including a portion of the -help stuff. Then
there is all the rest of the crap we detect from the -help. We could
just take the view, that "as of 1.2", we assume everything we previously
detected is just available by default, and thus don't need to probe
it. For stuff that is QOM based, I expect we'll be able to detect new
features in the future using the qom-XXX monitor commands. For stuff
that is non-qdev, and non-qom, libvirt can just do a plain version
number check, unless we decide there is specific info worth exposing
via other new 'query-XXX' monitor commands.
</danpb>
The one thing to note is that I didn't add a query-devices command because you
can already do:
qmp query-devices --implements=device --abstract=False
To get the equivalent output of -device ?. Instead, I added a command to list
specific properties of a device which is the equivalent of -device FOO,?
7
42
10 Aug '12
libvirt's sVirt security driver provides SELinux MAC isolation for
Qemu guest processes and their corresponding image files. In other
words, sVirt uses SELinux to prevent a QEMU process from opening
files that do not belong to it.
sVirt provides this support by labeling guests and resources with
security labels that are stored in file system extended attributes.
Some file systems, such as NFS, do not support the extended
attribute security namespace, and therefore cannot support sVirt
isolation.
A solution to this problem is to provide fd passing support, where
libvirt opens files and passes file descriptors to QEMU. This,
along with SELinux policy to prevent QEMU from opening files, can
provide image file isolation for NFS files stored on the same NFS
mount.
This patch series adds the add-fd, remove-fd, and query-fdsets
QMP monitor commands, which allow file descriptors to be passed
via SCM_RIGHTS, and assigned to specified fd sets. This allows
fd sets to be created per file with fds having, for example,
different access rights. When QEMU needs to reopen a file with
different access rights, it can search for a matching fd in the
fd set. Fd sets also allow for easy tracking of fds per file,
helping to prevent fd leaks.
Support is also added to the block layer to allow QEMU to dup an
fd from an fdset when the filename is of the /dev/fdset/nnn format,
where nnn is the fd set ID.
No new SELinux policy is required to prevent open of NFS files
(files with type nfs_t). The virt_use_nfs boolean type simply
needs to be set to false, and open will be prevented (and dup will
be allowed). For example:
# setsebool virt_use_nfs 0
# getsebool virt_use_nfs
virt_use_nfs --> off
Corey Bryant (7):
qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg
qapi: Introduce add-fd, remove-fd, query-fdsets
monitor: Clean up fd sets on monitor disconnect
block: Prevent detection of /dev/fdset/ as floppy
block: Convert open calls to qemu_open
block: Convert close calls to qemu_close
block: Enable qemu_open/close to work with fd sets
block/raw-posix.c | 46 +++++----
block/raw-win32.c | 6 +-
block/vdi.c | 5 +-
block/vmdk.c | 25 ++---
block/vpc.c | 4 +-
block/vvfat.c | 16 +--
cutils.c | 5 +
monitor.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++++++
monitor.h | 5 +
osdep.c | 117 +++++++++++++++++++++
qapi-schema.json | 98 ++++++++++++++++++
qemu-char.c | 12 ++-
qemu-common.h | 2 +
qemu-tool.c | 20 ++++
qmp-commands.hx | 117 +++++++++++++++++++++
savevm.c | 4 +-
16 files changed, 721 insertions(+), 55 deletions(-)
--
1.7.10.4
4
22
Here are some fixes I was still having in my local branch. I finally
found a way to generate search.php automatically (even though it is
not the way I wanted it) and since the others are fixing docs as well,
I'm sending them in a series.
Last patch of the series is more like a question if we can change it
or not.
Martin Kletzander (3):
docs: fix 404 page when fetched from different location
docs: autogenerate search.php
docs/virsh: various minor fixes
.gitignore | 1 +
docs/404.html.in | 2 +-
docs/Makefile.am | 24 +++++++-
docs/api_extension.html.in | 4 --
docs/pending.html.in | 4 --
docs/{search.php => search.php.code.in} | 90 ++-----------------------------
docs/search.php.in | 17 ++++++
docs/site.xsl | 11 ++++-
tools/virsh-host.c | 4 +-
9 files changed, 57 insertions(+), 100 deletions(-)
rename docs/{search.php => search.php.code.in} (66%)
create mode 100644 docs/search.php.in
--
1.7.8.6
2
9
Hi,
Is de /maven2 [0] directory at libvirt.org still maintained?
It currently contains up to libvirt-java 0.4.7, while 0.4.8 is out.
If it is still maintained, could 0.4.8 be added?
Thanks!
Wido
[0]: http://www.libvirt.org/maven2/org/libvirt/libvirt/
2
4
Hello All,
I have recently found a bug in my patches to support forward mode="hostdev".
The bug is that libvirtd restart forgets about the netdef->forwardIfs.
Steps to reproduce:
1) virsh net-define hostdev.xml
<network>
<name>hostdev</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a8f</uuid>
<forward mode='hostdev' managed='yes'>
<pf dev='eth4'/>
</forward>
</network>
2) virsh define guest.xml
3) virsh start guest
[root@c6100m libvirt]# virsh net-dumpxml hostdev
<network>
<name>hostdev</name>
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a8f</uuid>
<forward managed='yes' mode='hostdev'>
<pf dev='eth4'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x2'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x4'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x6'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x0'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x2'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x4'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x6'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
</forward>
</network>
4) service libvirtd restart
After libvirtd is restarted I observe that the guest is shutdown.
/var/log/libvirt/libvirtd.log complains with the following error message:
networkNotifyActualDevice:3299 : internal error network 'hostdev' doesn't have dev in use by domain.
Using gdb when I breakpoint on networkNotifyActualDevice on libvirtd start I observe that netdef->nForwardIfs has been reset to 0, but netdef->nForwardPfs is correctly assigned to 1.
So my question is does libvirtd restart cause the network to remember only the inactive XML and not the active XML?
Does anyone have any ideas on how I should proceed on this bug?
--
Many Thanks,
Regards,
Shradha Shah
2
1
[libvirt] Segfault problem with nwfilter-define in Libvirt
by [Vo2Labs] Jean-Charles Passard 10 Aug '12
by [Vo2Labs] Jean-Charles Passard 10 Aug '12
10 Aug '12
Hello,
At first a big thanks to Laine, who kindly tried to help me !
My problem is the following :
I use a linux from scratch distro ( home made)
pure X86_64
glibc 2.10.1
gcc 4.4.1
uname -a SMP Sat Aug 4 20:07:49 CEST 2012 x86_64 x86_64 x86_64 GNU/Linux
Each time I use nwfilter-define, libvirtd crash with a segfault. I tried
nearly all version from 0.9.8 to 0.9.13 and even 0.10 with the same problem
Here is a sample of newfilter.xml :
<filter name='nova-base'>
<filterref filter='no-ip-spoofing'/>
</filter>
and here the bt unde gdb with v0.9.13
#0 __pthread_mutex_lock (mutex=0x0) at pthread_mutex_lock.c:50
#1 0x00007ffff77ba07e in virNWFilterCallbackDriversLock () at
conf/nwfilter_conf.c:2846
#2 0x00007fffe8ed9d24 in nwfilterDefine (conn=0x67d8e0, xml=0x67e000
"<filter name='nova-base'>\n\t<filterref
filter='no-ip-spoofing'/>\n</filter>\n\n")
at nwfilter/nwfilter_driver.c:348
#3 0x00007ffff77eb753 in virNWFilterDefineXML (conn=0x67d8e0,
xmlDesc=0x67e000 "<filter name='nova-base'>\n\t<filterref
filter='no-ip-spoofing'/>\n</filter>\n\n") at libvirt.c:15925
#4 0x000000000041969c in remoteDispatchNWFilterDefineXML
(ret=<optimized out>, args=<optimized out>, rerr=<optimized out>,
msg=<optimized out>,
client=<optimized out>, server=<optimized out>) at
remote_dispatch.h:10442
#5 remoteDispatchNWFilterDefineXMLHelper (server=<optimized out>,
client=0x67d210, msg=<optimized out>, rerr=0x7fffec57cf60,
args=0x67dea0, ret=0x67ba20)
at remote_dispatch.h:10422
#6 0x00007ffff784d48d in virNetServerProgramDispatchCall
(msg=<optimized out>, client=<optimized out>, server=<optimized out>,
prog=<optimized out>)
at rpc/virnetserverprogram.c:416
#7 virNetServerProgramDispatch (prog=0x675090, server=0x670370,
client=0x67d210, msg=0x67e3d0) at rpc/virnetserverprogram.c:289
#8 0x00007ffff784a0d1 in virNetServerHandleJob (jobOpaque=<optimized
out>, opaque=0x670370) at rpc/virnetserver.c:161
#9 0x00007ffff776d282 in virThreadPoolWorker (opaque=<optimized out>)
at util/threadpool.c:143
#10 0x00007ffff776c926 in virThreadHelper (data=<optimized out>) at
util/threads-pthread.c:161
#11 0x00007ffff457257a in start_thread (arg=<optimized out>) at
pthread_create.c:297
#12 0x00007ffff3edd14d in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:115
Thank for help
JC
5
6
Otherwise, in locations like virobject.c where PROBE is used,
for certain configure options, the compiler warns:
util/virobject.c:110:1: error: 'intptr_t' undeclared (first use in this function)
As long as we are making this header always available, we can
clean up several other files.
* src/internal.h (includes): Pull in <stdint.h>.
* src/conf/nwfilter_conf.h: Rely on internal.h.
* src/storage/storage_backend.c: Likewise.
* src/storage/storage_backend.h: Likewise.
* src/util/cgroup.c: Likewise.
* src/util/sexpr.h: Likewise.
* src/util/virhashcode.h: Likewise.
* src/util/virnetdevvportprofile.h: Likewise.
* src/util/virnetlink.h: Likewise.
* src/util/virrandom.h: Likewise.
* src/vbox/vbox_driver.c: Likewise.
* src/xenapi/xenapi_driver.c: Likewise.
* src/xenapi/xenapi_utils.c: Likewise.
* src/xenapi/xenapi_utils.h: Likewise.
* src/xenxs/xenxs_private.h: Likewise.
* tests/storagebackendsheepdogtest.c: Likewise.
Reported by Matthias Bolte.
---
Almost qualifies for the build-breaker rule, except that I didn't
reproduce the particular configure settings that Matthias was
experiencing on IRC.
src/conf/nwfilter_conf.h | 5 +----
src/internal.h | 1 +
src/storage/storage_backend.c | 1 -
src/storage/storage_backend.h | 3 +--
src/util/cgroup.c | 1 -
src/util/sexpr.h | 8 ++------
src/util/virhashcode.h | 1 -
src/util/virnetdevvportprofile.h | 4 +---
src/util/virnetlink.h | 2 --
src/util/virrandom.h | 1 -
src/vbox/vbox_driver.c | 4 +---
src/xenapi/xenapi_driver.c | 1 -
src/xenapi/xenapi_utils.c | 1 -
src/xenapi/xenapi_utils.h | 2 +-
src/xenxs/xenxs_private.h | 3 +--
tests/storagebackendsheepdogtest.c | 2 --
16 files changed, 9 insertions(+), 31 deletions(-)
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 8b05d04..ca6bd16 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -2,7 +2,7 @@
* nwfilter_conf.h: network filter XML processing
* (derived from storage_conf.h)
*
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2010, 2012 Red Hat, Inc.
* Copyright (C) 2006-2008 Daniel P. Berrange
*
* Copyright (C) 2010 IBM Corporation
@@ -26,9 +26,6 @@
#ifndef NWFILTER_CONF_H
# define NWFILTER_CONF_H
-# include <stdint.h>
-# include <stddef.h>
-
# include "internal.h"
# include "util.h"
diff --git a/src/internal.h b/src/internal.h
index fd8d190..300de3a 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -9,6 +9,7 @@
# include <limits.h>
# include <verify.h>
# include <stdbool.h>
+# include <stdint.h>
# if STATIC_ANALYSIS
# undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 4a2109e..df3833a 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -32,7 +32,6 @@
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
-#include <stdint.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <dirent.h>
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index bafd6b6..5352f5d 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -1,7 +1,7 @@
/*
* storage_backend.h: internal storage driver backend contract
*
- * Copyright (C) 2007-2010 Red Hat, Inc.
+ * Copyright (C) 2007-2010, 2012 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -24,7 +24,6 @@
#ifndef __VIR_STORAGE_BACKEND_H__
# define __VIR_STORAGE_BACKEND_H__
-# include <stdint.h>
# include "internal.h"
# include "storage_conf.h"
# include "command.h"
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 6c29c87..2256c23 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -24,7 +24,6 @@
#include <config.h>
#include <stdio.h>
-#include <stdint.h>
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
# include <mntent.h>
#endif
diff --git a/src/util/sexpr.h b/src/util/sexpr.h
index 8dfd89a..b4b41ed 100644
--- a/src/util/sexpr.h
+++ b/src/util/sexpr.h
@@ -1,9 +1,8 @@
/*
* sexpr.h : S-Expression interfaces needed to communicate with the Xen Daemon
*
- * Copyright (C) 2005
- *
- * Anthony Liguori <aliguori(a)us.ibm.com>
+ * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2005 Anthony Liguori <aliguori(a)us.ibm.com>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file COPYING.LIB in the main directory of this
@@ -16,9 +15,6 @@
# include "internal.h"
# include "buf.h"
-# include <sys/types.h>
-# include <stdint.h>
-
enum sexpr_type {
SEXPR_NIL,
SEXPR_CONS,
diff --git a/src/util/virhashcode.h b/src/util/virhashcode.h
index 2fb7a95..34254b6 100644
--- a/src/util/virhashcode.h
+++ b/src/util/virhashcode.h
@@ -29,7 +29,6 @@
# define __VIR_HASH_CODE_H__
# include "internal.h"
-# include <stdint.h>
extern uint32_t virHashCodeGen(const void *key, size_t len, uint32_t seed);
diff --git a/src/util/virnetdevvportprofile.h b/src/util/virnetdevvportprofile.h
index 6cce1bb..f33da18 100644
--- a/src/util/virnetdevvportprofile.h
+++ b/src/util/virnetdevvportprofile.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2011 Red Hat, Inc.
+ * Copyright (C) 2009-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,8 +23,6 @@
#ifndef __VIR_NETDEV_VPORT_PROFILE_H__
# define __VIR_NETDEV_VPORT_PROFILE_H__
-# include <stdint.h>
-
# include "internal.h"
# include "uuid.h"
# include "util.h"
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
index 1997c8d..5d8337d 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -24,8 +24,6 @@
# include "internal.h"
# include "virmacaddr.h"
-# include <stdint.h>
-
# if defined(__linux__) && defined(HAVE_LIBNL)
# include <netlink/msg.h>
diff --git a/src/util/virrandom.h b/src/util/virrandom.h
index 8d3cad7..29a055d 100644
--- a/src/util/virrandom.h
+++ b/src/util/virrandom.h
@@ -23,7 +23,6 @@
# define __VIR_RANDOM_H__
# include "internal.h"
-# include <stdint.h>
uint64_t virRandomBits(int nbits);
int virRandomGenerateWWN(char **wwn, const char *virt_type);
diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index b340b7c..c4037f8 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This file is part of a free software library; you can redistribute
@@ -29,9 +29,7 @@
#include <config.h>
-#include <stdint.h>
#include <unistd.h>
-#include <sys/types.h>
#include "internal.h"
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 5608de8..f57449e 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -23,7 +23,6 @@
#include <config.h>
#include <limits.h>
-#include <stdint.h>
#include <string.h>
#include <curl/curl.h>
#include <xen/api/xen_all.h>
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 3031a17..d62192a 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -24,7 +24,6 @@
#include <stdio.h>
#include <string.h>
-#include <stdint.h>
#include <xen/api/xen_all.h>
#include "internal.h"
#include "domain_conf.h"
diff --git a/src/xenapi/xenapi_utils.h b/src/xenapi/xenapi_utils.h
index 5912446..86af07c 100644
--- a/src/xenapi/xenapi_utils.h
+++ b/src/xenapi/xenapi_utils.h
@@ -1,5 +1,6 @@
/*
* xenapi_utils.h: Xen API driver -- utils header
+ * Copyright (C) 2012, Red Hat, Inc.
* Copyright (C) 2009, 2010 Citrix Ltd.
*
* This library is free software; you can redistribute it and/or
@@ -22,7 +23,6 @@
#ifndef __VIR_XENAPI_UTILS__
# define __VIR_XENAPI_UTILS__
-# include <stdint.h>
# include <xen/api/xen_all.h>
# include "internal.h"
# include "viruri.h"
diff --git a/src/xenxs/xenxs_private.h b/src/xenxs/xenxs_private.h
index d0ba59a..17b481b 100644
--- a/src/xenxs/xenxs_private.h
+++ b/src/xenxs/xenxs_private.h
@@ -1,8 +1,8 @@
/*
* xenxs_private.h: Private definitions for Xen parsing
*
+ * Copyright (C) 2007, 2010, 2012 Red Hat, Inc.
* Copyright (C) 2011 Univention GmbH
- * Copyright (C) 2007, 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -27,7 +27,6 @@
# include "internal.h"
-# include <stdint.h>
# include <xen/xen.h>
# include "xen_sxpr.h"
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index b7b3b35..ba5bc36 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -25,10 +25,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <stdint.h>
#include <string.h>
-#include <sys/types.h>
#include <fcntl.h>
#include "internal.h"
--
1.7.11.2
2
1
An ESX server has one or more PhysicalNics that represent the actual
hardware NICs. Those can be listed via the interface driver.
A libvirt virtual network is mapped to a HostVirtualSwitch. On the
physical side a HostVirtualSwitch can be connected to PhysicalNics.
On the virtual side a HostVirtualSwitch has HostPortGroups that are
mapped to libvirt virtual network's portgroups. Typically there is
HostPortGroups named 'VM Network' that is used to connect virtual
machines to a HostVirtualSwitch. A second HostPortGroup typically
named 'Management Network' is used to connect the hypervisor itself
to the HostVirtualSwitch. This one is not mapped to a libvirt virtual
network's portgroup. There can be more HostPortGroups than those
typical two on a HostVirtualSwitch.
+---------------+-------------------+
...---| | | +-------------+
| HostPortGroup | |---| PhysicalNic |
| VM Network | | | vmnic0 |
...---| | | +-------------+
+---------------+ HostVirtualSwitch |
| vSwitch0 |
+---------------+ |
| HostPortGroup | |
...---| Management | |
| Network | |
+---------------+-------------------+
The virtual counterparts of the PhysicalNic is the HostVirtualNic for
the hypervisor and the VirtualEthernetCard for the virtual machines
that are grouped into HostPortGroups.
+---------------------+ +---------------+---...
| VirtualEthernetCard |---| |
+---------------------+ | HostPortGroup |
+---------------------+ | VM Network |
| VirtualEthernetCard |---| |
+---------------------+ +---------------+
|
+---------------+
+---------------------+ | HostPortGroup |
| HostVirtualNic |---| Management |
+---------------------+ | Network |
+---------------+---...
The currently implemented network driver can list, define and undefine
HostVirtualSwitches including HostPortGroups for virtual machines.
Existing HostVirtualSwitches cannot be edited yet. This will be added
in a followup patch.
---
po/POTFILES.in | 1 +
src/conf/network_conf.c | 3 +-
src/conf/network_conf.h | 3 +
src/esx/esx_network_driver.c | 867 +++++++++++++++++++++++++++++++++++++++-
src/esx/esx_vi.c | 171 ++++++++
src/esx/esx_vi.h | 14 +
src/esx/esx_vi_generator.input | 151 +++++++
src/esx/esx_vi_generator.py | 5 +
8 files changed, 1212 insertions(+), 3 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 37a00ee..e617952 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -27,6 +27,7 @@ src/cpu/cpu_x86.c
src/datatypes.c
src/driver.c
src/esx/esx_driver.c
+src/esx/esx_network_driver.c
src/esx/esx_storage_driver.c
src/esx/esx_util.c
src/esx/esx_vi.c
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index eb92d93..a3714d9 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -47,8 +47,6 @@
#define MAX_BRIDGE_ID 256
#define VIR_FROM_THIS VIR_FROM_NETWORK
-VIR_ENUM_DECL(virNetworkForward)
-
VIR_ENUM_IMPL(virNetworkForward,
VIR_NETWORK_FORWARD_LAST,
"none", "nat", "route", "bridge", "private", "vepa", "passthrough" )
@@ -967,6 +965,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
}
VIR_FREE(tmp);
+ def->uuid_specified = true;
}
/* Parse network domain information */
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 1c640a9..a95b382 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -148,6 +148,7 @@ typedef struct _virNetworkDef virNetworkDef;
typedef virNetworkDef *virNetworkDefPtr;
struct _virNetworkDef {
unsigned char uuid[VIR_UUID_BUFLEN];
+ bool uuid_specified;
char *name;
char *bridge; /* Name of bridge device */
@@ -289,4 +290,6 @@ int virNetworkObjIsDuplicate(virNetworkObjListPtr doms,
void virNetworkObjLock(virNetworkObjPtr obj);
void virNetworkObjUnlock(virNetworkObjPtr obj);
+VIR_ENUM_DECL(virNetworkForward)
+
#endif /* __NETWORK_CONF_H__ */
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 2e0e40b..b42f1d8 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -4,7 +4,7 @@
* host networks
*
* Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -24,11 +24,13 @@
#include <config.h>
+#include "md5.h"
#include "internal.h"
#include "util.h"
#include "memory.h"
#include "logging.h"
#include "uuid.h"
+#include "network_conf.h"
#include "esx_private.h"
#include "esx_network_driver.h"
#include "esx_vi.h"
@@ -37,6 +39,12 @@
#define VIR_FROM_THIS VIR_FROM_ESX
+/*
+ * The UUID of a network is the MD5 sum of it's key. Therefore, verify that
+ * UUID and MD5 sum match in size, because we rely on that.
+ */
+verify(MD5_DIGEST_SIZE == VIR_UUID_BUFLEN);
+
static virDrvOpenStatus
@@ -67,10 +75,867 @@ esxNetworkClose(virConnectPtr conn)
+static int
+esxNumberOfNetworks(virConnectPtr conn)
+{
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ int count = 0;
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupHostVirtualSwitchList(priv->primary,
+ &hostVirtualSwitchList) < 0) {
+ return -1;
+ }
+
+ for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
+ hostVirtualSwitch = hostVirtualSwitch->_next) {
+ ++count;
+ }
+
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
+
+ return count;
+}
+
+
+
+static int
+esxListNetworks(virConnectPtr conn, char **const names, int maxnames)
+{
+ bool success = false;
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ int count = 0;
+ int i;
+
+ if (maxnames == 0) {
+ return 0;
+ }
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupHostVirtualSwitchList(priv->primary,
+ &hostVirtualSwitchList) < 0) {
+ return -1;
+ }
+
+ for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
+ hostVirtualSwitch = hostVirtualSwitch->_next) {
+ names[count] = strdup(hostVirtualSwitch->name);
+
+ if (names[count] == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ ++count;
+ }
+
+ success = true;
+
+ cleanup:
+ if (! success) {
+ for (i = 0; i < count; ++i) {
+ VIR_FREE(names[i]);
+ }
+
+ count = -1;
+ }
+
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
+
+ return count;
+}
+
+
+
+static int
+esxNumberOfDefinedNetworks(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ /* ESX networks are always active */
+ return 0;
+}
+
+
+
+static int
+esxListDefinedNetworks(virConnectPtr conn ATTRIBUTE_UNUSED,
+ char **const names ATTRIBUTE_UNUSED,
+ int maxnames ATTRIBUTE_UNUSED)
+{
+ /* ESX networks are always active */
+ return 0;
+}
+
+
+
+static virNetworkPtr
+esxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+{
+ virNetworkPtr network = NULL;
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
+ char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupHostVirtualSwitchList(priv->primary,
+ &hostVirtualSwitchList) < 0) {
+ return NULL;
+ }
+
+ for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
+ hostVirtualSwitch = hostVirtualSwitch->_next) {
+ md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+
+ if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) {
+ break;
+ }
+ }
+
+ if (hostVirtualSwitch == NULL) {
+ virUUIDFormat(uuid, uuid_string);
+
+ virReportError(VIR_ERR_NO_NETWORK,
+ _("Could not find HostVirtualSwitch with UUID '%s'"),
+ uuid_string);
+
+ goto cleanup;
+ }
+
+ network = virGetNetwork(conn, hostVirtualSwitch->name, uuid);
+
+ cleanup:
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
+
+ return network;
+}
+
+
+
+static virNetworkPtr
+esxNetworkLookupByName(virConnectPtr conn, const char *name)
+{
+ virNetworkPtr network = NULL;
+ esxPrivate *priv = conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupHostVirtualSwitchByName(priv->primary, name,
+ &hostVirtualSwitch,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return NULL;
+ }
+
+ /*
+ * HostVirtualSwitch doesn't have a UUID, but we can use the key property
+ * as source for a UUID. The key is unique per host and cannot change
+ * during the lifetime of the HostVirtualSwitch.
+ *
+ * The MD5 sum of the key can be used as UUID, assuming MD5 is considered
+ * to be collision-free enough for this use case.
+ */
+ md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+
+ network = virGetNetwork(conn, hostVirtualSwitch->name, md5);
+
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitch);
+
+ return network;
+}
+
+
+
+static int
+esxBandwidthToShapingPolicy(virNetDevBandwidthPtr bandwidth,
+ esxVI_HostNetworkTrafficShapingPolicy **shapingPolicy)
+{
+ int result = -1;
+
+ if (shapingPolicy == NULL || *shapingPolicy != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (bandwidth->in == NULL || bandwidth->out == NULL ||
+ bandwidth->in->average != bandwidth->out->average ||
+ bandwidth->in->peak != bandwidth->out->peak ||
+ bandwidth->in->burst != bandwidth->out->burst) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Different inbound and outbound bandwidth is unsupported"));
+ return -1;
+ }
+
+ if (bandwidth->in->average == 0 && bandwidth->in->peak == 0 &&
+ bandwidth->in->burst == 0) {
+ return 0;
+ }
+
+ if (esxVI_HostNetworkTrafficShapingPolicy_Alloc(shapingPolicy) < 0) {
+ goto cleanup;
+ }
+
+ (*shapingPolicy)->enabled = esxVI_Boolean_True;
+
+ if (bandwidth->in->average > 0) {
+ if (esxVI_Long_Alloc(&(*shapingPolicy)->averageBandwidth) < 0) {
+ goto cleanup;
+ }
+
+ /* Scale kilobytes per second to bits per second */
+ (*shapingPolicy)->averageBandwidth->value = bandwidth->in->average * 8 * 1000;
+ }
+
+ if (bandwidth->in->peak > 0) {
+ if (esxVI_Long_Alloc(&(*shapingPolicy)->peakBandwidth) < 0) {
+ goto cleanup;
+ }
+
+ /* Scale kilobytes per second to bits per second */
+ (*shapingPolicy)->peakBandwidth->value = bandwidth->in->peak * 8 * 1000;
+ }
+
+ if (bandwidth->in->burst > 0) {
+ if (esxVI_Long_Alloc(&(*shapingPolicy)->burstSize) < 0) {
+ goto cleanup;
+ }
+
+ /* Scale kilobytes to bytes */
+ (*shapingPolicy)->burstSize->value = bandwidth->in->burst * 1024;
+ }
+
+ result = 0;
+
+ cleanup:
+ if (result < 0) {
+ esxVI_HostNetworkTrafficShapingPolicy_Free(shapingPolicy);
+ }
+
+ return result;
+}
+
+
+
+static virNetworkPtr
+esxNetworkDefineXML(virConnectPtr conn, const char *xml)
+{
+ virNetworkPtr network = NULL;
+ esxPrivate *priv = conn->networkPrivateData;
+ virNetworkDefPtr def = NULL;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ esxVI_HostPortGroup *hostPortGroupList = NULL;
+ esxVI_HostPortGroup *hostPortGroup = NULL;
+ esxVI_HostVirtualSwitchSpec *hostVirtualSwitchSpec = NULL;
+ esxVI_HostVirtualSwitchBondBridge *hostVirtualSwitchBondBridge = NULL;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *physicalNic = NULL;
+ esxVI_HostPortGroupSpec *hostPortGroupSpec = NULL;
+ int i;
+
+ unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
+
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return NULL;
+ }
+
+ /* Parse network XML */
+ def = virNetworkDefParseString(xml);
+
+ if (def == NULL) {
+ return NULL;
+ }
+
+ /* Check if an existing HostVirtualSwitch should be edited */
+ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, def->name,
+ &hostVirtualSwitch,
+ esxVI_Occurrence_OptionalItem) < 0) {
+ goto cleanup;
+ }
+
+ if (hostVirtualSwitch != NULL) {
+ /* FIXME */
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("HostVirtualSwitch already exists, editing existing "
+ "ones is not supported yet"));
+ goto cleanup;
+ }
+
+ /* UUID is derived from the HostVirtualSwitch's key and cannot be specified */
+ if (def->uuid_specified) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Cannot use predefined UUID"));
+ goto cleanup;
+ }
+
+ /* FIXME: Add support for NAT */
+ if (def->forwardType != VIR_NETWORK_FORWARD_NONE &&
+ def->forwardType != VIR_NETWORK_FORWARD_BRIDGE) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported forward mode '%s'"),
+ virNetworkForwardTypeToString(def->forwardType));
+ goto cleanup;
+ }
+
+ /* Verify that specified HostPortGroups don't exist already */
+ if (def->nPortGroups > 0) {
+ if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) {
+ goto cleanup;
+ }
+
+ for (i = 0; i < def->nPortGroups; ++i) {
+ for (hostPortGroup = hostPortGroupList; hostPortGroup != NULL;
+ hostPortGroup = hostPortGroup->_next) {
+ if (STREQ(def->portGroups[i].name, hostPortGroup->spec->name)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("HostPortGroup with name '%s' exists already"),
+ def->portGroups[i].name);
+ goto cleanup;
+ }
+ }
+ }
+ }
+
+ /* Create HostVirtualSwitch */
+ if (esxVI_HostVirtualSwitchSpec_Alloc(&hostVirtualSwitchSpec) < 0 ||
+ esxVI_Int_Alloc(&hostVirtualSwitchSpec->numPorts) < 0) {
+ goto cleanup;
+ }
+
+ if (def->forwardType != VIR_NETWORK_FORWARD_NONE && def->nForwardIfs > 0) {
+ if (esxVI_HostVirtualSwitchBondBridge_Alloc
+ (&hostVirtualSwitchBondBridge) < 0) {
+ goto cleanup;
+ }
+
+ hostVirtualSwitchSpec->bridge =
+ (esxVI_HostVirtualSwitchBridge *)hostVirtualSwitchBondBridge;
+
+ /* Lookup PhysicalNic list and match by name to get key */
+ if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
+ goto cleanup;
+ }
+
+ for (i = 0; i < def->nForwardIfs; ++i) {
+ bool found = false;
+
+ for (physicalNic = physicalNicList; physicalNic != NULL;
+ physicalNic = physicalNic->_next) {
+ if (STREQ(def->forwardIfs[i].dev, physicalNic->device)) {
+ if (esxVI_String_AppendValueToList
+ (&hostVirtualSwitchBondBridge->nicDevice,
+ physicalNic->key) < 0) {
+ goto cleanup;
+ }
+
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find PhysicalNic with name '%s'"),
+ def->forwardIfs[i].dev);
+ goto cleanup;
+ }
+ }
+ }
+
+ hostVirtualSwitchSpec->numPorts->value = 128;
+
+ if (def->bandwidth != NULL) {
+ if (esxVI_HostNetworkPolicy_Alloc(&hostVirtualSwitchSpec->policy) < 0) {
+ goto cleanup;
+ }
+
+ if (esxBandwidthToShapingPolicy
+ (def->bandwidth,
+ &hostVirtualSwitchSpec->policy->shapingPolicy) < 0) {
+ goto cleanup;
+ }
+ }
+
+ if (esxVI_AddVirtualSwitch
+ (priv->primary,
+ priv->primary->hostSystem->configManager->networkSystem,
+ def->name, hostVirtualSwitchSpec) < 0) {
+ goto cleanup;
+ }
+
+ /* Create HostPortGroup(s) */
+ for (i = 0; i < def->nPortGroups; ++i) {
+ esxVI_HostPortGroupSpec_Free(&hostPortGroupSpec);
+
+ if (esxVI_HostPortGroupSpec_Alloc(&hostPortGroupSpec) < 0 ||
+ esxVI_HostNetworkPolicy_Alloc(&hostPortGroupSpec->policy) < 0 ||
+ esxVI_Int_Alloc(&hostPortGroupSpec->vlanId) < 0 ||
+ esxVI_String_DeepCopyValue(&hostPortGroupSpec->name,
+ def->portGroups[i].name) < 0 ||
+ esxVI_String_DeepCopyValue(&hostPortGroupSpec->vswitchName,
+ def->name) < 0) {
+ goto cleanup;
+ }
+
+ hostPortGroupSpec->vlanId->value = 0;
+
+ if (def->portGroups[i].bandwidth != NULL) {
+ if (esxBandwidthToShapingPolicy
+ (def->portGroups[i].bandwidth,
+ &hostPortGroupSpec->policy->shapingPolicy) < 0) {
+ goto cleanup;
+ }
+ }
+
+ if (esxVI_AddPortGroup
+ (priv->primary,
+ priv->primary->hostSystem->configManager->networkSystem,
+ hostPortGroupSpec) < 0) {
+ goto cleanup;
+ }
+ }
+
+ /* Lookup created HostVirtualSwitch to get the UUID */
+ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, def->name,
+ &hostVirtualSwitch,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ goto cleanup;
+ }
+
+ md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5);
+
+ network = virGetNetwork(conn, hostVirtualSwitch->name, md5);
+
+ cleanup:
+ virNetworkDefFree(def);
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitch);
+ esxVI_HostPortGroup_Free(&hostPortGroupList);
+ esxVI_HostVirtualSwitchSpec_Free(&hostVirtualSwitchSpec);
+ esxVI_PhysicalNic_Free(&physicalNicList);
+ esxVI_HostPortGroupSpec_Free(&hostPortGroupSpec);
+
+ return network;
+}
+
+
+
+static int
+esxNetworkUndefine(virNetworkPtr network)
+{
+ int result = -1;
+ esxPrivate *priv = network->conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ esxVI_HostPortGroup *hostPortGroupList = NULL;
+ esxVI_String *hostPortGroupKey = NULL;
+ esxVI_HostPortGroup *hostPortGroup = NULL;
+ esxVI_HostPortGroupPort *hostPortGroupPort = NULL;
+
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return -1;
+ }
+
+ /* Lookup HostVirtualSwitch and HostPortGroup list*/
+ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network->name,
+ &hostVirtualSwitch,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) {
+ goto cleanup;
+ }
+
+ /* Verify that the HostVirtualSwitch is connected to virtual machines only */
+ for (hostPortGroupKey = hostVirtualSwitch->portgroup;
+ hostPortGroupKey != NULL; hostPortGroupKey = hostPortGroupKey->_next) {
+ bool found = false;
+
+ for (hostPortGroup = hostPortGroupList; hostPortGroup != NULL;
+ hostPortGroup = hostPortGroup->_next) {
+ if (STREQ(hostPortGroupKey->value, hostPortGroup->key)) {
+ for (hostPortGroupPort = hostPortGroup->port;
+ hostPortGroupPort != NULL;
+ hostPortGroupPort = hostPortGroupPort->_next) {
+ if (STRNEQ(hostPortGroupPort->type, "virtualMachine")) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Cannot undefine HostVirtualSwitch that has a '%s' port"),
+ hostPortGroupPort->type);
+ goto cleanup;
+ }
+ }
+
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find HostPortGroup for key '%s'"),
+ hostPortGroupKey->value);
+ goto cleanup;
+ }
+ }
+
+ /* Remove all HostPortGroups from the HostVirtualSwitch */
+ for (hostPortGroupKey = hostVirtualSwitch->portgroup;
+ hostPortGroupKey != NULL; hostPortGroupKey = hostPortGroupKey->_next) {
+ bool found = false;
+
+ for (hostPortGroup = hostPortGroupList; hostPortGroup != NULL;
+ hostPortGroup = hostPortGroup->_next) {
+ if (STREQ(hostPortGroupKey->value, hostPortGroup->key)) {
+ if (esxVI_RemovePortGroup
+ (priv->primary,
+ priv->primary->hostSystem->configManager->networkSystem,
+ hostPortGroup->spec->name) < 0) {
+ goto cleanup;
+ }
+
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find HostPortGroup for key '%s'"),
+ hostPortGroupKey->value);
+ goto cleanup;
+ }
+ }
+
+ /* Finally, remove HostVirtualSwitch itself */
+ if (esxVI_RemoveVirtualSwitch
+ (priv->primary,
+ priv->primary->hostSystem->configManager->networkSystem,
+ network->name) < 0) {
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitch);
+ esxVI_HostPortGroup_Free(&hostPortGroupList);
+
+ return result;
+}
+
+
+
+static int
+esxShapingPolicyToBandwidth(esxVI_HostNetworkTrafficShapingPolicy *shapingPolicy,
+ virNetDevBandwidthPtr *bandwidth)
+{
+ if (bandwidth == NULL || *bandwidth != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (shapingPolicy == NULL || shapingPolicy->enabled != esxVI_Boolean_True) {
+ return 0;
+ }
+
+ if (VIR_ALLOC(*bandwidth) < 0 ||
+ VIR_ALLOC((*bandwidth)->in) < 0 ||
+ VIR_ALLOC((*bandwidth)->out) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ if (shapingPolicy->averageBandwidth != NULL) {
+ /* Scale bits per second to kilobytes per second */
+ (*bandwidth)->in->average = shapingPolicy->averageBandwidth->value / 8 / 1000;
+ (*bandwidth)->out->average = shapingPolicy->averageBandwidth->value / 8 / 1000;
+ }
+
+ if (shapingPolicy->peakBandwidth != NULL) {
+ /* Scale bits per second to kilobytes per second */
+ (*bandwidth)->in->peak = shapingPolicy->peakBandwidth->value / 8 / 1000;
+ (*bandwidth)->out->peak = shapingPolicy->peakBandwidth->value / 8 / 1000;
+ }
+
+ if (shapingPolicy->burstSize != NULL) {
+ /* Scale bytes to kilobytes */
+ (*bandwidth)->in->burst = shapingPolicy->burstSize->value / 1024;
+ (*bandwidth)->out->burst = shapingPolicy->burstSize->value / 1024;
+ }
+
+ return 0;
+}
+
+
+
+static char *
+esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags)
+{
+ char *xml = NULL;
+ esxPrivate *priv = network_->conn->networkPrivateData;
+ esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+ int count = 0;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *physicalNic = NULL;
+ esxVI_String *physicalNicKey = NULL;
+ esxVI_HostPortGroup *hostPortGroupList = NULL;
+ esxVI_HostPortGroup *hostPortGroup = NULL;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_ObjectContent *networkList = NULL;
+ esxVI_ObjectContent *network = NULL;
+ esxVI_String *networkNameList = NULL;
+ esxVI_String *hostPortGroupKey = NULL;
+ esxVI_String *networkName = NULL;
+ virNetworkDefPtr def;
+
+ if (esxVI_EnsureSession(priv->primary) < 0) {
+ return NULL;
+ }
+
+ if (VIR_ALLOC(def) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* Lookup HostVirtualSwitch */
+ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network_->name,
+ &hostVirtualSwitch,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ goto cleanup;
+ }
+
+ md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), def->uuid);
+
+ def->name = strdup(hostVirtualSwitch->name);
+
+ if (def->name == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ def->forwardType = VIR_NETWORK_FORWARD_NONE;
+
+ /* Count PhysicalNics on HostVirtualSwitch */
+ count = 0;
+
+ for (physicalNicKey = hostVirtualSwitch->pnic;
+ physicalNicKey != NULL; physicalNicKey = physicalNicKey->_next) {
+ ++count;
+ }
+
+ if (count > 0) {
+ def->forwardType = VIR_NETWORK_FORWARD_BRIDGE;
+
+ if (VIR_ALLOC_N(def->forwardIfs, count) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* Find PhysicalNic by key */
+ if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
+ goto cleanup;
+ }
+
+ for (physicalNicKey = hostVirtualSwitch->pnic;
+ physicalNicKey != NULL; physicalNicKey = physicalNicKey->_next) {
+ bool found = false;
+
+ for (physicalNic = physicalNicList; physicalNic != NULL;
+ physicalNic = physicalNic->_next) {
+ if (STREQ(physicalNicKey->value, physicalNic->key)) {
+ def->forwardIfs[def->nForwardIfs].dev = strdup(physicalNic->device);
+
+ if (def->forwardIfs[def->nForwardIfs].dev == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ ++def->nForwardIfs;
+
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find PhysicalNic with key '%s'"),
+ physicalNicKey->value);
+ goto cleanup;
+ }
+ }
+ }
+
+ /* Count HostPortGroups on HostVirtualSwitch */
+ count = 0;
+
+ for (hostPortGroupKey = hostVirtualSwitch->portgroup;
+ hostPortGroupKey != NULL; hostPortGroupKey = hostPortGroupKey->_next) {
+ ++count;
+ }
+
+ if (count > 0) {
+ if (VIR_ALLOC_N(def->portGroups, count) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* Lookup Network list and create name list */
+ if (esxVI_String_AppendValueToList(&propertyNameList, "name") < 0 ||
+ esxVI_LookupNetworkList(priv->primary, propertyNameList,
+ &networkList) < 0) {
+ goto cleanup;
+ }
+
+ for (network = networkList; network != NULL; network = network->_next) {
+ char *tmp = NULL;
+
+ if (esxVI_GetStringValue(network, "name", &tmp,
+ esxVI_Occurrence_RequiredItem) < 0 ||
+ esxVI_String_AppendValueToList(&networkNameList, tmp) < 0) {
+ goto cleanup;
+ }
+ }
+
+ /* Find HostPortGroup by key */
+ if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) {
+ goto cleanup;
+ }
+
+ for (hostPortGroupKey = hostVirtualSwitch->portgroup;
+ hostPortGroupKey != NULL; hostPortGroupKey = hostPortGroupKey->_next) {
+ bool found = false;
+
+ for (hostPortGroup = hostPortGroupList; hostPortGroup != NULL;
+ hostPortGroup = hostPortGroup->_next) {
+ if (STREQ(hostPortGroupKey->value, hostPortGroup->key)) {
+ /* Find Network for HostPortGroup, there might be none */
+ for (networkName = networkNameList; networkName != NULL;
+ networkName = networkName->_next) {
+ if (STREQ(networkName->value, hostPortGroup->spec->name)) {
+ def->portGroups[def->nPortGroups].name = strdup(networkName->value);
+
+ if (def->portGroups[def->nPortGroups].name == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (hostPortGroup->spec->policy != NULL) {
+ if (esxShapingPolicyToBandwidth
+ (hostPortGroup->spec->policy->shapingPolicy,
+ &def->portGroups[def->nPortGroups].bandwidth) < 0) {
+ ++def->nPortGroups;
+ goto cleanup;
+ }
+ }
+
+ ++def->nPortGroups;
+ break;
+ }
+ }
+
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find HostPortGroup with key '%s'"),
+ hostPortGroupKey->value);
+ goto cleanup;
+ }
+ }
+ }
+
+ if (hostVirtualSwitch->spec->policy != NULL) {
+ if (esxShapingPolicyToBandwidth
+ (hostVirtualSwitch->spec->policy->shapingPolicy,
+ &def->bandwidth) < 0) {
+ goto cleanup;
+ }
+ }
+
+ xml = virNetworkDefFormat(def, flags);
+
+ cleanup:
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitch);
+ esxVI_PhysicalNic_Free(&physicalNicList);
+ esxVI_HostPortGroup_Free(&hostPortGroupList);
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&networkList);
+ esxVI_String_Free(&networkNameList);
+ virNetworkDefFree(def);
+
+ return xml;
+}
+
+
+
+static int
+esxNetworkGetAutostart(virNetworkPtr network ATTRIBUTE_UNUSED,
+ int *autostart)
+{
+ /* ESX networks are always active */
+ *autostart = 1;
+
+ return 0;
+}
+
+
+
+static int
+esxNetworkSetAutostart(virNetworkPtr network ATTRIBUTE_UNUSED,
+ int autostart)
+{
+ /* Just accept autostart activation, but fail on autostart deactivation */
+ autostart = (autostart != 0);
+
+ if (! autostart) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot deactivate network autostart"));
+ return -1;
+ }
+
+ return 0;
+}
+
+
+
+static int
+esxNetworkIsActive(virNetworkPtr network ATTRIBUTE_UNUSED)
+{
+ /* ESX networks are always active */
+ return 1;
+}
+
+
+
+static int
+esxNetworkIsPersistent(virNetworkPtr network ATTRIBUTE_UNUSED)
+{
+ /* ESX has no concept of transient networks, so all of them are persistent */
+ return 1;
+}
+
+
+
static virNetworkDriver esxNetworkDriver = {
.name = "ESX",
.open = esxNetworkOpen, /* 0.7.6 */
.close = esxNetworkClose, /* 0.7.6 */
+ .numOfNetworks = esxNumberOfNetworks, /* 0.10.0 */
+ .listNetworks = esxListNetworks, /* 0.10.0 */
+ .numOfDefinedNetworks = esxNumberOfDefinedNetworks, /* 0.10.0 */
+ .listDefinedNetworks = esxListDefinedNetworks, /* 0.10.0 */
+ .networkLookupByUUID = esxNetworkLookupByUUID, /* 0.10.0 */
+ .networkLookupByName = esxNetworkLookupByName, /* 0.10.0 */
+ .networkDefineXML = esxNetworkDefineXML, /* 0.10.0 */
+ .networkUndefine = esxNetworkUndefine, /* 0.10.0 */
+ .networkGetXMLDesc = esxNetworkGetXMLDesc, /* 0.10.0 */
+ .networkGetAutostart = esxNetworkGetAutostart, /* 0.10.0 */
+ .networkSetAutostart = esxNetworkSetAutostart, /* 0.10.0 */
+ .networkIsActive = esxNetworkIsActive, /* 0.10.0 */
+ .networkIsPersistent = esxNetworkIsPersistent, /* 0.10.0 */
};
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index f3a9e91..65e1d9a 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -783,6 +783,7 @@ ESX_VI__TEMPLATE__FREE(Context,
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToDatastore);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToHost);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToParentToParent);
+ esxVI_SelectionSpec_Free(&item->selectSet_datacenterToNetwork);
})
int
@@ -1927,6 +1928,13 @@ esxVI_BuildSelectSetCollection(esxVI_Context *ctx)
return -1;
}
+ /* Datacenter -> network (Network) */
+ if (esxVI_BuildSelectSet(&ctx->selectSet_datacenterToNetwork,
+ "datacenterToNetwork",
+ "Datacenter", "network", NULL) < 0) {
+ return -1;
+ }
+
return 0;
}
@@ -2094,6 +2102,15 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
type, root->type);
goto cleanup;
}
+ } else if (STREQ(root->type, "Datacenter")) {
+ if (STREQ(type, "Network")) {
+ objectSpec->selectSet = ctx->selectSet_datacenterToNetwork;
+ } else {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Invalid lookup of '%s' from '%s'"),
+ type, root->type);
+ goto cleanup;
+ }
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid lookup from '%s'"), root->type);
@@ -4091,6 +4108,160 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
int
+esxVI_LookupHostVirtualSwitchList(esxVI_Context *ctx,
+ esxVI_HostVirtualSwitch **hostVirtualSwitchList)
+{
+ int result = -1;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_ObjectContent *hostSystem = NULL;
+ esxVI_DynamicProperty *dynamicProperty = NULL;
+
+ if (hostVirtualSwitchList == NULL || *hostVirtualSwitchList != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_String_AppendValueToList(&propertyNameList,
+ "config.network.vswitch") < 0 ||
+ esxVI_LookupHostSystemProperties(ctx, propertyNameList,
+ &hostSystem) < 0) {
+ goto cleanup;
+ }
+
+ for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
+ dynamicProperty = dynamicProperty->_next) {
+ if (STREQ(dynamicProperty->name, "config.network.vswitch")) {
+ if (esxVI_HostVirtualSwitch_CastListFromAnyType
+ (dynamicProperty->val, hostVirtualSwitchList) < 0) {
+ goto cleanup;
+ }
+ } else {
+ VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
+ }
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&hostSystem);
+
+ return result;
+}
+
+
+
+int
+esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
+ esxVI_HostVirtualSwitch **hostVirtualSwitch,
+ esxVI_Occurrence occurrence)
+{
+ int result = -1;
+ esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
+ esxVI_HostVirtualSwitch *candidate = NULL;
+
+ if (hostVirtualSwitch == NULL || *hostVirtualSwitch != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0) {
+ goto cleanup;
+ }
+
+ /* Search for a matching HostVirtualSwitch */
+ for (candidate = hostVirtualSwitchList; candidate != NULL;
+ candidate = candidate->_next) {
+ if (STREQ(candidate->name, name)) {
+ if (esxVI_HostVirtualSwitch_DeepCopy(hostVirtualSwitch,
+ candidate) < 0) {
+ goto cleanup;
+ }
+
+ /* Found HostVirtualSwitch with matching name */
+ result = 0;
+
+ goto cleanup;
+ }
+ }
+
+ if (*hostVirtualSwitch == NULL &&
+ occurrence != esxVI_Occurrence_OptionalItem) {
+ virReportError(VIR_ERR_NO_NETWORK,
+ _("Could not find HostVirtualSwitch with name '%s'"),
+ name);
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
+
+ return result;
+}
+
+
+
+int
+esxVI_LookupHostPortGroupList(esxVI_Context *ctx,
+ esxVI_HostPortGroup **hostPortGroupList)
+{
+ int result = -1;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_ObjectContent *hostSystem = NULL;
+ esxVI_DynamicProperty *dynamicProperty = NULL;
+
+ if (hostPortGroupList == NULL || *hostPortGroupList != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_String_AppendValueToList(&propertyNameList,
+ "config.network.portgroup") < 0 ||
+ esxVI_LookupHostSystemProperties(ctx, propertyNameList,
+ &hostSystem) < 0) {
+ goto cleanup;
+ }
+
+ for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
+ dynamicProperty = dynamicProperty->_next) {
+ if (STREQ(dynamicProperty->name, "config.network.portgroup")) {
+ if (esxVI_HostPortGroup_CastListFromAnyType
+ (dynamicProperty->val, hostPortGroupList) < 0) {
+ goto cleanup;
+ }
+
+ break;
+ } else {
+ VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
+ }
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&hostSystem);
+
+ return result;
+}
+
+
+
+int
+esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
+ esxVI_ObjectContent **networkList)
+{
+ return esxVI_LookupObjectContentByType(ctx, ctx->datacenter->_reference,
+ "Network", propertyNameList,
+ networkList,
+ esxVI_Occurrence_OptionalList);
+}
+
+
+
+int
esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 597013c..12394e7 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -227,6 +227,7 @@ struct _esxVI_Context {
esxVI_SelectionSpec *selectSet_hostSystemToDatastore;
esxVI_SelectionSpec *selectSet_computeResourceToHost;
esxVI_SelectionSpec *selectSet_computeResourceToParentToParent;
+ esxVI_SelectionSpec *selectSet_datacenterToNetwork;
bool hasQueryVirtualDiskUuid;
bool hasSessionIsActive;
};
@@ -492,6 +493,19 @@ int esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
esxVI_PhysicalNic **physicalNic,
esxVI_Occurrence occurrence);
+int esxVI_LookupHostVirtualSwitchList
+ (esxVI_Context *ctx, esxVI_HostVirtualSwitch **hostVirtualSwitchList);
+
+int esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
+ esxVI_HostVirtualSwitch **hostVirtualSwitch,
+ esxVI_Occurrence occurrence);
+
+int esxVI_LookupHostPortGroupList(esxVI_Context *ctx,
+ esxVI_HostPortGroup **hostPortGroupList);
+
+int esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
+ esxVI_ObjectContent **networkList);
+
int esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
diff --git a/src/esx/esx_vi_generator.input b/src/esx/esx_vi_generator.input
index 5572b36..c4a3e56 100644
--- a/src/esx/esx_vi_generator.input
+++ b/src/esx/esx_vi_generator.input
@@ -338,12 +338,138 @@ object HostNasVolume extends HostFileSystemVolume
end
+object HostNetOffloadCapabilities
+ Boolean csumOffload o
+ Boolean tcpSegmentation o
+ Boolean zeroCopyXmit o
+end
+
+
+object HostNetworkPolicy
+ HostNetworkSecurityPolicy security o
+ HostNicTeamingPolicy nicTeaming o
+ HostNetOffloadCapabilities offloadPolicy o
+ HostNetworkTrafficShapingPolicy shapingPolicy o
+end
+
+
+object HostNetworkSecurityPolicy
+ Boolean allowPromiscuous o
+ Boolean macChanges o
+ Boolean forgedTransmits o
+end
+
+
+object HostNetworkTrafficShapingPolicy
+ Boolean enabled o
+ Long averageBandwidth o
+ Long peakBandwidth o
+ Long burstSize o
+end
+
+
+object HostNicFailureCriteria
+ String checkSpeed o
+ Int speed o
+ Boolean checkDuplex o
+ Boolean fullDuplex o
+ Boolean checkErrorPercent o
+ Int percentage o
+ Boolean checkBeacon o
+end
+
+
+object HostNicOrderPolicy
+ String activeNic ol
+ String standbyNic ol
+end
+
+
+object HostNicTeamingPolicy
+ String policy o
+ Boolean reversePolicy o
+ Boolean notifySwitches o
+ Boolean rollingOrder o
+ HostNicFailureCriteria failureCriteria o
+ HostNicOrderPolicy nicOrder o
+end
+
+
+object HostPortGroup
+ String key o
+ HostPortGroupPort port ol
+ String vswitch o
+ HostNetworkPolicy computedPolicy r
+ HostPortGroupSpec spec r
+end
+
+
+object HostPortGroupPort
+ String key o
+ String mac ol
+ String type r
+end
+
+
+object HostPortGroupSpec
+ String name r
+ Int vlanId r
+ String vswitchName r
+ HostNetworkPolicy policy r
+end
+
+
object HostScsiDiskPartition
String diskName r
Int partition r
end
+object HostVirtualSwitch
+ String name r
+ String key r
+ Int numPorts r
+ Int numPortsAvailable r
+ Int mtu o
+ String portgroup ol
+ String pnic ol
+ HostVirtualSwitchSpec spec r
+end
+
+
+object HostVirtualSwitchAutoBridge extends HostVirtualSwitchBridge
+ String excludedNicDevice ol
+end
+
+
+object HostVirtualSwitchBeaconConfig
+ Int interval r
+end
+
+
+object HostVirtualSwitchBondBridge extends HostVirtualSwitchBridge
+ String nicDevice rl
+ HostVirtualSwitchBeaconConfig beacon o
+end
+
+
+object HostVirtualSwitchBridge
+end
+
+
+object HostVirtualSwitchSimpleBridge extends HostVirtualSwitchBridge
+ String nicDevice r
+end
+
+
+object HostVirtualSwitchSpec
+ Int numPorts r
+ HostVirtualSwitchBridge bridge o
+ HostNetworkPolicy policy o
+ Int mtu o
+end
+
+
object HostVmfsVolume extends HostFileSystemVolume
Int blockSizeMb r
Int maxBlocks r
@@ -805,6 +931,19 @@ end
# Methods
#
+method AddPortGroup
+ ManagedObjectReference _this r
+ HostPortGroupSpec portgrp r
+end
+
+
+method AddVirtualSwitch
+ ManagedObjectReference _this r
+ String vswitchName r
+ HostVirtualSwitchSpec spec o
+end
+
+
method AnswerVM
ManagedObjectReference _this r
String questionId r
@@ -981,12 +1120,24 @@ method RegisterVM_Task returns ManagedObjectReference r
end
+method RemovePortGroup
+ ManagedObjectReference _this r
+ String pgName r
+end
+
+
method RemoveSnapshot_Task returns ManagedObjectReference r
ManagedObjectReference _this r
Boolean removeChildren r
end
+method RemoveVirtualSwitch
+ ManagedObjectReference _this r
+ String vswitchName r
+end
+
+
method RetrieveProperties returns ObjectContent ol
ManagedObjectReference _this:propertyCollector r
PropertyFilterSpec specSet rl
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 596bd16..b49db70 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -1520,6 +1520,11 @@ additional_object_features = { "AutoStartDefaults" : Object.FEATURE__AN
Object.FEATURE__ANY_TYPE,
"HostDatastoreBrowserSearchResults" : Object.FEATURE__LIST |
Object.FEATURE__ANY_TYPE,
+ "HostPortGroup" : Object.FEATURE__LIST |
+ Object.FEATURE__ANY_TYPE,
+ "HostVirtualSwitch" : Object.FEATURE__DEEP_COPY |
+ Object.FEATURE__LIST |
+ Object.FEATURE__ANY_TYPE,
"ManagedObjectReference" : Object.FEATURE__ANY_TYPE,
"ObjectContent" : Object.FEATURE__DEEP_COPY,
"PhysicalNic" : Object.FEATURE__DEEP_COPY |
--
1.7.4.1
2
2
Lists available PhysicalNic devices. A PhysicalNic is always active
and can neither be defined nor undefined.
A PhysicalNic is used to bridge a HostVirtualSwitch to the physical
network.
---
This implementation differs from Ata's. It just lists PhysicalNics
instead of listing HostVirtualNics as bridges.
src/esx/esx_interface_driver.c | 239 +++++++++++++++++++++++++++++++++++++++-
src/esx/esx_vi.c | 144 ++++++++++++++++++++++++-
src/esx/esx_vi.h | 13 ++-
src/esx/esx_vi_generator.input | 34 ++++++-
src/esx/esx_vi_generator.py | 5 +-
5 files changed, 430 insertions(+), 5 deletions(-)
diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index 501409a..a78a744 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -4,7 +4,7 @@
* host interfaces
*
* Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,8 @@
#include "memory.h"
#include "logging.h"
#include "uuid.h"
+#include "interface_conf.h"
+#include "virsocketaddr.h"
#include "esx_private.h"
#include "esx_interface_driver.h"
#include "esx_vi.h"
@@ -67,10 +69,245 @@ esxInterfaceClose(virConnectPtr conn)
+static int
+esxNumberOfInterfaces(virConnectPtr conn)
+{
+ esxPrivate *priv = conn->interfacePrivateData;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *physicalNic = NULL;
+ int count = 0;
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
+ return -1;
+ }
+
+ for (physicalNic = physicalNicList; physicalNic != NULL;
+ physicalNic = physicalNic->_next) {
+ ++count;
+ }
+
+ esxVI_PhysicalNic_Free(&physicalNicList);
+
+ return count;
+}
+
+
+
+static int
+esxListInterfaces(virConnectPtr conn, char **const names, int maxnames)
+{
+ bool success = false;
+ esxPrivate *priv = conn->interfacePrivateData;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *physicalNic = NULL;
+ int count = 0;
+ int i;
+
+ if (maxnames == 0) {
+ return 0;
+ }
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) {
+ return -1;
+ }
+
+ for (physicalNic = physicalNicList; physicalNic != NULL;
+ physicalNic = physicalNic->_next) {
+ names[count] = strdup(physicalNic->device);
+
+ if (names[count] == NULL) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ ++count;
+ }
+
+ success = true;
+
+ cleanup:
+ if (! success) {
+ for (i = 0; i < count; ++i) {
+ VIR_FREE(names[i]);
+ }
+
+ count = -1;
+ }
+
+ esxVI_PhysicalNic_Free(&physicalNicList);
+
+ return count;
+}
+
+
+
+static int
+esxNumberOfDefinedInterfaces(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+ /* ESX interfaces are always active */
+ return 0;
+}
+
+
+
+static int
+esxListDefinedInterfaces(virConnectPtr conn ATTRIBUTE_UNUSED,
+ char **const names ATTRIBUTE_UNUSED,
+ int maxnames ATTRIBUTE_UNUSED)
+{
+ /* ESX interfaces are always active */
+ return 0;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByName(virConnectPtr conn, const char *name)
+{
+ virInterfacePtr iface = NULL;
+ esxPrivate *priv = conn->interfacePrivateData;
+ esxVI_PhysicalNic *physicalNic = NULL;
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupPhysicalNicByMACAddress(priv->primary, name, &physicalNic,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return NULL;
+ }
+
+ iface = virGetInterface(conn, physicalNic->device, physicalNic->mac);
+
+ esxVI_PhysicalNic_Free(&physicalNic);
+
+ return iface;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByMACString(virConnectPtr conn, const char *mac)
+{
+ virInterfacePtr iface = NULL;
+ esxPrivate *priv = conn->interfacePrivateData;
+ esxVI_PhysicalNic *physicalNic = NULL;
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupPhysicalNicByMACAddress(priv->primary, mac, &physicalNic,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return NULL;
+ }
+
+ iface = virGetInterface(conn, physicalNic->device, physicalNic->mac);
+
+ esxVI_PhysicalNic_Free(&physicalNic);
+
+ return iface;
+}
+
+
+
+static char *
+esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
+{
+ char *xml = NULL;
+ esxPrivate *priv = iface->conn->interfacePrivateData;
+ esxVI_PhysicalNic *physicalNic = NULL;
+ virInterfaceDef def;
+ bool hasAddress = false;
+ virInterfaceProtocolDefPtr protocols;
+ virInterfaceProtocolDef protocol;
+ virSocketAddr socketAddress;
+ virInterfaceIpDefPtr ips;
+ virInterfaceIpDef ip;
+
+ virCheckFlags(VIR_INTERFACE_XML_INACTIVE, NULL);
+
+ memset(&def, 0, sizeof(def));
+ memset(&protocol, 0, sizeof(protocol));
+ memset(&socketAddress, 0, sizeof(socketAddress));
+ memset(&ip, 0, sizeof(ip));
+
+ if (esxVI_EnsureSession(priv->primary) < 0 ||
+ esxVI_LookupPhysicalNicByMACAddress(priv->primary, iface->mac,
+ &physicalNic,
+ esxVI_Occurrence_RequiredItem) < 0) {
+ return NULL;
+ }
+
+ def.type = VIR_INTERFACE_TYPE_ETHERNET;
+ def.name = physicalNic->device;
+ def.mac = physicalNic->mac;
+ def.startmode = VIR_INTERFACE_START_ONBOOT;
+
+ /* FIXME: Add support for IPv6, requires to use vSphere API 4.0 */
+ if (physicalNic->spec->ip != NULL) {
+ protocol.family = (char *)"ipv4";
+
+ if (physicalNic->spec->ip->dhcp == esxVI_Boolean_True) {
+ protocol.dhcp = 1;
+ }
+
+ if (physicalNic->spec->ip->ipAddress != NULL &&
+ physicalNic->spec->ip->subnetMask != NULL &&
+ strlen(physicalNic->spec->ip->ipAddress) > 0 &&
+ strlen(physicalNic->spec->ip->subnetMask) > 0) {
+ hasAddress = true;
+ }
+
+ if (protocol.dhcp || hasAddress) {
+ protocols = &protocol;
+ def.nprotos = 1;
+ def.protos = &protocols;
+ }
+
+ if (hasAddress &&
+ !(protocol.dhcp && (flags & VIR_INTERFACE_XML_INACTIVE))) {
+ ips = &ip;
+ protocol.nips = 1;
+ protocol.ips = &ips;
+
+ if (virSocketAddrParseIPv4(&socketAddress,
+ physicalNic->spec->ip->subnetMask) < 0) {
+ goto cleanup;
+ }
+
+ ip.address = physicalNic->spec->ip->ipAddress;
+ ip.prefix = virSocketAddrGetNumNetmaskBits(&socketAddress);
+ }
+ }
+
+ xml = virInterfaceDefFormat(&def);
+
+ cleanup:
+ esxVI_PhysicalNic_Free(&physicalNic);
+
+ return xml;
+}
+
+
+
+static int
+esxInterfaceIsActive(virInterfacePtr iface ATTRIBUTE_UNUSED)
+{
+ /* ESX interfaces are always active */
+ return 1;
+}
+
+
+
static virInterfaceDriver esxInterfaceDriver = {
.name = "ESX",
.open = esxInterfaceOpen, /* 0.7.6 */
.close = esxInterfaceClose, /* 0.7.6 */
+ .numOfInterfaces = esxNumberOfInterfaces, /* 0.10.0 */
+ .listInterfaces = esxListInterfaces, /* 0.10.0 */
+ .numOfDefinedInterfaces = esxNumberOfDefinedInterfaces, /* 0.10.0 */
+ .listDefinedInterfaces = esxListDefinedInterfaces, /* 0.10.0 */
+ .interfaceLookupByName = esxInterfaceLookupByName, /* 0.10.0 */
+ .interfaceLookupByMACString = esxInterfaceLookupByMACString, /* 0.10.0 */
+ .interfaceGetXMLDesc = esxInterfaceGetXMLDesc, /* 0.10.0 */
+ .interfaceIsActive = esxInterfaceIsActive, /* 0.10.0 */
};
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 2c789e1..c4217c9 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -3,7 +3,7 @@
* esx_vi.c: client for the VMware VI API 2.5 to manage ESX hosts
*
* Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -3949,6 +3949,148 @@ esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx,
int
+esxVI_LookupPhysicalNicList(esxVI_Context *ctx,
+ esxVI_PhysicalNic **physicalNicList)
+{
+ int result = -1;
+ esxVI_String *propertyNameList = NULL;
+ esxVI_ObjectContent *hostSystem = NULL;
+ esxVI_DynamicProperty *dynamicProperty = NULL;
+
+ if (physicalNicList == NULL || *physicalNicList != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_String_AppendValueToList(&propertyNameList,
+ "config.network.pnic") < 0 ||
+ esxVI_LookupHostSystemProperties(ctx, propertyNameList,
+ &hostSystem) < 0) {
+ goto cleanup;
+ }
+
+ for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
+ dynamicProperty = dynamicProperty->_next) {
+ if (STREQ(dynamicProperty->name, "config.network.pnic")) {
+ if (esxVI_PhysicalNic_CastListFromAnyType(dynamicProperty->val,
+ physicalNicList) < 0) {
+ goto cleanup;
+ }
+ } else {
+ VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
+ }
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_String_Free(&propertyNameList);
+ esxVI_ObjectContent_Free(&hostSystem);
+
+ return result;
+}
+
+
+
+int
+esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name,
+ esxVI_PhysicalNic **physicalNic,
+ esxVI_Occurrence occurrence)
+{
+ int result = -1;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *candidate = NULL;
+
+ if (physicalNic == NULL || *physicalNic != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) {
+ goto cleanup;
+ }
+
+ /* Search for a matching physical NIC */
+ for (candidate = physicalNicList; candidate != NULL;
+ candidate = candidate->_next) {
+ if (STRCASEEQ(candidate->device, name)) {
+ if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) {
+ goto cleanup;
+ }
+
+ /* Found physical NIC with matching name */
+ result = 0;
+
+ goto cleanup;
+ }
+ }
+
+ if (*physicalNic == NULL && occurrence != esxVI_Occurrence_OptionalItem) {
+ virReportError(VIR_ERR_NO_INTERFACE,
+ _("Could not find physical NIC with name '%s'"), name);
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_PhysicalNic_Free(&physicalNicList);
+
+ return result;
+}
+
+
+
+int
+esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
+ esxVI_PhysicalNic **physicalNic,
+ esxVI_Occurrence occurrence)
+{
+ int result = -1;
+ esxVI_PhysicalNic *physicalNicList = NULL;
+ esxVI_PhysicalNic *candidate = NULL;
+
+ if (physicalNic == NULL || *physicalNic != NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+ return -1;
+ }
+
+ if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) {
+ goto cleanup;
+ }
+
+ /* Search for a matching physical NIC */
+ for (candidate = physicalNicList; candidate != NULL;
+ candidate = candidate->_next) {
+ if (STRCASEEQ(candidate->mac, mac)) {
+ if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) {
+ goto cleanup;
+ }
+
+ /* Found physical NIC with matching MAC address */
+ result = 0;
+
+ goto cleanup;
+ }
+ }
+
+ if (*physicalNic == NULL && occurrence != esxVI_Occurrence_OptionalItem) {
+ virReportError(VIR_ERR_NO_INTERFACE,
+ _("Could not find physical NIC with MAC address '%s'"), mac);
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ esxVI_PhysicalNic_Free(&physicalNicList);
+
+ return result;
+}
+
+
+
+int
esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 4b84be8..597013c 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -3,7 +3,7 @@
* esx_vi.h: client for the VMware VI API 2.5 to manage ESX hosts
*
* Copyright (C) 2011 Red Hat, Inc.
- * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -481,6 +481,17 @@ int esxVI_LookupAutoStartDefaults(esxVI_Context *ctx,
int esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx,
esxVI_AutoStartPowerInfo **powerInfoList);
+int esxVI_LookupPhysicalNicList(esxVI_Context *ctx,
+ esxVI_PhysicalNic **physicalNicList);
+
+int esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name,
+ esxVI_PhysicalNic **physicalNic,
+ esxVI_Occurrence occurrence);
+
+int esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
+ esxVI_PhysicalNic **physicalNic,
+ esxVI_Occurrence occurrence);
+
int esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
diff --git a/src/esx/esx_vi_generator.input b/src/esx/esx_vi_generator.input
index 1a67a8c..5572b36 100644
--- a/src/esx/esx_vi_generator.input
+++ b/src/esx/esx_vi_generator.input
@@ -317,6 +317,13 @@ object HostFileSystemVolume
end
+object HostIpConfig
+ Boolean dhcp r
+ String ipAddress o
+ String subnetMask o
+end
+
+
object HostMountInfo
String path o
String accessMode r
@@ -455,6 +462,31 @@ object PerfSampleInfo
end
+object PhysicalNic
+ String key o
+ String device r
+ String pci r
+ String driver o
+ PhysicalNicLinkInfo linkSpeed o
+ PhysicalNicLinkInfo validLinkSpecification ol
+ PhysicalNicSpec spec r
+ Boolean wakeOnLanSupported r
+ String mac r
+end
+
+
+object PhysicalNicLinkInfo
+ Int speedMb r
+ Boolean duplex r
+end
+
+
+object PhysicalNicSpec
+ HostIpConfig ip o
+ PhysicalNicLinkInfo linkSpeed o
+end
+
+
object PropertyChange
String name r
PropertyChangeOp op r
@@ -569,7 +601,7 @@ object TemplateConfigFileQuery extends VmConfigFileQuery
end
-object TraversalSpec extends SelectionSpec
+object TraversalSpec extends SelectionSpec
String type r
String path r
Boolean skip o
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index af2d57e..596bd16 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -3,7 +3,7 @@
#
# esx_vi_generator.py: generates most of the SOAP type mapping code
#
-# Copyright (C) 2010-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
+# Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -1522,6 +1522,9 @@ additional_object_features = { "AutoStartDefaults" : Object.FEATURE__AN
Object.FEATURE__ANY_TYPE,
"ManagedObjectReference" : Object.FEATURE__ANY_TYPE,
"ObjectContent" : Object.FEATURE__DEEP_COPY,
+ "PhysicalNic" : Object.FEATURE__DEEP_COPY |
+ Object.FEATURE__LIST |
+ Object.FEATURE__ANY_TYPE,
"ResourcePoolResourceUsage" : Object.FEATURE__ANY_TYPE,
"ServiceContent" : Object.FEATURE__DESERIALIZE,
"SharesInfo" : Object.FEATURE__ANY_TYPE,
--
1.7.4.1
2
2
[libvirt] [PATCH] esx: Remove redundant checks for esxVI_LookupHostSystemProperties result
by Matthias Bolte 10 Aug '12
by Matthias Bolte 10 Aug '12
10 Aug '12
esxVI_LookupHostSystemProperties guarantees that hostSystem is non-NULL.
Remove redundant NULL checks from callers.
Also prefer esxVI_GetStringValue over open-coding the logic.
---
src/esx/esx_driver.c | 82 +++++++++---------------------------------------
src/esx/esx_vi.c | 4 +-
src/esx/esx_vi_types.c | 3 +-
3 files changed, 19 insertions(+), 70 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 47957cc..72a7acc 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3,7 +3,7 @@
* esx_driver.c: core driver functions for managing VMware ESX hosts
*
* Copyright (C) 2010-2012 Red Hat, Inc.
- * Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte(a)googlemail.com>
+ * Copyright (C) 2009-2012 Matthias Bolte <matthias.bolte(a)googlemail.com>
* Copyright (C) 2009 Maximilian Wilhelm <max(a)rfc2324.org>
*
* This library is free software; you can redistribute it and/or
@@ -467,12 +467,6 @@ esxSupportsLongMode(esxPrivate *priv)
goto cleanup;
}
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
- goto cleanup;
- }
-
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "hardware.cpuFeature")) {
@@ -534,7 +528,7 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
- esxVI_DynamicProperty *dynamicProperty = NULL;
+ char *uuid_string = NULL;
if (esxVI_EnsureSession(priv->primary) < 0) {
return -1;
@@ -543,41 +537,22 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
if (esxVI_String_AppendValueToList(&propertyNameList,
"hardware.systemInfo.uuid") < 0 ||
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
- &hostSystem) < 0) {
- goto cleanup;
- }
-
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
+ &hostSystem) < 0 ||
+ esxVI_GetStringValue(hostSystem, "hardware.systemInfo.uuid",
+ &uuid_string, esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
}
- for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
- dynamicProperty = dynamicProperty->_next) {
- if (STREQ(dynamicProperty->name, "hardware.systemInfo.uuid")) {
- if (esxVI_AnyType_ExpectType(dynamicProperty->val,
- esxVI_Type_String) < 0) {
- goto cleanup;
- }
-
- if (strlen(dynamicProperty->val->string) > 0) {
- if (virUUIDParse(dynamicProperty->val->string, uuid) < 0) {
- VIR_WARN("Could not parse host UUID from string '%s'",
- dynamicProperty->val->string);
+ if (strlen(uuid_string) > 0) {
+ if (virUUIDParse(uuid_string, uuid) < 0) {
+ VIR_WARN("Could not parse host UUID from string '%s'", uuid_string);
- /* HostSystem has an invalid UUID, ignore it */
- memset(uuid, 0, VIR_UUID_BUFLEN);
- }
- } else {
- /* HostSystem has an empty UUID */
- memset(uuid, 0, VIR_UUID_BUFLEN);
- }
-
- break;
- } else {
- VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
+ /* HostSystem has an invalid UUID, ignore it */
+ memset(uuid, 0, VIR_UUID_BUFLEN);
}
+ } else {
+ /* HostSystem has an empty UUID */
+ memset(uuid, 0, VIR_UUID_BUFLEN);
}
result = 0;
@@ -1176,17 +1151,8 @@ esxSupportsVMotion(esxPrivate *priv)
if (esxVI_String_AppendValueToList(&propertyNameList,
"capability.vmotionSupported") < 0 ||
esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
- &hostSystem) < 0) {
- goto cleanup;
- }
-
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
- goto cleanup;
- }
-
- if (esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
+ &hostSystem) < 0 ||
+ esxVI_GetBoolean(hostSystem, "capability.vmotionSupported",
&priv->supportsVMotion,
esxVI_Occurrence_RequiredItem) < 0) {
goto cleanup;
@@ -1281,12 +1247,6 @@ esxGetHostname(virConnectPtr conn)
goto cleanup;
}
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
- goto cleanup;
- }
-
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name,
@@ -1379,12 +1339,6 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
goto cleanup;
}
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
- goto cleanup;
- }
-
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "hardware.cpuInfo.hz")) {
@@ -2702,12 +2656,6 @@ esxDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
goto cleanup;
}
- if (hostSystem == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Could not retrieve the HostSystem object"));
- goto cleanup;
- }
-
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "capability.maxSupportedVcpus")) {
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index c4217c9..f3a9e91 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -4570,8 +4570,8 @@ esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersio
esxVI_DynamicProperty *dynamicProperty = NULL; \
\
if (ptrptr == NULL || *ptrptr != NULL) { \
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
- _("Invalid argument")); \
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
+ _("Invalid argument")); \
return -1; \
} \
\
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index 36f3196..2236751 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -296,7 +296,8 @@
childNode = childNode->next) { \
if (childNode->type != XML_ELEMENT_NODE) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
- _("Wrong XML element type %d"), childNode->type); \
+ _("Wrong XML element type %d"), \
+ childNode->type); \
goto failure; \
} \
\
--
1.7.4.1
3
3