From eblima at linux.vnet.ibm.com Wed Jun 1 14:20:12 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 01 Jun 2011 11:20:12 -0300 Subject: [Libvirt-cim] [PATCH] #3 Configure tweaks Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1306269980 10800 # Node ID f1f5ef86c865fc0f6e475685ece31eeb1ea1fc88 # Parent 8e7c9a8ad1f9e5bf6765c89a36ccca43f0564934 Configure tweaks acinclude.m4 - Better output when checking for CMPI includes configure.ac - Use automake silent rules if available - Introduce libtool version-info. Changes from #1 Makefile.am - Generate versioned .so files Changes from #2 libxkutil/Makefile.am - version-info only makes sense for libraries Signed-off-by: Eduardo Lima (Etrunko) diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -71,11 +71,9 @@ ], [ have_CMPI=yes - dnl AC_MSG_RESULT(yes) ], [ have_CMPI=no - dnl AC_MSG_RESULT(no) ]) ]) @@ -88,7 +86,7 @@ AC_DEFUN([CHECK_CMPI], [ - AC_MSG_CHECKING(for CMPI headers) + AC_MSG_NOTICE([checking for CMPI headers...]) dnl Check just with the standard include paths CMPI_CPP_FLAGS="$CPPFLAGS" _CHECK_CMPI(standard) @@ -96,6 +94,7 @@ dnl The standard include paths worked. AC_MSG_RESULT(yes) else + AC_MSG_RESULT(no) _DIRS_="/usr/include/cmpi \ /usr/local/include/cmpi \ $PEGASUS_ROOT/src/Pegasus/Provider/CMPI \ @@ -115,13 +114,15 @@ dnl Save the new -I parameter CMPI_CPP_FLAGS="$CPPFLAGS" break + else + AC_MSG_RESULT(no) fi CPPFLAGS=$_cppflags done fi CPPFLAGS="$CMPI_CPP_FLAGS" if test "$have_CMPI" == "no"; then - AC_MSG_ERROR(no. Sorry cannot find CMPI headers files.) + AC_MSG_ERROR(Cannot find CMPI headers files.) fi ] ) @@ -133,7 +134,7 @@ AC_DEFUN([CHECK_PROVIDERDIR], [ - AC_MSG_CHECKING(for CMPI provider directory) + AC_MSG_NOTICE([checking for CMPI provider directory]) _DIRS="$libdir/cmpi" save_exec_prefix=${exec_prefix} save_prefix=${prefix} @@ -146,7 +147,7 @@ for _dir in $_DIRS do _xdir=`eval echo $_dir` - AC_MSG_CHECKING( $_dir ) + AC_MSG_CHECKING([for $_dir]) if test -d $_xdir ; then dnl Found it AC_MSG_RESULT(yes) @@ -172,7 +173,7 @@ AC_DEFUN([CHECK_CIMSERVER], [ - AC_MSG_CHECKING(for CIM servers) + AC_MSG_NOTICE([checking for CIM servers]) if test x"$CIMSERVER" = x then _SERVERS="sfcbd cimserver owcimomd" @@ -194,13 +195,18 @@ esac fi break; - fi + fi + done + if test x"$CIMSERVER" == x; then + AC_MSG_RESULT(no) + else + break + fi done - done PATH=$_SAVE_PATH if test x"$CIMSERVER" == x ; then CIMSERVER=sfcb - AC_MSG_RESULT(implied: $CIMSERVER) + AC_MSG_WARN([CIM server implied: $CIMSERVER]) fi fi # Cross platform only needed for sfcb currently diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,34 @@ # (C) Copyright IBM Corp. 2005 +m4_define([libvirtcim_maj], [0]) +m4_define([libvirtcim_min], [5]) +m4_define([libvirtcim_mic], [12]) +m4_define([libvirtcim_version], [libvirtcim_maj.libvirtcim_min.libvirtcim_mic]) -AC_INIT(libvirt CMPI provider, 0.5.12, cvincent at us.ibm.com, libvirt-cim) +AC_INIT([libvirt CMPI provider], [libvirtcim_version], [cvincent at us.ibm.com], + [libvirt-cim]) AC_CONFIG_SRCDIR([src/Virt_ComputerSystem.c]) +# Autogenerate the autoconf header file to store build settings +AC_CONFIG_HEADER([config.h]) + +# Use silent rules if possible +AM_INIT_AUTOMAKE +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +m4_define([lt_cur], m4_eval(libvirtcim_maj + libvirtcim_min)) +m4_define([lt_rev], libvirtcim_mic) +m4_define([lt_age], libvirtcim_min) +VERSION_INFO="lt_cur:lt_rev:lt_age" +AC_SUBST(VERSION_INFO) + +AC_PROG_CC +AC_C_CONST +AC_PROG_LIBTOOL +AC_PROG_INSTALL +AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) AC_CHECK_HEADERS([stdarg.h errno.h]) +AC_HEADER_STDC AC_CHECK_FUNCS([popen pclose fgets asprintf vfprintf fprintf snprintf sscanf]) CPPFLAGS="$CPPFLAGS -DCMPI_VERSION=100" @@ -109,12 +133,6 @@ AC_SUBST(XEN_EMULATOR) AC_DEFINE_UNQUOTED(XEN_EMULATOR, "$XEN_EMULATOR", [Location of Xen FullVirt emulator]) -# Autogenerate the autoconf header file to store build settings -AC_CONFIG_HEADER([config.h]) - -topdir=`pwd` -AC_SUBST(topdir) - AC_PATH_PROG(XSLTPROC, xsltproc, /usr/bin/xsltproc) # Autogenerate the Makefile @@ -129,14 +147,6 @@ Makefile ]) -AM_INIT_AUTOMAKE - -AC_PROG_CC -AC_C_CONST -AC_PROG_LIBTOOL -AC_PROG_INSTALL -AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) -AC_HEADER_STDC # Check for the required CMPI header files (this macro is defined in acinclude.m4) CHECK_CMPI diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -10,7 +10,7 @@ libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ xmlgen.c infostore.c pool_parsing.c - +libxkutil_la_LDFLAGS = -version-info @VERSION_INFO@ libxkutil_la_LIBADD = @LIBVIRT_LIBS@ \ @LIBUUID_LIBS@ diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,8 @@ CFLAGS += -I$(top_builddir)/libxkutil $(CFLAGS_STRICT) -AM_LDFLAGS = $(XKUADD) +AM_LDFLAGS = $(XKUADD) \ + -version-info @VERSION_INFO@ providerdir = $(PROVIDERDIR) From eblima at linux.vnet.ibm.com Wed Jun 1 14:28:58 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 01 Jun 2011 11:28:58 -0300 Subject: [Libvirt-cim] CIMTest run performance In-Reply-To: <4DE56565.4090007@linux.vnet.ibm.com> References: <4DDFC317.2070502@linux.vnet.ibm.com> <4DE3D547.4010805@linux.vnet.ibm.com> <4DE56565.4090007@linux.vnet.ibm.com> Message-ID: <4DE64CAA.5050000@linux.vnet.ibm.com> On 05/31/2011 07:02 PM, Chip Vincent wrote: > Functionally, I can't think of a single reason why the tests are always > run remotely. I always run wbemcli and virsh commands locally, not > through ssh, so I can't imagine why cimtest should be different. It is > curious that the tests behave different with the patch. I would only > expect the migration tests to behave different if, for example, the test > checks the VM made it to the destination system. > > Rather than make this auto-detect, why not make it manually configurable > in the near term so we can do more testing? Well, actually it is already "configurable" if you specify the machine hostname instead of localhost, or 127.0.0.1 with -i option. -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Wed Jun 1 19:46:47 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 01 Jun 2011 16:46:47 -0300 Subject: [Libvirt-cim] [PATCH] Cimtest: Fix typo in SettingsDefine/01_forward.py Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1306957479 10800 # Node ID f303bd9615f23b8b79c5532dd5489899a13a0f8e # Parent 8dd7c0167cfaf3fe6b0274dbf98a0d875ae96355 Cimtest: Fix typo in SettingsDefine/01_forward.py File "01_forward.py", line 58, in setup_env return FAIL, cmxl NameError: global name 'cmxl' is not defined It should be cxml instead of cmxl Signed-off-by: Eduardo Lima (Etrunko) diff --git a/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py b/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py --- a/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py +++ b/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py @@ -55,7 +55,7 @@ ret = cxml.cim_define(server) if not ret: logger.error("Failed to Create the dom: %s", test_dom) - return FAIL, cmxl + return FAIL, cxml status = cxml.cim_start(server) if status != PASS: From eblima at linux.vnet.ibm.com Wed Jun 1 20:43:57 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 01 Jun 2011 17:43:57 -0300 Subject: [Libvirt-cim] [PATCH] Cimtest: Check for None return value Message-ID: <373d418b222c25309db3.1306961037@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1306960999 10800 # Node ID 373d418b222c25309db3d83dd384abf61127ebe9 # Parent f303bd9615f23b8b79c5532dd5489899a13a0f8e Cimtest: Check for None return value Some tests were raising Attribute Exception due to None value returned. Signed-off-by: Eduardo Lima (Etrunko) diff --git a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py @@ -57,7 +57,10 @@ dev = GetInstance(options.ip, disk, key_list) status = 0 - if dev.Name != test_dev: + if not dev: + logger.error("GetInstance() returned None") + status = 1 + else if dev.Name != test_dev: logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) status = 1 diff --git a/suites/libvirt-cim/cimtest/Memory/01_memory.py b/suites/libvirt-cim/cimtest/Memory/01_memory.py --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py @@ -56,7 +56,10 @@ status = 0 - if dev.ConsumableBlocks > dev.NumberOfBlocks: + if not dev: + logger.error("GetInstance() returned None") + status = 1 + else if dev.ConsumableBlocks > dev.NumberOfBlocks: logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") status = 1 diff --git a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py --- a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py +++ b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py @@ -83,6 +83,11 @@ vsxml.undefine(options.ip) return FAIL + if not dev: + logger.error("GetInstance() returned None") + vsxml.undefine(options.ip) + return FAIL + if dev.DeviceID == None: logger.error("Error retrieving instance for devid %s", devid) vsxml.undefine(options.ip) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py @@ -47,6 +47,10 @@ rasds = get_default_rasds(options.ip, options.virt) + if not rasds: + logger.error("get_default_rasds() returned None") + return FAIL + rasd_list = {} for rasd in rasds: @@ -56,6 +60,10 @@ rasd['AllocationUnits'] = units rasd_list[mrasd_cn] = inst_to_mof(rasd) + if mrasd_cn not in rasd_list.keys(): + logger.error("Key '%s' not found in dictionary '%s'" % (mrasd_cn, rasd_list)) + return FAIL + if rasd_list[mrasd_cn] is None: logger.error("Unable to get template MemRASD") return FAIL diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py @@ -154,7 +154,7 @@ logger.error(details) status = FAIL - if os.path.exists(addr): + if addr and os.path.exists(addr): os.remove(addr) if guest_defined == True: From snmishra at us.ibm.com Thu Jun 2 00:33:18 2011 From: snmishra at us.ibm.com (Sharad Mishra) Date: Wed, 01 Jun 2011 17:33:18 -0700 Subject: [Libvirt-cim] [PATCH] Migration was failing due to lost libvirt connection Message-ID: <7ecdbe3a4e204ff52fb0.1306974798@elm3a148.beaverton.ibm.com> # HG changeset patch # User Sharad Mishra # Date 1306954834 25200 # Node ID 7ecdbe3a4e204ff52fb0c336fdd6cd9f7c80b14a # Parent 8e7c9a8ad1f9e5bf6765c89a36ccca43f0564934 Migration was failing due to lost libvirt connection. One of the changes made to fix libvirt connection leaks, broke VM migration. The change has been undone. This change was not causing the leaks. Signed-off-by: Sharad Mishra diff -r 8e7c9a8ad1f9 -r 7ecdbe3a4e20 src/Virt_VSMigrationService.c --- a/src/Virt_VSMigrationService.c Tue May 24 15:29:32 2011 -0300 +++ b/src/Virt_VSMigrationService.c Wed Jun 01 12:00:34 2011 -0700 @@ -1294,6 +1294,7 @@ "Completed"); raise_deleted_ind(job); + virConnectClose(job->conn); free(job->domain); free(job->ref_cn); free(job->ref_ns); @@ -1510,7 +1511,6 @@ out: CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); - virConnectClose(job->conn); return s; } From eblima at linux.vnet.ibm.com Thu Jun 2 16:18:23 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Thu, 02 Jun 2011 13:18:23 -0300 Subject: [Libvirt-cim] [PATCH] Migration was failing due to lost libvirt connection In-Reply-To: <7ecdbe3a4e204ff52fb0.1306974798@elm3a148.beaverton.ibm.com> References: <7ecdbe3a4e204ff52fb0.1306974798@elm3a148.beaverton.ibm.com> Message-ID: <4DE7B7CF.30506@linux.vnet.ibm.com> On 06/01/2011 09:33 PM, Sharad Mishra wrote: > # HG changeset patch > # User Sharad Mishra > # Date 1306954834 25200 > # Node ID 7ecdbe3a4e204ff52fb0c336fdd6cd9f7c80b14a > # Parent 8e7c9a8ad1f9e5bf6765c89a36ccca43f0564934 > Migration was failing due to lost libvirt connection. > > One of the changes made to fix libvirt connection leaks, broke VM migration. The change has been undone. This change was not causing the leaks. > > Signed-off-by: Sharad Mishra > > diff -r 8e7c9a8ad1f9 -r 7ecdbe3a4e20 src/Virt_VSMigrationService.c > --- a/src/Virt_VSMigrationService.c Tue May 24 15:29:32 2011 -0300 > +++ b/src/Virt_VSMigrationService.c Wed Jun 01 12:00:34 2011 -0700 > @@ -1294,6 +1294,7 @@ > "Completed"); > > raise_deleted_ind(job); > + virConnectClose(job->conn); > free(job->domain); > free(job->ref_cn); > free(job->ref_ns); > @@ -1510,7 +1511,6 @@ > > out: > CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); > - virConnectClose(job->conn); > > return s; > } > +1. On a side note, I think we should employ one rule that is already used on libvirt development process. If a patch is trivial enough or if it fixes a crash or a broken build, it can be pushed without a prior acknowledge. Cheers! -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From cvincent at linux.vnet.ibm.com Mon Jun 6 17:24:07 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 06 Jun 2011 13:24:07 -0400 Subject: [Libvirt-cim] [PATCH] Migration was failing due to lost libvirt connection In-Reply-To: <4DE7B7CF.30506@linux.vnet.ibm.com> References: <7ecdbe3a4e204ff52fb0.1306974798@elm3a148.beaverton.ibm.com> <4DE7B7CF.30506@linux.vnet.ibm.com> Message-ID: <4DED0D37.9080000@linux.vnet.ibm.com> On 06/02/2011 12:18 PM, Eduardo Lima (Etrunko) wrote: > On 06/01/2011 09:33 PM, Sharad Mishra wrote: >> # HG changeset patch >> # User Sharad Mishra >> # Date 1306954834 25200 >> # Node ID 7ecdbe3a4e204ff52fb0c336fdd6cd9f7c80b14a >> # Parent 8e7c9a8ad1f9e5bf6765c89a36ccca43f0564934 >> Migration was failing due to lost libvirt connection. >> >> One of the changes made to fix libvirt connection leaks, broke VM >> migration. The change has been undone. This change was not causing the >> leaks. >> >> Signed-off-by: Sharad Mishra >> >> diff -r 8e7c9a8ad1f9 -r 7ecdbe3a4e20 src/Virt_VSMigrationService.c >> --- a/src/Virt_VSMigrationService.c Tue May 24 15:29:32 2011 -0300 >> +++ b/src/Virt_VSMigrationService.c Wed Jun 01 12:00:34 2011 -0700 >> @@ -1294,6 +1294,7 @@ >> "Completed"); >> >> raise_deleted_ind(job); >> + virConnectClose(job->conn); >> free(job->domain); >> free(job->ref_cn); >> free(job->ref_ns); >> @@ -1510,7 +1511,6 @@ >> >> out: >> CMReturnData(results, (CMPIValue *)&retcode, CMPI_uint32); >> - virConnectClose(job->conn); >> >> return s; >> } >> +1 and pushed. > > +1. > > On a side note, I think we should employ one rule that is already used > on libvirt development process. If a patch is trivial enough or if it > fixes a crash or a broken build, it can be pushed without a prior > acknowledge. +1 > > Cheers! > -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Mon Jun 6 16:19:47 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 06 Jun 2011 12:19:47 -0400 Subject: [Libvirt-cim] CIMTest run performance In-Reply-To: <4DE64CAA.5050000@linux.vnet.ibm.com> References: <4DDFC317.2070502@linux.vnet.ibm.com> <4DE3D547.4010805@linux.vnet.ibm.com> <4DE56565.4090007@linux.vnet.ibm.com> <4DE64CAA.5050000@linux.vnet.ibm.com> Message-ID: <4DECFE23.1040102@linux.vnet.ibm.com> Yep, you're right. Seems like then the lack of a -i option would default to localhost using a local connection. I can't think of a good reason to have an option for forcing ssh when -i is localhost. On 06/01/2011 10:28 AM, Eduardo Lima (Etrunko) wrote: > On 05/31/2011 07:02 PM, Chip Vincent wrote: >> Functionally, I can't think of a single reason why the tests are always >> run remotely. I always run wbemcli and virsh commands locally, not >> through ssh, so I can't imagine why cimtest should be different. It is >> curious that the tests behave different with the patch. I would only >> expect the migration tests to behave different if, for example, the test >> checks the VM made it to the destination system. >> >> Rather than make this auto-detect, why not make it manually configurable >> in the near term so we can do more testing? > > Well, actually it is already "configurable" if you specify the machine > hostname instead of localhost, or 127.0.0.1 with -i option. > -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From snmishra at us.ibm.com Tue Jun 7 01:29:46 2011 From: snmishra at us.ibm.com (Sharad Mishra) Date: Mon, 6 Jun 2011 18:29:46 -0700 Subject: [Libvirt-cim] [PATCH] (#2) Add DCN ACL classes & providers In-Reply-To: <68e37b55a0687ca55554.1306472923@oc0840652111.ibm.com> References: <68e37b55a0687ca55554.1306472923@oc0840652111.ibm.com> Message-ID: This is a big patch. I have visually reviewed the code and it looks good. Ran cimtests which completed successfully, meaning that there is no regression :-) There are no automated tests to verify this feature at this time. I ran few manual tests using wbemcli. I Ack this patch but would like someone else to review and test it too before pushing it upstream. Thanks Sharad Mishra Open Virtualization Linux Technology Center IBM libvirt-cim-bounces at redhat.com wrote on 05/26/2011 10:08:43 PM: > Chip Vincent > Sent by: libvirt-cim-bounces at redhat.com > > 05/26/11 10:08 PM > > Please respond to > List for discussion and development of libvirt CIM > > To > > libvirt-cim at redhat.com > > cc > > Subject > > [Libvirt-cim] [PATCH] (#2) Add DCN ACL classes & providers > > # HG changeset patch > # User Chip Vincent > # Date 1305221061 14400 > # Node ID 68e37b55a0687ca55554ca84c79c3358c05aee90 > # Parent 8e7c9a8ad1f9e5bf6765c89a36ccca43f0564934 > (#2) Add DCN ACL classes & providers > > Changes in this version: > #2 - Scoped code to primary use case: link network interfaces to > existing fitlers. > - Updated copyright year in a few places. > - Fixed octets_to_cmpi() to work when called from an associattion provider > > This patch adds several new classes and providers to add support for filter > rules and filter lists. > > The patch is rather large since all aspects are intertwined. > Here's an overview of the implementation: > > libxkutil: > The instrumentation is implemented in acl_parsing.c/.h since this function > is essentially independent of the device and/or pool parsing. ACLs are > associated to devices (via filterref) so there are some minor changes in > device_parsing.c & xmlgen.c to support this. > > +libxkutil/acl_parsing.h & .c > Adds several new structures to represent filters and rules. Since rules can > only exist within the context of a filter, the main structure used in the APIs > is acl_fitler. > > Also adds several new APIs to libxkutil to allow providers (see below) to > convert acl_filter and acl_rule structures to CIM objects, and to support > associations between themselves and existing resource (host system & network > port). > > schema & providers: > The ACL function does not map to an exiting profile so a subset of the > classes defined in the CIM Network schema are used. > > +schema/FilterEntry.mof &.registration > +src/FilterEntry.h & .c > Adds two new classes to represent IP-level rules (IPHeadersFilter) and > MAC-level (Hdr8021Filter). These classes include two new properties to > surface libvirt features not defined by the schema (Direction & Priority). > > +schema/FilterList.mof & .registration > +src/FilterList.h & .c > Adds a class to represent ACL filters (FilterList) > > NOTE: Read-write. Requires Name property only. > > +schema/EntriesInFilterList.mof & .registration > +src/EntriesInFilterList.c > Adds a class to represent the relationship (association) between a filter > (FilterList) and the rules it contains (IPHeadersFilter or Hdr8021Filter). > > +schema/NestedFilterList.mof & .registration > +src/NestedFilterList.c > Adds a class to represent filters that have references (filterref) to > other pre-defined filters. This is not covered by the current schema so > a new class was introduced to a) allow filters to reference each other, and > b) do it in a way that allows the client to determine if a filter > reference_s_ a filter or is reference_d_ by a filter. > > +schema/HostedFilterList.mof & .registration > +src/HostedFilterList.c > Adds a class to represent the relationship (association) between a filter > and the computer system that hosts them. In the case of ACL filters, which > are essentially defined once but available to all VMs, they are always linked > to the host system (hypervisor) rather than the individual computer > systems (VMs). > > +schema/AppliedFilterList.mof & .registration > +src/AppliedFilterList.c > Adds a class to represent the relationship (association) between a filter > and a network port referencing it. This is not covered by the current schema > so a new class was introduced. > > NOTE: New associations are created via CIM intrinsic methods (create/modify/ > delete). It requires the client to provide fully qualified object paths to > the filter and network port so the providers can a) validate their existance, > and b) apply the necessary links in the XML so new associations appear when > queried. > > Signed-off-by: Chip Vincent > > diff --git a/Makefile.am b/Makefile.am > --- a/Makefile.am > +++ b/Makefile.am > @@ -57,7 +57,13 @@ > schema/InputPool.mof \ > schema/HostedAccessPoint.mof \ > schema/ServiceAccessBySAP.mof \ > - schema/SAPAvailableForElement.mof > + schema/SAPAvailableForElement.mof \ > + schema/FilterEntry.mof \ > + schema/FilterList.mof \ > + schema/EntriesInFilterList.mof \ > + schema/NestedFilterList.mof \ > + schema/AppliedFilterList.mof \ > + schema/HostedFilterList.mof > > INTEROP_MOFS = \ > schema/ComputerSystem.mof \ > @@ -138,7 +144,13 @@ > schema/InputPool.registration \ > schema/HostedAccessPoint.registration \ > schema/ServiceAccessBySAP.registration \ > - schema/SAPAvailableForElement.registration > + schema/SAPAvailableForElement.registration \ > + schema/FilterEntry.registration \ > + schema/FilterList.registration \ > + schema/EntriesInFilterList.registration \ > + schema/NestedFilterList.registration \ > + schema/AppliedFilterList.registration \ > + schema/HostedFilterList.registration > > INTEROP_REGS = \ > schema/RegisteredProfile.registration \ > diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am > --- a/libxkutil/Makefile.am > +++ b/libxkutil/Makefile.am > @@ -4,12 +4,12 @@ > CFLAGS += $(CFLAGS_STRICT) > > noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h > infostore.h \ > - pool_parsing.h > + pool_parsing.h acl_parsing.h > > lib_LTLIBRARIES = libxkutil.la > > libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ > - xmlgen.c infostore.c pool_parsing.c > + xmlgen.c infostore.c pool_parsing.c acl_parsing.c > > libxkutil_la_LIBADD = @LIBVIRT_LIBS@ \ > @LIBUUID_LIBS@ > diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c > new file mode 100644 > --- /dev/null > +++ b/libxkutil/acl_parsing.c > @@ -0,0 +1,639 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#include "acl_parsing.h" > +#include "device_parsing.h" > +#include "xmlgen.h" > +#include "../src/svpc_types.h" > + > +void cleanup_rule(struct acl_rule *rule) > +{ > + if(rule == NULL) > + return; > + > + free(rule->name); > + free(rule->protocol_id); > + free(rule->action); > + free(rule->direction); > + free(rule->priority); > + > + switch(rule->type) { > + case MAC_RULE: > + free(rule->var.mac.srcmacaddr); > + free(rule->var.mac.srcmacmask); > + free(rule->var.mac.dstmacaddr); > + free(rule->var.mac.dstmacmask); > + free(rule->var.mac.protocol_id); > + free(rule->var.mac.comment); > + break; > + case ARP_RULE: > + free(rule->var.arp.srcmacaddr); > + free(rule->var.arp.srcmacmask); > + free(rule->var.arp.dstmacaddr); > + free(rule->var.arp.dstmacmask); > + free(rule->var.arp.hw_type); > + free(rule->var.arp.protocol_type); > + free(rule->var.arp.opcode); > + free(rule->var.arp.arpsrcmacaddr); > + free(rule->var.arp.arpdstmacaddr); > + free(rule->var.arp.arpsrcipaddr); > + free(rule->var.arp.arpdstipaddr); > + free(rule->var.arp.comment); > + break; > + case IP_RULE: > + free(rule->var.ip.srcmacaddr); > + free(rule->var.ip.srcmacmask); > + free(rule->var.ip.dstmacaddr); > + free(rule->var.ip.dstmacmask); > + free(rule->var.ip.srcipaddr); > + free(rule->var.ip.srcipmask); > + free(rule->var.ip.dstipaddr); > + free(rule->var.ip.dstipmask); > + free(rule->var.ip.srcportstart); > + free(rule->var.ip.srcportend); > + free(rule->var.ip.dstportstart); > + free(rule->var.ip.dstportend); > + free(rule->var.ip.comment); > + break; > + case TCP_RULE: > + free(rule->var.tcp.srcmacaddr); > + free(rule->var.tcp.srcipaddr); > + free(rule->var.tcp.srcipmask); > + free(rule->var.tcp.dstipaddr); > + free(rule->var.tcp.srcipfrom); > + free(rule->var.tcp.srcipto); > + free(rule->var.tcp.dstipfrom); > + free(rule->var.tcp.dstipto); > + free(rule->var.tcp.srcportstart); > + free(rule->var.tcp.srcportend); > + free(rule->var.tcp.dstportstart); > + free(rule->var.tcp.dstportend); > + free(rule->var.tcp.comment); > + free(rule->var.tcp.state); > + break; > + case IGMP_RULE: > + free(rule->var.igmp.srcmacaddr); > + free(rule->var.igmp.srcmacmask); > + free(rule->var.igmp.dstmacaddr); > + free(rule->var.igmp.dstmacmask); > + free(rule->var.igmp.srcipaddr); > + free(rule->var.igmp.srcipmask); > + free(rule->var.igmp.dstipaddr); > + free(rule->var.igmp.dstipmask); > + free(rule->var.igmp.srcipfrom); > + free(rule->var.igmp.srcipto); > + free(rule->var.igmp.dstipfrom); > + free(rule->var.igmp.dstipto); > + free(rule->var.igmp.type); > + free(rule->var.igmp.code); > + free(rule->var.igmp.comment); > + free(rule->var.igmp.state); > + break; > + case ICMP_RULE: > + free(rule->var.icmp.srcmacaddr); > + free(rule->var.icmp.srcmacmask); > + free(rule->var.icmp.dstmacaddr); > + free(rule->var.icmp.dstmacmask); > + free(rule->var.icmp.srcipaddr); > + free(rule->var.icmp.srcipmask); > + free(rule->var.icmp.dstipaddr); > + free(rule->var.icmp.dstipmask); > + free(rule->var.icmp.srcipfrom); > + free(rule->var.icmp.srcipto); > + free(rule->var.icmp.dstipfrom); > + free(rule->var.icmp.dstipto); > + free(rule->var.icmp.type); > + free(rule->var.icmp.code); > + free(rule->var.icmp.comment); > + free(rule->var.icmp.state); > + break; > + case UNKNOWN_RULE: > + default: > + break; > + }; > + > + rule->type = UNKNOWN_RULE; > +} > + > +void cleanup_filter(struct acl_filter *filter) > +{ > + int i; > + > + if(filter == NULL) > + return; > + > + free(filter->uuid); > + free(filter->name); > + free(filter->chain); > + > + for (i = 0; i < filter->rule_ct; i++) { > + cleanup_rule(filter->rules[i]); > + free(filter->rules[i]); > + } > + > + free(filter->rules); > + filter->rule_ct = 0; > + > + for (i = 0; i < filter->ref_ct; i++) > + free(filter->refs[i]); > + > + free(filter->refs); > + filter->ref_ct = 0; > +} > + > +void cleanup_filters(struct acl_filter **filters, int count) > +{ > + int i; > + struct acl_filter *_filters = *filters; > + > + if((filters == NULL) || (*filters == NULL) || (count == 0)) > + return; > + > + for (i = 0; i < count; i++) > + cleanup_filter(&_filters[i]); > + > + free(_filters); > + *filters = NULL; > +} > + > + > +static int parse_acl_mac_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACL mac rule %s", rnode->name); > + > + rule->type = MAC_RULE; > + rule->var.mac.protocol_id = get_attr_value(rnode, "protocolid"); > + rule->var.mac.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.mac.srcmacmask = get_attr_value(rnode, "srcmacmask"); > + rule->var.mac.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); > + rule->var.mac.dstmacmask = get_attr_value(rnode, "dstmacmask"); > + rule->var.mac.comment = get_attr_value(rnode, "comment"); > + > + return 1; > +} > + > +static int parse_acl_arp_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACL arp rule %s", rnode->name); > + > + rule->type = ARP_RULE; > + rule->var.arp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.arp.srcmacmask = get_attr_value(rnode, "srcmacmask"); > + rule->var.arp.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); > + rule->var.arp.dstmacmask = get_attr_value(rnode, "dstmacmask"); > + rule->var.arp.hw_type = get_attr_value(rnode, "hwtype"); > + rule->var.arp.protocol_type = get_attr_value(rnode, "protocoltype"); > + rule->var.arp.opcode = get_attr_value(rnode, "opcode"); > + rule->var.arp.arpsrcmacaddr = get_attr_value(rnode, "arpsrcmacaddr"); > + rule->var.arp.arpdstmacaddr = get_attr_value(rnode, "arpdstmacaddr"); > + rule->var.arp.arpsrcipaddr = get_attr_value(rnode, "arpsrcipaddr"); > + rule->var.arp.arpdstipaddr = get_attr_value(rnode, "arpdstipaddr"); > + rule->var.arp.comment = get_attr_value(rnode, "comment"); > + > + return 1; > +} > + > +static int parse_acl_ip_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACP ip rule %s", rnode->name); > + > + rule->type = IP_RULE; > + rule->var.ip.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.ip.srcmacmask = get_attr_value(rnode, "srcmacmask"); > + rule->var.ip.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); > + rule->var.ip.dstmacmask = get_attr_value(rnode, "dstmacmaks"); > + rule->var.ip.srcipaddr = get_attr_value(rnode, "srcipaddr"); > + rule->var.ip.srcipmask = get_attr_value(rnode, "srcipmask"); > + rule->var.ip.dstipaddr = get_attr_value(rnode, "dstipaddr"); > + rule->var.ip.dstipmask = get_attr_value(rnode, "dstipmask"); > + rule->var.ip.protocol = get_attr_value(rnode, "protocol"); > + rule->var.ip.srcportstart = get_attr_value(rnode, "srcportstart"); > + rule->var.ip.srcportend = get_attr_value(rnode, "srcportend"); > + rule->var.ip.dstportstart = get_attr_value(rnode, "dstportstart"); > + rule->var.ip.dstportend = get_attr_value(rnode, "dstportend"); > + rule->var.ip.comment = get_attr_value(rnode, "comment"); > + > + return 1; > +} > + > +static int parse_acl_tcp_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACL tcp rule %s", rnode->name); > + > + rule->type = TCP_RULE; > + rule->var.tcp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.tcp.srcipaddr = get_attr_value(rnode, "srcipaddr"); > + rule->var.tcp.srcipmask = get_attr_value(rnode, "srcipmask"); > + rule->var.tcp.dstipaddr = get_attr_value(rnode, "dstipaddr"); > + rule->var.tcp.dstipmask = get_attr_value(rnode, "dstipmask"); > + rule->var.tcp.srcipfrom = get_attr_value(rnode, "srcipfrom"); > + rule->var.tcp.srcipto = get_attr_value(rnode, "srcipto"); > + rule->var.tcp.dstipfrom = get_attr_value(rnode, "dstipfrom"); > + rule->var.tcp.dstipto = get_attr_value(rnode, "dstipto"); > + rule->var.tcp.srcportstart = get_attr_value(rnode, "srcportstart"); > + rule->var.tcp.srcportend = get_attr_value(rnode, "srcportend"); > + rule->var.tcp.dstportstart = get_attr_value(rnode, "dstportstart"); > + rule->var.tcp.dstportend = get_attr_value(rnode, "dstportend"); > + rule->var.tcp.comment = get_attr_value(rnode, "comment"); > + rule->var.tcp.state = get_attr_value(rnode, "state"); > + > + return 1; > +} > + > +static int parse_acl_icmp_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACL icmp rule %s", rnode->name); > + > + rule->type = ICMP_RULE; > + rule->var.icmp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.icmp.srcmacmask = get_attr_value(rnode, "srcmacmask"); > + rule->var.icmp.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); > + rule->var.icmp.dstmacmask = get_attr_value(rnode, "dstmacmask"); > + rule->var.icmp.srcipaddr = get_attr_value(rnode, "srcipaddr"); > + rule->var.icmp.srcipmask = get_attr_value(rnode, "srcipmask"); > + rule->var.icmp.dstipaddr = get_attr_value(rnode, "dstipaddr"); > + rule->var.icmp.dstipmask = get_attr_value(rnode, "dstipmask"); > + rule->var.icmp.srcipfrom = get_attr_value(rnode, "srcipfrom"); > + rule->var.icmp.srcipto = get_attr_value(rnode, "srcipto"); > + rule->var.icmp.dstipfrom = get_attr_value(rnode, "dstipfrom"); > + rule->var.icmp.dstipto = get_attr_value(rnode, "dstipto"); > + rule->var.icmp.comment = get_attr_value(rnode, "comment"); > + rule->var.icmp.state = get_attr_value(rnode, "state"); > + > + return 1; > +} > + > +static int parse_acl_igmp_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + CU_DEBUG("ACL igmp rule %s", rnode->name); > + > + rule->type = IGMP_RULE; > + rule->var.igmp.srcmacaddr = get_attr_value(rnode, "srcmacaddr"); > + rule->var.igmp.srcmacmask = get_attr_value(rnode, "srcmacmask"); > + rule->var.igmp.dstmacaddr = get_attr_value(rnode, "dstmacaddr"); > + rule->var.igmp.dstmacmask = get_attr_value(rnode, "dstmacmask"); > + rule->var.igmp.srcipaddr = get_attr_value(rnode, "srcipaddr"); > + rule->var.igmp.srcipmask = get_attr_value(rnode, "srcipmask"); > + rule->var.igmp.dstipaddr = get_attr_value(rnode, "dstipaddr"); > + rule->var.igmp.dstipmask = get_attr_value(rnode, "dstipmask"); > + rule->var.igmp.srcipfrom = get_attr_value(rnode, "srcipfrom"); > + rule->var.igmp.srcipto = get_attr_value(rnode, "srcipto"); > + rule->var.igmp.dstipfrom = get_attr_value(rnode, "dstipfrom"); > + rule->var.igmp.dstipto = get_attr_value(rnode, "dstipto"); > + rule->var.igmp.type = get_attr_value(rnode, "type"); > + rule->var.igmp.code = get_attr_value(rnode, "code"); > + rule->var.igmp.comment = get_attr_value(rnode, "comment"); > + rule->var.igmp.state = get_attr_value(rnode, "state"); > + > + return 1; > +} > + > +static int parse_acl_rule(xmlNode *rnode, struct acl_rule *rule) > +{ > + xmlNode *child = NULL; > + > + memset(rule, 0, sizeof(*rule)); > + > + rule->action = get_attr_value(rnode, "action"); > + if (rule->action == NULL) > + goto err; > + > + rule->direction = get_attr_value(rnode, "direction"); > + if (rule->direction == NULL) > + goto err; > + > + rule->priority = get_attr_value(rnode, "priority"); > + rule->statematch = get_attr_value(rnode, "statematch"); > + > + for (child = rnode->children; child != NULL; child = child-> next) { > + if (XSTREQ(child->name, "mac")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_mac_rule(child, rule); > + } else if (XSTREQ(child->name, "arp") || > + XSTREQ(child->name, "rarp")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_arp_rule(child, rule); > + } else if (XSTREQ(child->name, "ip") || > + XSTREQ(child->name, "ipv6")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_ip_rule(child, rule); > + } else if (XSTREQ(child->name, "tcp") || > + XSTREQ(child->name, "tcp-ipv6") || > + XSTREQ(child->name, "udp") || > + XSTREQ(child->name, "udp-ipv6") || > + XSTREQ(child->name, "sctp") || > + XSTREQ(child->name, "sctp-ipv6")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_tcp_rule(child, rule); > + } else if (XSTREQ(child->name, "icmp") || > + XSTREQ(child->name, "icmpv6")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_icmp_rule(child, rule); > + } else if (XSTREQ(child->name, "igmp") || > + XSTREQ(child->name, "igmp-ipv6") || > + XSTREQ(child->name, "esp") || > + XSTREQ(child->name, "esp-ipv6") || > + XSTREQ(child->name, "ah") || > + XSTREQ(child->name, "ah-ipv6") || > + XSTREQ(child->name, "udplite") || > + XSTREQ(child->name, "udplite-ipv6") || > + XSTREQ(child->name, "all") || > + XSTREQ(child->name, "all-ipv6")) { > + rule->protocol_id = strdup((char *)child->name); > + parse_acl_igmp_rule(child, rule); > + } > + } > + > + return 1; > + > + err: > + cleanup_rule(rule); > + > + return 0; > +} > + > +static int parse_acl_filter(xmlNode *fnode, struct acl_filter *filter) > +{ > + struct acl_rule *rule = NULL; > + char *filter_ref = NULL; > + xmlNode *child = NULL; > + > + filter->name = get_attr_value(fnode, "name"); > + if (filter->name == NULL) > + goto err; > + > + filter->chain = get_attr_value(fnode, "chain"); > + > + for (child = fnode->children; child != NULL; child = child-> next) { > + if (XSTREQ(child->name, "uuid")) { > + STRPROP(filter, uuid, child); > + } else if (XSTREQ(child->name, "rule")) { > + rule = malloc(sizeof(*rule)); > + if (rule == NULL) > + goto err; > + > + if (parse_acl_rule(child, rule) == 0) > + goto err; > + > + append_filter_rule(filter, rule); > + } > + else if (XSTREQ(child->name, "filterref")) { > + filter_ref = get_attr_value(child, "filter"); > + if (filter_ref == NULL) > + goto err; > + > + append_filter_ref(filter, filter_ref); > + } > + } > + > + return 1; > + > + err: > + cleanup_filter(filter); > + > + return 0; > +} > + > +/* Dummy function to suppress error message from libxml2 */ > +static void swallow_err_msg(void *ctx, const char *msg, ...) > +{ > + /* do nothing, just swallow the message. */ > +} > + > +int get_filter_from_xml(const char *xml, struct acl_filter **filter) > +{ > + xmlDoc *xmldoc = NULL; > + > + if (xml == NULL || filter == NULL) > + return 0; > + > + xmlSetGenericErrorFunc(NULL, swallow_err_msg); > + > + xmldoc = xmlParseMemory(xml, strlen(xml) + 1); > + if (xmldoc == NULL) > + goto err; > + > + *filter = malloc(sizeof(**filter)); > + > + memset(*filter, 0, sizeof(**filter)); > + parse_acl_filter(xmldoc->children, *filter); > + > + err: > + xmlSetGenericErrorFunc(NULL, NULL); > + xmlFreeDoc(xmldoc); > + > + return 1; > +} > + > +int get_filter_by_name( > + virConnectPtr conn, > + const char *name, > + struct acl_filter **filter) > +{ > + virNWFilterPtr vfilter = NULL; > + char *xml = NULL; > + > + if (name == NULL || filter == NULL) > + return 0; > + > + vfilter = virNWFilterLookupByName(conn, name); > + > + xml = virNWFilterGetXMLDesc(vfilter, 0); > + > + virNWFilterFree(vfilter); > + > + if (xml == NULL) > + return 0; > + > + get_filter_from_xml(xml, filter); > + > + return 1; > +} > + > +int get_filter_by_uuid( > + virConnectPtr conn, > + const char *uuid, > + struct acl_filter **filter) > +{ > + virNWFilterPtr vfilter = NULL; > + char *xml = NULL; > + > + if (uuid == NULL || filter == NULL) > + return 0; > + > + vfilter = virNWFilterLookupByUUIDString(conn, uuid); > + > + xml = virNWFilterGetXMLDesc(vfilter, 0); > + > + virNWFilterFree(vfilter); > + > + if (xml == NULL) > + return 0; > + > + get_filter_from_xml(xml, filter); > + > + return 1; > +} > + > +int get_filters( > + virConnectPtr conn, > + struct acl_filter **list) > +{ > + int count = 0; > + char **names = NULL; > + struct acl_filter *filters = NULL; > + int i = 0; > + > + count = virConnectNumOfNWFilters(conn); > + > + names = calloc(count, sizeof(char *)); > + if (names == NULL) > + goto err; > + > + virConnectListNWFilters(conn, names, count); > + > + filters = malloc(count * sizeof(struct acl_filter)); > + if (filters == NULL) > + goto err; > + > + for(i = 0; i < count; i++) > + { > + struct acl_filter *filter = NULL; > + > + get_filter_by_name(conn, names[i], &filter); > + > + memcpy(&filters[i], filter, sizeof(*filter)); > + } > + > + *list = filters; > + > + err: > + free(names); > + > + return i; > +} > + > + > +int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule) > +{ > + struct acl_rule **old_rules = NULL; > + > + if ((filter == NULL) || (rule == NULL)) > + return 0; > + > + rule->name = make_rule_id(filter->name, filter->rule_ct); > + if (rule->name == NULL) > + return 0; > + > + old_rules = filter->rules; > + > + filter->rules = > + malloc((filter->rule_ct + 1) * sizeof(struct acl_rule *)); > + > + memcpy(filter->rules, > + old_rules, > + filter->rule_ct * sizeof(struct acl_rule *)); > + > + filter->rules[filter->rule_ct] = rule; > + filter->rule_ct++; > + > + free(old_rules); > + > + return 1; > +} > + > +int append_filter_ref(struct acl_filter *filter, char *name) > +{ > + int i; > + char **old_refs = NULL; > + > + if ((filter == NULL) || (name == NULL)) > + return 0; > + > + for (i = 0; i < filter->ref_ct; i++) > + if (STREQC(filter->refs[i], name)) > + return 0; /* already exists */ > + > + old_refs = filter->refs; > + > + filter->refs = malloc((filter->ref_ct + 1) * sizeof(char *)); > + memcpy(filter->refs, old_refs, filter->ref_ct * sizeof(char *)); > + > + filter->refs[filter->ref_ct] = name; > + filter->ref_ct++; > + > + free(old_refs); > + > + return 1; > +} > + > +char *make_rule_id(const char *filter, int index) > +{ > + int ret; > + char *rule_id = NULL; > + > + if (filter == NULL) > + return NULL; > + > + ret = asprintf(&rule_id, "%s:%u", filter, index); > + if (ret == -1) { > + free(rule_id); > + rule_id = NULL; > + } > + > + > + return rule_id; > +} > + > +int parse_rule_id(const char *rule_id, char **filter, int *index) > +{ > + int ret; > + > + if ((filter == NULL) || (index == NULL)) > + return 0; > + ret = sscanf(rule_id, "%as[^:]:%u", filter, index); > + if (ret != 2) { > + free(*filter); > + *filter = NULL; > + > + return 0; > + } > + > + return 1; > +} > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/libxkutil/acl_parsing.h b/libxkutil/acl_parsing.h > new file mode 100644 > --- /dev/null > +++ b/libxkutil/acl_parsing.h > @@ -0,0 +1,212 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#ifndef __ACL_PARSING_H > +#define __ACL_PARSING_H > + > +#include > +#include > +#include > +#include > + > +struct acl_mac_rule { > + char *srcmacaddr; > + char *srcmacmask; > + char *dstmacaddr; > + char *dstmacmask; > + > + char *protocol_id; > + char *comment; > +}; > + > +struct acl_arp_rule { > + char *srcmacaddr; > + char *srcmacmask; > + char *dstmacaddr; > + char *dstmacmask; > + > + char *hw_type; > + char *protocol_type; > + char *opcode; > + char *arpsrcmacaddr; > + char *arpdstmacaddr; > + char *arpsrcipaddr; > + char *arpdstipaddr; > + char *comment; > +}; > + > +struct acl_ip_rule { > + char *srcmacaddr; > + char *srcmacmask; > + char *dstmacaddr; > + char *dstmacmask; > + > + char *srcipaddr; > + char *srcipmask; > + char *dstipaddr; > + char *dstipmask; > + > + char *protocol; > + > + char *srcportstart; > + char *srcportend; > + char *dstportstart; > + char *dstportend; > + > + char *comment; > +}; > + > +struct acl_tcp_rule { > + char *srcmacaddr; > + > + char *srcipaddr; > + char *srcipmask; > + char *dstipaddr; > + char *dstipmask; > + > + char *srcipfrom; > + char *srcipto; > + char *dstipfrom; > + char *dstipto; > + > + char *srcportstart; > + char *srcportend; > + char *dstportstart; > + char *dstportend; > + > + char *comment; > + char *state; > +}; > + > +struct acl_igmp_rule { > + char *srcmacaddr; > + char *srcmacmask; > + char *dstmacaddr; > + char *dstmacmask; > + > + char *srcipaddr; > + char *srcipmask; > + char *dstipaddr; > + char *dstipmask; > + > + char *srcipfrom; > + char *srcipto; > + char *dstipfrom; > + char *dstipto; > + > + char *type; > + char *code; > + char *comment; > + char *state; > +}; > + > +struct acl_icmp_rule { > + char *srcmacaddr; > + char *srcmacmask; > + char *dstmacaddr; > + char *dstmacmask; > + > + char *srcipaddr; > + char *srcipmask; > + char *dstipaddr; > + char *dstipmask; > + > + char *srcipfrom; > + char *srcipto; > + char *dstipfrom; > + char *dstipto; > + > + char *type; > + char *code; > + char *comment; > + char *state; > +}; > + > +struct acl_rule { > + char *name; > + char *protocol_id; > + char *action; > + char *direction; > + char *priority; > + char *statematch; > + > + enum { > + UNKNOWN_RULE, > + MAC_RULE, > + ARP_RULE, > + IP_RULE, > + TCP_RULE, > + ICMP_RULE, > + IGMP_RULE > + } type; > + > + union { > + struct acl_mac_rule mac; > + struct acl_arp_rule arp; > + struct acl_ip_rule ip; > + struct acl_tcp_rule tcp; > + struct acl_icmp_rule icmp; > + struct acl_igmp_rule igmp; > + } var; > +}; > + > +struct acl_filter { > + char *uuid; > + char *name; > + char *chain; > + > + struct acl_rule **rules; > + int rule_ct; > + > + char **refs; > + int ref_ct; > +}; > + > +void cleanup_rule(struct acl_rule *rule); > +void cleanup_filter(struct acl_filter *filter); > +void cleanup_filters(struct acl_filter **filters, int count); > + > +int get_filters(virConnectPtr conn, struct acl_filter **list); > + > +int get_filter_from_xml(const char *xml, struct acl_filter **filter); > +int get_filter_by_uuid(virConnectPtr conn, const char *uuid, > + struct acl_filter **filter); > +int get_filter_by_name(virConnectPtr conn, const char *name, > + struct acl_filter **filter); > + > +char *make_rule_id(const char *filter, int index); > +int parse_rule_id(const char *rule_id, char **filter, int *index); > + > +/** NOTE: Both append functions take parameters allocated by caller and > + * freed by cleanup_filter(s) > + */ > +int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule); > +int append_filter_ref(struct acl_filter *filter, char *name); > +#endif > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c > --- a/libxkutil/device_parsing.c > +++ b/libxkutil/device_parsing.c > @@ -80,6 +80,7 @@ > free(dev->model); > free(dev->device); > free(dev->net_mode); > + free(dev->filter_ref); > } > > static void cleanup_emu_device(struct emu_device *dev) > @@ -386,9 +387,12 @@ > ndev->model = get_attr_value(child, "type"); > if (ndev->model == NULL) > goto err; > + } else if (XSTREQ(child->name, "filterref")) { > + ndev->filter_ref = get_attr_value(child, "filter"); > } else if (XSTREQ(child->name, "virtualport")) { > parse_vsi_device(child, ndev); > } > + > } > > if (ndev->source == NULL) > @@ -764,6 +768,7 @@ > DUP_FIELD(dev, _dev, dev.net.model); > DUP_FIELD(dev, _dev, dev.net.device); > DUP_FIELD(dev, _dev, dev.net.net_mode); > + DUP_FIELD(dev, _dev, dev.net.filter_ref); > DUP_FIELD(dev, _dev, dev.net.vsi.vsi_type); > DUP_FIELD(dev, _dev, dev.net.vsi.manager_id); > DUP_FIELD(dev, _dev, dev.net.vsi.type_id); > diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h > --- a/libxkutil/device_parsing.h > +++ b/libxkutil/device_parsing.h > @@ -64,6 +64,7 @@ > char *model; > char *device; > char *net_mode; > + char *filter_ref; > struct vsi_device vsi; > }; > > diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c > --- a/libxkutil/xmlgen.c > +++ b/libxkutil/xmlgen.c > @@ -301,6 +301,15 @@ > xmlNewProp(tmp, BAD_CAST "type", BAD_CAST > net->model); > } > > + if (net->filter_ref != NULL) { > + tmp = xmlNewChild(nic, NULL, > + BAD_CAST "filterref", NULL); > + if (tmp == NULL) > + return XML_ERROR; > + xmlNewProp(tmp, BAD_CAST "filter", > + BAD_CAST net->filter_ref); > + } > + > if (STREQ(dev->dev.net.type, "network")) > msg = set_net_source(nic, net, "network"); > else if (STREQ(dev->dev.net.type, "bridge")) > diff --git a/libxkutil/xmlgen.h b/libxkutil/xmlgen.h > --- a/libxkutil/xmlgen.h > +++ b/libxkutil/xmlgen.h > @@ -23,6 +23,7 @@ > > #include "device_parsing.h" > #include "pool_parsing.h" > +#include "acl_parsing.h" > > #include "cmpidt.h" > > @@ -38,4 +39,6 @@ > > char *res_to_xml(struct virt_pool_res *res); > > +char *filter_to_xml(struct acl_filter *filter); > + > #endif > diff --git a/schema/AppliedFilterList.mof b/schema/AppliedFilterList.mof > new file mode 100644 > --- /dev/null > +++ b/schema/AppliedFilterList.mof > @@ -0,0 +1,8 @@ > +// Copyright IBM Corp. 2011 > +[Association, > + Provider("cmpi::Virt_AppliedFilterList")] > +class KVM_AppliedFilterList : CIM_ConcreteDependency > +{ > + CIM_NetworkPort ref Antecedent; > + CIM_FilterList ref Dependent; > +}; > diff --git a/schema/AppliedFilterList.registration b/schema/ > AppliedFilterList.registration > new file mode 100644 > --- /dev/null > +++ b/schema/AppliedFilterList.registration > @@ -0,0 +1,3 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_AppliedFilterList root/virt Virt_AppliedFilterList > Virt_AppliedFilterList association > diff --git a/schema/EntriesInFilterList.mof b/schema/EntriesInFilterList.mof > new file mode 100644 > --- /dev/null > +++ b/schema/EntriesInFilterList.mof > @@ -0,0 +1,6 @@ > +// Copyright IBM Corp. 2011 > +[Association, > + Provider("cmpi::Virt_EntriesInFilterList")] > +class KVM_EntriesInFilterList : CIM_EntriesInFilterList > +{ > +}; > diff --git a/schema/EntriesInFilterList.registration b/schema/ > EntriesInFilterList.registration > new file mode 100644 > --- /dev/null > +++ b/schema/EntriesInFilterList.registration > @@ -0,0 +1,3 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_EntriesInFilterList root/virt Virt_EntriesInFilterList > Virt_EntriesInFilterList association > diff --git a/schema/FilterEntry.mof b/schema/FilterEntry.mof > new file mode 100644 > --- /dev/null > +++ b/schema/FilterEntry.mof > @@ -0,0 +1,60 @@ > +// Copyright IBM Corp. 2011 > +[Provider("cmpi::Virt_FilterEntry")] > +class KVM_Hdr8021Filter : CIM_Hdr8021Filter > +{ > + [Description("This defines whether the Filter is used for input, " > + "output, or both input and output filtering. All values are " > + "used with respect to the interface for which the Filter " > + "applies. \"Not Applicable\" (0) is used when there is no " > + "direction applicable to the Filter. \"Input\" (1) is " > + "used when the Filter applies to packets that are inbound " > + "on the related interface. \"Output\" (2) is used when the " > + "Filter applies to packets that are outbound on the " > + "related interface. \"Both\" (3) is used to indicate that " > + "the direction is immaterial, e.g., to filter on a source " > + "subnet regardless of whether the flow is inbound or " > + "outbound."), > + ValueMap { "0", "1", "2", "3", "4" }, > + Values { "Not Applicable", "Input, Output", "Both", "Mirrored" }] > + uint16 Direction; > + > + [Description("The priority of the rule controls the order in which " > + "the rule will be, instantiated relative to other rules. " > + "Rules with lower value will be instantiated and therefore " > + "evaluated before rules with higher value. Valid values are " > + "in the range of 0 to 1000. If this attribute is not " > + "provided, the value 500 will automatically be assigned."), > + MinValue(0), > + MaxValue(1000)] > + uint16 Priority = 500; > +}; > + > +[Provider("cmpi::Virt_FilterEntry")] > +class KVM_IPHeadersFilter : CIM_IPHeadersFilter > +{ > + [Description("This defines whether the Filter is used for input, " > + "output, or both input and output filtering. All values are " > + "used with respect to the interface for which the Filter " > + "applies. \"Not Applicable\" (0) is used when there is no " > + "direction applicable to the Filter. \"Input\" (1) is " > + "used when the Filter applies to packets that are inbound " > + "on the related interface. \"Output\" (2) is used when the " > + "Filter applies to packets that are outbound on the " > + "related interface. \"Both\" (3) is used to indicate that " > + "the direction is immaterial, e.g., to filter on a source " > + "subnet regardless of whether the flow is inbound or " > + "outbound."), > + ValueMap { "0", "1", "2", "3", "4" }, > + Values { "Not Applicable", "Input, Output", "Both", "Mirrored" }] > + uint16 Direction; > + > + [Description("The priority of the rule controls the order in which " > + "the rule will be, instantiated relative to other rules. " > + "Rules with lower value will be instantiated and therefore " > + "evaluated before rules with higher value. Valid values are " > + "in the range of 0 to 1000. If this attribute is not " > + "provided, the value 500 will automatically be assigned."), > + MinValue(0), > + MaxValue(1000)] > + uint16 Priority = 500; > +}; > diff --git a/schema/FilterEntry.registration b/schema/FilterEntry.registration > new file mode 100644 > --- /dev/null > +++ b/schema/FilterEntry.registration > @@ -0,0 +1,4 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_Hdr8021Filter root/virt Virt_FilterEntry Virt_FilterEntry instance > +KVM_IPHeadersFilter root/virt Virt_FilterEntry Virt_FilterEntry instance > diff --git a/schema/FilterList.mof b/schema/FilterList.mof > new file mode 100644 > --- /dev/null > +++ b/schema/FilterList.mof > @@ -0,0 +1,4 @@ > +// Copyright IBM Corp. 2011 > +class KVM_FilterList : CIM_FilterList > +{ > +}; > diff --git a/schema/FilterList.registration b/schema/FilterList.registration > new file mode 100755 > --- /dev/null > +++ b/schema/FilterList.registration > @@ -0,0 +1,3 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_FilterList root/virt Virt_FilterList Virt_FilterList instance > diff --git a/schema/HostedFilterList.mof b/schema/HostedFilterList.mof > new file mode 100644 > --- /dev/null > +++ b/schema/HostedFilterList.mof > @@ -0,0 +1,6 @@ > +// Copyright IBM Corp. 2011 > +[Association, > + Provider("cmpi::Virt_HostedFilterList")] > +class KVM_HostedFilterList : CIM_HostedFilterList > +{ > +}; > diff --git a/schema/HostedFilterList.registration b/schema/ > HostedFilterList.registration > new file mode 100644 > --- /dev/null > +++ b/schema/HostedFilterList.registration > @@ -0,0 +1,3 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_HostedFilterList root/virt Virt_HostedFilterList > Virt_HostedFilterList association > diff --git a/schema/NestedFilterList.mof b/schema/NestedFilterList.mof > new file mode 100644 > --- /dev/null > +++ b/schema/NestedFilterList.mof > @@ -0,0 +1,8 @@ > +// Copyright IBM Corp. 2011 > +[Association, > + Provider("cmpi::Virt_NestedFilterList")] > +class KVM_NestedFilterList : CIM_ConcreteDependency > +{ > + CIM_FilterList ref Antecedent; > + CIM_FilterList ref Dependent; > +}; > diff --git a/schema/NestedFilterList.registration b/schema/ > NestedFilterList.registration > new file mode 100644 > --- /dev/null > +++ b/schema/NestedFilterList.registration > @@ -0,0 +1,3 @@ > +# Copyright IBM Corp. 2011 > +# Classname Namespace ProviderName ProviderModule ProviderTypes > +KVM_NestedFilterList root/virt Virt_NestedFilterList > Virt_NestedFilterList association > diff --git a/src/Makefile.am b/src/Makefile.am > --- a/src/Makefile.am > +++ b/src/Makefile.am > @@ -23,7 +23,9 @@ > Virt_VSMigrationSettingData.h \ > Virt_ConsoleRedirectionService.h \ > Virt_ConsoleRedirectionServiceCapabilities.h \ > - Virt_KVMRedirectionSAP.h > + Virt_KVMRedirectionSAP.h \ > + Virt_FilterList.h \ > + Virt_FilterEntry.h > > XKUADD = $(top_builddir)/libxkutil/libxkutil.la > > @@ -77,7 +79,13 @@ > libVirt_ServiceAffectsElement.la \ > libVirt_HostedAccessPoint.la \ > libVirt_ServiceAccessBySAP.la \ > - libVirt_SAPAvailableForElement.la > + libVirt_SAPAvailableForElement.la \ > + libVirt_FilterList.la \ > + libVirt_FilterEntry.la \ > + libVirt_EntriesInFilterList.la \ > + libVirt_NestedFilterList.la \ > + libVirt_HostedFilterList.la \ > + libVirt_AppliedFilterList.la > > libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c > libVirt_ComputerSystem_la_DEPENDENCIES = > libVirt_VirtualSystemSnapshotService.la > @@ -243,3 +251,26 @@ > libVirt_SAPAvailableForElement_la_SOURCES = Virt_SAPAvailableForElement.c > libVirt_SAPAvailableForElement_la_LIBADD = -lVirt_ComputerSystem - > lVirt_KVMRedirectionSAP > > +libVirt_FilterEntry_la_DEPENDENCIES = libVirt_HostSystem.la > +libVirt_FilterEntry_la_SOURCES = Virt_FilterEntry.c > +libVirt_FilterEntry_la_LIBADD = -lVirt_HostSystem > + > +libVirt_FilterList_la_DEPENDENCIES = libVirt_HostSystem.la > +libVirt_FilterList_la_SOURCES = Virt_FilterList.c > +libVirt_FilterList_la_LIBADD = -lVirt_HostSystem > + > +libVirt_EntriesInFilterList_la_DEPENDENCIES = > libVirt_FilterEntry.la libVirt_FilterList.la > +libVirt_EntriesInFilterList_la_SOURCES = Virt_EntriesInFilterList.c > +libVirt_EntriesInFilterList_la_LIBADD = -lVirt_FilterEntry -lVirt_FilterList > + > +libVirt_NestedFilterList_la_DEPENDENCIES = libVirt_FilterList.la > +libVirt_NestedFilterList_la_SOURCES = Virt_NestedFilterList.c > +libVirt_NestedFilterList_la_LIBADD = -lVirt_FilterList > + > +libVirt_HostedFilterList_la_DEPENDENCIES = libVirt_HostSystem.la > libVirt_FilterList.la > +libVirt_HostedFilterList_la_SOURCES = Virt_HostedFilterList.c > +libVirt_HostedFilterList_la_LIBADD = -lVirt_HostSystem -lVirt_FilterList > + > +libVirt_AppliedFilterList_la_DEPENDENCIES = libVirt_Device.la > libVirt_FilterList.la > +libVirt_AppliedFilterList_la_SOURCES = Virt_AppliedFilterList.c > +libVirt_AppliedFilterList_la_LIBADD = -lVirt_Device -lVirt_FilterList > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_AppliedFilterList.c > @@ -0,0 +1,634 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "device_parsing.h" > +#include "acl_parsing.h" > +#include "misc_util.h" > +#include "cs_util.h" > + > +#include "Virt_Device.h" > +#include "Virt_FilterList.h" > + > +static const CMPIBroker *_BROKER; > + > +/* TODO: Port to libcmpiutil/args_util.c */ > +/** > + * Get a reference property of an instance > + * > + * @param inst The instance > + * @param prop The property name > + * @param reference A pointer to a CMPIObjectPath* that will be set > + * if successful > + * @returns > + * - CMPI_RC_OK on success > + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present > + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference > + * - CMPI_RC_OK otherwise > + */ > +static CMPIrc cu_get_ref_prop(const CMPIInstance *instance, > + const char *prop, > + CMPIObjectPath **reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIData value; > + > + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ > + value = CMGetProperty(instance, prop, &s); > + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) > + return CMPI_RC_ERR_NO_SUCH_PROPERTY; > + > + if ((value.type != CMPI_ref) || CMIsNullObject (value.value.ref)) > + return CMPI_RC_ERR_TYPE_MISMATCH; > + > + *reference = value.value.ref; > + > + return CMPI_RC_OK; > +} > + > +/* TODO: Port to libcmpiutil/args_util.c */ > +/** > + * Get a reference component of an object path > + * > + * @param _reference The reference > + * @param key The key name > + * @param reference A pointer to a CMPIObjectPath* that will be set > + * if successful > + * @returns > + * - CMPI_RC_OK on success > + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present > + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference > + * - CMPI_RC_OK otherwise > + */ > +static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference, > + const char *key, > + CMPIObjectPath **_reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIData value; > + > + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ > + value = CMGetKey(reference, key, &s); > + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) > + return CMPI_RC_ERR_NO_SUCH_PROPERTY; > + > + /* how to parse and object path? */ > + > + return CMPI_RC_OK; > +} > + > +/* TODO: Port to libxkutil/device_parsing.c */ > +static int update_device(virDomainPtr dom, > + struct virt_device *dev) > +{ > + char *xml = NULL; > + int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT | > + VIR_DOMAIN_DEVICE_MODIFY_CONFIG; > + int ret = 0; > + > + /** device_to_xml() is not exported, so this function needs > + * to be moved > + */ > + > + /* xml = device_to_xml(dev); */ > + > + if (xml == NULL) { > + CU_DEBUG("Failed to get XML for device '%s'", dev->id); > + goto out; > + } > + > + if (virDomainUpdateDeviceFlags(dom, xml, flags) != 0) { > + CU_DEBUG("Failed to dynamically update device:"); > + CU_DEBUG("%s", xml); > + goto out; > + } > + > + ret = 1; > + out: > + free(xml); > + > + return ret; > +} > + > +/* TODO: Port to libxkutil/device_parsing.c */ > +static int get_device_by_devid(virDomainPtr dom, > + const char *devid, > + int type, > + struct virt_device **dev) > +{ > + int i, ret = 0; > + struct virt_device *devices = NULL; > + int count = get_devices(dom, &devices, type); > + > + for (i = 0; i < count; i++) { > + if (STREQC(devid, devices[i].id)) { > + CU_DEBUG("Found '%s'", devices[i].id); > + > + *dev = virt_device_dup(&devices[i]); > + if (*dev != NULL) > + ret = 1; > + > + break; > + } > + } > + > + cleanup_virt_devices(&devices, count); > + > + return ret; > +} > + > +/** > + * given a filter, get the network interface > + */ > +static CMPIStatus list_to_net( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + const char *name = NULL; > + struct acl_filter *filter = NULL; > + virDomainPtr *doms = NULL; > + virConnectPtr conn = NULL; > + int i, j, dcount, ncount; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + /* validate filter */ > + get_filter_by_name(conn, name, &filter); > + if (filter == NULL) > + goto out; > + > + cleanup_filter(filter); > + > + /* get domains */ > + dcount = get_domain_list(conn, &doms); > + if (dcount < 0) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to get domain list"); > + goto out; > + } > + > + for (i = 0; i < dcount; i++) { > + /* get domain's network devices */ > + struct virt_device *devices = NULL; > + ncount = get_devices(doms[i], &devices, CIM_RES_TYPE_NET); > + > + CU_DEBUG("Found %u network devices", ncount); > + > + for (j = 0; j < ncount; j++) { > + struct net_device *ndev = &(devices[j].dev.net); > + > + CU_DEBUG("filterref = %s", ndev->filter_ref); > + > + if ((ndev->filter_ref != NULL) && > + STREQC(name, ndev->filter_ref)) { > + CU_DEBUG("Getting network device instance"); > + > + CMPIInstance *instance = NULL; > + char *device_id = > + get_fq_devid( > + (char *)virDomainGetName(doms [i]), > + devices[j].id); > + > + CU_DEBUG("Processing %s", device_id); > + > + s = get_device_by_name(_BROKER, > + reference, > + device_id, > + CIM_RES_TYPE_NET, > + &instance); > + > + if (instance != NULL) { > + CU_DEBUG("adding instance to list"); > + inst_list_add(list, instance); > + } > + } > + } > + > + cleanup_virt_devices(&devices, ncount); > + virDomainFree(doms[i]); > + } > + > + out: > + virConnectClose(conn); > + > + return s; > +} > + > +/** > + * given a network interface, find the filter lists > + */ > +static CMPIStatus net_to_list( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + const char *device_name = NULL; > + char *domain_name = NULL; > + char *net_name = NULL; > + virConnectPtr conn = NULL; > + virDomainPtr dom = NULL; > + int i; > + struct acl_filter *filter = NULL; > + > + CU_DEBUG("Reference %s", REF2STR(reference)); > + > + /* validate device > + * TODO: This may be redundant since it's necessary to get > + * the device structure in order to determine the filter_ref > + */ > + if (!STREQC(CLASSNAME(reference), "KVM_NetworkPort")) > + goto out; > + > + s = get_device_by_ref(_BROKER, reference, &instance); > + if ((s.rc != CMPI_RC_OK) || (instance == NULL)) > + goto out; > + > + if (cu_get_str_path(reference, "DeviceID", > + &device_name) != CMPI_RC_OK) { > + CU_DEBUG("Failed to get DeviceID"); > + goto out; > + } > + > + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { > + CU_DEBUG("Failed to parse devid"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + /* connect to domain */ > + dom = virDomainLookupByName(conn, domain_name); > + if (dom == NULL) { > + CU_DEBUG("Failed to connect to Domain '%s'", domain_name); > + goto out; > + } > + > + /* get domain's network devices */ > + struct virt_device *devices = NULL; > + int count = get_devices(dom, &devices, CIM_RES_TYPE_NET); > + > + CU_DEBUG("Found %u net devices on dom '%s'", count, domain_name); > + > + for (i = 0; i < count; i++) { > + struct net_device *ndev = &(devices[i].dev.net); > + > + CU_DEBUG("Checking net device '%s' for filterref", > + devices[i].id); > + > + if (STREQC(device_name, devices[i].id)) { > + CMPIInstance *instance = NULL; > + > + CU_DEBUG("Processing %s", ndev->filter_ref); > + > + get_filter_by_name(conn, ndev->filter_ref, &filter); > + if (filter == NULL) > + continue; > + > + s = instance_from_filter(_BROKER, > + info->context, > + reference, > + filter, > + &instance); > + > + if (instance != NULL) > + inst_list_add(list, instance); > + > + } > + > + } > + > + cleanup_virt_devices(&devices, count); > + out: > + > + free(domain_name); > + free((char *)device_name); > + free(net_name); > + > + virDomainFree(dom); > + virConnectClose(conn); > + > + return s; > +} > + > +LIBVIRT_CIM_DEFAULT_MAKEREF() > + > +static char *antecedent[] = { > + "KVM_FilterList", > + NULL > +}; > + > +static char *dependent[] = { > + "KVM_NetworkPort", > + NULL > +}; > + > +static char *assoc_class_name[] = { > + "KVM_AppliedFilterList", > + NULL > +}; > + > +static struct std_assoc _list_to_net = { > + .source_class = (char **)&antecedent, > + .source_prop = "Antecedent", > + > + .target_class = (char **)&dependent, > + .target_prop = "Dependent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = list_to_net, > + .make_ref = make_ref > +}; > + > +static struct std_assoc _net_to_list = { > + .source_class = (char **)&dependent, > + .source_prop = "Dependent", > + > + .target_class = (char **)&antecedent, > + .target_prop = "Antecedent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = net_to_list, > + .make_ref = make_ref > +}; > + > +static struct std_assoc *handlers[] = { > + &_list_to_net, > + &_net_to_list, > + NULL > +}; > + > +STDA_AssocMIStub(, > + Virt_AppliedFilterList, > + _BROKER, > + libvirt_cim_init(), > + handlers); > + > +DEFAULT_GI(); > +DEFAULT_EIN(); > +DEFAULT_EI(); > + > +static CMPIStatus CreateInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const CMPIInstance *instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIObjectPath *antecedent = NULL; > + const char *filter_name = NULL; > + struct acl_filter *filter = NULL; > + CMPIObjectPath *dependent = NULL; > + char *domain_name = NULL; > + const char *device_name = NULL; > + char *net_name = NULL; > + struct virt_device *device = NULL; > + virConnectPtr conn = NULL; > + virDomainPtr dom = NULL; > + > + if (cu_get_ref_prop(instance, "Antecedent", > + &antecedent) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name", &filter_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, filter_name, &filter); > + if (filter == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Antecedent.Name object does not exist"); > + goto out; > + } > + > + if (cu_get_ref_prop(instance, "Dependent", > + &dependent) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "DeviceID", > + &device_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent.DeviceID property"); > + goto out; > + } > + > + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { > + CU_DEBUG("Failed to parse devid"); > + goto out; > + } > + > + dom = virDomainLookupByName(conn, domain_name); > + if (dom == NULL) { > + CU_DEBUG("Failed to connect to Domain '%s'", domain_name); > + goto out; > + } > + > + get_device_by_devid(dom, net_name, CIM_RES_TYPE_NET, &device); > + if (device == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Dependent.Name object does not exist"); > + goto out; > + } > + > + free(device->dev.net.filter_ref); > + device->dev.net.filter_ref = strdup(filter_name); > + > + if (update_device(dom, device) == 0) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to update device"); > + goto out; > + } > + > + out: > + free((char *)filter_name); > + free(domain_name); > + free((char *)device_name); > + free(net_name); > + > + cleanup_filter(filter); > + cleanup_virt_device(device); > + > + virDomainFree(dom); > + virConnectClose(conn); > + > + return s; > +} > + > +static CMPIStatus DeleteInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIObjectPath *antecedent = NULL; > + const char *filter_name = NULL; > + struct acl_filter *filter = NULL; > + CMPIObjectPath *dependent = NULL; > + char *domain_name = NULL; > + const char *device_name = NULL; > + char *net_name = NULL; > + struct virt_device *device = NULL; > + virConnectPtr conn = NULL; > + virDomainPtr dom = NULL; > + > + if (cu_get_ref_path(reference, "Antecedent", > + &antecedent) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name", &filter_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, filter_name, &filter); > + if (filter == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Antecedent.Name object does not exist"); > + goto out; > + } > + > + if (cu_get_ref_path(reference, "Dependent", > + &dependent) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "DeviceID", > + &device_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent.DeviceID property"); > + goto out; > + } > + > + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { > + CU_DEBUG("Failed to parse devid"); > + goto out; > + } > + > + dom = virDomainLookupByName(conn, domain_name); > + if (dom == NULL) { > + CU_DEBUG("Failed to connect to Domain '%s'", domain_name); > + goto out; > + } > + > + get_device_by_devid(dom, net_name, CIM_RES_TYPE_NET, &device); > + if (device == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Dependent.Name object does not exist"); > + goto out; > + } > + > + free(device->dev.net.filter_ref); > + device->dev.net.filter_ref = NULL; > + > + if (update_device(dom, device) == 0) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to update device"); > + goto out; > + } > + > + out: > + free((char *)filter_name); > + free(domain_name); > + free((char *)device_name); > + free(net_name); > + > + cleanup_filter(filter); > + cleanup_virt_device(device); > + > + virDomainFree(dom); > + virConnectClose(conn); > + > + return s; > +} > + > +DEFAULT_MI(); > +DEFAULT_EQ(); > +DEFAULT_INST_CLEANUP(); > + > +STD_InstanceMIStub(, > + Virt_AppliedFilterEntry, > + _BROKER, > + libvirt_cim_init()); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_EntriesInFilterList.c b/src/Virt_EntriesInFilterList.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_EntriesInFilterList.c > @@ -0,0 +1,219 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > + > +#include > + > +#include "acl_parsing.h" > +#include "misc_util.h" > +#include "Virt_FilterList.h" > +#include "Virt_FilterEntry.h" > + > +static const CMPIBroker *_BROKER; > + > +/** > + * given a filter, find all *direct* children > + */ > +static CMPIStatus list_to_rule( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + struct acl_filter *filter = NULL; > + const char *name = NULL; > + virConnectPtr conn = NULL; > + int i; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, name, &filter); > + if (filter == NULL) { > + CU_DEBUG("Filter '%s' does not exist", name); > + goto out; > + } > + > + for (i = 0; i < filter->rule_ct; i++) { > + CU_DEBUG("Processing %s", filter->rules[i]->name); > + > + s = instance_from_rule(_BROKER, > + info->context, > + reference, > + filter->rules[i], > + &instance); > + > + if (instance != NULL) { > + inst_list_add(list, instance); > + instance = NULL; > + } > + } > + > + cleanup_filter(filter); > + > + out: > + virConnectClose(conn); > + > + return s; > +} > + > +/** > + * given a rule, fine the parent filter > + */ > +static CMPIStatus rule_to_list( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct acl_filter *filters = NULL; > + CMPIInstance *instance = NULL; > + const char *name = NULL; > + virConnectPtr conn = NULL; > + int count = 0; > + int i, j = 0; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + count = get_filters(conn, &filters); > + if (filters == NULL) > + goto out; > + > + /* return the filter that contains the rule */ > + for (i = 0; i < count; i++) { > + for (j = 0; j < filters[i].rule_ct; j++) { > + if (STREQC(name, filters[i].rules[j]->name)) { > + CU_DEBUG("Processing %s,",filters [i].name); > + > + s = instance_from_filter(_BROKER, > + info->context, > + reference, > + &filters[i], > + &instance); > + > + if (instance != NULL) { > + inst_list_add(list, instance); > + instance = NULL; > + } > + > + } > + } > + } > + > + out: > + cleanup_filters(&filters, count); > + virConnectClose(conn); > + > + return s; > +} > + > +LIBVIRT_CIM_DEFAULT_MAKEREF() > + > +static char *group_component[] = { > + "KVM_FilterList", > + NULL > +}; > + > +static char *part_component[] = { > + "KVM_Hdr8021Filter", > + "KVM_IPHeadersFilter", > + NULL > +}; > + > +static char *assoc_class_name[] = { > + "KVM_EntriesInFilterList", > + NULL > +}; > + > +static struct std_assoc _list_to_rule = { > + .source_class = (char **)&group_component, > + .source_prop = "GroupComponent", > + > + .target_class = (char **)&part_component, > + .target_prop = "PartComponent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = list_to_rule, > + .make_ref = make_ref > +}; > + > +static struct std_assoc _rule_to_list = { > + .source_class = (char **)&part_component, > + .source_prop = "PartComponent", > + > + .target_class = (char **)&group_component, > + .target_prop = "GroupComponent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = rule_to_list, > + .make_ref = make_ref > +}; > + > +static struct std_assoc *handlers[] = { > + &_list_to_rule, > + &_rule_to_list, > + NULL > +}; > + > +STDA_AssocMIStub(, > + Virt_EntriesInFilterList, > + _BROKER, > + libvirt_cim_init(), > + handlers); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_FilterEntry.c > @@ -0,0 +1,678 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > + > +#include > + > +#include "acl_parsing.h" > +#include "misc_util.h" > +#include "xmlgen.h" > + > +#include "Virt_FilterEntry.h" > +#include "Virt_HostSystem.h" > + > +const static CMPIBroker *_BROKER; > + > +static bool is_mac_rule(int type) > +{ > + if (type == MAC_RULE || type == ARP_RULE) > + return 1; > + > + return 0; > +} > + > +static bool is_ip_rule(int type) > +{ > + if (type == IP_RULE || type == TCP_RULE || type == ICMP_RULE || > + type == IGMP_RULE) > + return 1; > + > + return 0; > +} > + > +static int octets_from_mac(const char * s, unsigned int *buffer, > + unsigned int size) > +{ > + unsigned int _buffer[6]; > + unsigned int i, n = 0; > + > + if ((s == 0) || (s[0] == '\0') || (buffer == NULL) || (size < 6)) > + return 0; > + > + if (s[0] == '$') { > + for (i = 0; (s[i] != '\0') && (i < size); i++) > + buffer[i] = s[i]; > + > + n = i; > + } > + else { > + n = sscanf(s, "%x:%x:%x:%x:%x:%x", > + &_buffer[0], &_buffer[1], &_buffer[2], > + &_buffer[3], &_buffer[4], &_buffer[5]); > + > + for (i = 0; (i < n) && (i < size); i++) > + buffer[i] = _buffer[i]; > + } > + > + return n; > +} > + > +static int octets_from_ip(const char * s, unsigned int *buffer, > + unsigned int size) > +{ > + struct in6_addr addr; > + unsigned int family = 0; > + unsigned int i, n = 0; > + > + if ((s == 0) || (s[0] == '\0') || (buffer == NULL) || (size < 4)) > + return 0; > + > + if (s[0] == '$') { > + for (i = 0; (s[i] != '\0') && (i < size); i++) > + buffer[i] = s[i]; > + > + n = i; > + } > + else { > + family = strstr(s, ":") ? AF_INET6 : AF_INET; > + n = family == AF_INET6 ? 16 : 4; > + > + if (size < n) > + return 0; > + > + if (inet_pton(family, s, &addr)) { > + n = n <= size ? n : size; > + for (i = 0; i < n; i++) > + buffer[i] = addr.s6_addr[i]; > + } > + } > + > + return n; > +} > + > +static CMPIArray *octets_to_cmpi(const CMPIBroker *broker, unsigned > int *bytes, int size) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIArray *array = NULL; > + int i; > + > + if (bytes == 0 || size == 0) > + return array; > + > + array = CMNewArray(broker, size, CMPI_uint8, &s); > + > + for (i = 0; i < size; i++) { > + s = CMSetArrayElementAt(array, i, > + (CMPIValue*)&bytes[i], CMPI_uint8); > + } > + > + return array; > +} > + > +static int convert_direction(const char *s) > +{ > + enum {NOT_APPLICABLE, INPUT, OUTPUT, BOTH} direction = > NOT_APPLICABLE; > + > + if (s != NULL) { > + if (STREQC(s, "in")) > + direction = INPUT; > + else if (STREQC(s, "out")) > + direction = OUTPUT; > + else if (STREQC(s, "inout")) > + direction = BOTH; > + } > + > + return direction; > +} > + > +static int convert_priority(const char *s) > +{ > + int priority = 0; > + > + if (s != NULL) { > + priority = atoi(s); > + } > + > + return priority; > +} > + > +static CMPIInstance *convert_mac_rule_to_instance( > + struct acl_rule *rule, > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIStatus *s) > +{ > + CMPIInstance *inst = NULL; > + const char *sys_name = NULL; > + const char *sys_ccname = NULL; > + int direction, priority = 0; > + unsigned int bytes[48]; > + unsigned int size = 0; > + CMPIArray *array = NULL; > + > + inst = get_typed_instance(broker, > + CLASSNAME(reference), > + "Hdr8021Filter", > + NAMESPACE(reference)); > + if (inst == NULL) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get 8021 filter instance"); > + > + goto out; > + } > + > + *s = get_host_system_properties(&sys_name, > + &sys_ccname, > + reference, > + broker, > + context); > + > + if (s->rc != CMPI_RC_OK) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get host attributes"); > + goto out; > + } > + > + CMSetProperty(inst, "SystemName", sys_name, CMPI_chars); > + CMSetProperty(inst, "SystemCreationClassName", sys_ccname, > CMPI_chars); > + CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars); > + > + direction = convert_direction(rule->direction); > + CMSetProperty(inst, "Direction", (CMPIValue *)&direction, > CMPI_uint16); > + > + priority = convert_priority(rule->priority); > + CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_mac(rule->var.mac.srcmacaddr, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcMACAddr8021", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_mac(rule->var.mac.srcmacmask, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcMACMask8021", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_mac(rule->var.mac.dstmacaddr, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestMACAddr8021", (CMPIValue *) > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_mac(rule->var.mac.dstmacmask, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestMACMask8021", (CMPIValue *) > + (CMPIValue *)&array, CMPI_uint8A); > + > + out: > + return inst; > +} > + > +static CMPIInstance *convert_ip_rule_to_instance( > + struct acl_rule *rule, > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIStatus *s) > +{ > + CMPIInstance *inst = NULL; > + const char *sys_name = NULL; > + const char *sys_ccname = NULL; > + int direction, priority = 0; > + unsigned int bytes[48]; > + unsigned int size = 0; > + unsigned int n = 0; > + CMPIArray *array = NULL; > + > + inst = get_typed_instance(broker, > + CLASSNAME(reference), > + "IPHeadersFilter", > + NAMESPACE(reference)); > + if (inst == NULL) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get ip headers filter instance"); > + goto out; > + } > + > + *s = get_host_system_properties(&sys_name, > + &sys_ccname, > + reference, > + broker, > + context); > + > + if (s->rc != CMPI_RC_OK) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get host attributes"); > + goto out; > + } > + > + CMSetProperty(inst, "SystemName", sys_name, CMPI_chars); > + CMSetProperty(inst, "SystemCreationClassName", sys_ccname, > CMPI_chars); > + CMSetProperty(inst, "Name", (CMPIValue *)rule->name, CMPI_chars); > + > + direction = convert_direction(rule->direction); > + CMSetProperty(inst, "Direction", (CMPIValue *)&direction, > CMPI_uint16); > + > + priority = convert_priority(rule->priority); > + CMSetProperty(inst, "Priority", (CMPIValue *)&priority, CMPI_uint16); > + > + if (strstr(rule->protocol_id, "v6")) > + n = 6; > + else > + n = 4; > + > + CMSetProperty(inst, "HdrIPVersion",(CMPIValue *)&n, CMPI_uint8); > + > + if (rule->var.tcp.srcipfrom && rule->var.tcp.srcipto) { > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.srcipfrom, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcAddress", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.srcipto, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcAddressEndOfRange", > + (CMPIValue *)&array, CMPI_uint8A); > + } else { > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.srcmacaddr, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcAddress", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.srcipmask, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrSrcMask", > + (CMPIValue *)&array, CMPI_uint8A); > + } > + > + if (rule->var.tcp.dstipfrom && rule->var.tcp.dstipto) { > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.dstipfrom, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestAddress", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.dstipto, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestAddressEndOfRange", > + (CMPIValue *)&array, CMPI_uint8A); > + } else { > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.dstipaddr, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestAddress", > + (CMPIValue *)&array, CMPI_uint8A); > + > + memset(bytes, 0, sizeof(bytes)); > + size = octets_from_ip(rule->var.tcp.dstipmask, > + bytes, sizeof(bytes)); > + > + array = octets_to_cmpi(broker, bytes, size); > + if (array != NULL) > + CMSetProperty(inst, "HdrDestMask", > + (CMPIValue *)&array, CMPI_uint8A); > + } > + > + if ((rule->type == IP_RULE) || (rule->type == TCP_RULE)) { > + if (rule->var.tcp.srcportstart) { > + n = atoi(rule->var.tcp.srcportstart); > + CMSetProperty(inst, "HdrSrcPortStart", > + (CMPIValue *)&n, CMPI_uint16); > + } > + > + if (rule->var.tcp.srcportend) { > + n = atoi(rule->var.tcp.srcportend); > + CMSetProperty(inst, "HdrSrcPortEnd", > + (CMPIValue *)&n, CMPI_uint16); > + } > + > + if (rule->var.tcp.dstportstart) { > + n = atoi(rule->var.tcp.dstportstart); > + CMSetProperty(inst, "HdrDestPortStart", > + (CMPIValue *)&n, CMPI_uint16); > + } > + > + if (rule->var.tcp.dstportend) { > + n = atoi(rule->var.tcp.dstportend); > + CMSetProperty(inst, "HdrDestPortEnd", > + (CMPIValue *)&n, CMPI_uint16); > + } > + } > + > + out: > + return inst; > +} > + > +static CMPIInstance *convert_rule_to_instance( > + struct acl_rule *rule, > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIStatus *s) > +{ > + CMPIInstance *instance = NULL; > + > + if (rule == NULL) > + return NULL; > + > + if(is_mac_rule(rule->type)) { > + instance = convert_mac_rule_to_instance(rule, > + broker, > + context, > + reference, > + s); > + } > + else if(is_ip_rule(rule->type)) { > + instance = convert_ip_rule_to_instance(rule, > + broker, > + context, > + reference, > + s); > + } > + > + return instance; > +} > + > +CMPIStatus enum_filter_rules( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct inst_list *list) > +{ > + virConnectPtr conn = NULL; > + struct acl_filter *filters = NULL; > + int i, j, count = 0; > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + enum {NONE, MAC, IP} class_type = NONE; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (STREQC(CLASSNAME(reference), "KVM_Hdr8021Filter")) > + class_type = MAC; > + else if (STREQC(CLASSNAME(reference), "KVM_IPHeadersFilter")) > + class_type = IP; > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + count = get_filters(conn, &filters); > + > + for (i = 0; i < count; i++) { > + for (j = 0; j < filters[i].rule_ct; j++) { > + CMPIInstance *instance = NULL; > + > + if (((class_type == NONE) || > + (class_type == MAC)) && > + is_mac_rule(filters[i].rules[j]->type)) { > + instance = convert_mac_rule_to_instance( > + filters[i].rules[j], > + broker, > + context, > + reference, > + &s); > + } > + else if (((class_type == NONE) || > + (class_type == IP)) && > + is_ip_rule(filters[i].rules[j]->type)) { > + instance = convert_ip_rule_to_instance( > + filters[i].rules[j], > + broker, > + context, > + reference, > + &s); > + } > + else > + CU_DEBUG("Unrecognized rule type %u", > + filters[i].rules[j]->type); > + > + if (instance != NULL) > + inst_list_add(list, instance); > + } > + > + } > + > + out: > + cleanup_filters(&filters, count); > + virConnectClose(conn); > + > + return s; > +} > + > +CMPIStatus get_rule_by_ref( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIInstance **instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct acl_filter *filter = NULL; > + struct acl_rule *rule = NULL; > + const char *name = NULL; > + char *filter_name = NULL; > + int rule_index; > + virConnectPtr conn = NULL; > + int i; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + if (parse_rule_id(name, &filter_name, &rule_index) == 0) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Could not parse filter name"); > + goto out; > + } > + > + CU_DEBUG("Filter name = %s, rule index = %u", filter_name, > rule_index); > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, filter_name, &filter); > + if (filter == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Could not retrieve filter"); > + goto out; > + } > + > + for (i = 0; i < filter->rule_ct; i++) { > + if (rule_index == i) { > + rule = filter->rules[i]; > + break; > + } > + } > + > + if (rule == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Could not retrieve rule"); > + goto out; > + } > + > + *instance = convert_rule_to_instance(rule, > + broker, > + context, > + reference, > + &s); > + out: > + free(filter_name); > + cleanup_filter(filter); > + virConnectClose(conn); > + > + return s; > +} > + > +CMPIStatus instance_from_rule( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct acl_rule *rule, > + CMPIInstance **instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + > + *instance = convert_rule_to_instance(rule, > + broker, > + context, > + reference, > + &s); > + > + return s; > + > +} > + > +static CMPIStatus GetInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const char **properties) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + > + s = get_rule_by_ref(_BROKER, context, reference, &instance); > + > + if (instance != NULL) > + CMReturnInstance(results, instance); > + > + return s; > +} > + > +static CMPIStatus EnumInstanceNames( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct inst_list list; > + > + inst_list_init(&list); > + > + s = enum_filter_rules(_BROKER, context, reference, &list); > + > + cu_return_instance_names(results, &list); > + > + inst_list_free(&list); > + > + return s; > +} > + > +static CMPIStatus EnumInstances( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const char **properties) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct inst_list list; > + > + inst_list_init(&list); > + > + s = enum_filter_rules(_BROKER, context, reference, &list); > + > + cu_return_instances(results, &list); > + > + return s; > +} > + > +DEFAULT_CI(); > +DEFAULT_MI(); > +DEFAULT_DI(); > +DEFAULT_EQ(); > +DEFAULT_INST_CLEANUP(); > + > +STD_InstanceMIStub(, > + Virt_FilterEntry, > + _BROKER, > + libvirt_cim_init()); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_FilterEntry.h b/src/Virt_FilterEntry.h > new file mode 100644 > --- /dev/null > +++ b/src/Virt_FilterEntry.h > @@ -0,0 +1,85 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#ifndef __VIRT_FILTERENTRY_H > +#define __VIRT_FILTERENTRY_H > + > +/** > + * Return a list of filter instances > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying the parent filter > + * @param list A pointer to an array of CMPIInstance objects > + * (called inits before and frees after) > + */ > +CMPIStatus enum_filter_rules( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct inst_list *list); > + > +/** > + * Return a single filter instance by reference > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying the parent filter > + * @param list A pointer to a CMPIInstance * > + */ > +CMPIStatus get_rule_by_ref( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIInstance **instance); > + > +/** > + * Get an instance representing a filter rule > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying the parent filter > + * @param rule A pointer to a filter rule > + * @param instance A pointer to a CMPIInstance * > + */ > +CMPIStatus instance_from_rule( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct acl_rule *rule, > + CMPIInstance **instance); > + > +#endif > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_FilterList.c > @@ -0,0 +1,252 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > + > +#include "acl_parsing.h" > +#include "misc_util.h" > +#include "xmlgen.h" > + > +#include "Virt_FilterList.h" > +#include "Virt_HostSystem.h" > + > +const static CMPIBroker *_BROKER; > + > +static CMPIInstance *convert_filter_to_instance( > + struct acl_filter *filter, > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIStatus *s) > +{ > + CMPIInstance *inst = NULL; > + const char *sys_name = NULL; > + const char *sys_ccname = NULL; > + int direction = 0; > + > + inst = get_typed_instance(broker, > + CLASSNAME(reference), > + "FilterList", > + NAMESPACE(reference)); > + if (inst == NULL) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get filter list instance"); > + goto out; > + } > + > + *s = get_host_system_properties(&sys_name, > + &sys_ccname, > + reference, > + broker, > + context); > + > + if (s->rc != CMPI_RC_OK) { > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get host attributes"); > + goto out; > + } > + > + CMSetProperty(inst, "SystemName", sys_name, CMPI_chars); > + CMSetProperty(inst, "SystemCreationClassName", sys_ccname, > CMPI_chars); > + CMSetProperty(inst, "Name", (CMPIValue *)filter->name, CMPI_chars); > + CMSetProperty(inst, "InstanceID", (CMPIValue *)filter->uuid, > + CMPI_chars); > + CMSetProperty(inst, "Direction", (CMPIValue *)&direction, > CMPI_uint16); > + > + out: > + return inst; > +} > + > +CMPIStatus enum_filter_lists(const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct inst_list *list) > +{ > + virConnectPtr conn = NULL; > + struct acl_filter *filters = NULL; > + int i, count = 0; > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + > + conn = connect_by_classname(broker, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + count = get_filters(conn, &filters); > + > + CU_DEBUG("found %d filters", count); > + > + for (i = 0; i < count; i++) { > + instance = convert_filter_to_instance(&filters[i], > + broker, > + context, > + reference, > + &s); > + > + if (instance != NULL) > + inst_list_add(list, instance); > + } > + > + out: > + cleanup_filters(&filters, count); > + virConnectClose(conn); > + > + return s; > +} > + > +CMPIStatus get_filter_by_ref(const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + CMPIInstance **instance) > +{ > + virConnectPtr conn = NULL; > + struct acl_filter *filter = NULL; > + > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + const char *name = NULL; > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(broker, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, name, &filter); > + if (filter == NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "No such instance (Name)"); > + goto out; > + } > + > + s = instance_from_filter(broker, context, reference, > filter, instance); > + > + out: > + cleanup_filter(filter); > + virConnectClose(conn); > + > + return s; > +} > + > +CMPIStatus instance_from_filter(const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct acl_filter *filter, > + CMPIInstance **instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + > + *instance = convert_filter_to_instance(filter, broker, context, > + reference, &s); > + > + return s; > +} > + > +static CMPIStatus GetInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const char **properties) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + > + s = get_filter_by_ref(_BROKER, context, reference, &instance); > + > + if (instance != NULL) > + CMReturnInstance(results, instance); > + > + return s; > +} > + > +static CMPIStatus EnumInstanceNames( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct inst_list list; > + > + inst_list_init(&list); > + > + s = enum_filter_lists(_BROKER, context, reference, &list); > + > + cu_return_instance_names(results, &list); > + > + inst_list_free(&list); > + > + return s; > +} > + > +static CMPIStatus EnumInstances( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const char **properties) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct inst_list list; > + > + inst_list_init(&list); > + > + s = enum_filter_lists(_BROKER, context, reference, &list); > + > + cu_return_instances(results, &list); > + > + inst_list_free(&list); > + > + return s; > +} > + > +DEFAULT_CI(); > +DEFAULT_MI(); > +DEFAULT_DI(); > +DEFAULT_EQ(); > +DEFAULT_INST_CLEANUP(); > + > +STD_InstanceMIStub(, > + Virt_FilterList, > + _BROKER, > + libvirt_cim_init()); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_FilterList.h b/src/Virt_FilterList.h > new file mode 100644 > --- /dev/null > +++ b/src/Virt_FilterList.h > @@ -0,0 +1,87 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#ifndef __VIRT_FILTERLIST_H > +#define __VIRT_FILTERLIST_H > + > +#include "acl_parsing.h" > + > +/** > + * Return a list of filter lists > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying a specific filter > + * @param list A pointer to an array of CMPIInstance objects > + * (caller inits before and frees after) > + */ > +CMPIStatus enum_filter_lists( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct inst_list *list); > + > +/** > + * Return a filter instance by reference > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying a specific filter > + * @param instance A pointer to a CMPIInstance * to place the new instance > + */ > +CMPIStatus get_filter_by_ref( > + const CMPIBroker *broker, > + const CMPIContext *contest, > + const CMPIObjectPath *reference, > + CMPIInstance **instance); > + > +/** > + * Return a list of filter lists > + * > + * @param broker A pointer to the CIM broker > + * @param context A pointer to an operation context > + * @param reference Defines the libvirt connection to use (via class name > + * prefix), but can also be used to scope the results by > + * specifying a specific filter > + * @param filter A pointer to a acl_filter > + * @param instance A pointer to a CMPIInstance * to place the new instance > + */ > +CMPIStatus instance_from_filter( > + const CMPIBroker *broker, > + const CMPIContext *context, > + const CMPIObjectPath *reference, > + struct acl_filter *filter, > + CMPIInstance **instance); > + > +#endif > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_HostedFilterList.c b/src/Virt_HostedFilterList.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_HostedFilterList.c > @@ -0,0 +1,144 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > + > +#include "misc_util.h" > +#include "Virt_HostSystem.h" > +#include "Virt_FilterList.h" > + > +static const CMPIBroker *_BROKER; > + > +static CMPIStatus host_to_list( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + > + /* validate host reference */ > + s = get_host(_BROKER, info->context, reference, &instance, false); > + if (s.rc != CMPI_RC_OK) > + goto out; > + > + s = cu_validate_ref(_BROKER, reference, instance); > + if (s.rc != CMPI_RC_OK) > + goto out; > + > + s = enum_filter_lists(_BROKER, info->context, reference, list); > + > + out: > + return s; > +} > + > +static CMPIStatus list_to_host( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *instance = NULL; > + > + /* validate filter reference */ > + s = get_filter_by_ref(_BROKER, info->context, reference, &instance); > + if (s.rc != CMPI_RC_OK) > + goto out; > + > + s = get_host(_BROKER, info->context, reference, &instance, false); > + if (s.rc != CMPI_RC_OK) > + goto out; > + > + if (instance != NULL) > + inst_list_add(list, instance); > + > + out: > + return s; > +} > + > +LIBVIRT_CIM_DEFAULT_MAKEREF() > + > +static char *antecedent[] = { > + "KVM_HostSystem", > + NULL > +}; > + > +static char *dependent[] = { > + "KVM_FilterList", > + NULL > +}; > + > +static char *assoc_class_name[] = { > + "KVM_HostedFilterList", > + NULL > +}; > + > +static struct std_assoc _host_to_list = { > + .source_class = (char **)&antecedent, > + .source_prop = "Antecedent", > + > + .target_class = (char **)&dependent, > + .target_prop = "Dependent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = host_to_list, > + .make_ref = make_ref > +}; > + > +static struct std_assoc _list_to_host = { > + .source_class = (char **)&dependent, > + .source_prop = "Dependent", > + > + .target_class = (char **)&antecedent, > + .target_prop = "Antecedent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = list_to_host, > + .make_ref = make_ref > +}; > + > +static struct std_assoc *handlers[] = { > + &_host_to_list, > + &_list_to_host, > + NULL > +}; > + > +STDA_AssocMIStub(, > + Virt_HostedFilterList, > + _BROKER, > + libvirt_cim_init(), > + handlers); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/src/Virt_NestedFilterList.c b/src/Virt_NestedFilterList.c > new file mode 100644 > --- /dev/null > +++ b/src/Virt_NestedFilterList.c > @@ -0,0 +1,235 @@ > +/* > + * Copyright IBM Corp. 2011 > + * > + * Authors: > + * Chip Vincent > + * > + * This library is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * This library is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with this library; if not, write to the Free Software > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +/* FIXME: This seems to be needed to compile STREQC, which suggests > + * libcmpiutil.h needs to add the include since the marco is defined there. > + */ > +#include > +#include > + > +#include "acl_parsing.h" > +#include "misc_util.h" > +#include "Virt_FilterList.h" > + > +static const CMPIBroker *_BROKER; > + > +/** > + * given a filter, find all *direct* filter_refs > + */ > +static CMPIStatus parent_to_child( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct acl_filter *parent_filter = NULL; > + struct acl_filter *child_filter = NULL; > + CMPIInstance *instance = NULL; > + const char * name = NULL; > + virConnectPtr conn = NULL; > + int i; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, name, &parent_filter); > + if (parent_filter == NULL) > + goto out; > + > + for (i = 0; i < parent_filter->ref_ct; i++) { > + get_filter_by_name(conn, parent_filter->refs[i], > + &child_filter); > + if (child_filter == NULL) > + continue; > + > + CU_DEBUG("Processing %s,", child_filter->name); > + > + s = instance_from_filter(_BROKER, > + info->context, > + reference, > + child_filter, > + &instance); > + > + if (instance != NULL) { > + CU_DEBUG("Adding instance to inst_list"); > + inst_list_add(list, instance); > + } > + > + cleanup_filter(child_filter); > + > + child_filter = NULL; > + instance = NULL; > + } > + > + cleanup_filter(parent_filter); > + > + out: > + virConnectClose(conn); > + > + return s; > +} > + > +/** > + * given a filter, find all the other filters that reference it > + */ > +static CMPIStatus child_to_parent( > + const CMPIObjectPath *reference, > + struct std_assoc_info *info, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + struct acl_filter *_list = NULL; > + CMPIInstance *instance = NULL; > + const char *name = NULL; > + virConnectPtr conn = NULL; > + int count, i, j; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + if (conn == NULL) > + goto out; > + > + /* TODO: Ensure the referenced filter exists */ > + > + count = get_filters(conn, &_list); > + if (_list == NULL) > + goto out; > + > + /* return any filter that has name in refs */ > + for (i = 0; i < count; i++) { > + for (j = 0; j < _list[i].ref_ct; j++) { > + if (STREQC(name, _list[i].refs[j])) { > + CU_DEBUG("Processing %s,", _list [i].name); > + > + s = instance_from_filter(_BROKER, > + info->context, > + reference, > + &_list[i], > + &instance); > + > + if (instance != NULL) > + inst_list_add(list, instance); > + > + instance = NULL; > + } > + > + } > + > + cleanup_filter(&_list[i]); > + } > + > + free(_list); > + > + out: > + virConnectClose(conn); > + > + return s; > +} > + > +LIBVIRT_CIM_DEFAULT_MAKEREF() > + > +static char *antecedent[] = { > + "KVM_FilterList", > + NULL > +}; > + > +static char *dependent[] = { > + "KVM_FilterList", > + NULL > +}; > + > +static char *assoc_class_name[] = { > + "KVM_NestedFilterList", > + NULL > +}; > + > +static struct std_assoc _list_to_filter_ref = { > + .source_class = (char **)&antecedent, > + .source_prop = "Antecedent", > + > + .target_class = (char **)&dependent, > + .target_prop = "Dependent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = parent_to_child, > + .make_ref = make_ref > +}; > + > +static struct std_assoc _filter_ref_to_list = { > + .source_class = (char **)&dependent, > + .source_prop = "Dependent", > + > + .target_class = (char **)&antecedent, > + .target_prop = "Antecedent", > + > + .assoc_class = (char **)&assoc_class_name, > + > + .handler = child_to_parent, > + .make_ref = make_ref > +}; > + > +static struct std_assoc *handlers[] = { > + &_list_to_filter_ref, > + &_filter_ref_to_list, > + NULL > +}; > + > +STDA_AssocMIStub(, > + Virt_NestedFilterList, > + _BROKER, > + libvirt_cim_init(), > + handlers); > + > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From cvincent at linux.vnet.ibm.com Wed Jun 8 14:09:59 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 10:09:59 -0400 Subject: [Libvirt-cim] Release of libcmpiutil-0.5.6 Message-ID: <4DEF82B7.6050909@linux.vnet.ibm.com> The new release is available at: ftp://libvirt.org/libvirt-cim/libcmpiutil-0.5.6.tar.gz libcmpiutil-0.5.6 * Add libtool version info (Eduardo Lima) * Proper definition of LEX_OUTPUT_ROOT (Eduardo Lima) * Fix file permissions (Eduardo Lima) * Remove trailing whitespaces (Eduardo Lima) * Update .hgignore (Eduardo Lima) * Configure tweaks (Eduardo Lima) * Cleanup includes (Eduardo Lima) * Remove warnings (Eduardo Lima) -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 8 14:40:28 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 10:40:28 -0400 Subject: [Libvirt-cim] [PATCH] Update RPM spec file to match Fedora In-Reply-To: References: Message-ID: <4DEF89DC.5070804@linux.vnet.ibm.com> +1. Pushed. On 05/31/2011 04:41 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306874177 10800 > # Node ID da242202e48891c6003c21817ecf67844b91b1a6 > # Parent f934d53d40ef2521b6b8242c06a58db84f85f71f > Update RPM spec file to match Fedora > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in > --- a/libvirt-cim.spec.in > +++ b/libvirt-cim.spec.in > @@ -10,11 +10,13 @@ > BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root > URL: http://libvirt.org/CIM/ > Requires: libxml2>= 2.6.0 > -Requires: libvirt>= 0.6.3 > +Requires: libvirt>= 0.6.4 > Requires: unzip > +Requires: tog-pegasus > +BuildRequires: libcmpiutil>= 0.5.4 > BuildRequires: tog-pegasus-devel > -BuildRequires: libvirt-devel>= 0.5.4 > -BuildRequires: e2fsprogs-devel > +BuildRequires: libvirt-devel>= 0.6.4 > +BuildRequires: libuuid-devel > BuildRequires: libxml2-devel > BuildRequires: libcmpiutil-devel > BuildConflicts: sblim-cmpi-devel > @@ -27,11 +29,11 @@ > > %prep > %setup -q > -chmod -x src/* libxkutil/* schema/* README doc/* base_schema/README* > -chmod +X src/* libxkutil/* schema/* > > %build > %configure --disable-werror > +sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool > +sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool > make %{?_smp_mflags} > > %install > @@ -43,6 +45,9 @@ > rm -f $RPM_BUILD_ROOT%{_libdir}/cmpi/*.la > rm -f $RPM_BUILD_ROOT%{_libdir}/cmpi/*.a > rm -f $RPM_BUILD_ROOT%{_libdir}/libxkutil.so > +mkdir -p $RPM_BUILD_ROOT/etc/ld.so.conf.d > +echo %{_libdir}/cmpi> $RPM_BUILD_ROOT/etc/ld.so.conf.d/libvirt-cim.conf > +mkdir -p $RPM_BUILD_ROOT at INFO_STORE@ > > %clean > rm -fr $RPM_BUILD_ROOT > @@ -60,17 +65,19 @@ > %define CIMV2_REG %{_datadir}/%{name}/{HostedResourcePool,ElementCapabilities,HostedService,HostedDependency,ElementConformsToProfile,HostedAccessPoint}.registration > %define CIMV2_MOF %{_datadir}/%{name}/{HostedResourcePool,ElementCapabilities,HostedService,HostedDependency,RegisteredProfile,ComputerSystem,ElementConformsToProfile,HostedAccessPoint}.mof > > +# _If_ there is already a version of this installed, we must deregister > +# the classes we plan to install in post, otherwise we may corrupt > +# the pegasus repository. This is convention in other provider packages > %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ > -n @CIM_VIRT_NS@ \ > -r %{REGISTRATION} -m %{SCHEMA}>/dev/null 2>&1 || true > > %post > /sbin/ldconfig > -mkdir -p @INFO_STORE@ > > %{_datadir}/%{name}/install_base_schema.sh %{_datadir}/%{name} > > -/etc/init.d/tog-pegasus restart > +/etc/init.d/tog-pegasus condrestart > > %{_datadir}/%{name}/provider-register.sh -t pegasus \ > -n @CIM_VIRT_NS@ \ > @@ -93,25 +100,34 @@ > -n @CIM_VIRT_NS@ \ > -r %{REGISTRATION} -m %{SCHEMA}>/dev/null 2>&1 || true > %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ > - -n root/PG_InterOp \ > - -r %{PGINTEROP_REG} -m %{PGINTEROP_MOF}>/dev/null 2>&1 || true > + -n root/interop \ > + -r %{INTEROP_REG} -m %{INTEROP_MOF}>/dev/null 2>&1 || true > +%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ > + -n root/PG_InterOp \ > + -r %{PGINTEROP_REG} -m %{PGINTEROP_MOF}>/dev/null 2>&1 || true > +%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ > + -n root/cimv2 \ > + -r %{CIMV2_REG} -m %{CIMV2_MOF}>/dev/null 2>&1 || true > > %postun -p /sbin/ldconfig > > -%files > +%files > %defattr(-, root, root) > +%{_sysconfdir}/libvirt/cim > > %doc README COPYING doc/CodingStyle doc/SubmittingPatches > %doc base_schema/README.DMTF > %doc doc/*.html > %{_libdir}/lib*.so* > %{_libdir}/cmpi/lib*.so* > +%{_datadir}/libvirt-cim > %{_datadir}/libvirt-cim/*.sh > %{_datadir}/libvirt-cim/*.mof > %{_datadir}/libvirt-cim/cimv*-interop_mof > %{_datadir}/libvirt-cim/cimv*-cimv2_mof > %{_datadir}/libvirt-cim/*.registration > %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip > +%{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf > > %changelog > * Wed Oct 28 2009 Richard Maciel - 0.1-1 > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 8 15:12:16 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 11:12:16 -0400 Subject: [Libvirt-cim] [PATCH] #2 Cimtest: Handle keyboard interrupt In-Reply-To: References: Message-ID: <4DEF9150.90903@linux.vnet.ibm.com> Worked like a charm, thanks. +1. Pushed. On 05/27/2011 03:01 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306522145 10800 > # Node ID c8670eeacbb02db390825e4dda776a2a4cf67ff8 > # Parent 01aa645a1e1269eb31d1fdd9de8d7e9120f5fa74 > Cimtest: Handle keyboard interrupt > > During my tests I have noticed that if the user interrupts the program > execution, by pressing Ctrl+C, the next time cimtest runs, it will fail > due to leftovers of previous execution, especially, a disk pool called > cimtest-diskpool and a network called cimtest-netpool. > > With this patch, if a KeyboardInterrupt exception occurs, the > cleanup_env() function will be called before the program exit. > > Changes from #1: > * Avoid NameError (ret) if another exception other than > KeyboardInterrupt occurs > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/suites/libvirt-cim/main.py b/suites/libvirt-cim/main.py > --- a/suites/libvirt-cim/main.py > +++ b/suites/libvirt-cim/main.py > @@ -176,8 +176,7 @@ > testsuite.debug("%s %sh | %smin | %ssec | %smsec" % > (prefix, h, m, s, msec)) > > -def main(): > - (options, args) = parser.parse_args() > +def main(options, args): > to_addr = None > from_addr = None > relay = None > @@ -302,7 +301,21 @@ > (from_addr, to_addr, relay) > send_report(to_addr, from_addr, relay, msg_body, heading) > > + return 0 > +# main() > + > if __name__ == '__main__': > - sys.exit(main()) > + ret = -1 > + try: > + options, args = parser.parse_args() > + ret = main(options, args) > + except (KeyboardInterrupt, SystemExit): > + print "\nKeyboardInterrupt. Cleaning up..." > + status = cleanup_env(options.ip, options.virt) > + if status != PASS: > + print "Unable to clean up. Please check your environment." > + else: > + print "Clean up successful" > > + sys.exit(ret) > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 8 16:29:55 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 12:29:55 -0400 Subject: [Libvirt-cim] [PATCH] Cimtest: Use python xml to parse virsh net-dumpxml output In-Reply-To: <51bd999e881e96c8c2af.1306774623@etrunko-t410.br.ibm.com> References: <51bd999e881e96c8c2af.1306774623@etrunko-t410.br.ibm.com> Message-ID: <4DEFA383.6000500@linux.vnet.ibm.com> +1 & pushed. On 05/30/2011 12:57 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306533151 10800 > # Node ID 51bd999e881e96c8c2af698a7968d00b7009aaf2 > # Parent 589512c8ddff8224f16fbaa4348cc17df4d0536a > Cimtest: Use python xml to parse virsh net-dumpxml output > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/suites/libvirt-cim/lib/XenKvmLib/vxml.py b/suites/libvirt-cim/lib/XenKvmLib/vxml.py > --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py > +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py > @@ -38,6 +38,12 @@ > import pywbem > from xml.dom import minidom, Node > from xml import xpath > + > +try: > + from xml.etree import cElementTree as ElementTree > +except: > + from xml.etree import ElementTree > + > from VirtLib import utils, live > from XenKvmLib.xm_virt_util import get_bridge_from_network_xml, bootloader, \ > net_list > @@ -210,6 +216,17 @@ > else: > vbr = bridgename > return vbr > + # get_valid_bridge_name > + > + def _parse_net_dumpxml(_xml): > + try: > + root = ElementTree.fromstring(_xml) > + ip_element = root.find("ip") > + return ip_element.get("address") > + except: > + logger.error("Encounter error dump netxml") > + return None > + # _parse_net_dumpxml > > self.vbr = get_valid_bridge_name(server) > if self.vbr is None: > @@ -223,7 +240,7 @@ > self.server = server > > if is_new_net is False: > - cmd = "virsh net-dumpxml %s 2>/dev/null" % self.net_name > + cmd = "virsh -c %s net-dumpxml %s 2>/dev/null" % (self.vuri, self.net_name) > s, net_xml = utils.run_remote(server, cmd) > if s != 0: > logger.error("Encounter error dump netxml") > @@ -245,10 +262,13 @@ > > n_list = net_list(server, virt) > for _net_name in n_list: > - cmd = "virsh net-dumpxml %s 2>/dev/null | \ > - awk '/ip address/ {print}' | \ > - cut -d ' ' -f 4 | sed 's/address=//'" % _net_name > - s, in_use_addr = utils.run_remote(server, cmd) > + cmd = "virsh -c %s net-dumpxml %s 2>/dev/null" % (self.vuri, _net_name) > + s, xml = utils.run_remote(server, cmd) > + > + in_use_addr = _parse_net_dumpxml(xml) > + if in_use_addr is None: > + logger.error("Unable to find IP address") > + return None > > sub_net_in_use = in_use_addr > sub_net_in_use = sub_net_in_use.rsplit('.', 1)[0].strip("'") + "." > @@ -310,7 +330,7 @@ > self.server = server > > if is_new_pool is False: > - cmd = "virsh pool-dumpxml %s 2>/dev/null" % self.pool_name > + cmd = "virsh -c %s pool-dumpxml %s 2>/dev/null" % (self.vuri, self.pool_name) > s, disk_xml = utils.run_remote(server, cmd) > if s != 0: > logger.error("Encounter error dump netxml") > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 8 16:35:44 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 12:35:44 -0400 Subject: [Libvirt-cim] [PATCH] Cimtest: Fix typo in SettingsDefine/01_forward.py In-Reply-To: References: Message-ID: <4DEFA4E0.5010003@linux.vnet.ibm.com> -------------------------------------------------------------------- SettingsDefine - 01_forward.py: PASS -------------------------------------------------------------------- +1 & pushed. On 06/01/2011 03:46 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306957479 10800 > # Node ID f303bd9615f23b8b79c5532dd5489899a13a0f8e > # Parent 8dd7c0167cfaf3fe6b0274dbf98a0d875ae96355 > Cimtest: Fix typo in SettingsDefine/01_forward.py > > File "01_forward.py", line 58, in setup_env > return FAIL, cmxl > NameError: global name 'cmxl' is not defined > > It should be cxml instead of cmxl > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py b/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py > --- a/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py > +++ b/suites/libvirt-cim/cimtest/SettingsDefine/01_forward.py > @@ -55,7 +55,7 @@ > ret = cxml.cim_define(server) > if not ret: > logger.error("Failed to Create the dom: %s", test_dom) > - return FAIL, cmxl > + return FAIL, cxml > > status = cxml.cim_start(server) > if status != PASS: > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 8 17:00:12 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 08 Jun 2011 13:00:12 -0400 Subject: [Libvirt-cim] [PATCH] Cimtest: Check for None return value In-Reply-To: <373d418b222c25309db3.1306961037@etrunko-t410.br.ibm.com> References: <373d418b222c25309db3.1306961037@etrunko-t410.br.ibm.com> Message-ID: <4DEFAA9C.7080806@linux.vnet.ibm.com> I'm seeing a new failure with this patch: NetworkPort - 01_netport.py: FAIL ERROR - CIMError : (16, u'CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__') Traceback (most recent call last): File "/home/cvincent/tmp/cimtest/suites/libvirt-cim/lib/XenKvmLib/const.py", line 140, in do_try rc = f() File "01_netport.py", line 86, in main if not dev: File "/home/cvincent/tmp/cimtest/lib/CimTest/CimExt.py", line 32, in __call__ return self.__invoker(self.__name, args) File "/home/cvincent/tmp/cimtest/suites/libvirt-cim/lib/XenKvmLib/enumclass.py", line 108, in __invoke **params) File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line 801, in InvokeMethod result = self.methodcall(MethodName, obj, **params) File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line 362, in methodcall raise CIMError(code, tt[0][1]['DESCRIPTION']) CIMError: (16, u'CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__') ERROR - None InvokeMethod(__nonzero__): CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__ On 06/01/2011 04:43 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306960999 10800 > # Node ID 373d418b222c25309db3d83dd384abf61127ebe9 > # Parent f303bd9615f23b8b79c5532dd5489899a13a0f8e > Cimtest: Check for None return value > > Some tests were raising Attribute Exception due to None value returned. > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > @@ -57,7 +57,10 @@ > dev = GetInstance(options.ip, disk, key_list) > status = 0 > > - if dev.Name != test_dev: > + if not dev: > + logger.error("GetInstance() returned None") > + status = 1 > + else if dev.Name != test_dev: > logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) > status = 1 > > diff --git a/suites/libvirt-cim/cimtest/Memory/01_memory.py b/suites/libvirt-cim/cimtest/Memory/01_memory.py > --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py > +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py > @@ -56,7 +56,10 @@ > > status = 0 > > - if dev.ConsumableBlocks> dev.NumberOfBlocks: > + if not dev: > + logger.error("GetInstance() returned None") > + status = 1 > + else if dev.ConsumableBlocks> dev.NumberOfBlocks: > logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") > status = 1 > > diff --git a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py > --- a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py > +++ b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py > @@ -83,6 +83,11 @@ > vsxml.undefine(options.ip) > return FAIL > > + if not dev: > + logger.error("GetInstance() returned None") > + vsxml.undefine(options.ip) > + return FAIL > + > if dev.DeviceID == None: > logger.error("Error retrieving instance for devid %s", devid) > vsxml.undefine(options.ip) > diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py > --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py > +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py > @@ -47,6 +47,10 @@ > > rasds = get_default_rasds(options.ip, options.virt) > > + if not rasds: > + logger.error("get_default_rasds() returned None") > + return FAIL > + > rasd_list = {} > > for rasd in rasds: > @@ -56,6 +60,10 @@ > rasd['AllocationUnits'] = units > rasd_list[mrasd_cn] = inst_to_mof(rasd) > > + if mrasd_cn not in rasd_list.keys(): > + logger.error("Key '%s' not found in dictionary '%s'" % (mrasd_cn, rasd_list)) > + return FAIL > + > if rasd_list[mrasd_cn] is None: > logger.error("Unable to get template MemRASD") > return FAIL > diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py > --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py > +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py > @@ -154,7 +154,7 @@ > logger.error(details) > status = FAIL > > - if os.path.exists(addr): > + if addr and os.path.exists(addr): > os.remove(addr) > > if guest_defined == True: > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Wed Jun 8 17:21:40 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 08 Jun 2011 14:21:40 -0300 Subject: [Libvirt-cim] [PATCH] Cimtest: Check for None return value In-Reply-To: <4DEFAA9C.7080806@linux.vnet.ibm.com> References: <373d418b222c25309db3.1306961037@etrunko-t410.br.ibm.com> <4DEFAA9C.7080806@linux.vnet.ibm.com> Message-ID: <4DEFAFA4.1020105@linux.vnet.ibm.com> On 06/08/2011 02:00 PM, Chip Vincent wrote: > I'm seeing a new failure with this patch: > > NetworkPort - 01_netport.py: FAIL > ERROR - CIMError : (16, u'CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__') > Traceback (most recent call last): > File > "/home/cvincent/tmp/cimtest/suites/libvirt-cim/lib/XenKvmLib/const.py", > line 140, in do_try > rc = f() > File "01_netport.py", line 86, in main > if not dev: > File "/home/cvincent/tmp/cimtest/lib/CimTest/CimExt.py", line 32, in > __call__ > return self.__invoker(self.__name, args) > File > "/home/cvincent/tmp/cimtest/suites/libvirt-cim/lib/XenKvmLib/enumclass.py", > line 108, in __invoke > **params) > File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line > 801, in InvokeMethod > result = self.methodcall(MethodName, obj, **params) > File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line > 362, in methodcall > raise CIMError(code, tt[0][1]['DESCRIPTION']) > CIMError: (16, u'CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__') > ERROR - None > InvokeMethod(__nonzero__): CIM_ERR_METHOD_NOT_AVAILABLE: __nonzero__ > Weird, I don't get these messages. So better change the test case to explicitly compare to None: - if not dev: + if dev is None: Will provide a patch with this fix soon. Best regards, -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Wed Jun 8 17:34:04 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 08 Jun 2011 14:34:04 -0300 Subject: [Libvirt-cim] [PATCH] #2 Cimtest: Check for None return value Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1306960999 10800 # Node ID df7d1969cedff2ba8cbb6bdd8a465939d815e2bc # Parent f303bd9615f23b8b79c5532dd5489899a13a0f8e Cimtest: Check for None return value Some tests were raising Attribute Exception due to None value returned. Changes from #1: - Explicitly check for None if value returned from GetInstance() Signed-off-by: Eduardo Lima (Etrunko) diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py Wed Jun 01 16:44:39 2011 -0300 +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py Wed Jun 01 17:43:19 2011 -0300 @@ -57,7 +57,10 @@ dev = GetInstance(options.ip, disk, key_list) status = 0 - if dev.Name != test_dev: + if dev is None: + logger.error("GetInstance() returned None") + status = 1 + else if dev.Name != test_dev: logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) status = 1 diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/Memory/01_memory.py --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py Wed Jun 01 16:44:39 2011 -0300 +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py Wed Jun 01 17:43:19 2011 -0300 @@ -56,7 +56,10 @@ status = 0 - if dev.ConsumableBlocks > dev.NumberOfBlocks: + if dev is None: + logger.error("GetInstance() returned None") + status = 1 + else if dev.ConsumableBlocks > dev.NumberOfBlocks: logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") status = 1 diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/NetworkPort/01_netport.py --- a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py Wed Jun 01 16:44:39 2011 -0300 +++ b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py Wed Jun 01 17:43:19 2011 -0300 @@ -83,6 +83,11 @@ vsxml.undefine(options.ip) return FAIL + if dev is None: + logger.error("GetInstance() returned None") + vsxml.undefine(options.ip) + return FAIL + if dev.DeviceID == None: logger.error("Error retrieving instance for devid %s", devid) vsxml.undefine(options.ip) diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py Wed Jun 01 16:44:39 2011 -0300 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py Wed Jun 01 17:43:19 2011 -0300 @@ -47,6 +47,10 @@ rasds = get_default_rasds(options.ip, options.virt) + if not rasds: + logger.error("get_default_rasds() returned None") + return FAIL + rasd_list = {} for rasd in rasds: @@ -56,6 +60,10 @@ rasd['AllocationUnits'] = units rasd_list[mrasd_cn] = inst_to_mof(rasd) + if mrasd_cn not in rasd_list.keys(): + logger.error("Key '%s' not found in dictionary '%s'" % (mrasd_cn, rasd_list)) + return FAIL + if rasd_list[mrasd_cn] is None: logger.error("Unable to get template MemRASD") return FAIL diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Wed Jun 01 16:44:39 2011 -0300 +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Wed Jun 01 17:43:19 2011 -0300 @@ -154,7 +154,7 @@ logger.error(details) status = FAIL - if os.path.exists(addr): + if addr and os.path.exists(addr): os.remove(addr) if guest_defined == True: From cvincent at linux.vnet.ibm.com Thu Jun 9 15:12:32 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Thu, 09 Jun 2011 11:12:32 -0400 Subject: [Libvirt-cim] [PATCH] #2 Cimtest: Check for None return value In-Reply-To: References: Message-ID: <4DF0E2E0.1000304@linux.vnet.ibm.com> -------------------------------------------------------------------- NetworkPort - 01_netport.py: PASS -------------------------------------------------------------------- +1 & pushed. On 06/08/2011 01:34 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1306960999 10800 > # Node ID df7d1969cedff2ba8cbb6bdd8a465939d815e2bc > # Parent f303bd9615f23b8b79c5532dd5489899a13a0f8e > Cimtest: Check for None return value > > Some tests were raising Attribute Exception due to None value returned. > > Changes from #1: > - Explicitly check for None if value returned from GetInstance() > > Signed-off-by: Eduardo Lima (Etrunko) > > diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py Wed Jun 01 16:44:39 2011 -0300 > +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py Wed Jun 01 17:43:19 2011 -0300 > @@ -57,7 +57,10 @@ > dev = GetInstance(options.ip, disk, key_list) > status = 0 > > - if dev.Name != test_dev: > + if dev is None: > + logger.error("GetInstance() returned None") > + status = 1 > + else if dev.Name != test_dev: > logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) > status = 1 > > diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/Memory/01_memory.py > --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py Wed Jun 01 16:44:39 2011 -0300 > +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py Wed Jun 01 17:43:19 2011 -0300 > @@ -56,7 +56,10 @@ > > status = 0 > > - if dev.ConsumableBlocks> dev.NumberOfBlocks: > + if dev is None: > + logger.error("GetInstance() returned None") > + status = 1 > + else if dev.ConsumableBlocks> dev.NumberOfBlocks: > logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") > status = 1 > > diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/NetworkPort/01_netport.py > --- a/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py Wed Jun 01 16:44:39 2011 -0300 > +++ b/suites/libvirt-cim/cimtest/NetworkPort/01_netport.py Wed Jun 01 17:43:19 2011 -0300 > @@ -83,6 +83,11 @@ > vsxml.undefine(options.ip) > return FAIL > > + if dev is None: > + logger.error("GetInstance() returned None") > + vsxml.undefine(options.ip) > + return FAIL > + > if dev.DeviceID == None: > logger.error("Error retrieving instance for devid %s", devid) > vsxml.undefine(options.ip) > diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py > --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py Wed Jun 01 16:44:39 2011 -0300 > +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/11_define_memrasdunits.py Wed Jun 01 17:43:19 2011 -0300 > @@ -47,6 +47,10 @@ > > rasds = get_default_rasds(options.ip, options.virt) > > + if not rasds: > + logger.error("get_default_rasds() returned None") > + return FAIL > + > rasd_list = {} > > for rasd in rasds: > @@ -56,6 +60,10 @@ > rasd['AllocationUnits'] = units > rasd_list[mrasd_cn] = inst_to_mof(rasd) > > + if mrasd_cn not in rasd_list.keys(): > + logger.error("Key '%s' not found in dictionary '%s'" % (mrasd_cn, rasd_list)) > + return FAIL > + > if rasd_list[mrasd_cn] is None: > logger.error("Unable to get template MemRASD") > return FAIL > diff -r f303bd9615f2 -r df7d1969cedf suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py > --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Wed Jun 01 16:44:39 2011 -0300 > +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/14_define_sys_disk.py Wed Jun 01 17:43:19 2011 -0300 > @@ -154,7 +154,7 @@ > logger.error(details) > status = FAIL > > - if os.path.exists(addr): > + if addr and os.path.exists(addr): > os.remove(addr) > > if guest_defined == True: > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Tue Jun 14 14:25:07 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 14 Jun 2011 10:25:07 -0400 Subject: [Libvirt-cim] [PATCH] #3 Configure tweaks Message-ID: <4DF76F43.2040503@linux.vnet.ibm.com> Sorry it took so long to review this patch. It's seems to have escaped my mailbox so thank goodnews for list archives :-) Output is as expected: ... libVirt_ComputerSystem.so libVirt_ComputerSystem.so.0 libVirt_ComputerSystem.so.0.5.12 ... +1 and pushed. -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Thu Jun 16 17:56:14 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Thu, 16 Jun 2011 14:56:14 -0300 Subject: [Libvirt-cim] [PATCH] [NetRASD]: Fill up NetworkName attribute for non-bridged network Message-ID: <6c29c5b284443e226e7d.1308246974@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308246930 10800 # Node ID 6c29c5b284443e226e7d97e7e5f11848b0c4e761 # Parent a37f80f80d4b2dab73391989168592866c23ba9b [NetRASD]: Fill up NetworkName attribute for non-bridged network This patch fixes the behavior for the read operation. Signed-off-by: Eduardo Lima (Etrunko) diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c --- a/src/Virt_RASD.c +++ b/src/Virt_RASD.c @@ -370,8 +370,7 @@ (CMPIValue *)dev->dev.net.mac, CMPI_chars); - if ((dev->dev.net.source != NULL) && - (STREQ(dev->dev.net.type, "bridge"))) + if (dev->dev.net.source != NULL) CMSetProperty(inst, "NetworkName", (CMPIValue *)dev->dev.net.source, From cvincent at linux.vnet.ibm.com Thu Jun 16 20:41:56 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Thu, 16 Jun 2011 16:41:56 -0400 Subject: [Libvirt-cim] [PATCH] [NetRASD]: Fill up NetworkName attribute for non-bridged network In-Reply-To: <6c29c5b284443e226e7d.1308246974@etrunko-t410.br.ibm.com> References: <6c29c5b284443e226e7d.1308246974@etrunko-t410.br.ibm.com> Message-ID: <4DFA6A94.4080504@linux.vnet.ibm.com> +1. Looking at device_parsing.c, 'net.source' is only supported with bridge and network types, so this patch really adds support for network types, not all non-bridged types as the title suggests. Pushed. On 06/16/2011 01:56 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308246930 10800 > # Node ID 6c29c5b284443e226e7d97e7e5f11848b0c4e761 > # Parent a37f80f80d4b2dab73391989168592866c23ba9b > [NetRASD]: Fill up NetworkName attribute for non-bridged network > > This patch fixes the behavior for the read operation. > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c > --- a/src/Virt_RASD.c > +++ b/src/Virt_RASD.c > @@ -370,8 +370,7 @@ > (CMPIValue *)dev->dev.net.mac, > CMPI_chars); > > - if ((dev->dev.net.source != NULL)&& > - (STREQ(dev->dev.net.type, "bridge"))) > + if (dev->dev.net.source != NULL) > CMSetProperty(inst, > "NetworkName", > (CMPIValue *)dev->dev.net.source, > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From kevenzhu at tencent.com Fri Jun 17 03:27:16 2011 From: kevenzhu at tencent.com (=?gb2312?B?a2V2ZW56aHUo1uzS1L78KQ==?=) Date: Fri, 17 Jun 2011 11:27:16 +0800 Subject: [Libvirt-cim] =?gb2312?b?zNrRtiBmYWlsZWQgdG8gcmVtb3ZlIHRoZSBwdG14?= =?gb2312?b?IGZpbGUgd2hlbiB0aGUgdm0gaXMgZG93bg==?= Message-ID: <6E1BD28467762041B0B057D6CA74B1E411E28A@EX-BJ04.tencent.com> Hi Guys: I'm writing an web-based vm managerment system using libvirt which is convenient to use. but when I want to remove the template, the PTMX file could NOT be removed. below is the error message, would you please give me some suggestions, thanks a lot. virsh # list --all Id Name State ---------------------------------- - lxc6 shut off root at Tencent:/usr/local/project/LXC/template/suse/dev/pts # ls -l total 0 crw-rw-rw- 1 root root 5, 2 Jun 17 10:23 ptmx root at Tencent:/usr/local/project/LXC/template/suse/dev/pts # rm ptmx -f rm: cannot remove `ptmx': Operation not permitted -------------- next part -------------- An HTML attachment was scrubbed... URL: From cvincent at linux.vnet.ibm.com Tue Jun 21 15:35:25 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 21 Jun 2011 11:35:25 -0400 Subject: [Libvirt-cim] [PATCH] Fix MemoryPool.Reserved to show only actively allocated memory Message-ID: <637801be4b6f6cc0c065.1308670525@oc0840652111.ibm.com> # HG changeset patch # User Chip Vincent # Date 1308669482 14400 # Node ID 637801be4b6f6cc0c065f4fe406e85b78186654b # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 Fix MemoryPool.Reserved to show only actively allocated memory. It appears Reserved is meant to show memory that is taken (actively in use by VMs) as opposed to memory that is potentially taken (assigned to defined, but not running VMs). Also added CurrentlyConsumedResource (a much clearer name for the same thing) and ConsumedResourceUnits, fixed units to conform with DSP1045, and cleaned up some extraneous whitespace. Signed-off-by: Chip Vincent diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -676,17 +676,47 @@ return memory != 0; } -static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn) +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) { - uint64_t memory; + uint64_t memory = 0; + int *domain_ids = NULL; + int count, i = 0; - /* NB: This doesn't account for memory to be claimed - * by ballooning dom0 - */ - memory = allocated_memory(conn); + count = virConnectNumOfDomains(conn); + if (count <= 0) + goto out; + + domain_ids = calloc(count, sizeof(domain_ids[0])); + if (domain_ids == 0) + goto out; + + if (virConnectListDomains(conn, domain_ids, count) == 0) + goto out; + + for (i = 0; i < count; i++) { + virDomainPtr dom = NULL; + virDomainInfo dom_info; + + dom = virDomainLookupByID(conn, domain_ids[i]); + if (dom == NULL) { + CU_DEBUG("Cannot connect to domain %n: excluding", + domain_ids[i]); + continue; + } + + if (virDomainGetInfo(dom, &dom_info) == 0) + memory += dom_info.memory; + + virDomainFree(dom); + } + + out: + free(domain_ids); CMSetProperty(inst, "Reserved", (CMPIValue *)&memory, CMPI_uint64); + CMSetProperty(inst, "CurrentlyConsumedResource", + (CMPIValue *)&memory, CMPI_uint64); return memory != 0; } @@ -726,10 +756,14 @@ CMSetProperty(inst, "ResourceType", (CMPIValue *)&type, CMPI_uint16); - if (units != NULL) + if (units != NULL) { CMSetProperty(inst, "AllocationUnits", (CMPIValue *)units, CMPI_chars); + CMSetProperty(inst, "ConsumedResourceUnits", + (CMPIValue *)units, CMPI_chars); + } + if (caption != NULL) CMSetProperty(inst, "Caption", (CMPIValue *)caption, CMPI_chars); @@ -761,9 +795,9 @@ ns); mempool_set_total(inst, conn); - mempool_set_reserved(inst, conn); + mempool_set_consumed(inst, conn); - set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true); + set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true); inst_list_add(list, inst); From eblima at linux.vnet.ibm.com Tue Jun 21 19:36:39 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 21 Jun 2011 16:36:39 -0300 Subject: [Libvirt-cim] [PATCH] Fix MemoryPool.Reserved to show only actively allocated memory In-Reply-To: <637801be4b6f6cc0c065.1308670525@oc0840652111.ibm.com> References: <637801be4b6f6cc0c065.1308670525@oc0840652111.ibm.com> Message-ID: <4E00F2C7.1090307@linux.vnet.ibm.com> On 06/21/2011 12:35 PM, Chip Vincent wrote: > # HG changeset patch > # User Chip Vincent > # Date 1308669482 14400 > # Node ID 637801be4b6f6cc0c065f4fe406e85b78186654b > # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 > Fix MemoryPool.Reserved to show only actively allocated memory. > > It appears Reserved is meant to show memory that is taken (actively in use by > VMs) as opposed to memory that is potentially taken (assigned to defined, but > not running VMs). > Also added CurrentlyConsumedResource (a much clearer name for the same thing) > and ConsumedResourceUnits, fixed units to conform with DSP1045, and cleaned > up some extraneous whitespace. > > Signed-off-by: Chip Vincent > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -676,17 +676,47 @@ > return memory != 0; > } > > -static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn) > +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) > { > - uint64_t memory; > + uint64_t memory = 0; > + int *domain_ids = NULL; > + int count, i = 0; > > - /* NB: This doesn't account for memory to be claimed > - * by ballooning dom0 > - */ > - memory = allocated_memory(conn); > + count = virConnectNumOfDomains(conn); > + if (count<= 0) > + goto out; > + > + domain_ids = calloc(count, sizeof(domain_ids[0])); > + if (domain_ids == 0) > + goto out; > + Shouldn't you be checking for NULL instead of 0 here? > + if (virConnectListDomains(conn, domain_ids, count) == 0) > + goto out; > + And here for -1 instead of 0? > + for (i = 0; i< count; i++) { > + virDomainPtr dom = NULL; > + virDomainInfo dom_info; > + > + dom = virDomainLookupByID(conn, domain_ids[i]); > + if (dom == NULL) { > + CU_DEBUG("Cannot connect to domain %n: excluding", > + domain_ids[i]); > + continue; > + } > + > + if (virDomainGetInfo(dom,&dom_info) == 0) > + memory += dom_info.memory; > + > + virDomainFree(dom); > + } > + > + out: > + free(domain_ids); > > CMSetProperty(inst, "Reserved", > (CMPIValue *)&memory, CMPI_uint64); > + CMSetProperty(inst, "CurrentlyConsumedResource", > + (CMPIValue *)&memory, CMPI_uint64); > > return memory != 0; > } > @@ -726,10 +756,14 @@ > CMSetProperty(inst, "ResourceType", > (CMPIValue *)&type, CMPI_uint16); > > - if (units != NULL) > + if (units != NULL) { > CMSetProperty(inst, "AllocationUnits", > (CMPIValue *)units, CMPI_chars); > > + CMSetProperty(inst, "ConsumedResourceUnits", > + (CMPIValue *)units, CMPI_chars); > + } > + > if (caption != NULL) > CMSetProperty(inst, "Caption", > (CMPIValue *)caption, CMPI_chars); > @@ -761,9 +795,9 @@ > ns); > > mempool_set_total(inst, conn); > - mempool_set_reserved(inst, conn); > + mempool_set_consumed(inst, conn); > > - set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true); > + set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true); > > inst_list_add(list, inst); Best Regards, -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Wed Jun 22 13:18:00 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 22 Jun 2011 10:18:00 -0300 Subject: [Libvirt-cim] [PATCH] Conditional build requirement for RPM package Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308748522 10800 # Node ID d47d6105d725641ed8fdbb2d2fd0c300c9f1e773 # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 Conditional build requirement for RPM package In RHEL5 uuid development files are provided by e2fsprogs-devel package, while in most recent distros, it is provided by libuuid-devel. Signed-off-by: Eduardo Lima (Etrunko) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -16,9 +16,17 @@ BuildRequires: libcmpiutil >= 0.5.4 BuildRequires: tog-pegasus-devel BuildRequires: libvirt-devel >= 0.6.4 + +# In RHEL5 uuid-devel is provided by e2fsprogs +%if 0%{?el5} +BuildRequires: e2fsprogs-devel +%else BuildRequires: libuuid-devel +%endif + BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description From eblima at linux.vnet.ibm.com Wed Jun 22 13:41:28 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 22 Jun 2011 10:41:28 -0300 Subject: [Libvirt-cim] [PATCH] (#2) Conditional build requirement for RPM package Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308750020 10800 # Node ID c6f1723d2c68c5e8ba371e4dea4d7aaae6cca326 # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 Conditional build requirement for RPM package In RHEL5 uuid development files are provided by e2fsprogs-devel package, while in most recent distros, it is provided by libuuid-devel. Changes from #1: - Remove libconfig-devel build dependency Signed-off-by: Eduardo Lima (Etrunko) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -16,7 +16,14 @@ BuildRequires: libcmpiutil >= 0.5.4 BuildRequires: tog-pegasus-devel BuildRequires: libvirt-devel >= 0.6.4 + +# In RHEL5 uuid-devel is provided by e2fsprogs +%if 0%{?el5} +BuildRequires: e2fsprogs-devel +%else BuildRequires: libuuid-devel +%endif + BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel BuildConflicts: sblim-cmpi-devel From cvincent at linux.vnet.ibm.com Wed Jun 22 15:16:20 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 22 Jun 2011 11:16:20 -0400 Subject: [Libvirt-cim] [PATCH] (#2) Conditional build requirement for RPM package In-Reply-To: References: Message-ID: <4E020744.5080407@linux.vnet.ibm.com> +1. Thanks and pushed. On 06/22/2011 09:41 AM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308750020 10800 > # Node ID c6f1723d2c68c5e8ba371e4dea4d7aaae6cca326 > # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 > Conditional build requirement for RPM package > > In RHEL5 uuid development files are provided by e2fsprogs-devel package, > while in most recent distros, it is provided by libuuid-devel. > > Changes from #1: > - Remove libconfig-devel build dependency > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in > --- a/libvirt-cim.spec.in > +++ b/libvirt-cim.spec.in > @@ -16,7 +16,14 @@ > BuildRequires: libcmpiutil>= 0.5.4 > BuildRequires: tog-pegasus-devel > BuildRequires: libvirt-devel>= 0.6.4 > + > +# In RHEL5 uuid-devel is provided by e2fsprogs > +%if 0%{?el5} > +BuildRequires: e2fsprogs-devel > +%else > BuildRequires: libuuid-devel > +%endif > + > BuildRequires: libxml2-devel > BuildRequires: libcmpiutil-devel > BuildConflicts: sblim-cmpi-devel -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Wed Jun 22 15:33:03 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 22 Jun 2011 11:33:03 -0400 Subject: [Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only actively allocated memory Message-ID: # HG changeset patch # User Chip Vincent # Date 1308756569 14400 # Node ID c5a9510b6bd1569c6ab0966624306e29ecd81727 # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 (#2) Fix MemoryPool.Reserved to show only actively allocated memory. It appears Reserved is meant to show memory that is taken (actively in use by VMs) as opposed to memory that is potentially taken (assigned to defined, but not running VMs). Also added CurrentlyConsumedResource (a much clearer name for the same thing) and ConsumedResourceUnits, fixed units to conform with DSP1045, and cleaned up some extraneous whitespace. Changes from #1: - Fix return code checking Signed-off-by: Chip Vincent diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -676,17 +676,47 @@ return memory != 0; } -static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn) +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) { - uint64_t memory; + uint64_t memory = 0; + int *domain_ids = NULL; + int count, i = 0; - /* NB: This doesn't account for memory to be claimed - * by ballooning dom0 - */ - memory = allocated_memory(conn); + count = virConnectNumOfDomains(conn); + if (count <= 0) + goto out; + + domain_ids = calloc(count, sizeof(domain_ids[0])); + if (domain_ids == NULL) + goto out; + + if (virConnectListDomains(conn, domain_ids, count) == -1) + goto out; + + for (i = 0; i < count; i++) { + virDomainPtr dom = NULL; + virDomainInfo dom_info; + + dom = virDomainLookupByID(conn, domain_ids[i]); + if (dom == NULL) { + CU_DEBUG("Cannot connect to domain %n: excluding", + domain_ids[i]); + continue; + } + + if (virDomainGetInfo(dom, &dom_info) == 0) + memory += dom_info.memory; + + virDomainFree(dom); + } + + out: + free(domain_ids); CMSetProperty(inst, "Reserved", (CMPIValue *)&memory, CMPI_uint64); + CMSetProperty(inst, "CurrentlyConsumedResource", + (CMPIValue *)&memory, CMPI_uint64); return memory != 0; } @@ -726,10 +756,14 @@ CMSetProperty(inst, "ResourceType", (CMPIValue *)&type, CMPI_uint16); - if (units != NULL) + if (units != NULL) { CMSetProperty(inst, "AllocationUnits", (CMPIValue *)units, CMPI_chars); + CMSetProperty(inst, "ConsumedResourceUnits", + (CMPIValue *)units, CMPI_chars); + } + if (caption != NULL) CMSetProperty(inst, "Caption", (CMPIValue *)caption, CMPI_chars); @@ -761,9 +795,9 @@ ns); mempool_set_total(inst, conn); - mempool_set_reserved(inst, conn); + mempool_set_consumed(inst, conn); - set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true); + set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true); inst_list_add(list, inst); From eblima at linux.vnet.ibm.com Wed Jun 22 17:34:22 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Wed, 22 Jun 2011 14:34:22 -0300 Subject: [Libvirt-cim] [PATCH] [TEST] Fix syntax errors introduced by previous patch Message-ID: <51b9e8dda4ed81bd692c.1308764062@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308764046 10800 # Node ID 51b9e8dda4ed81bd692c6a23f14506b4561da09b # Parent 9dcade76d903ae2c28fb35d1b28546a2324c1190 [TEST] Fix syntax errors introduced by previous patch LogicalDisk - 01_disk.py: FAIL File "01_disk.py", line 63 else if dev.Name != test_dev: ^ SyntaxError: invalid syntax Memory - 01_memory.py: FAIL File "01_memory.py", line 62 else if dev.ConsumableBlocks > dev.NumberOfBlocks: ^ SyntaxError: invalid syntax Signed-off-by: Eduardo Lima (Etrunko) diff --git a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py @@ -60,7 +60,7 @@ if dev is None: logger.error("GetInstance() returned None") status = 1 - else if dev.Name != test_dev: + elif dev.Name != test_dev: logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) status = 1 diff --git a/suites/libvirt-cim/cimtest/Memory/01_memory.py b/suites/libvirt-cim/cimtest/Memory/01_memory.py --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py @@ -59,7 +59,7 @@ if dev is None: logger.error("GetInstance() returned None") status = 1 - else if dev.ConsumableBlocks > dev.NumberOfBlocks: + elif dev.ConsumableBlocks > dev.NumberOfBlocks: logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") status = 1 From cvincent at linux.vnet.ibm.com Wed Jun 22 18:05:13 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 22 Jun 2011 14:05:13 -0400 Subject: [Libvirt-cim] [PATCH] Check libvirt version before compiling ACL library code Message-ID: <090e8ae2a0c18fad143d.1308765913@oc0840652111.ibm.com> # HG changeset patch # User Chip Vincent # Date 1308765905 14400 # Node ID 090e8ae2a0c18fad143df826dececb48d4de6b3a # Parent f5c86ef03e64f61bb142f1aeaf448c438b28bd23 Check libvirt version before compiling ACL library code. RHEL 5.5 that ships with libvirt 0.6.3. The NWFilter* APIs were created in 0.8.1 so the ACL code should be stubbed when LIBVIR_VERSION_NUMBER > 8000. Same thing with using virDomainUpdateDeviceFlags(). Signed-off-by: Chip Vincent diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c --- a/libxkutil/acl_parsing.c +++ b/libxkutil/acl_parsing.c @@ -456,6 +456,7 @@ const char *name, struct acl_filter **filter) { +#if LIBVIR_VERSION_NUMBER > 8000 virNWFilterPtr vfilter = NULL; char *xml = NULL; @@ -474,6 +475,9 @@ get_filter_from_xml(xml, filter); return 1; +#else + return 0; +#endif } int get_filter_by_uuid( @@ -481,6 +485,7 @@ const char *uuid, struct acl_filter **filter) { +#if LIBVIR_VERSION_NUMBER > 8000 virNWFilterPtr vfilter = NULL; char *xml = NULL; @@ -499,12 +504,16 @@ get_filter_from_xml(xml, filter); return 1; +#else + return 0; +#endif } int get_filters( virConnectPtr conn, struct acl_filter **list) { +#if LIBVIR_VERSION_NUMBER > 8000 int count = 0; char **names = NULL; struct acl_filter *filters = NULL; @@ -537,6 +546,9 @@ free(names); return i; +#else + return 0; +#endif } diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c --- a/src/Virt_AppliedFilterList.c +++ b/src/Virt_AppliedFilterList.c @@ -105,6 +105,7 @@ static int update_device(virDomainPtr dom, struct virt_device *dev) { +#if LIBVIR_VERSION_NUMBER > 8000 char *xml = NULL; int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT | VIR_DOMAIN_DEVICE_MODIFY_CONFIG; @@ -132,6 +133,9 @@ free(xml); return ret; +#else + return 0; +#endif } /* TODO: Port to libxkutil/device_parsing.c */ From cvincent at linux.vnet.ibm.com Thu Jun 23 01:26:14 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 22 Jun 2011 21:26:14 -0400 Subject: [Libvirt-cim] [PATCH] Fix AppliedFilterList Associators Message-ID: <26cfeade3cb76c4ee43a.1308792374@oc0840652111.ibm.com> # HG changeset patch # User Chip Vincent # Date 1308792349 14400 # Node ID 26cfeade3cb76c4ee43a7bd33ea456a250c1c1c2 # Parent a37f80f80d4b2dab73391989168592866c23ba9b Fix AppliedFilterList Associators. Fixed a few small issues relating to reading AppliedFilterList. Signed-off-by: Chip Vincent diff --git a/schema/AppliedFilterList.registration b/schema/AppliedFilterList.registration --- a/schema/AppliedFilterList.registration +++ b/schema/AppliedFilterList.registration @@ -1,3 +1,3 @@ # Copyright IBM Corp. 2011 # Classname Namespace ProviderName ProviderModule ProviderTypes -KVM_AppliedFilterList root/virt Virt_AppliedFilterList Virt_AppliedFilterList association +KVM_AppliedFilterList root/virt Virt_AppliedFilterList Virt_AppliedFilterList instance association diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c --- a/src/Virt_AppliedFilterList.c +++ b/src/Virt_AppliedFilterList.c @@ -218,7 +218,7 @@ CU_DEBUG("filterref = %s", ndev->filter_ref); if ((ndev->filter_ref != NULL) && - STREQC(name, ndev->filter_ref)) { + STREQC(name, ndev->filter_ref)) { CU_DEBUG("Getting network device instance"); CMPIInstance *instance = NULL; @@ -235,10 +235,10 @@ CIM_RES_TYPE_NET, &instance); - if (instance != NULL) { - CU_DEBUG("adding instance to list"); + free(device_id); + + if (instance != NULL) inst_list_add(list, instance); - } } } @@ -317,7 +317,7 @@ CU_DEBUG("Checking net device '%s' for filterref", devices[i].id); - if (STREQC(device_name, devices[i].id)) { + if (STREQC(net_name, devices[i].id)) { CMPIInstance *instance = NULL; CU_DEBUG("Processing %s", ndev->filter_ref); @@ -332,18 +332,18 @@ filter, &instance); + cleanup_filter(filter); + if (instance != NULL) inst_list_add(list, instance); - } } cleanup_virt_devices(&devices, count); + out: - free(domain_name); - free((char *)device_name); free(net_name); virDomainFree(dom); From cvincent at linux.vnet.ibm.com Thu Jun 23 01:59:29 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Wed, 22 Jun 2011 21:59:29 -0400 Subject: [Libvirt-cim] [PATCH] [TEST] Fix syntax errors introduced by previous patch In-Reply-To: <51b9e8dda4ed81bd692c.1308764062@etrunko-t410.br.ibm.com> References: <51b9e8dda4ed81bd692c.1308764062@etrunko-t410.br.ibm.com> Message-ID: <4E029E01.3070505@linux.vnet.ibm.com> -------------------------------------------------------------------- LogicalDisk - 01_disk.py: PASS -------------------------------------------------------------------- [...] -------------------------------------------------------------------- Memory - 01_memory.py: PASS -------------------------------------------------------------------- +1. Pushed. On 06/22/2011 01:34 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308764046 10800 > # Node ID 51b9e8dda4ed81bd692c6a23f14506b4561da09b > # Parent 9dcade76d903ae2c28fb35d1b28546a2324c1190 > [TEST] Fix syntax errors introduced by previous patch > > LogicalDisk - 01_disk.py: FAIL > File "01_disk.py", line 63 > else if dev.Name != test_dev: > ^ > SyntaxError: invalid syntax > > Memory - 01_memory.py: FAIL > File "01_memory.py", line 62 > else if dev.ConsumableBlocks> dev.NumberOfBlocks: > ^ > SyntaxError: invalid syntax > > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > --- a/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > +++ b/suites/libvirt-cim/cimtest/LogicalDisk/01_disk.py > @@ -60,7 +60,7 @@ > if dev is None: > logger.error("GetInstance() returned None") > status = 1 > - else if dev.Name != test_dev: > + elif dev.Name != test_dev: > logger.error("Name should be `%s' instead of `%s'", test_dev, dev.Name) > status = 1 > > diff --git a/suites/libvirt-cim/cimtest/Memory/01_memory.py b/suites/libvirt-cim/cimtest/Memory/01_memory.py > --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py > +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py > @@ -59,7 +59,7 @@ > if dev is None: > logger.error("GetInstance() returned None") > status = 1 > - else if dev.ConsumableBlocks> dev.NumberOfBlocks: > + elif dev.ConsumableBlocks> dev.NumberOfBlocks: > logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") > status = 1 > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From snmishra at us.ibm.com Sun Jun 26 16:37:34 2011 From: snmishra at us.ibm.com (Sharad Mishra) Date: Sun, 26 Jun 2011 09:37:34 -0700 Subject: [Libvirt-cim] [PATCH] Fix AppliedFilterList Associators In-Reply-To: <26cfeade3cb76c4ee43a.1308792374@oc0840652111.ibm.com> References: <26cfeade3cb76c4ee43a.1308792374@oc0840652111.ibm.com> Message-ID: Sharad Mishra Open Virtualization Linux Technology Center IBM libvirt-cim-bounces at redhat.com wrote on 06/22/2011 06:26:14 PM: > Chip Vincent > Sent by: libvirt-cim-bounces at redhat.com > > 06/22/11 06:26 PM > > Please respond to > List for discussion and development of libvirt CIM > > To > > libvirt-cim at redhat.com > > cc > > Subject > > [Libvirt-cim] [PATCH] Fix AppliedFilterList Associators > > # HG changeset patch > # User Chip Vincent > # Date 1308792349 14400 > # Node ID 26cfeade3cb76c4ee43a7bd33ea456a250c1c1c2 > # Parent a37f80f80d4b2dab73391989168592866c23ba9b > Fix AppliedFilterList Associators. > > Fixed a few small issues relating to reading AppliedFilterList. > > Signed-off-by: Chip Vincent > > diff --git a/schema/AppliedFilterList.registration b/schema/ > AppliedFilterList.registration > --- a/schema/AppliedFilterList.registration > +++ b/schema/AppliedFilterList.registration > @@ -1,3 +1,3 @@ > # Copyright IBM Corp. 2011 > # Classname Namespace ProviderName ProviderModule ProviderTypes > -KVM_AppliedFilterList root/virt Virt_AppliedFilterList > Virt_AppliedFilterList association > +KVM_AppliedFilterList root/virt Virt_AppliedFilterList > Virt_AppliedFilterList instance association > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > --- a/src/Virt_AppliedFilterList.c > +++ b/src/Virt_AppliedFilterList.c > @@ -218,7 +218,7 @@ > CU_DEBUG("filterref = %s", ndev->filter_ref); > > if ((ndev->filter_ref != NULL) && > - STREQC(name, ndev->filter_ref)) { > + STREQC(name, ndev->filter_ref)) { Its a nit, can you fix the indentation above? > CU_DEBUG("Getting network device instance"); > > CMPIInstance *instance = NULL; > @@ -235,10 +235,10 @@ > CIM_RES_TYPE_NET, > &instance); > > - if (instance != NULL) { > - CU_DEBUG("adding instance to list"); > + free(device_id); > + > + if (instance != NULL) > inst_list_add(list, instance); > - } > } > } > > @@ -317,7 +317,7 @@ > CU_DEBUG("Checking net device '%s' for filterref", > devices[i].id); > > - if (STREQC(device_name, devices[i].id)) { > + if (STREQC(net_name, devices[i].id)) { > CMPIInstance *instance = NULL; > > CU_DEBUG("Processing %s", ndev->filter_ref); > @@ -332,18 +332,18 @@ > filter, > &instance); > > + cleanup_filter(filter); > + > if (instance != NULL) > inst_list_add(list, instance); > - > } > > } > > cleanup_virt_devices(&devices, count); > + > out: > - > free(domain_name); > - free((char *)device_name); > free(net_name); > > virDomainFree(dom); > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From snmishra at us.ibm.com Sun Jun 26 17:18:44 2011 From: snmishra at us.ibm.com (Sharad Mishra) Date: Sun, 26 Jun 2011 10:18:44 -0700 Subject: [Libvirt-cim] [PATCH] Check libvirt version before compiling ACL library code In-Reply-To: <090e8ae2a0c18fad143d.1308765913@oc0840652111.ibm.com> References: <090e8ae2a0c18fad143d.1308765913@oc0840652111.ibm.com> Message-ID: Code looks fine and compiles. Haven't tested it. Please test and push. +1 Sharad Mishra Open Virtualization Linux Technology Center IBM libvirt-cim-bounces at redhat.com wrote on 06/22/2011 11:05:13 AM: > Chip Vincent > Sent by: libvirt-cim-bounces at redhat.com > > 06/22/11 11:05 AM > > Please respond to > List for discussion and development of libvirt CIM > > To > > libvirt-cim at redhat.com > > cc > > Subject > > [Libvirt-cim] [PATCH] Check libvirt version before compiling ACL library code > > # HG changeset patch > # User Chip Vincent > # Date 1308765905 14400 > # Node ID 090e8ae2a0c18fad143df826dececb48d4de6b3a > # Parent f5c86ef03e64f61bb142f1aeaf448c438b28bd23 > Check libvirt version before compiling ACL library code. > > RHEL 5.5 that ships with libvirt 0.6.3. The NWFilter* APIs were created in > 0.8.1 so the ACL code should be stubbed when LIBVIR_VERSION_NUMBER > 8000. > Same thing with using virDomainUpdateDeviceFlags(). > > Signed-off-by: Chip Vincent > > diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c > --- a/libxkutil/acl_parsing.c > +++ b/libxkutil/acl_parsing.c > @@ -456,6 +456,7 @@ > const char *name, > struct acl_filter **filter) > { > +#if LIBVIR_VERSION_NUMBER > 8000 > virNWFilterPtr vfilter = NULL; > char *xml = NULL; > > @@ -474,6 +475,9 @@ > get_filter_from_xml(xml, filter); > > return 1; > +#else > + return 0; > +#endif > } > > int get_filter_by_uuid( > @@ -481,6 +485,7 @@ > const char *uuid, > struct acl_filter **filter) > { > +#if LIBVIR_VERSION_NUMBER > 8000 > virNWFilterPtr vfilter = NULL; > char *xml = NULL; > > @@ -499,12 +504,16 @@ > get_filter_from_xml(xml, filter); > > return 1; > +#else > + return 0; > +#endif > } > > int get_filters( > virConnectPtr conn, > struct acl_filter **list) > { > +#if LIBVIR_VERSION_NUMBER > 8000 > int count = 0; > char **names = NULL; > struct acl_filter *filters = NULL; > @@ -537,6 +546,9 @@ > free(names); > > return i; > +#else > + return 0; > +#endif > } > > > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > --- a/src/Virt_AppliedFilterList.c > +++ b/src/Virt_AppliedFilterList.c > @@ -105,6 +105,7 @@ > static int update_device(virDomainPtr dom, > struct virt_device *dev) > { > +#if LIBVIR_VERSION_NUMBER > 8000 > char *xml = NULL; > int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT | > VIR_DOMAIN_DEVICE_MODIFY_CONFIG; > @@ -132,6 +133,9 @@ > free(xml); > > return ret; > +#else > + return 0; > +#endif > } > > /* TODO: Port to libxkutil/device_parsing.c */ > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From snmishra at us.ibm.com Sun Jun 26 17:30:17 2011 From: snmishra at us.ibm.com (Sharad Mishra) Date: Sun, 26 Jun 2011 10:30:17 -0700 Subject: [Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only actively allocated memory In-Reply-To: References: Message-ID: code looks fine. please test and push. +1 Sharad Mishra Open Virtualization Linux Technology Center IBM libvirt-cim-bounces at redhat.com wrote on 06/22/2011 08:33:03 AM: > Chip Vincent > Sent by: libvirt-cim-bounces at redhat.com > > 06/22/11 08:33 AM > > Please respond to > List for discussion and development of libvirt CIM > > To > > libvirt-cim at redhat.com > > cc > > Subject > > [Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only > actively allocated memory > > # HG changeset patch > # User Chip Vincent > # Date 1308756569 14400 > # Node ID c5a9510b6bd1569c6ab0966624306e29ecd81727 > # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 > (#2) Fix MemoryPool.Reserved to show only actively allocated memory. > > It appears Reserved is meant to show memory that is taken (actively in use by > VMs) as opposed to memory that is potentially taken (assigned to defined, but > not running VMs). > Also added CurrentlyConsumedResource (a much clearer name for the same thing) > and ConsumedResourceUnits, fixed units to conform with DSP1045, and cleaned > up some extraneous whitespace. > > Changes from #1: > - Fix return code checking > > Signed-off-by: Chip Vincent > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -676,17 +676,47 @@ > return memory != 0; > } > > -static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn) > +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) > { > - uint64_t memory; > + uint64_t memory = 0; > + int *domain_ids = NULL; > + int count, i = 0; > > - /* NB: This doesn't account for memory to be claimed > - * by ballooning dom0 > - */ > - memory = allocated_memory(conn); > + count = virConnectNumOfDomains(conn); > + if (count <= 0) > + goto out; > + > + domain_ids = calloc(count, sizeof(domain_ids[0])); > + if (domain_ids == NULL) > + goto out; > + > + if (virConnectListDomains(conn, domain_ids, count) == -1) > + goto out; > + > + for (i = 0; i < count; i++) { > + virDomainPtr dom = NULL; > + virDomainInfo dom_info; > + > + dom = virDomainLookupByID(conn, domain_ids[i]); > + if (dom == NULL) { > + CU_DEBUG("Cannot connect to domain %n: excluding", > + domain_ids[i]); > + continue; > + } > + > + if (virDomainGetInfo(dom, &dom_info) == 0) > + memory += dom_info.memory; > + > + virDomainFree(dom); > + } > + > + out: > + free(domain_ids); > > CMSetProperty(inst, "Reserved", > (CMPIValue *)&memory, CMPI_uint64); > + CMSetProperty(inst, "CurrentlyConsumedResource", > + (CMPIValue *)&memory, CMPI_uint64); > > return memory != 0; > } > @@ -726,10 +756,14 @@ > CMSetProperty(inst, "ResourceType", > (CMPIValue *)&type, CMPI_uint16); > > - if (units != NULL) > + if (units != NULL) { > CMSetProperty(inst, "AllocationUnits", > (CMPIValue *)units, CMPI_chars); > > + CMSetProperty(inst, "ConsumedResourceUnits", > + (CMPIValue *)units, CMPI_chars); > + } > + > if (caption != NULL) > CMSetProperty(inst, "Caption", > (CMPIValue *)caption, CMPI_chars); > @@ -761,9 +795,9 @@ > ns); > > mempool_set_total(inst, conn); > - mempool_set_reserved(inst, conn); > + mempool_set_consumed(inst, conn); > > - set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true); > + set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true); > > inst_list_add(list, inst); > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From cvincent at linux.vnet.ibm.com Mon Jun 27 14:11:33 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 27 Jun 2011 10:11:33 -0400 Subject: [Libvirt-cim] [PATCH] Fix AppliedFilterList Associators In-Reply-To: References: <26cfeade3cb76c4ee43a.1308792374@oc0840652111.ibm.com> Message-ID: <4E088F95.3090502@linux.vnet.ibm.com> Nit fixed and pushed. On 06/26/2011 12:37 PM, Sharad Mishra wrote: > Sharad Mishra > Open Virtualization > Linux Technology Center > IBM > > libvirt-cim-bounces at redhat.com wrote on 06/22/2011 06:26:14 PM: > > > Chip Vincent > > Sent by: libvirt-cim-bounces at redhat.com > > > > 06/22/11 06:26 PM > > > > Please respond to > > List for discussion and development of libvirt CIM > > > > > To > > > > libvirt-cim at redhat.com > > > > cc > > > > Subject > > > > [Libvirt-cim] [PATCH] Fix AppliedFilterList Associators > > > > # HG changeset patch > > # User Chip Vincent > > # Date 1308792349 14400 > > # Node ID 26cfeade3cb76c4ee43a7bd33ea456a250c1c1c2 > > # Parent a37f80f80d4b2dab73391989168592866c23ba9b > > Fix AppliedFilterList Associators. > > > > Fixed a few small issues relating to reading AppliedFilterList. > > > > Signed-off-by: Chip Vincent > > > > diff --git a/schema/AppliedFilterList.registration b/schema/ > > AppliedFilterList.registration > > --- a/schema/AppliedFilterList.registration > > +++ b/schema/AppliedFilterList.registration > > @@ -1,3 +1,3 @@ > > # Copyright IBM Corp. 2011 > > # Classname Namespace ProviderName ProviderModule ProviderTypes > > -KVM_AppliedFilterList root/virt Virt_AppliedFilterList > > Virt_AppliedFilterList association > > +KVM_AppliedFilterList root/virt Virt_AppliedFilterList > > Virt_AppliedFilterList instance association > > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > > --- a/src/Virt_AppliedFilterList.c > > +++ b/src/Virt_AppliedFilterList.c > > @@ -218,7 +218,7 @@ > > CU_DEBUG("filterref = %s", ndev->filter_ref); > > > > if ((ndev->filter_ref != NULL) && > > - STREQC(name, ndev->filter_ref)) { > > + STREQC(name, ndev->filter_ref)) { > > Its a nit, can you fix the indentation above? > > > CU_DEBUG("Getting network device instance"); > > > > CMPIInstance *instance = NULL; > > @@ -235,10 +235,10 @@ > > CIM_RES_TYPE_NET, > > &instance); > > > > - if (instance != NULL) { > > - CU_DEBUG("adding instance to list"); > > + free(device_id); > > + > > + if (instance != NULL) > > inst_list_add(list, instance); > > - } > > } > > } > > > > @@ -317,7 +317,7 @@ > > CU_DEBUG("Checking net device '%s' for filterref", > > devices[i].id); > > > > - if (STREQC(device_name, devices[i].id)) { > > + if (STREQC(net_name, devices[i].id)) { > > CMPIInstance *instance = NULL; > > > > CU_DEBUG("Processing %s", ndev->filter_ref); > > @@ -332,18 +332,18 @@ > > filter, > > &instance); > > > > + cleanup_filter(filter); > > + > > if (instance != NULL) > > inst_list_add(list, instance); > > - > > } > > > > } > > > > cleanup_virt_devices(&devices, count); > > + > > out: > > - > > free(domain_name); > > - free((char *)device_name); > > free(net_name); > > > > virDomainFree(dom); > > > > _______________________________________________ > > Libvirt-cim mailing list > > Libvirt-cim at redhat.com > > https://www.redhat.com/mailman/listinfo/libvirt-cim > > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Mon Jun 27 14:16:45 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 27 Jun 2011 10:16:45 -0400 Subject: [Libvirt-cim] [PATCH] Check libvirt version before compiling ACL library code In-Reply-To: References: <090e8ae2a0c18fad143d.1308765913@oc0840652111.ibm.com> Message-ID: <4E0890CD.4000900@linux.vnet.ibm.com> Tested that the ACL effectively does nothing on RHEL 5.5 w libvirt-0.6.3. Pushed. On 06/26/2011 01:18 PM, Sharad Mishra wrote: > Code looks fine and compiles. Haven't tested it. > Please test and push. > > +1 > > Sharad Mishra > Open Virtualization > Linux Technology Center > IBM > > libvirt-cim-bounces at redhat.com wrote on 06/22/2011 11:05:13 AM: > > > Chip Vincent > > Sent by: libvirt-cim-bounces at redhat.com > > > > 06/22/11 11:05 AM > > > > Please respond to > > List for discussion and development of libvirt CIM > > > > > To > > > > libvirt-cim at redhat.com > > > > cc > > > > Subject > > > > [Libvirt-cim] [PATCH] Check libvirt version before compiling ACL > library code > > > > # HG changeset patch > > # User Chip Vincent > > # Date 1308765905 14400 > > # Node ID 090e8ae2a0c18fad143df826dececb48d4de6b3a > > # Parent f5c86ef03e64f61bb142f1aeaf448c438b28bd23 > > Check libvirt version before compiling ACL library code. > > > > RHEL 5.5 that ships with libvirt 0.6.3. The NWFilter* APIs were > created in > > 0.8.1 so the ACL code should be stubbed when LIBVIR_VERSION_NUMBER > > 8000. > > Same thing with using virDomainUpdateDeviceFlags(). > > > > Signed-off-by: Chip Vincent > > > > diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c > > --- a/libxkutil/acl_parsing.c > > +++ b/libxkutil/acl_parsing.c > > @@ -456,6 +456,7 @@ > > const char *name, > > struct acl_filter **filter) > > { > > +#if LIBVIR_VERSION_NUMBER > 8000 > > virNWFilterPtr vfilter = NULL; > > char *xml = NULL; > > > > @@ -474,6 +475,9 @@ > > get_filter_from_xml(xml, filter); > > > > return 1; > > +#else > > + return 0; > > +#endif > > } > > > > int get_filter_by_uuid( > > @@ -481,6 +485,7 @@ > > const char *uuid, > > struct acl_filter **filter) > > { > > +#if LIBVIR_VERSION_NUMBER > 8000 > > virNWFilterPtr vfilter = NULL; > > char *xml = NULL; > > > > @@ -499,12 +504,16 @@ > > get_filter_from_xml(xml, filter); > > > > return 1; > > +#else > > + return 0; > > +#endif > > } > > > > int get_filters( > > virConnectPtr conn, > > struct acl_filter **list) > > { > > +#if LIBVIR_VERSION_NUMBER > 8000 > > int count = 0; > > char **names = NULL; > > struct acl_filter *filters = NULL; > > @@ -537,6 +546,9 @@ > > free(names); > > > > return i; > > +#else > > + return 0; > > +#endif > > } > > > > > > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > > --- a/src/Virt_AppliedFilterList.c > > +++ b/src/Virt_AppliedFilterList.c > > @@ -105,6 +105,7 @@ > > static int update_device(virDomainPtr dom, > > struct virt_device *dev) > > { > > +#if LIBVIR_VERSION_NUMBER > 8000 > > char *xml = NULL; > > int flags = VIR_DOMAIN_DEVICE_MODIFY_CURRENT | > > VIR_DOMAIN_DEVICE_MODIFY_CONFIG; > > @@ -132,6 +133,9 @@ > > free(xml); > > > > return ret; > > +#else > > + return 0; > > +#endif > > } > > > > /* TODO: Port to libxkutil/device_parsing.c */ > > > > _______________________________________________ > > Libvirt-cim mailing list > > Libvirt-cim at redhat.com > > https://www.redhat.com/mailman/listinfo/libvirt-cim > > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Mon Jun 27 14:25:14 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 27 Jun 2011 10:25:14 -0400 Subject: [Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only actively allocated memory In-Reply-To: References: Message-ID: <4E0892CA.80101@linux.vnet.ibm.com> Thanks. Pushed. On 06/26/2011 01:30 PM, Sharad Mishra wrote: > code looks fine. > please test and push. > > +1 > > Sharad Mishra > Open Virtualization > Linux Technology Center > IBM > > libvirt-cim-bounces at redhat.com wrote on 06/22/2011 08:33:03 AM: > > > Chip Vincent > > Sent by: libvirt-cim-bounces at redhat.com > > > > 06/22/11 08:33 AM > > > > Please respond to > > List for discussion and development of libvirt CIM > > > > > To > > > > libvirt-cim at redhat.com > > > > cc > > > > Subject > > > > [Libvirt-cim] [PATCH] (#2) Fix MemoryPool.Reserved to show only > > actively allocated memory > > > > # HG changeset patch > > # User Chip Vincent > > # Date 1308756569 14400 > > # Node ID c5a9510b6bd1569c6ab0966624306e29ecd81727 > > # Parent 6c29c5b284443e226e7d97e7e5f11848b0c4e761 > > (#2) Fix MemoryPool.Reserved to show only actively allocated memory. > > > > It appears Reserved is meant to show memory that is taken (actively > in use by > > VMs) as opposed to memory that is potentially taken (assigned to > defined, but > > not running VMs). > > Also added CurrentlyConsumedResource (a much clearer name for the > same thing) > > and ConsumedResourceUnits, fixed units to conform with DSP1045, and > cleaned > > up some extraneous whitespace. > > > > Changes from #1: > > - Fix return code checking > > > > Signed-off-by: Chip Vincent > > > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > > --- a/src/Virt_DevicePool.c > > +++ b/src/Virt_DevicePool.c > > @@ -676,17 +676,47 @@ > > return memory != 0; > > } > > > > -static bool mempool_set_reserved(CMPIInstance *inst, virConnectPtr conn) > > +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) > > { > > - uint64_t memory; > > + uint64_t memory = 0; > > + int *domain_ids = NULL; > > + int count, i = 0; > > > > - /* NB: This doesn't account for memory to be claimed > > - * by ballooning dom0 > > - */ > > - memory = allocated_memory(conn); > > + count = virConnectNumOfDomains(conn); > > + if (count <= 0) > > + goto out; > > + > > + domain_ids = calloc(count, sizeof(domain_ids[0])); > > + if (domain_ids == NULL) > > + goto out; > > + > > + if (virConnectListDomains(conn, domain_ids, count) == -1) > > + goto out; > > + > > + for (i = 0; i < count; i++) { > > + virDomainPtr dom = NULL; > > + virDomainInfo dom_info; > > + > > + dom = virDomainLookupByID(conn, domain_ids[i]); > > + if (dom == NULL) { > > + CU_DEBUG("Cannot connect to domain %n: excluding", > > + domain_ids[i]); > > + continue; > > + } > > + > > + if (virDomainGetInfo(dom, &dom_info) == 0) > > + memory += dom_info.memory; > > + > > + virDomainFree(dom); > > + } > > + > > + out: > > + free(domain_ids); > > > > CMSetProperty(inst, "Reserved", > > (CMPIValue *)&memory, CMPI_uint64); > > + CMSetProperty(inst, "CurrentlyConsumedResource", > > + (CMPIValue *)&memory, CMPI_uint64); > > > > return memory != 0; > > } > > @@ -726,10 +756,14 @@ > > CMSetProperty(inst, "ResourceType", > > (CMPIValue *)&type, CMPI_uint16); > > > > - if (units != NULL) > > + if (units != NULL) { > > CMSetProperty(inst, "AllocationUnits", > > (CMPIValue *)units, CMPI_chars); > > > > + CMSetProperty(inst, "ConsumedResourceUnits", > > + (CMPIValue *)units, CMPI_chars); > > + } > > + > > if (caption != NULL) > > CMSetProperty(inst, "Caption", > > (CMPIValue *)caption, CMPI_chars); > > @@ -761,9 +795,9 @@ > > ns); > > > > mempool_set_total(inst, conn); > > - mempool_set_reserved(inst, conn); > > + mempool_set_consumed(inst, conn); > > > > - set_params(inst, CIM_RES_TYPE_MEM, id, "KiloBytes", NULL, true); > > + set_params(inst, CIM_RES_TYPE_MEM, id, "byte*2^10", NULL, true); > > > > inst_list_add(list, inst); > > > > > > _______________________________________________ > > Libvirt-cim mailing list > > Libvirt-cim at redhat.com > > https://www.redhat.com/mailman/listinfo/libvirt-cim > > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Mon Jun 27 17:45:15 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Mon, 27 Jun 2011 14:45:15 -0300 Subject: [Libvirt-cim] [PATCH] Add read-only support Message-ID: <9be9d0b2eed352a96bd0.1309196715@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308270993 14400 # Node ID 9be9d0b2eed352a96bd07dcff435b8de5f7a43c6 # Parent a2f523cd39c29977ed07247a38316d44f5123874 Add read-only support. This patch enables a consumer of libvirt-cim to put it in read-only mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. Also clean-up some extra whitespace in touched files. Signed-off-by: Chip Vincent Signed-off-by: Eduardo Lima (Etrunko) diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -172,6 +172,9 @@ pkgdata_SCRIPTS = provider-register.sh +libvirtcim_confdir = @sysconfdir@ +dist_libvirtcim_conf_DATA = @PACKAGE at .conf + EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ doc/CodingStyle doc/SubmittingPatches \ diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -270,6 +270,15 @@ LDFLAGS="$LDFLAGS $LIBUUID_LIBS" ]) +AC_DEFUN([CHECK_LIBCONFIG], + [ + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) + AC_SUBST([LIBCONFIG_CFLAGS]) + AC_SUBST([LIBCONFIG_LIBS]) + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" + ]) + # A convenience macro that spits out a fail message for a particular test # # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,7 @@ CHECK_LIBXML2 CHECK_LIBCU CHECK_LIBUUID +CHECK_LIBCONFIG CFLAGS_STRICT="-Werror" diff --git a/libvirt-cim.conf b/libvirt-cim.conf new file mode 100644 --- /dev/null +++ b/libvirt-cim.conf @@ -0,0 +1,13 @@ +# +# libvirt-cim config file +# +# This config file is based on the libconfig format. For more information, +# please check http://www.hyperrealm.com/libconfig/ +# + +# readonly (boolean) +# Defines wether connection to libvirt is read-only or not +# Possible values: {true,false} +# Default value: false +# +# readonly = false; diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -26,6 +26,7 @@ BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description @@ -135,6 +136,7 @@ %{_datadir}/libvirt-cim/*.registration %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf +%{_sysconfdir}/libvirt-cim.conf %changelog * Wed Oct 28 2009 Richard Maciel - 0.1-1 diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -1,7 +1,8 @@ # Copyright IBM Corp. 2007 SUBDIRS = tests -CFLAGS += $(CFLAGS_STRICT) +AM_CFLAGS = $(CFLAGS_STRICT) \ + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ pool_parsing.h acl_parsing.h diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -35,11 +35,12 @@ #include #include +#include #include "misc_util.h" #include "cs_util.h" -#include +#include "config.h" #define URI_ENV "HYPURI" @@ -55,6 +56,37 @@ return NULL; } +static int is_read_only(void) +{ + config_t conf; + int ret, readonly = 0; + const char *readonly_str = "readonly"; + + config_init(&conf); + + ret = config_read_file(&conf, LIBVIRTCIM_CONF); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error reading config file(%d): '%s'\n", + conf.error_type, conf.error_text); + goto out; + } + + ret = config_lookup_bool(&conf, readonly_str, &readonly); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error: '%s' not found in config file\n", + readonly_str); + goto out; + } + + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, + LIBVIRTCIM_CONF, readonly); +out: + config_destroy(&conf); + + /* Default value is 0 (false) */ + return readonly; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) @@ -66,7 +98,7 @@ uri = cn_to_uri(classname); if (!uri) { - cu_statusf(broker, s, + cu_statusf(broker, s, CMPI_RC_ERR_FAILED, "Unable to generate URI from classname"); return NULL; @@ -74,7 +106,11 @@ CU_DEBUG("Connecting to libvirt with uri `%s'", uri); - conn = virConnectOpen(uri); + if (is_read_only()) + conn = virConnectOpenReadOnly(uri); + else + conn = virConnectOpen(uri); + if (!conn) { CU_DEBUG("Unable to connect to `%s'", uri); return NULL; @@ -258,7 +294,7 @@ inst = CMNewInstance(broker, op, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - + CMSetProperty(inst, "CreationClassName", (CMPIValue *)new_cn, CMPI_chars); @@ -310,7 +346,7 @@ if (STREQC(pfx, "CIM")) { cu_statusf(broker, status, CMPI_RC_ERR_FAILED, - "Please exactly specify the class (check CIMOM behavior!): %s", + "Please exactly specify the class (check CIMOM behavior!): %s", CLASSNAME(reference)); rc = false; } @@ -347,7 +383,7 @@ free(pfx); } - + free(ref_pfx); return rc; } @@ -367,13 +403,13 @@ CLASSNAME(source_ref), assoc_classname, NAMESPACE(source_ref)); - + if (ref_inst != NULL) { CMPIObjectPath *target_ref; - + target_ref = CMGetObjectPath(target_inst, NULL); - set_reference(assoc, ref_inst, + set_reference(assoc, ref_inst, source_ref, target_ref); } From cvincent at linux.vnet.ibm.com Mon Jun 27 22:35:15 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 27 Jun 2011 18:35:15 -0400 Subject: [Libvirt-cim] [PATCH] Add write support for FilterList and NestedFilterList Message-ID: <03e3f95547078be19d8d.1309214115@oc0840652111.ibm.com> # HG changeset patch # User Chip Vincent # Date 1309213800 14400 # Node ID 03e3f95547078be19d8d22cac83ce38daf7510b9 # Parent 75411f53df02159c3fa6ce5810c9446579e3d66d Add write support for FilterList and NestedFilterList This allows clients to create new filter lists and then associate them with other filter lists to create complex filters. This patch also has some minor bug fixes to AppliedFilterList so the new filters can be applied to existing NetworkPort instances. The new cimtests for the create/delete associations are still under construction, but you can easily test FilterList create/delete (foundation) with the following commands: # wbemcli ci 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="",Name="",SystemCreationClassName="",SystemName=""' 'Name="test"' # wbemcli di 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="KVM_FilterList",Name="test",SystemCreationClassName="KVM_HostSystem",SystemName="oc0840652111.ibm.com"' Signed-off-by: Chip Vincent diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c --- a/libxkutil/acl_parsing.c +++ b/libxkutil/acl_parsing.c @@ -551,6 +551,57 @@ #endif } +int create_filter(virConnectPtr conn, struct acl_filter *filter) +{ + virNWFilterPtr vfilter = NULL; + char *xml = NULL; + + if (filter == NULL) + return 0; + + xml = filter_to_xml(filter); + if (xml == NULL) + return 0; + + vfilter = virNWFilterDefineXML(conn, xml); + + free(xml); + + if (vfilter == NULL) + return 0; + + virNWFilterFree(vfilter); + + return 1; +} + +int update_filter(virConnectPtr conn, struct acl_filter *filter) +{ + if (delete_filter(conn, filter) == 0 || + create_filter(conn, filter) == 0) + return 0; + + return 1; +} + +int delete_filter(virConnectPtr conn, struct acl_filter *filter) +{ + virNWFilterPtr vfilter = NULL; + + if (filter == NULL) + return 0; + + vfilter = virNWFilterLookupByUUIDString(conn, filter->uuid); + if (vfilter == NULL) + return 0; + + if (virNWFilterUndefine(vfilter) != 0) { + virNWFilterFree(vfilter); + return 0; + } + + return 1; +} int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule) { @@ -605,6 +656,28 @@ return 1; } +int remove_filter_ref(struct acl_filter *filter, const char *name) +{ + int i; + char **old_refs = NULL; + + if ((filter == NULL) || (name == NULL)) + return 0; + + /* TODO: called infrequently, but needs optimization */ + old_refs = filter->refs; + + for (i = 0; i < filter->ref_ct; i++) { + if (STREQC(old_refs[i], name)) { + free(old_refs[i]); + } + else + append_filter_ref(filter, old_refs[i]); + } + + return 1; +} + char *make_rule_id(const char *filter, int index) { int ret; diff --git a/libxkutil/acl_parsing.h b/libxkutil/acl_parsing.h --- a/libxkutil/acl_parsing.h +++ b/libxkutil/acl_parsing.h @@ -194,11 +194,17 @@ char *make_rule_id(const char *filter, int index); int parse_rule_id(const char *rule_id, char **filter, int *index); +int create_filter(virConnectPtr conn, struct acl_filter *filter); +int update_filter(virConnectPtr conn, struct acl_filter *filter); +int delete_filter(virConnectPtr conn, struct acl_filter *filter); + /** NOTE: Both append functions take parameters allocated by caller and * freed by cleanup_filter(s) */ int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule); int append_filter_ref(struct acl_filter *filter, char *name); +int remove_filter_ref(struct acl_filter *filter, const char *name); + #endif /* diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c +++ b/libxkutil/xmlgen.c @@ -1360,6 +1360,59 @@ return xml; } +char *filter_to_xml(struct acl_filter *filter) +{ + char *msg = XML_ERROR; + char *xml = NULL; + xmlNodePtr root = NULL; + xmlNodePtr tmp = NULL; + int i; + + root = xmlNewNode(NULL, BAD_CAST "filter"); + if (root == NULL) + goto out; + + if (xmlNewProp(root, BAD_CAST "name", BAD_CAST filter->name) == NULL) + goto out; + + if (filter->chain != NULL) + if (xmlNewProp(root, BAD_CAST "chain", + BAD_CAST filter->chain) == NULL) + goto out; + + if (filter->uuid != NULL) { + tmp = xmlNewChild(root, NULL, BAD_CAST "uuid", NULL); + if (xmlNewProp(tmp, NULL, BAD_CAST filter->uuid) == NULL) + goto out; + } + + for (i = 0; i < filter->ref_ct; i++) { + tmp = xmlNewChild(root, NULL, BAD_CAST "filterref", NULL); + if (xmlNewProp(tmp, BAD_CAST "filter", + BAD_CAST filter->refs[i]) == NULL) + goto out; + } + + /* TODO: Not yet supported + for (i = 0; i < filter->rule_ct; i++) { + msg = rule_to_xml(root, filter->rules[i]); + if (msg != NULL) + goto out; + } + */ + + xml = tree_to_xml(root); + if (xml != NULL) + msg = NULL; /* no errors */ + + out: + CU_DEBUG("Filter XML: %s", msg); + + xmlFreeNode(root); + + return xml; +} + /* * Local Variables: * mode: C diff --git a/schema/NestedFilterList.registration b/schema/NestedFilterList.registration --- a/schema/NestedFilterList.registration +++ b/schema/NestedFilterList.registration @@ -1,3 +1,3 @@ # Copyright IBM Corp. 2011 # Classname Namespace ProviderName ProviderModule ProviderTypes -KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList association +KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList instance association diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c --- a/src/Virt_AppliedFilterList.c +++ b/src/Virt_AppliedFilterList.c @@ -411,10 +411,6 @@ libvirt_cim_init(), handlers); -DEFAULT_GI(); -DEFAULT_EIN(); -DEFAULT_EI(); - static CMPIStatus CreateInstance( CMPIInstanceMI *self, const CMPIContext *context, @@ -434,6 +430,8 @@ virConnectPtr conn = NULL; virDomainPtr dom = NULL; + CU_DEBUG("Reference = %s", REF2STR(reference)); + if (cu_get_ref_prop(instance, "Antecedent", &antecedent) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -473,6 +471,8 @@ goto out; } + CU_DEBUG("DeviceID = %s", device_name); + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { CU_DEBUG("Failed to parse devid"); goto out; @@ -492,7 +492,11 @@ goto out; } - free(device->dev.net.filter_ref); + if (device->dev.net.filter_ref != NULL) { + free(device->dev.net.filter_ref); + device->dev.net.filter_ref = NULL; + } + device->dev.net.filter_ref = strdup(filter_name); if (update_device(dom, device) == 0) { @@ -502,10 +506,10 @@ goto out; } + CU_DEBUG("CreateInstance complete"); + out: - free((char *)filter_name); free(domain_name); - free((char *)device_name); free(net_name); cleanup_filter(filter); @@ -535,6 +539,8 @@ virConnectPtr conn = NULL; virDomainPtr dom = NULL; + CU_DEBUG("Reference = %s", REF2STR(reference)); + if (cu_get_ref_path(reference, "Antecedent", &antecedent) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -574,6 +580,8 @@ goto out; } + CU_DEBUG("DeviceID = %s", device_name); + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { CU_DEBUG("Failed to parse devid"); goto out; @@ -593,8 +601,10 @@ goto out; } - free(device->dev.net.filter_ref); - device->dev.net.filter_ref = NULL; + if (device->dev.net.filter_ref != NULL) { + free(device->dev.net.filter_ref); + device->dev.net.filter_ref = NULL; + } if (update_device(dom, device) == 0) { cu_statusf(_BROKER, &s, @@ -603,10 +613,10 @@ goto out; } + CU_DEBUG("CreateInstance complete"); + out: - free((char *)filter_name); free(domain_name); - free((char *)device_name); free(net_name); cleanup_filter(filter); @@ -618,12 +628,15 @@ return s; } +DEFAULT_GI(); +DEFAULT_EIN(); +DEFAULT_EI(); DEFAULT_MI(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); STD_InstanceMIStub(, - Virt_AppliedFilterEntry, + Virt_AppliedFilterList, _BROKER, libvirt_cim_init()); diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c --- a/src/Virt_FilterList.c +++ b/src/Virt_FilterList.c @@ -81,6 +81,32 @@ return inst; } +static struct acl_filter *convert_instance_to_filter( + const CMPIInstance *instance, + const CMPIContext *context, + CMPIStatus *s) +{ + struct acl_filter *filter = NULL; + const char *name = NULL; + + if (cu_get_str_prop(instance, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unable to get Name property"); + goto out; + } + + filter = malloc(sizeof(*filter)); + if (filter == NULL) + goto out; + + memset(filter, 0, sizeof(*filter)); + filter->name = strdup(name); + + out: + return filter; +} + CMPIStatus enum_filter_lists(const CMPIBroker *broker, const CMPIContext *context, const CMPIObjectPath *reference, @@ -230,9 +256,114 @@ return s; } -DEFAULT_CI(); +static CMPIStatus CreateInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name = NULL; + struct acl_filter *filter = NULL; + CMPIInstance *_instance = NULL; + virConnectPtr conn = NULL; + + /**Get Name from instance rather than reference since keys + * are set by this provider, not the client. + */ + if (cu_get_str_prop(instance, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Name property"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + get_filter_by_name(conn, name, &filter); + if (filter != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_ALREADY_EXISTS, + "Instance already exists"); + goto out; + } + + filter = convert_instance_to_filter(instance, context, &s); + if (filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to convert instance to filter"); + goto out; + } + + if (create_filter(conn, filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to create filter"); + goto out; + } + + _instance = convert_filter_to_instance(filter, + _BROKER, + context, + reference, + &s); + + if(_instance != NULL) + cu_return_instance_name(results, _instance); + + CU_DEBUG("CreateInstance complete"); + + out: + cleanup_filter(filter); + virConnectClose(conn); + + return s; +} + +static CMPIStatus DeleteInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name = NULL; + struct acl_filter *filter = NULL; + virConnectPtr conn = NULL; + + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Unable to get Name from reference"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + get_filter_by_name(conn, name, &filter); + if (filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Instance does not exist"); + goto out; + } + + delete_filter(conn, filter); + + out: + cleanup_filter(filter); + virConnectClose(conn); + + return s; +} + DEFAULT_MI(); -DEFAULT_DI(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); diff --git a/src/Virt_NestedFilterList.c b/src/Virt_NestedFilterList.c --- a/src/Virt_NestedFilterList.c +++ b/src/Virt_NestedFilterList.c @@ -38,6 +38,71 @@ static const CMPIBroker *_BROKER; +/* TODO: Port to libcmpiutil/args_util.c */ +/** + * Get a reference property of an instance + * + * @param inst The instance + * @param prop The property name + * @param reference A pointer to a CMPIObjectPath* that will be set + * if successful + * @returns + * - CMPI_RC_OK on success + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference + * - CMPI_RC_OK otherwise + */ +static CMPIrc cu_get_ref_prop(const CMPIInstance *instance, + const char *prop, + CMPIObjectPath **reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIData value; + + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ + value = CMGetProperty(instance, prop, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) + return CMPI_RC_ERR_NO_SUCH_PROPERTY; + + if ((value.type != CMPI_ref) || CMIsNullObject(value.value.ref)) + return CMPI_RC_ERR_TYPE_MISMATCH; + + *reference = value.value.ref; + + return CMPI_RC_OK; +} + +/* TODO: Port to libcmpiutil/args_util.c */ +/** + * Get a reference component of an object path + * + * @param _reference The reference + * @param key The key name + * @param reference A pointer to a CMPIObjectPath* that will be set + * if successful + * @returns + * - CMPI_RC_OK on success + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference + * - CMPI_RC_OK otherwise + */ +static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference, + const char *key, + CMPIObjectPath **_reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIData value; + + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ + value = CMGetKey(reference, key, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) + return CMPI_RC_ERR_NO_SUCH_PROPERTY; + + /* how to parse and object path? */ + + return CMPI_RC_OK; +} + /** * given a filter, find all *direct* filter_refs */ @@ -224,6 +289,203 @@ libvirt_cim_init(), handlers); +DEFAULT_GI(); +DEFAULT_EIN(); +DEFAULT_EI(); + +static CMPIStatus CreateInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIObjectPath *antecedent = NULL; + const char *parent_name = NULL; + struct acl_filter *parent_filter = NULL; + CMPIObjectPath *dependent = NULL; + const char *child_name = NULL; + struct acl_filter *child_filter = NULL; + virConnectPtr conn = NULL; + + CU_DEBUG("Reference = %s", REF2STR(reference)); + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + if (cu_get_ref_prop(instance, "Antecedent", + &antecedent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &parent_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent.Name property"); + goto out; + } + + get_filter_by_name(conn, parent_name, &parent_filter); + if (parent_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Antecedent.Name object does not exist"); + goto out; + } + + if (cu_get_ref_prop(instance, "Dependent", + &dependent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &child_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent.Name property"); + goto out; + } + + get_filter_by_name(conn, child_name, &child_filter); + if (child_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Dependent.Name object does not exist"); + goto out; + } + + if (append_filter_ref(parent_filter, strdup(child_name)) == 0) { + free(dup); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to append filter reference"); + goto out; + } + + if (update_filter(conn, parent_filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to update filter"); + goto out; + } + + CU_DEBUG("CreateInstance completed"); + + out: + cleanup_filter(parent_filter); + cleanup_filter(child_filter); + virConnectClose(conn); + + return s; +} + +static CMPIStatus DeleteInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIObjectPath *antecedent = NULL; + const char *parent_name = NULL; + struct acl_filter *parent_filter = NULL; + CMPIObjectPath *dependent = NULL; + const char *child_name = NULL; + struct acl_filter *child_filter = NULL; + virConnectPtr conn = NULL; + + CU_DEBUG("Reference = %s", REF2STR(reference)); + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + if (cu_get_ref_path(reference, "Antecedent", + &antecedent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &parent_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent.Name property"); + goto out; + } + + get_filter_by_name(conn, parent_name, &parent_filter); + if (parent_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Antecedent.Name object does not exist"); + goto out; + } + + if (cu_get_ref_path(reference, "Dependent", + &dependent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &child_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent.Name property"); + goto out; + } + + get_filter_by_name(conn, child_name, &child_filter); + if (child_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Dependent.Name object does not exist"); + goto out; + } + + if (remove_filter_ref(parent_filter, child_name) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to remove filter reference"); + goto out; + } + + if (update_filter(conn, parent_filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to update filter"); + goto out; + } + + CU_DEBUG("CreateInstance completed"); + + out: + cleanup_filter(parent_filter); + cleanup_filter(child_filter); + virConnectClose(conn); + + return s; +} + +DEFAULT_MI(); +DEFAULT_EQ(); +DEFAULT_INST_CLEANUP(); + +STD_InstanceMIStub(, + Virt_NestedFilterList, + _BROKER, + libvirt_cim_init()); + /* * Local Variables: * mode: C From cvincent at linux.vnet.ibm.com Mon Jun 27 23:09:02 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Mon, 27 Jun 2011 19:09:02 -0400 Subject: [Libvirt-cim] [PATCH] Add read-only support In-Reply-To: <9be9d0b2eed352a96bd0.1309196715@etrunko-t410.br.ibm.com> References: <9be9d0b2eed352a96bd0.1309196715@etrunko-t410.br.ibm.com> Message-ID: <4E090D8E.1030405@linux.vnet.ibm.com> On 06/27/2011 01:45 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308270993 14400 > # Node ID 9be9d0b2eed352a96bd07dcff435b8de5f7a43c6 > # Parent a2f523cd39c29977ed07247a38316d44f5123874 > Add read-only support. > > This patch enables a consumer of libvirt-cim to put it in read-only > mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. > > Also clean-up some extra whitespace in touched files. > > Signed-off-by: Chip Vincent > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/Makefile.am b/Makefile.am > --- a/Makefile.am > +++ b/Makefile.am > @@ -172,6 +172,9 @@ > > pkgdata_SCRIPTS = provider-register.sh > > +libvirtcim_confdir = @sysconfdir@ > +dist_libvirtcim_conf_DATA = @PACKAGE at .conf > + > EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ > $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ > doc/CodingStyle doc/SubmittingPatches \ > diff --git a/acinclude.m4 b/acinclude.m4 > --- a/acinclude.m4 > +++ b/acinclude.m4 > @@ -270,6 +270,15 @@ > LDFLAGS="$LDFLAGS $LIBUUID_LIBS" > ]) > > +AC_DEFUN([CHECK_LIBCONFIG], > + [ > + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) > + AC_SUBST([LIBCONFIG_CFLAGS]) > + AC_SUBST([LIBCONFIG_LIBS]) > + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" > + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" > + ]) > + > # A convenience macro that spits out a fail message for a particular test > # > # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) > diff --git a/configure.ac b/configure.ac > --- a/configure.ac > +++ b/configure.ac > @@ -166,6 +166,7 @@ > CHECK_LIBXML2 > CHECK_LIBCU > CHECK_LIBUUID > +CHECK_LIBCONFIG > > CFLAGS_STRICT="-Werror" > > diff --git a/libvirt-cim.conf b/libvirt-cim.conf > new file mode 100644 > --- /dev/null > +++ b/libvirt-cim.conf > @@ -0,0 +1,13 @@ > +# > +# libvirt-cim config file > +# > +# This config file is based on the libconfig format. For more information, > +# please check http://www.hyperrealm.com/libconfig/ > +# > + > +# readonly (boolean) > +# Defines wether connection to libvirt is read-only or not s/wether/whether/ May just want to say 'if' > +# Possible values: {true,false} > +# Default value: false > +# > +# readonly = false; > diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in > --- a/libvirt-cim.spec.in > +++ b/libvirt-cim.spec.in > @@ -26,6 +26,7 @@ > > BuildRequires: libxml2-devel > BuildRequires: libcmpiutil-devel > +BuildRequires: libconfig-devel > BuildConflicts: sblim-cmpi-devel > > %description > @@ -135,6 +136,7 @@ > %{_datadir}/libvirt-cim/*.registration > %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip > %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf > +%{_sysconfdir}/libvirt-cim.conf > > %changelog > * Wed Oct 28 2009 Richard Maciel - 0.1-1 > diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am > --- a/libxkutil/Makefile.am > +++ b/libxkutil/Makefile.am > @@ -1,7 +1,8 @@ > # Copyright IBM Corp. 2007 > SUBDIRS = tests > > -CFLAGS += $(CFLAGS_STRICT) > +AM_CFLAGS = $(CFLAGS_STRICT) \ > + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" > > noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ > pool_parsing.h acl_parsing.h > diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c > --- a/libxkutil/misc_util.c > +++ b/libxkutil/misc_util.c > @@ -35,11 +35,12 @@ > > #include > #include > +#include > > #include "misc_util.h" > #include "cs_util.h" > > -#include > +#include "config.h" > > #define URI_ENV "HYPURI" > > @@ -55,6 +56,37 @@ > return NULL; > } > > +static int is_read_only(void) > +{ > + config_t conf; > + int ret, readonly = 0; > + const char *readonly_str = "readonly"; > + > + config_init(&conf); > + > + ret = config_read_file(&conf, LIBVIRTCIM_CONF); > + if (ret == CONFIG_FALSE) { > + CU_DEBUG("Error reading config file(%d): '%s'\n", > + conf.error_type, conf.error_text); > + goto out; > + } The above does not compile on RHEL 6 with libconfig-1.3.2-1.1.el6.x86_64 misc_util.c: In function ?is_read_only?: misc_util.c:69: error: ?config_t? has no member named ?error_type? > + > + ret = config_lookup_bool(&conf, readonly_str,&readonly); > + if (ret == CONFIG_FALSE) { > + CU_DEBUG("Error: '%s' not found in config file\n", > + readonly_str); > + goto out; > + } > + > + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, > + LIBVIRTCIM_CONF, readonly); > +out: > + config_destroy(&conf); > + > + /* Default value is 0 (false) */ > + return readonly; > +} > + > virConnectPtr connect_by_classname(const CMPIBroker *broker, > const char *classname, > CMPIStatus *s) > @@ -66,7 +98,7 @@ > > uri = cn_to_uri(classname); > if (!uri) { > - cu_statusf(broker, s, > + cu_statusf(broker, s, > CMPI_RC_ERR_FAILED, > "Unable to generate URI from classname"); > return NULL; > @@ -74,7 +106,11 @@ > > CU_DEBUG("Connecting to libvirt with uri `%s'", uri); > > - conn = virConnectOpen(uri); > + if (is_read_only()) > + conn = virConnectOpenReadOnly(uri); > + else > + conn = virConnectOpen(uri); > + > if (!conn) { > CU_DEBUG("Unable to connect to `%s'", uri); > return NULL; > @@ -258,7 +294,7 @@ > inst = CMNewInstance(broker, op,&s); > if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) > goto out; > - > + > CMSetProperty(inst, "CreationClassName", > (CMPIValue *)new_cn, CMPI_chars); > > @@ -310,7 +346,7 @@ > if (STREQC(pfx, "CIM")) { > cu_statusf(broker, status, > CMPI_RC_ERR_FAILED, > - "Please exactly specify the class (check CIMOM behavior!): %s", > + "Please exactly specify the class (check CIMOM behavior!): %s", > CLASSNAME(reference)); > rc = false; > } > @@ -347,7 +383,7 @@ > > free(pfx); > } > - > + > free(ref_pfx); > return rc; > } > @@ -367,13 +403,13 @@ > CLASSNAME(source_ref), > assoc_classname, > NAMESPACE(source_ref)); > - > + > if (ref_inst != NULL) { > CMPIObjectPath *target_ref; > - > + > target_ref = CMGetObjectPath(target_inst, NULL); > > - set_reference(assoc, ref_inst, > + set_reference(assoc, ref_inst, > source_ref, target_ref); > } > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Tue Jun 28 14:26:19 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 10:26:19 -0400 Subject: [Libvirt-cim] [PATCH] Add write support for FilterList and NestedFilterList In-Reply-To: <03e3f95547078be19d8d.1309214115@oc0840652111.ibm.com> References: <03e3f95547078be19d8d.1309214115@oc0840652111.ibm.com> Message-ID: <4E09E48B.1050904@linux.vnet.ibm.com> Disregard.. Found some issues. Will post a version shortly. On 06/27/2011 06:35 PM, Chip Vincent wrote: > # HG changeset patch > # User Chip Vincent > # Date 1309213800 14400 > # Node ID 03e3f95547078be19d8d22cac83ce38daf7510b9 > # Parent 75411f53df02159c3fa6ce5810c9446579e3d66d > Add write support for FilterList and NestedFilterList > > This allows clients to create new filter lists and then associate them > with other filter lists to create complex filters. This patch also has some > minor bug fixes to AppliedFilterList so the new filters can be applied > to existing NetworkPort instances. The new cimtests for the create/delete > associations are still under construction, but you can easily test > FilterList create/delete (foundation) with the following commands: > > # wbemcli ci 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="",Name="",SystemCreationClassName="",SystemName=""' 'Name="test"' > > # wbemcli di 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="KVM_FilterList",Name="test",SystemCreationClassName="KVM_HostSystem",SystemName="oc0840652111.ibm.com"' > > Signed-off-by: Chip Vincent > > diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c > --- a/libxkutil/acl_parsing.c > +++ b/libxkutil/acl_parsing.c > @@ -551,6 +551,57 @@ > #endif > } > > +int create_filter(virConnectPtr conn, struct acl_filter *filter) > +{ > + virNWFilterPtr vfilter = NULL; > + char *xml = NULL; > + > + if (filter == NULL) > + return 0; > + > + xml = filter_to_xml(filter); > + if (xml == NULL) > + return 0; > + > + vfilter = virNWFilterDefineXML(conn, xml); > + > + free(xml); > + > + if (vfilter == NULL) > + return 0; > + > + virNWFilterFree(vfilter); > + > + return 1; > +} > + > +int update_filter(virConnectPtr conn, struct acl_filter *filter) > +{ > + if (delete_filter(conn, filter) == 0 || > + create_filter(conn, filter) == 0) > + return 0; > + > + return 1; > +} > + > +int delete_filter(virConnectPtr conn, struct acl_filter *filter) > +{ > + virNWFilterPtr vfilter = NULL; > + > + if (filter == NULL) > + return 0; > + > + vfilter = virNWFilterLookupByUUIDString(conn, filter->uuid); > + if (vfilter == NULL) > + return 0; > + > + if (virNWFilterUndefine(vfilter) != 0) { > + virNWFilterFree(vfilter); > + return 0; > + } > + > + return 1; > +} > > int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule) > { > @@ -605,6 +656,28 @@ > return 1; > } > > +int remove_filter_ref(struct acl_filter *filter, const char *name) > +{ > + int i; > + char **old_refs = NULL; > + > + if ((filter == NULL) || (name == NULL)) > + return 0; > + > + /* TODO: called infrequently, but needs optimization */ > + old_refs = filter->refs; > + > + for (i = 0; i< filter->ref_ct; i++) { > + if (STREQC(old_refs[i], name)) { > + free(old_refs[i]); > + } > + else > + append_filter_ref(filter, old_refs[i]); > + } > + > + return 1; > +} > + > char *make_rule_id(const char *filter, int index) > { > int ret; > diff --git a/libxkutil/acl_parsing.h b/libxkutil/acl_parsing.h > --- a/libxkutil/acl_parsing.h > +++ b/libxkutil/acl_parsing.h > @@ -194,11 +194,17 @@ > char *make_rule_id(const char *filter, int index); > int parse_rule_id(const char *rule_id, char **filter, int *index); > > +int create_filter(virConnectPtr conn, struct acl_filter *filter); > +int update_filter(virConnectPtr conn, struct acl_filter *filter); > +int delete_filter(virConnectPtr conn, struct acl_filter *filter); > + > /** NOTE: Both append functions take parameters allocated by caller and > * freed by cleanup_filter(s) > */ > int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule); > int append_filter_ref(struct acl_filter *filter, char *name); > +int remove_filter_ref(struct acl_filter *filter, const char *name); > + > #endif > > /* > diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c > --- a/libxkutil/xmlgen.c > +++ b/libxkutil/xmlgen.c > @@ -1360,6 +1360,59 @@ > return xml; > } > > +char *filter_to_xml(struct acl_filter *filter) > +{ > + char *msg = XML_ERROR; > + char *xml = NULL; > + xmlNodePtr root = NULL; > + xmlNodePtr tmp = NULL; > + int i; > + > + root = xmlNewNode(NULL, BAD_CAST "filter"); > + if (root == NULL) > + goto out; > + > + if (xmlNewProp(root, BAD_CAST "name", BAD_CAST filter->name) == NULL) > + goto out; > + > + if (filter->chain != NULL) > + if (xmlNewProp(root, BAD_CAST "chain", > + BAD_CAST filter->chain) == NULL) > + goto out; > + > + if (filter->uuid != NULL) { > + tmp = xmlNewChild(root, NULL, BAD_CAST "uuid", NULL); > + if (xmlNewProp(tmp, NULL, BAD_CAST filter->uuid) == NULL) > + goto out; > + } > + > + for (i = 0; i< filter->ref_ct; i++) { > + tmp = xmlNewChild(root, NULL, BAD_CAST "filterref", NULL); > + if (xmlNewProp(tmp, BAD_CAST "filter", > + BAD_CAST filter->refs[i]) == NULL) > + goto out; > + } > + > + /* TODO: Not yet supported > + for (i = 0; i< filter->rule_ct; i++) { > + msg = rule_to_xml(root, filter->rules[i]); > + if (msg != NULL) > + goto out; > + } > + */ > + > + xml = tree_to_xml(root); > + if (xml != NULL) > + msg = NULL; /* no errors */ > + > + out: > + CU_DEBUG("Filter XML: %s", msg); > + > + xmlFreeNode(root); > + > + return xml; > +} > + > /* > * Local Variables: > * mode: C > diff --git a/schema/NestedFilterList.registration b/schema/NestedFilterList.registration > --- a/schema/NestedFilterList.registration > +++ b/schema/NestedFilterList.registration > @@ -1,3 +1,3 @@ > # Copyright IBM Corp. 2011 > # Classname Namespace ProviderName ProviderModule ProviderTypes > -KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList association > +KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList instance association > diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c > --- a/src/Virt_AppliedFilterList.c > +++ b/src/Virt_AppliedFilterList.c > @@ -411,10 +411,6 @@ > libvirt_cim_init(), > handlers); > > -DEFAULT_GI(); > -DEFAULT_EIN(); > -DEFAULT_EI(); > - > static CMPIStatus CreateInstance( > CMPIInstanceMI *self, > const CMPIContext *context, > @@ -434,6 +430,8 @@ > virConnectPtr conn = NULL; > virDomainPtr dom = NULL; > > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > if (cu_get_ref_prop(instance, "Antecedent", > &antecedent) != CMPI_RC_OK) { > cu_statusf(_BROKER,&s, > @@ -473,6 +471,8 @@ > goto out; > } > > + CU_DEBUG("DeviceID = %s", device_name); > + > if (parse_fq_devid(device_name,&domain_name,&net_name) == 0) { > CU_DEBUG("Failed to parse devid"); > goto out; > @@ -492,7 +492,11 @@ > goto out; > } > > - free(device->dev.net.filter_ref); > + if (device->dev.net.filter_ref != NULL) { > + free(device->dev.net.filter_ref); > + device->dev.net.filter_ref = NULL; > + } > + > device->dev.net.filter_ref = strdup(filter_name); > > if (update_device(dom, device) == 0) { > @@ -502,10 +506,10 @@ > goto out; > } > > + CU_DEBUG("CreateInstance complete"); > + > out: > - free((char *)filter_name); > free(domain_name); > - free((char *)device_name); > free(net_name); > > cleanup_filter(filter); > @@ -535,6 +539,8 @@ > virConnectPtr conn = NULL; > virDomainPtr dom = NULL; > > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > if (cu_get_ref_path(reference, "Antecedent", > &antecedent) != CMPI_RC_OK) { > cu_statusf(_BROKER,&s, > @@ -574,6 +580,8 @@ > goto out; > } > > + CU_DEBUG("DeviceID = %s", device_name); > + > if (parse_fq_devid(device_name,&domain_name,&net_name) == 0) { > CU_DEBUG("Failed to parse devid"); > goto out; > @@ -593,8 +601,10 @@ > goto out; > } > > - free(device->dev.net.filter_ref); > - device->dev.net.filter_ref = NULL; > + if (device->dev.net.filter_ref != NULL) { > + free(device->dev.net.filter_ref); > + device->dev.net.filter_ref = NULL; > + } > > if (update_device(dom, device) == 0) { > cu_statusf(_BROKER,&s, > @@ -603,10 +613,10 @@ > goto out; > } > > + CU_DEBUG("CreateInstance complete"); > + > out: > - free((char *)filter_name); > free(domain_name); > - free((char *)device_name); > free(net_name); > > cleanup_filter(filter); > @@ -618,12 +628,15 @@ > return s; > } > > +DEFAULT_GI(); > +DEFAULT_EIN(); > +DEFAULT_EI(); > DEFAULT_MI(); > DEFAULT_EQ(); > DEFAULT_INST_CLEANUP(); > > STD_InstanceMIStub(, > - Virt_AppliedFilterEntry, > + Virt_AppliedFilterList, > _BROKER, > libvirt_cim_init()); > > diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c > --- a/src/Virt_FilterList.c > +++ b/src/Virt_FilterList.c > @@ -81,6 +81,32 @@ > return inst; > } > > +static struct acl_filter *convert_instance_to_filter( > + const CMPIInstance *instance, > + const CMPIContext *context, > + CMPIStatus *s) > +{ > + struct acl_filter *filter = NULL; > + const char *name = NULL; > + > + if (cu_get_str_prop(instance, "Name",&name) != CMPI_RC_OK) { > + cu_statusf(_BROKER, s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Name property"); > + goto out; > + } > + > + filter = malloc(sizeof(*filter)); > + if (filter == NULL) > + goto out; > + > + memset(filter, 0, sizeof(*filter)); > + filter->name = strdup(name); > + > + out: > + return filter; > +} > + > CMPIStatus enum_filter_lists(const CMPIBroker *broker, > const CMPIContext *context, > const CMPIObjectPath *reference, > @@ -230,9 +256,114 @@ > return s; > } > > -DEFAULT_CI(); > +static CMPIStatus CreateInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const CMPIInstance *instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + const char *name = NULL; > + struct acl_filter *filter = NULL; > + CMPIInstance *_instance = NULL; > + virConnectPtr conn = NULL; > + > + /**Get Name from instance rather than reference since keys > + * are set by this provider, not the client. > + */ > + if (cu_get_str_prop(instance, "Name",&name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Name property"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference),&s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, name,&filter); > + if (filter != NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_ALREADY_EXISTS, > + "Instance already exists"); > + goto out; > + } > + > + filter = convert_instance_to_filter(instance, context,&s); > + if (filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to convert instance to filter"); > + goto out; > + } > + > + if (create_filter(conn, filter) == 0) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to create filter"); > + goto out; > + } > + > + _instance = convert_filter_to_instance(filter, > + _BROKER, > + context, > + reference, > +&s); > + > + if(_instance != NULL) > + cu_return_instance_name(results, _instance); > + > + CU_DEBUG("CreateInstance complete"); > + > + out: > + cleanup_filter(filter); > + virConnectClose(conn); > + > + return s; > +} > + > +static CMPIStatus DeleteInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + const char *name = NULL; > + struct acl_filter *filter = NULL; > + virConnectPtr conn = NULL; > + > + if (cu_get_str_path(reference, "Name",&name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_NOT_FOUND, > + "Unable to get Name from reference"); > + goto out; > + } > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference),&s); > + if (conn == NULL) > + goto out; > + > + get_filter_by_name(conn, name,&filter); > + if (filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_NOT_FOUND, > + "Instance does not exist"); > + goto out; > + } > + > + delete_filter(conn, filter); > + > + out: > + cleanup_filter(filter); > + virConnectClose(conn); > + > + return s; > +} > + > DEFAULT_MI(); > -DEFAULT_DI(); > DEFAULT_EQ(); > DEFAULT_INST_CLEANUP(); > > diff --git a/src/Virt_NestedFilterList.c b/src/Virt_NestedFilterList.c > --- a/src/Virt_NestedFilterList.c > +++ b/src/Virt_NestedFilterList.c > @@ -38,6 +38,71 @@ > > static const CMPIBroker *_BROKER; > > +/* TODO: Port to libcmpiutil/args_util.c */ > +/** > + * Get a reference property of an instance > + * > + * @param inst The instance > + * @param prop The property name > + * @param reference A pointer to a CMPIObjectPath* that will be set > + * if successful > + * @returns > + * - CMPI_RC_OK on success > + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present > + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference > + * - CMPI_RC_OK otherwise > + */ > +static CMPIrc cu_get_ref_prop(const CMPIInstance *instance, > + const char *prop, > + CMPIObjectPath **reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIData value; > + > + /* REQUIRE_PROPERY_DEFINED(instance, prop, value,&s); */ > + value = CMGetProperty(instance, prop,&s); > + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) > + return CMPI_RC_ERR_NO_SUCH_PROPERTY; > + > + if ((value.type != CMPI_ref) || CMIsNullObject(value.value.ref)) > + return CMPI_RC_ERR_TYPE_MISMATCH; > + > + *reference = value.value.ref; > + > + return CMPI_RC_OK; > +} > + > +/* TODO: Port to libcmpiutil/args_util.c */ > +/** > + * Get a reference component of an object path > + * > + * @param _reference The reference > + * @param key The key name > + * @param reference A pointer to a CMPIObjectPath* that will be set > + * if successful > + * @returns > + * - CMPI_RC_OK on success > + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present > + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference > + * - CMPI_RC_OK otherwise > + */ > +static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference, > + const char *key, > + CMPIObjectPath **_reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIData value; > + > + /* REQUIRE_PROPERY_DEFINED(instance, prop, value,&s); */ > + value = CMGetKey(reference, key,&s); > + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) > + return CMPI_RC_ERR_NO_SUCH_PROPERTY; > + > + /* how to parse and object path? */ > + > + return CMPI_RC_OK; > +} > + > /** > * given a filter, find all *direct* filter_refs > */ > @@ -224,6 +289,203 @@ > libvirt_cim_init(), > handlers); > > +DEFAULT_GI(); > +DEFAULT_EIN(); > +DEFAULT_EI(); > + > +static CMPIStatus CreateInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference, > + const CMPIInstance *instance) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIObjectPath *antecedent = NULL; > + const char *parent_name = NULL; > + struct acl_filter *parent_filter = NULL; > + CMPIObjectPath *dependent = NULL; > + const char *child_name = NULL; > + struct acl_filter *child_filter = NULL; > + virConnectPtr conn = NULL; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference),&s); > + if (conn == NULL) > + goto out; > + > + if (cu_get_ref_prop(instance, "Antecedent", > +&antecedent) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name",&parent_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, parent_name,&parent_filter); > + if (parent_filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Antecedent.Name object does not exist"); > + goto out; > + } > + > + if (cu_get_ref_prop(instance, "Dependent", > +&dependent) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name",&child_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, child_name,&child_filter); > + if (child_filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Dependent.Name object does not exist"); > + goto out; > + } > + > + if (append_filter_ref(parent_filter, strdup(child_name)) == 0) { > + free(dup); > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to append filter reference"); > + goto out; > + } > + > + if (update_filter(conn, parent_filter) == 0) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to update filter"); > + goto out; > + } > + > + CU_DEBUG("CreateInstance completed"); > + > + out: > + cleanup_filter(parent_filter); > + cleanup_filter(child_filter); > + virConnectClose(conn); > + > + return s; > +} > + > +static CMPIStatus DeleteInstance( > + CMPIInstanceMI *self, > + const CMPIContext *context, > + const CMPIResult *results, > + const CMPIObjectPath *reference) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIObjectPath *antecedent = NULL; > + const char *parent_name = NULL; > + struct acl_filter *parent_filter = NULL; > + CMPIObjectPath *dependent = NULL; > + const char *child_name = NULL; > + struct acl_filter *child_filter = NULL; > + virConnectPtr conn = NULL; > + > + CU_DEBUG("Reference = %s", REF2STR(reference)); > + > + conn = connect_by_classname(_BROKER, CLASSNAME(reference),&s); > + if (conn == NULL) > + goto out; > + > + if (cu_get_ref_path(reference, "Antecedent", > +&antecedent) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name",&parent_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Antecedent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, parent_name,&parent_filter); > + if (parent_filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Antecedent.Name object does not exist"); > + goto out; > + } > + > + if (cu_get_ref_path(reference, "Dependent", > +&dependent) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent property"); > + goto out; > + } > + > + if (cu_get_str_path(reference, "Name",&child_name) != CMPI_RC_OK) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Unable to get Dependent.Name property"); > + goto out; > + } > + > + get_filter_by_name(conn, child_name,&child_filter); > + if (child_filter == NULL) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Dependent.Name object does not exist"); > + goto out; > + } > + > + if (remove_filter_ref(parent_filter, child_name) == 0) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to remove filter reference"); > + goto out; > + } > + > + if (update_filter(conn, parent_filter) == 0) { > + cu_statusf(_BROKER,&s, > + CMPI_RC_ERR_FAILED, > + "Failed to update filter"); > + goto out; > + } > + > + CU_DEBUG("CreateInstance completed"); > + > + out: > + cleanup_filter(parent_filter); > + cleanup_filter(child_filter); > + virConnectClose(conn); > + > + return s; > +} > + > +DEFAULT_MI(); > +DEFAULT_EQ(); > +DEFAULT_INST_CLEANUP(); > + > +STD_InstanceMIStub(, > + Virt_NestedFilterList, > + _BROKER, > + libvirt_cim_init()); > + > /* > * Local Variables: > * mode: C > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Tue Jun 28 14:27:48 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 10:27:48 -0400 Subject: [Libvirt-cim] [PATCH] (#2) Add write support for FilterList and NestedFilterList Message-ID: <2a1c7e5112590eb7157b.1309271268@oc0840652111.ibm.com> # HG changeset patch # User Chip Vincent # Date 1309213800 14400 # Node ID 2a1c7e5112590eb7157b566facd61ea9fc815b85 # Parent 75411f53df02159c3fa6ce5810c9446579e3d66d (#2) Add write support for FilterList and NestedFilterList Changes since #1: - fixed compilation issue This allows clients to create new filter lists and then associate them with other filter lists to create complex filters. This patch also has some minor bug fixes to AppliedFilterList so the new filters can be applied to existing NetworkPort instances. The new cimtests for the create/delete associations are still under construction, but you can easily test FilterList create/delete (foundation) with the following commands: # wbemcli ci 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="",Name="",SystemCreationClassName="",SystemName=""' 'Name="test"' # wbemcli di 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="KVM_FilterList",Name="test",SystemCreationClassName="KVM_HostSystem",SystemName="oc0840652111.ibm.com"' Signed-off-by: Chip Vincent diff --git a/libxkutil/acl_parsing.c b/libxkutil/acl_parsing.c --- a/libxkutil/acl_parsing.c +++ b/libxkutil/acl_parsing.c @@ -551,6 +551,57 @@ #endif } +int create_filter(virConnectPtr conn, struct acl_filter *filter) +{ + virNWFilterPtr vfilter = NULL; + char *xml = NULL; + + if (filter == NULL) + return 0; + + xml = filter_to_xml(filter); + if (xml == NULL) + return 0; + + vfilter = virNWFilterDefineXML(conn, xml); + + free(xml); + + if (vfilter == NULL) + return 0; + + virNWFilterFree(vfilter); + + return 1; +} + +int update_filter(virConnectPtr conn, struct acl_filter *filter) +{ + if (delete_filter(conn, filter) == 0 || + create_filter(conn, filter) == 0) + return 0; + + return 1; +} + +int delete_filter(virConnectPtr conn, struct acl_filter *filter) +{ + virNWFilterPtr vfilter = NULL; + + if (filter == NULL) + return 0; + + vfilter = virNWFilterLookupByUUIDString(conn, filter->uuid); + if (vfilter == NULL) + return 0; + + if (virNWFilterUndefine(vfilter) != 0) { + virNWFilterFree(vfilter); + return 0; + } + + return 1; +} int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule) { @@ -605,6 +656,28 @@ return 1; } +int remove_filter_ref(struct acl_filter *filter, const char *name) +{ + int i; + char **old_refs = NULL; + + if ((filter == NULL) || (name == NULL)) + return 0; + + /* TODO: called infrequently, but needs optimization */ + old_refs = filter->refs; + + for (i = 0; i < filter->ref_ct; i++) { + if (STREQC(old_refs[i], name)) { + free(old_refs[i]); + } + else + append_filter_ref(filter, old_refs[i]); + } + + return 1; +} + char *make_rule_id(const char *filter, int index) { int ret; diff --git a/libxkutil/acl_parsing.h b/libxkutil/acl_parsing.h --- a/libxkutil/acl_parsing.h +++ b/libxkutil/acl_parsing.h @@ -194,11 +194,17 @@ char *make_rule_id(const char *filter, int index); int parse_rule_id(const char *rule_id, char **filter, int *index); +int create_filter(virConnectPtr conn, struct acl_filter *filter); +int update_filter(virConnectPtr conn, struct acl_filter *filter); +int delete_filter(virConnectPtr conn, struct acl_filter *filter); + /** NOTE: Both append functions take parameters allocated by caller and * freed by cleanup_filter(s) */ int append_filter_rule(struct acl_filter *filter, struct acl_rule *rule); int append_filter_ref(struct acl_filter *filter, char *name); +int remove_filter_ref(struct acl_filter *filter, const char *name); + #endif /* diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c +++ b/libxkutil/xmlgen.c @@ -1360,6 +1360,59 @@ return xml; } +char *filter_to_xml(struct acl_filter *filter) +{ + char *msg = XML_ERROR; + char *xml = NULL; + xmlNodePtr root = NULL; + xmlNodePtr tmp = NULL; + int i; + + root = xmlNewNode(NULL, BAD_CAST "filter"); + if (root == NULL) + goto out; + + if (xmlNewProp(root, BAD_CAST "name", BAD_CAST filter->name) == NULL) + goto out; + + if (filter->chain != NULL) + if (xmlNewProp(root, BAD_CAST "chain", + BAD_CAST filter->chain) == NULL) + goto out; + + if (filter->uuid != NULL) { + tmp = xmlNewChild(root, NULL, BAD_CAST "uuid", NULL); + if (xmlNewProp(tmp, NULL, BAD_CAST filter->uuid) == NULL) + goto out; + } + + for (i = 0; i < filter->ref_ct; i++) { + tmp = xmlNewChild(root, NULL, BAD_CAST "filterref", NULL); + if (xmlNewProp(tmp, BAD_CAST "filter", + BAD_CAST filter->refs[i]) == NULL) + goto out; + } + + /* TODO: Not yet supported + for (i = 0; i < filter->rule_ct; i++) { + msg = rule_to_xml(root, filter->rules[i]); + if (msg != NULL) + goto out; + } + */ + + xml = tree_to_xml(root); + if (xml != NULL) + msg = NULL; /* no errors */ + + out: + CU_DEBUG("Filter XML: %s", msg); + + xmlFreeNode(root); + + return xml; +} + /* * Local Variables: * mode: C diff --git a/schema/NestedFilterList.registration b/schema/NestedFilterList.registration --- a/schema/NestedFilterList.registration +++ b/schema/NestedFilterList.registration @@ -1,3 +1,3 @@ # Copyright IBM Corp. 2011 # Classname Namespace ProviderName ProviderModule ProviderTypes -KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList association +KVM_NestedFilterList root/virt Virt_NestedFilterList Virt_NestedFilterList instance association diff --git a/src/Virt_AppliedFilterList.c b/src/Virt_AppliedFilterList.c --- a/src/Virt_AppliedFilterList.c +++ b/src/Virt_AppliedFilterList.c @@ -411,10 +411,6 @@ libvirt_cim_init(), handlers); -DEFAULT_GI(); -DEFAULT_EIN(); -DEFAULT_EI(); - static CMPIStatus CreateInstance( CMPIInstanceMI *self, const CMPIContext *context, @@ -434,6 +430,8 @@ virConnectPtr conn = NULL; virDomainPtr dom = NULL; + CU_DEBUG("Reference = %s", REF2STR(reference)); + if (cu_get_ref_prop(instance, "Antecedent", &antecedent) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -473,6 +471,8 @@ goto out; } + CU_DEBUG("DeviceID = %s", device_name); + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { CU_DEBUG("Failed to parse devid"); goto out; @@ -492,7 +492,11 @@ goto out; } - free(device->dev.net.filter_ref); + if (device->dev.net.filter_ref != NULL) { + free(device->dev.net.filter_ref); + device->dev.net.filter_ref = NULL; + } + device->dev.net.filter_ref = strdup(filter_name); if (update_device(dom, device) == 0) { @@ -502,10 +506,10 @@ goto out; } + CU_DEBUG("CreateInstance complete"); + out: - free((char *)filter_name); free(domain_name); - free((char *)device_name); free(net_name); cleanup_filter(filter); @@ -535,6 +539,8 @@ virConnectPtr conn = NULL; virDomainPtr dom = NULL; + CU_DEBUG("Reference = %s", REF2STR(reference)); + if (cu_get_ref_path(reference, "Antecedent", &antecedent) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -574,6 +580,8 @@ goto out; } + CU_DEBUG("DeviceID = %s", device_name); + if (parse_fq_devid(device_name, &domain_name, &net_name) == 0) { CU_DEBUG("Failed to parse devid"); goto out; @@ -593,8 +601,10 @@ goto out; } - free(device->dev.net.filter_ref); - device->dev.net.filter_ref = NULL; + if (device->dev.net.filter_ref != NULL) { + free(device->dev.net.filter_ref); + device->dev.net.filter_ref = NULL; + } if (update_device(dom, device) == 0) { cu_statusf(_BROKER, &s, @@ -603,10 +613,10 @@ goto out; } + CU_DEBUG("CreateInstance complete"); + out: - free((char *)filter_name); free(domain_name); - free((char *)device_name); free(net_name); cleanup_filter(filter); @@ -618,12 +628,15 @@ return s; } +DEFAULT_GI(); +DEFAULT_EIN(); +DEFAULT_EI(); DEFAULT_MI(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); STD_InstanceMIStub(, - Virt_AppliedFilterEntry, + Virt_AppliedFilterList, _BROKER, libvirt_cim_init()); diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c --- a/src/Virt_FilterList.c +++ b/src/Virt_FilterList.c @@ -81,6 +81,32 @@ return inst; } +static struct acl_filter *convert_instance_to_filter( + const CMPIInstance *instance, + const CMPIContext *context, + CMPIStatus *s) +{ + struct acl_filter *filter = NULL; + const char *name = NULL; + + if (cu_get_str_prop(instance, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unable to get Name property"); + goto out; + } + + filter = malloc(sizeof(*filter)); + if (filter == NULL) + goto out; + + memset(filter, 0, sizeof(*filter)); + filter->name = strdup(name); + + out: + return filter; +} + CMPIStatus enum_filter_lists(const CMPIBroker *broker, const CMPIContext *context, const CMPIObjectPath *reference, @@ -230,9 +256,114 @@ return s; } -DEFAULT_CI(); +static CMPIStatus CreateInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name = NULL; + struct acl_filter *filter = NULL; + CMPIInstance *_instance = NULL; + virConnectPtr conn = NULL; + + /**Get Name from instance rather than reference since keys + * are set by this provider, not the client. + */ + if (cu_get_str_prop(instance, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Name property"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + get_filter_by_name(conn, name, &filter); + if (filter != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_ALREADY_EXISTS, + "Instance already exists"); + goto out; + } + + filter = convert_instance_to_filter(instance, context, &s); + if (filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to convert instance to filter"); + goto out; + } + + if (create_filter(conn, filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to create filter"); + goto out; + } + + _instance = convert_filter_to_instance(filter, + _BROKER, + context, + reference, + &s); + + if(_instance != NULL) + cu_return_instance_name(results, _instance); + + CU_DEBUG("CreateInstance complete"); + + out: + cleanup_filter(filter); + virConnectClose(conn); + + return s; +} + +static CMPIStatus DeleteInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name = NULL; + struct acl_filter *filter = NULL; + virConnectPtr conn = NULL; + + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Unable to get Name from reference"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + get_filter_by_name(conn, name, &filter); + if (filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Instance does not exist"); + goto out; + } + + delete_filter(conn, filter); + + out: + cleanup_filter(filter); + virConnectClose(conn); + + return s; +} + DEFAULT_MI(); -DEFAULT_DI(); DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); diff --git a/src/Virt_NestedFilterList.c b/src/Virt_NestedFilterList.c --- a/src/Virt_NestedFilterList.c +++ b/src/Virt_NestedFilterList.c @@ -38,6 +38,71 @@ static const CMPIBroker *_BROKER; +/* TODO: Port to libcmpiutil/args_util.c */ +/** + * Get a reference property of an instance + * + * @param inst The instance + * @param prop The property name + * @param reference A pointer to a CMPIObjectPath* that will be set + * if successful + * @returns + * - CMPI_RC_OK on success + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference + * - CMPI_RC_OK otherwise + */ +static CMPIrc cu_get_ref_prop(const CMPIInstance *instance, + const char *prop, + CMPIObjectPath **reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIData value; + + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ + value = CMGetProperty(instance, prop, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) + return CMPI_RC_ERR_NO_SUCH_PROPERTY; + + if ((value.type != CMPI_ref) || CMIsNullObject(value.value.ref)) + return CMPI_RC_ERR_TYPE_MISMATCH; + + *reference = value.value.ref; + + return CMPI_RC_OK; +} + +/* TODO: Port to libcmpiutil/args_util.c */ +/** + * Get a reference component of an object path + * + * @param _reference The reference + * @param key The key name + * @param reference A pointer to a CMPIObjectPath* that will be set + * if successful + * @returns + * - CMPI_RC_OK on success + * - CMPI_RC_ERR_NO_SUCH_PROPERTY if prop is not present + * - CMPI_RC_ERR_TYPE_MISMATCH if prop is not a reference + * - CMPI_RC_OK otherwise + */ +static CMPIrc cu_get_ref_path(const CMPIObjectPath *reference, + const char *key, + CMPIObjectPath **_reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIData value; + + /* REQUIRE_PROPERY_DEFINED(instance, prop, value, &s); */ + value = CMGetKey(reference, key, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(value)) + return CMPI_RC_ERR_NO_SUCH_PROPERTY; + + /* how to parse and object path? */ + + return CMPI_RC_OK; +} + /** * given a filter, find all *direct* filter_refs */ @@ -224,6 +289,202 @@ libvirt_cim_init(), handlers); +DEFAULT_GI(); +DEFAULT_EIN(); +DEFAULT_EI(); + +static CMPIStatus CreateInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIInstance *instance) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIObjectPath *antecedent = NULL; + const char *parent_name = NULL; + struct acl_filter *parent_filter = NULL; + CMPIObjectPath *dependent = NULL; + const char *child_name = NULL; + struct acl_filter *child_filter = NULL; + virConnectPtr conn = NULL; + + CU_DEBUG("Reference = %s", REF2STR(reference)); + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + if (cu_get_ref_prop(instance, "Antecedent", + &antecedent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &parent_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent.Name property"); + goto out; + } + + get_filter_by_name(conn, parent_name, &parent_filter); + if (parent_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Antecedent.Name object does not exist"); + goto out; + } + + if (cu_get_ref_prop(instance, "Dependent", + &dependent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &child_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent.Name property"); + goto out; + } + + get_filter_by_name(conn, child_name, &child_filter); + if (child_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Dependent.Name object does not exist"); + goto out; + } + + if (append_filter_ref(parent_filter, strdup(child_name)) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to append filter reference"); + goto out; + } + + if (update_filter(conn, parent_filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to update filter"); + goto out; + } + + CU_DEBUG("CreateInstance completed"); + + out: + cleanup_filter(parent_filter); + cleanup_filter(child_filter); + virConnectClose(conn); + + return s; +} + +static CMPIStatus DeleteInstance( + CMPIInstanceMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIObjectPath *antecedent = NULL; + const char *parent_name = NULL; + struct acl_filter *parent_filter = NULL; + CMPIObjectPath *dependent = NULL; + const char *child_name = NULL; + struct acl_filter *child_filter = NULL; + virConnectPtr conn = NULL; + + CU_DEBUG("Reference = %s", REF2STR(reference)); + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) + goto out; + + if (cu_get_ref_path(reference, "Antecedent", + &antecedent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &parent_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Antecedent.Name property"); + goto out; + } + + get_filter_by_name(conn, parent_name, &parent_filter); + if (parent_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Antecedent.Name object does not exist"); + goto out; + } + + if (cu_get_ref_path(reference, "Dependent", + &dependent) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent property"); + goto out; + } + + if (cu_get_str_path(reference, "Name", &child_name) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get Dependent.Name property"); + goto out; + } + + get_filter_by_name(conn, child_name, &child_filter); + if (child_filter == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Dependent.Name object does not exist"); + goto out; + } + + if (remove_filter_ref(parent_filter, child_name) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to remove filter reference"); + goto out; + } + + if (update_filter(conn, parent_filter) == 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to update filter"); + goto out; + } + + CU_DEBUG("CreateInstance completed"); + + out: + cleanup_filter(parent_filter); + cleanup_filter(child_filter); + virConnectClose(conn); + + return s; +} + +DEFAULT_MI(); +DEFAULT_EQ(); +DEFAULT_INST_CLEANUP(); + +STD_InstanceMIStub(, + Virt_NestedFilterList, + _BROKER, + libvirt_cim_init()); + /* * Local Variables: * mode: C From eblima at linux.vnet.ibm.com Tue Jun 28 17:04:22 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 14:04:22 -0300 Subject: [Libvirt-cim] [PATCH] (#2) Add read-only support Message-ID: <5f1a03d548ef810f67be.1309280662@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308270993 14400 # Node ID 5f1a03d548ef810f67be9e326d565222e01a0451 # Parent a2f523cd39c29977ed07247a38316d44f5123874 Add read-only support. This patch enables a consumer of libvirt-cim to put it in read-only mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. Also clean-up some extra whitespace in touched files. Changes from #1: - Fix build error on RHEL 6 Signed-off-by: Chip Vincent Signed-off-by: Eduardo Lima (Etrunko) diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -172,6 +172,9 @@ pkgdata_SCRIPTS = provider-register.sh +libvirtcim_confdir = @sysconfdir@ +dist_libvirtcim_conf_DATA = @PACKAGE at .conf + EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ doc/CodingStyle doc/SubmittingPatches \ diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -270,6 +270,15 @@ LDFLAGS="$LDFLAGS $LIBUUID_LIBS" ]) +AC_DEFUN([CHECK_LIBCONFIG], + [ + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) + AC_SUBST([LIBCONFIG_CFLAGS]) + AC_SUBST([LIBCONFIG_LIBS]) + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" + ]) + # A convenience macro that spits out a fail message for a particular test # # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,7 @@ CHECK_LIBXML2 CHECK_LIBCU CHECK_LIBUUID +CHECK_LIBCONFIG CFLAGS_STRICT="-Werror" diff --git a/libvirt-cim.conf b/libvirt-cim.conf new file mode 100644 --- /dev/null +++ b/libvirt-cim.conf @@ -0,0 +1,13 @@ +# +# libvirt-cim config file +# +# This config file is based on the libconfig format. For more information, +# please check http://www.hyperrealm.com/libconfig/ +# + +# readonly (boolean) +# Defines wether connection to libvirt is read-only or not +# Possible values: {true,false} +# Default value: false +# +# readonly = false; diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -26,6 +26,7 @@ BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description @@ -135,6 +136,7 @@ %{_datadir}/libvirt-cim/*.registration %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf +%{_sysconfdir}/libvirt-cim.conf %changelog * Wed Oct 28 2009 Richard Maciel - 0.1-1 diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -1,7 +1,8 @@ # Copyright IBM Corp. 2007 SUBDIRS = tests -CFLAGS += $(CFLAGS_STRICT) +AM_CFLAGS = $(CFLAGS_STRICT) \ + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ pool_parsing.h acl_parsing.h diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -35,11 +35,12 @@ #include #include +#include #include "misc_util.h" #include "cs_util.h" -#include +#include "config.h" #define URI_ENV "HYPURI" @@ -55,6 +56,37 @@ return NULL; } +static int is_read_only(void) +{ + config_t conf; + int ret, readonly = 0; + const char *readonly_str = "readonly"; + + config_init(&conf); + + ret = config_read_file(&conf, LIBVIRTCIM_CONF); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error reading config file at line %d: '%s'\n", + conf.error_line, conf.error_text); + goto out; + } + + ret = config_lookup_bool(&conf, readonly_str, &readonly); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error: '%s' not found in config file\n", + readonly_str); + goto out; + } + + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, + LIBVIRTCIM_CONF, readonly); +out: + config_destroy(&conf); + + /* Default value is 0 (false) */ + return readonly; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) @@ -66,7 +98,7 @@ uri = cn_to_uri(classname); if (!uri) { - cu_statusf(broker, s, + cu_statusf(broker, s, CMPI_RC_ERR_FAILED, "Unable to generate URI from classname"); return NULL; @@ -74,7 +106,11 @@ CU_DEBUG("Connecting to libvirt with uri `%s'", uri); - conn = virConnectOpen(uri); + if (is_read_only()) + conn = virConnectOpenReadOnly(uri); + else + conn = virConnectOpen(uri); + if (!conn) { CU_DEBUG("Unable to connect to `%s'", uri); return NULL; @@ -258,7 +294,7 @@ inst = CMNewInstance(broker, op, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - + CMSetProperty(inst, "CreationClassName", (CMPIValue *)new_cn, CMPI_chars); @@ -310,7 +346,7 @@ if (STREQC(pfx, "CIM")) { cu_statusf(broker, status, CMPI_RC_ERR_FAILED, - "Please exactly specify the class (check CIMOM behavior!): %s", + "Please exactly specify the class (check CIMOM behavior!): %s", CLASSNAME(reference)); rc = false; } @@ -347,7 +383,7 @@ free(pfx); } - + free(ref_pfx); return rc; } @@ -367,13 +403,13 @@ CLASSNAME(source_ref), assoc_classname, NAMESPACE(source_ref)); - + if (ref_inst != NULL) { CMPIObjectPath *target_ref; - + target_ref = CMGetObjectPath(target_inst, NULL); - set_reference(assoc, ref_inst, + set_reference(assoc, ref_inst, source_ref, target_ref); } diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c +++ b/src/Virt_AllocationCapabilities.c @@ -47,6 +47,7 @@ CLASSNAME(ref), "AllocationCapabilities", NAMESPACE(ref)); + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (*alloc_cap == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -70,6 +71,7 @@ goto out; } out: + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -85,6 +87,7 @@ const char *inst_id; int i; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&device_pool_list); if (!provider_is_responsible(broker, ref, &s)) @@ -132,6 +135,7 @@ out: inst_list_free(&device_pool_list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -144,14 +148,20 @@ CMPIInstance *pool; CMPIStatus s; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); s = get_pool_by_name(broker, ref, poolid, &pool); - if ((pool == NULL) || (s.rc != CMPI_RC_OK)) + if ((pool == NULL) || (s.rc != CMPI_RC_OK)) { + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; + } s = ac_from_pool(broker, ref, pool, inst); - if (s.rc != CMPI_RC_OK) + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("%s(%d): return 2 ", __FUNCTION__, __LINE__); return s; + } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return cu_validate_ref(broker, ref, *inst); } @@ -165,6 +175,7 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; struct inst_list list; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&list); s = enum_alloc_cap_instances(broker, @@ -183,6 +194,7 @@ out: inst_list_free(&list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -195,13 +207,16 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; const char* id; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "No InstanceID specified"); + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return return_alloc_cap_instances(_BROKER, reference, results, From eblima at linux.vnet.ibm.com Tue Jun 28 17:06:44 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 14:06:44 -0300 Subject: [Libvirt-cim] [PATCH] Add read-only support In-Reply-To: <4E090D8E.1030405@linux.vnet.ibm.com> References: <9be9d0b2eed352a96bd0.1309196715@etrunko-t410.br.ibm.com> <4E090D8E.1030405@linux.vnet.ibm.com> Message-ID: <4E0A0A24.204@linux.vnet.ibm.com> On 06/27/2011 08:09 PM, Chip Vincent wrote: > > > On 06/27/2011 01:45 PM, Eduardo Lima (Etrunko) wrote: >> # HG changeset patch >> # User Eduardo Lima (Etrunko) >> # Date 1308270993 14400 >> # Node ID 9be9d0b2eed352a96bd07dcff435b8de5f7a43c6 >> # Parent a2f523cd39c29977ed07247a38316d44f5123874 >> Add read-only support. >> >> This patch enables a consumer of libvirt-cim to put it in read-only >> mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. >> >> Also clean-up some extra whitespace in touched files. >> >> Signed-off-by: Chip Vincent >> Signed-off-by: Eduardo Lima (Etrunko) >> >> diff --git a/Makefile.am b/Makefile.am >> --- a/Makefile.am >> +++ b/Makefile.am >> @@ -172,6 +172,9 @@ >> >> pkgdata_SCRIPTS = provider-register.sh >> >> +libvirtcim_confdir = @sysconfdir@ >> +dist_libvirtcim_conf_DATA = @PACKAGE at .conf >> + >> EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ >> $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ >> doc/CodingStyle doc/SubmittingPatches \ >> diff --git a/acinclude.m4 b/acinclude.m4 >> --- a/acinclude.m4 >> +++ b/acinclude.m4 >> @@ -270,6 +270,15 @@ >> LDFLAGS="$LDFLAGS $LIBUUID_LIBS" >> ]) >> >> +AC_DEFUN([CHECK_LIBCONFIG], >> + [ >> + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) >> + AC_SUBST([LIBCONFIG_CFLAGS]) >> + AC_SUBST([LIBCONFIG_LIBS]) >> + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" >> + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" >> + ]) >> + >> # A convenience macro that spits out a fail message for a particular test >> # >> # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) >> diff --git a/configure.ac b/configure.ac >> --- a/configure.ac >> +++ b/configure.ac >> @@ -166,6 +166,7 @@ >> CHECK_LIBXML2 >> CHECK_LIBCU >> CHECK_LIBUUID >> +CHECK_LIBCONFIG >> >> CFLAGS_STRICT="-Werror" >> >> diff --git a/libvirt-cim.conf b/libvirt-cim.conf >> new file mode 100644 >> --- /dev/null >> +++ b/libvirt-cim.conf >> @@ -0,0 +1,13 @@ >> +# >> +# libvirt-cim config file >> +# >> +# This config file is based on the libconfig format. For more >> information, >> +# please check http://www.hyperrealm.com/libconfig/ >> +# >> + >> +# readonly (boolean) >> +# Defines wether connection to libvirt is read-only or not > > s/wether/whether/ May just want to say 'if' Roger. > >> +# Possible values: {true,false} >> +# Default value: false >> +# >> +# readonly = false; >> diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in >> --- a/libvirt-cim.spec.in >> +++ b/libvirt-cim.spec.in >> @@ -26,6 +26,7 @@ >> >> BuildRequires: libxml2-devel >> BuildRequires: libcmpiutil-devel >> +BuildRequires: libconfig-devel >> BuildConflicts: sblim-cmpi-devel >> >> %description >> @@ -135,6 +136,7 @@ >> %{_datadir}/libvirt-cim/*.registration >> %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip >> %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf >> +%{_sysconfdir}/libvirt-cim.conf >> >> %changelog >> * Wed Oct 28 2009 Richard Maciel - 0.1-1 >> diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am >> --- a/libxkutil/Makefile.am >> +++ b/libxkutil/Makefile.am >> @@ -1,7 +1,8 @@ >> # Copyright IBM Corp. 2007 >> SUBDIRS = tests >> >> -CFLAGS += $(CFLAGS_STRICT) >> +AM_CFLAGS = $(CFLAGS_STRICT) \ >> + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" >> >> noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h >> infostore.h \ >> pool_parsing.h acl_parsing.h >> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c >> --- a/libxkutil/misc_util.c >> +++ b/libxkutil/misc_util.c >> @@ -35,11 +35,12 @@ >> >> #include >> #include >> +#include >> >> #include "misc_util.h" >> #include "cs_util.h" >> >> -#include >> +#include "config.h" >> >> #define URI_ENV "HYPURI" >> >> @@ -55,6 +56,37 @@ >> return NULL; >> } >> >> +static int is_read_only(void) >> +{ >> + config_t conf; >> + int ret, readonly = 0; >> + const char *readonly_str = "readonly"; >> + >> + config_init(&conf); >> + >> + ret = config_read_file(&conf, LIBVIRTCIM_CONF); >> + if (ret == CONFIG_FALSE) { >> + CU_DEBUG("Error reading config file(%d): '%s'\n", >> + conf.error_type, conf.error_text); >> + goto out; >> + } > > The above does not compile on RHEL 6 with libconfig-1.3.2-1.1.el6.x86_64 > > misc_util.c: In function ?is_read_only?: > misc_util.c:69: error: ?config_t? has no member named ?error_type? > Thanks for the spot. New version on the way. -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Tue Jun 28 17:09:25 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 14:09:25 -0300 Subject: [Libvirt-cim] [PATCH] (#2) Add read-only support In-Reply-To: <5f1a03d548ef810f67be.1309280662@etrunko-t410.br.ibm.com> References: <5f1a03d548ef810f67be.1309280662@etrunko-t410.br.ibm.com> Message-ID: <4E0A0AC5.1090700@linux.vnet.ibm.com> On 06/28/2011 02:04 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308270993 14400 > # Node ID 5f1a03d548ef810f67be9e326d565222e01a0451 > # Parent a2f523cd39c29977ed07247a38316d44f5123874 > Add read-only support. > > This patch enables a consumer of libvirt-cim to put it in read-only > mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. > > Also clean-up some extra whitespace in touched files. > > Changes from #1: > - Fix build error on RHEL 6 > > Signed-off-by: Chip Vincent > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/Makefile.am b/Makefile.am > --- a/Makefile.am > +++ b/Makefile.am > @@ -172,6 +172,9 @@ > > pkgdata_SCRIPTS = provider-register.sh > > +libvirtcim_confdir = @sysconfdir@ > +dist_libvirtcim_conf_DATA = @PACKAGE at .conf > + > EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ > $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ > doc/CodingStyle doc/SubmittingPatches \ > diff --git a/acinclude.m4 b/acinclude.m4 > --- a/acinclude.m4 > +++ b/acinclude.m4 > @@ -270,6 +270,15 @@ > LDFLAGS="$LDFLAGS $LIBUUID_LIBS" > ]) > > +AC_DEFUN([CHECK_LIBCONFIG], > + [ > + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) > + AC_SUBST([LIBCONFIG_CFLAGS]) > + AC_SUBST([LIBCONFIG_LIBS]) > + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" > + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" > + ]) > + > # A convenience macro that spits out a fail message for a particular test > # > # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) > diff --git a/configure.ac b/configure.ac > --- a/configure.ac > +++ b/configure.ac > @@ -166,6 +166,7 @@ > CHECK_LIBXML2 > CHECK_LIBCU > CHECK_LIBUUID > +CHECK_LIBCONFIG > > CFLAGS_STRICT="-Werror" > > diff --git a/libvirt-cim.conf b/libvirt-cim.conf > new file mode 100644 > --- /dev/null > +++ b/libvirt-cim.conf > @@ -0,0 +1,13 @@ > +# > +# libvirt-cim config file > +# > +# This config file is based on the libconfig format. For more information, > +# please check http://www.hyperrealm.com/libconfig/ > +# > + > +# readonly (boolean) > +# Defines wether connection to libvirt is read-only or not Ouch, forgot to add the config file to the commit, please ignore this. -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Tue Jun 28 17:11:51 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 14:11:51 -0300 Subject: [Libvirt-cim] [PATCH] (#3) Add read-only support Message-ID: <3a299dba1101ed6fc4c1.1309281111@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308270993 14400 # Node ID 3a299dba1101ed6fc4c13fb90bdad7f24ed0d2ea # Parent a2f523cd39c29977ed07247a38316d44f5123874 Add read-only support. This patch enables a consumer of libvirt-cim to put it in read-only mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. Also clean-up some extra whitespace in touched files. Changes from #1: - Fix build error on RHEL 6 Changes from #2: - Small typo in libvirt-cim.conf Signed-off-by: Chip Vincent Signed-off-by: Eduardo Lima (Etrunko) diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -172,6 +172,9 @@ pkgdata_SCRIPTS = provider-register.sh +libvirtcim_confdir = @sysconfdir@ +dist_libvirtcim_conf_DATA = @PACKAGE at .conf + EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ doc/CodingStyle doc/SubmittingPatches \ diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -270,6 +270,15 @@ LDFLAGS="$LDFLAGS $LIBUUID_LIBS" ]) +AC_DEFUN([CHECK_LIBCONFIG], + [ + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) + AC_SUBST([LIBCONFIG_CFLAGS]) + AC_SUBST([LIBCONFIG_LIBS]) + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" + ]) + # A convenience macro that spits out a fail message for a particular test # # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,7 @@ CHECK_LIBXML2 CHECK_LIBCU CHECK_LIBUUID +CHECK_LIBCONFIG CFLAGS_STRICT="-Werror" diff --git a/libvirt-cim.conf b/libvirt-cim.conf new file mode 100644 --- /dev/null +++ b/libvirt-cim.conf @@ -0,0 +1,13 @@ +# +# libvirt-cim config file +# +# This config file is based on the libconfig format. For more information, +# please check http://www.hyperrealm.com/libconfig/ +# + +# readonly (boolean) +# Defines if connection to libvirt is read-only or not +# Possible values: {true,false} +# Default value: false +# +# readonly = false; diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -26,6 +26,7 @@ BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description @@ -135,6 +136,7 @@ %{_datadir}/libvirt-cim/*.registration %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf +%{_sysconfdir}/libvirt-cim.conf %changelog * Wed Oct 28 2009 Richard Maciel - 0.1-1 diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -1,7 +1,8 @@ # Copyright IBM Corp. 2007 SUBDIRS = tests -CFLAGS += $(CFLAGS_STRICT) +AM_CFLAGS = $(CFLAGS_STRICT) \ + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ pool_parsing.h acl_parsing.h diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -35,11 +35,12 @@ #include #include +#include #include "misc_util.h" #include "cs_util.h" -#include +#include "config.h" #define URI_ENV "HYPURI" @@ -55,6 +56,37 @@ return NULL; } +static int is_read_only(void) +{ + config_t conf; + int ret, readonly = 0; + const char *readonly_str = "readonly"; + + config_init(&conf); + + ret = config_read_file(&conf, LIBVIRTCIM_CONF); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error reading config file at line %d: '%s'\n", + conf.error_line, conf.error_text); + goto out; + } + + ret = config_lookup_bool(&conf, readonly_str, &readonly); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error: '%s' not found in config file\n", + readonly_str); + goto out; + } + + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, + LIBVIRTCIM_CONF, readonly); +out: + config_destroy(&conf); + + /* Default value is 0 (false) */ + return readonly; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) @@ -66,7 +98,7 @@ uri = cn_to_uri(classname); if (!uri) { - cu_statusf(broker, s, + cu_statusf(broker, s, CMPI_RC_ERR_FAILED, "Unable to generate URI from classname"); return NULL; @@ -74,7 +106,11 @@ CU_DEBUG("Connecting to libvirt with uri `%s'", uri); - conn = virConnectOpen(uri); + if (is_read_only()) + conn = virConnectOpenReadOnly(uri); + else + conn = virConnectOpen(uri); + if (!conn) { CU_DEBUG("Unable to connect to `%s'", uri); return NULL; @@ -258,7 +294,7 @@ inst = CMNewInstance(broker, op, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - + CMSetProperty(inst, "CreationClassName", (CMPIValue *)new_cn, CMPI_chars); @@ -310,7 +346,7 @@ if (STREQC(pfx, "CIM")) { cu_statusf(broker, status, CMPI_RC_ERR_FAILED, - "Please exactly specify the class (check CIMOM behavior!): %s", + "Please exactly specify the class (check CIMOM behavior!): %s", CLASSNAME(reference)); rc = false; } @@ -347,7 +383,7 @@ free(pfx); } - + free(ref_pfx); return rc; } @@ -367,13 +403,13 @@ CLASSNAME(source_ref), assoc_classname, NAMESPACE(source_ref)); - + if (ref_inst != NULL) { CMPIObjectPath *target_ref; - + target_ref = CMGetObjectPath(target_inst, NULL); - set_reference(assoc, ref_inst, + set_reference(assoc, ref_inst, source_ref, target_ref); } diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c +++ b/src/Virt_AllocationCapabilities.c @@ -47,6 +47,7 @@ CLASSNAME(ref), "AllocationCapabilities", NAMESPACE(ref)); + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (*alloc_cap == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -70,6 +71,7 @@ goto out; } out: + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -85,6 +87,7 @@ const char *inst_id; int i; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&device_pool_list); if (!provider_is_responsible(broker, ref, &s)) @@ -132,6 +135,7 @@ out: inst_list_free(&device_pool_list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -144,14 +148,20 @@ CMPIInstance *pool; CMPIStatus s; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); s = get_pool_by_name(broker, ref, poolid, &pool); - if ((pool == NULL) || (s.rc != CMPI_RC_OK)) + if ((pool == NULL) || (s.rc != CMPI_RC_OK)) { + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; + } s = ac_from_pool(broker, ref, pool, inst); - if (s.rc != CMPI_RC_OK) + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("%s(%d): return 2 ", __FUNCTION__, __LINE__); return s; + } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return cu_validate_ref(broker, ref, *inst); } @@ -165,6 +175,7 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; struct inst_list list; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&list); s = enum_alloc_cap_instances(broker, @@ -183,6 +194,7 @@ out: inst_list_free(&list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -195,13 +207,16 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; const char* id; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "No InstanceID specified"); + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return return_alloc_cap_instances(_BROKER, reference, results, From eblima at linux.vnet.ibm.com Tue Jun 28 18:05:07 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 15:05:07 -0300 Subject: [Libvirt-cim] [PATCH] (#3) Add read-only support In-Reply-To: <3a299dba1101ed6fc4c1.1309281111@etrunko-t410.br.ibm.com> References: <3a299dba1101ed6fc4c1.1309281111@etrunko-t410.br.ibm.com> Message-ID: <4E0A17D3.9070907@linux.vnet.ibm.com> On 06/28/2011 02:11 PM, Eduardo Lima (Etrunko) wrote: [snip] > diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c > --- a/src/Virt_AllocationCapabilities.c > +++ b/src/Virt_AllocationCapabilities.c > @@ -47,6 +47,7 @@ > CLASSNAME(ref), > "AllocationCapabilities", > NAMESPACE(ref)); > + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); > if (*alloc_cap == NULL) { > cu_statusf(broker,&s, > CMPI_RC_ERR_FAILED, > @@ -70,6 +71,7 @@ > goto out; > } > out: > + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); > return s; > } > > @@ -85,6 +87,7 @@ > const char *inst_id; > int i; > > + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); > inst_list_init(&device_pool_list); > > if (!provider_is_responsible(broker, ref,&s)) > @@ -132,6 +135,7 @@ > > out: > inst_list_free(&device_pool_list); > + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); > > return s; > } > @@ -144,14 +148,20 @@ > CMPIInstance *pool; > CMPIStatus s; > > + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); > s = get_pool_by_name(broker, ref, poolid,&pool); > - if ((pool == NULL) || (s.rc != CMPI_RC_OK)) > + if ((pool == NULL) || (s.rc != CMPI_RC_OK)) { > + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); > return s; > + } > > s = ac_from_pool(broker, ref, pool, inst); > - if (s.rc != CMPI_RC_OK) > + if (s.rc != CMPI_RC_OK) { > + CU_DEBUG("%s(%d): return 2 ", __FUNCTION__, __LINE__); > return s; > + } > > + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); > return cu_validate_ref(broker, ref, *inst); > } > > @@ -165,6 +175,7 @@ > CMPIStatus s = {CMPI_RC_OK, NULL}; > struct inst_list list; > > + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); > inst_list_init(&list); > > s = enum_alloc_cap_instances(broker, > @@ -183,6 +194,7 @@ > out: > inst_list_free(&list); > > + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); > return s; > } > > @@ -195,13 +207,16 @@ > CMPIStatus s = {CMPI_RC_OK, NULL}; > const char* id; > > + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); > if (cu_get_str_path(reference, "InstanceID",&id) != CMPI_RC_OK) { > cu_statusf(_BROKER,&s, > CMPI_RC_ERR_FAILED, > "No InstanceID specified"); > + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); > return s; > } > > + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); > return return_alloc_cap_instances(_BROKER, > reference, > results, > Again, something that shouldn't be here. Sorry for including these debug messages. Yet another new version of the patch on the way. -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From eblima at linux.vnet.ibm.com Tue Jun 28 18:13:01 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 15:13:01 -0300 Subject: [Libvirt-cim] [PATCH] (#4) Add read-only support Message-ID: <83f0e989145d86bc84da.1309284781@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1308270993 14400 # Node ID 83f0e989145d86bc84dac05ef371c536a9734673 # Parent a2f523cd39c29977ed07247a38316d44f5123874 Add read-only support. This patch enables a consumer of libvirt-cim to put it in read-only mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. Also clean-up some extra whitespace in touched files. Changes from #1: - Fix build error on RHEL 6 Changes from #2: - Small typo in libvirt-cim.conf Changes from #3: - Removed unecessary debug messages Signed-off-by: Chip Vincent Signed-off-by: Eduardo Lima (Etrunko) diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -172,6 +172,9 @@ pkgdata_SCRIPTS = provider-register.sh +libvirtcim_confdir = @sysconfdir@ +dist_libvirtcim_conf_DATA = @PACKAGE at .conf + EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ doc/CodingStyle doc/SubmittingPatches \ diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -270,6 +270,15 @@ LDFLAGS="$LDFLAGS $LIBUUID_LIBS" ]) +AC_DEFUN([CHECK_LIBCONFIG], + [ + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) + AC_SUBST([LIBCONFIG_CFLAGS]) + AC_SUBST([LIBCONFIG_LIBS]) + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" + ]) + # A convenience macro that spits out a fail message for a particular test # # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,7 @@ CHECK_LIBXML2 CHECK_LIBCU CHECK_LIBUUID +CHECK_LIBCONFIG CFLAGS_STRICT="-Werror" diff --git a/libvirt-cim.conf b/libvirt-cim.conf new file mode 100644 --- /dev/null +++ b/libvirt-cim.conf @@ -0,0 +1,13 @@ +# +# libvirt-cim config file +# +# This config file is based on the libconfig format. For more information, +# please check http://www.hyperrealm.com/libconfig/ +# + +# readonly (boolean) +# Defines if connection to libvirt is read-only or not +# Possible values: {true,false} +# Default value: false +# +# readonly = false; diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -26,6 +26,7 @@ BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description @@ -135,6 +136,7 @@ %{_datadir}/libvirt-cim/*.registration %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf +%{_sysconfdir}/libvirt-cim.conf %changelog * Wed Oct 28 2009 Richard Maciel - 0.1-1 diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -1,7 +1,8 @@ # Copyright IBM Corp. 2007 SUBDIRS = tests -CFLAGS += $(CFLAGS_STRICT) +AM_CFLAGS = $(CFLAGS_STRICT) \ + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ pool_parsing.h acl_parsing.h diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -35,11 +35,12 @@ #include #include +#include #include "misc_util.h" #include "cs_util.h" -#include +#include "config.h" #define URI_ENV "HYPURI" @@ -55,6 +56,37 @@ return NULL; } +static int is_read_only(void) +{ + config_t conf; + int ret, readonly = 0; + const char *readonly_str = "readonly"; + + config_init(&conf); + + ret = config_read_file(&conf, LIBVIRTCIM_CONF); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error reading config file at line %d: '%s'\n", + conf.error_line, conf.error_text); + goto out; + } + + ret = config_lookup_bool(&conf, readonly_str, &readonly); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error: '%s' not found in config file\n", + readonly_str); + goto out; + } + + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, + LIBVIRTCIM_CONF, readonly); +out: + config_destroy(&conf); + + /* Default value is 0 (false) */ + return readonly; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) @@ -66,7 +98,7 @@ uri = cn_to_uri(classname); if (!uri) { - cu_statusf(broker, s, + cu_statusf(broker, s, CMPI_RC_ERR_FAILED, "Unable to generate URI from classname"); return NULL; @@ -74,7 +106,11 @@ CU_DEBUG("Connecting to libvirt with uri `%s'", uri); - conn = virConnectOpen(uri); + if (is_read_only()) + conn = virConnectOpenReadOnly(uri); + else + conn = virConnectOpen(uri); + if (!conn) { CU_DEBUG("Unable to connect to `%s'", uri); return NULL; @@ -258,7 +294,7 @@ inst = CMNewInstance(broker, op, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - + CMSetProperty(inst, "CreationClassName", (CMPIValue *)new_cn, CMPI_chars); @@ -310,7 +346,7 @@ if (STREQC(pfx, "CIM")) { cu_statusf(broker, status, CMPI_RC_ERR_FAILED, - "Please exactly specify the class (check CIMOM behavior!): %s", + "Please exactly specify the class (check CIMOM behavior!): %s", CLASSNAME(reference)); rc = false; } @@ -347,7 +383,7 @@ free(pfx); } - + free(ref_pfx); return rc; } @@ -367,13 +403,13 @@ CLASSNAME(source_ref), assoc_classname, NAMESPACE(source_ref)); - + if (ref_inst != NULL) { CMPIObjectPath *target_ref; - + target_ref = CMGetObjectPath(target_inst, NULL); - set_reference(assoc, ref_inst, + set_reference(assoc, ref_inst, source_ref, target_ref); } From cvincent at linux.vnet.ibm.com Tue Jun 28 19:30:39 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 15:30:39 -0400 Subject: [Libvirt-cim] [PATCH] (#4) Add read-only support In-Reply-To: <83f0e989145d86bc84da.1309284781@etrunko-t410.br.ibm.com> References: <83f0e989145d86bc84da.1309284781@etrunko-t410.br.ibm.com> Message-ID: <4E0A2BDF.2090001@linux.vnet.ibm.com> According to cimtest, setting readonly = true works. I see lots of this on RHEL 6: omputerSystem - 41_cs_to_settingdefinestate.py: FAIL ERROR - Got CIM error Unauthorized with return code 0 ERROR - Failed to define the dom: CrossClass_GuestDom InvokeMethod(DefineSystem): Unauthorized -------------------------------------------------------------------- ComputerSystem - 42_cs_gi_errs.py: FAIL ERROR - Got CIM error Unauthorized with return code 0 ERROR - Unable to define guest ETdomain InvokeMethod(DefineSystem): Unauthorized -------------------------------------------------------------------- +1. Pushed. Thanks. On 06/28/2011 02:13 PM, Eduardo Lima (Etrunko) wrote: > # HG changeset patch > # User Eduardo Lima (Etrunko) > # Date 1308270993 14400 > # Node ID 83f0e989145d86bc84dac05ef371c536a9734673 > # Parent a2f523cd39c29977ed07247a38316d44f5123874 > Add read-only support. > > This patch enables a consumer of libvirt-cim to put it in read-only > mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. > > Also clean-up some extra whitespace in touched files. > > Changes from #1: > - Fix build error on RHEL 6 > Changes from #2: > - Small typo in libvirt-cim.conf > Changes from #3: > - Removed unecessary debug messages > > Signed-off-by: Chip Vincent > Signed-off-by: Eduardo Lima (Etrunko) > > diff --git a/Makefile.am b/Makefile.am > --- a/Makefile.am > +++ b/Makefile.am > @@ -172,6 +172,9 @@ > > pkgdata_SCRIPTS = provider-register.sh > > +libvirtcim_confdir = @sysconfdir@ > +dist_libvirtcim_conf_DATA = @PACKAGE at .conf > + > EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ > $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ > doc/CodingStyle doc/SubmittingPatches \ > diff --git a/acinclude.m4 b/acinclude.m4 > --- a/acinclude.m4 > +++ b/acinclude.m4 > @@ -270,6 +270,15 @@ > LDFLAGS="$LDFLAGS $LIBUUID_LIBS" > ]) > > +AC_DEFUN([CHECK_LIBCONFIG], > + [ > + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) > + AC_SUBST([LIBCONFIG_CFLAGS]) > + AC_SUBST([LIBCONFIG_LIBS]) > + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" > + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" > + ]) > + > # A convenience macro that spits out a fail message for a particular test > # > # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) > diff --git a/configure.ac b/configure.ac > --- a/configure.ac > +++ b/configure.ac > @@ -166,6 +166,7 @@ > CHECK_LIBXML2 > CHECK_LIBCU > CHECK_LIBUUID > +CHECK_LIBCONFIG > > CFLAGS_STRICT="-Werror" > > diff --git a/libvirt-cim.conf b/libvirt-cim.conf > new file mode 100644 > --- /dev/null > +++ b/libvirt-cim.conf > @@ -0,0 +1,13 @@ > +# > +# libvirt-cim config file > +# > +# This config file is based on the libconfig format. For more information, > +# please check http://www.hyperrealm.com/libconfig/ > +# > + > +# readonly (boolean) > +# Defines if connection to libvirt is read-only or not > +# Possible values: {true,false} > +# Default value: false > +# > +# readonly = false; > diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in > --- a/libvirt-cim.spec.in > +++ b/libvirt-cim.spec.in > @@ -26,6 +26,7 @@ > > BuildRequires: libxml2-devel > BuildRequires: libcmpiutil-devel > +BuildRequires: libconfig-devel > BuildConflicts: sblim-cmpi-devel > > %description > @@ -135,6 +136,7 @@ > %{_datadir}/libvirt-cim/*.registration > %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip > %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf > +%{_sysconfdir}/libvirt-cim.conf > > %changelog > * Wed Oct 28 2009 Richard Maciel - 0.1-1 > diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am > --- a/libxkutil/Makefile.am > +++ b/libxkutil/Makefile.am > @@ -1,7 +1,8 @@ > # Copyright IBM Corp. 2007 > SUBDIRS = tests > > -CFLAGS += $(CFLAGS_STRICT) > +AM_CFLAGS = $(CFLAGS_STRICT) \ > + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" > > noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ > pool_parsing.h acl_parsing.h > diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c > --- a/libxkutil/misc_util.c > +++ b/libxkutil/misc_util.c > @@ -35,11 +35,12 @@ > > #include > #include > +#include > > #include "misc_util.h" > #include "cs_util.h" > > -#include > +#include "config.h" > > #define URI_ENV "HYPURI" > > @@ -55,6 +56,37 @@ > return NULL; > } > > +static int is_read_only(void) > +{ > + config_t conf; > + int ret, readonly = 0; > + const char *readonly_str = "readonly"; > + > + config_init(&conf); > + > + ret = config_read_file(&conf, LIBVIRTCIM_CONF); > + if (ret == CONFIG_FALSE) { > + CU_DEBUG("Error reading config file at line %d: '%s'\n", > + conf.error_line, conf.error_text); > + goto out; > + } > + > + ret = config_lookup_bool(&conf, readonly_str,&readonly); > + if (ret == CONFIG_FALSE) { > + CU_DEBUG("Error: '%s' not found in config file\n", > + readonly_str); > + goto out; > + } > + > + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, > + LIBVIRTCIM_CONF, readonly); > +out: > + config_destroy(&conf); > + > + /* Default value is 0 (false) */ > + return readonly; > +} > + > virConnectPtr connect_by_classname(const CMPIBroker *broker, > const char *classname, > CMPIStatus *s) > @@ -66,7 +98,7 @@ > > uri = cn_to_uri(classname); > if (!uri) { > - cu_statusf(broker, s, > + cu_statusf(broker, s, > CMPI_RC_ERR_FAILED, > "Unable to generate URI from classname"); > return NULL; > @@ -74,7 +106,11 @@ > > CU_DEBUG("Connecting to libvirt with uri `%s'", uri); > > - conn = virConnectOpen(uri); > + if (is_read_only()) > + conn = virConnectOpenReadOnly(uri); > + else > + conn = virConnectOpen(uri); > + > if (!conn) { > CU_DEBUG("Unable to connect to `%s'", uri); > return NULL; > @@ -258,7 +294,7 @@ > inst = CMNewInstance(broker, op,&s); > if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) > goto out; > - > + > CMSetProperty(inst, "CreationClassName", > (CMPIValue *)new_cn, CMPI_chars); > > @@ -310,7 +346,7 @@ > if (STREQC(pfx, "CIM")) { > cu_statusf(broker, status, > CMPI_RC_ERR_FAILED, > - "Please exactly specify the class (check CIMOM behavior!): %s", > + "Please exactly specify the class (check CIMOM behavior!): %s", > CLASSNAME(reference)); > rc = false; > } > @@ -347,7 +383,7 @@ > > free(pfx); > } > - > + > free(ref_pfx); > return rc; > } > @@ -367,13 +403,13 @@ > CLASSNAME(source_ref), > assoc_classname, > NAMESPACE(source_ref)); > - > + > if (ref_inst != NULL) { > CMPIObjectPath *target_ref; > - > + > target_ref = CMGetObjectPath(target_inst, NULL); > > - set_reference(assoc, ref_inst, > + set_reference(assoc, ref_inst, > source_ref, target_ref); > } > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Tue Jun 28 19:39:21 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 16:39:21 -0300 Subject: [Libvirt-cim] [PATCH] [TEST] Fix exception in tests Message-ID: <6397c0670c35acc78ac1.1309289961@etrunko-t410.br.ibm.com> # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1309289907 10800 # Node ID 6397c0670c35acc78ac13d737b408bb90e30632e # Parent 3c218fe48bb7b9d89549dcca213dd7e0b60035af [TEST] Fix exception in tests -------------------------------------------------------------------- Memory - 01_memory.py: FAIL ERROR - Got CIM error CIM_ERR_FAILED: Failed to define domain: operation virDomainDefineXML forbidden for read only access with return code 1 Traceback (most recent call last): File "/home/etrunko/projects/virt/cimtest/suites/libvirt-cim/lib/XenKvmLib/const.py", line 140, in do_try rc = f() File "01_memory.py", line 66, in main capacity = dev.ConsumableBlocks * dev.BlockSize / 1024 AttributeError: 'NoneType' object has no attribute 'ConsumableBlocks' -------------------------------------------------------------------- SettingsDefineCapabilities - 01_forward.py: FAIL ERROR - [dpool, mpool, ppool, npool] None ERROR - TypeError : 'int' object is not iterable Traceback (most recent call last): File "/home/etrunko/projects/virt/cimtest/suites/libvirt-cim/lib/XenKvmLib/const.py", line 140, in do_try rc = f() File "01_forward.py", line 204, in main status, pool = get_pool_details(virt, server) TypeError: 'int' object is not iterable -------------------------------------------------------------------- VirtualSystemManagementService - 28_definesystem_with_vsi_profile.py: FAIL ERROR - Exception: 'NoneType' object has no attribute 'InstanceID' ERROR - Unable to get template RASDs for vsi_guest ERROR - UnboundLocalError : local variable 'cxml' referenced before assignment Traceback (most recent call last): File "/home/etrunko/projects/virt/cimtest/suites/libvirt-cim/lib/XenKvmLib/const.py", line 140, in do_try rc = f() File "28_definesystem_with_vsi_profile.py", line 211, in main cxml.cim_destroy(server) UnboundLocalError: local variable 'cxml' referenced before assignment Signed-off-by: Eduardo Lima (Etrunko) diff --git a/suites/libvirt-cim/cimtest/Memory/01_memory.py b/suites/libvirt-cim/cimtest/Memory/01_memory.py --- a/suites/libvirt-cim/cimtest/Memory/01_memory.py +++ b/suites/libvirt-cim/cimtest/Memory/01_memory.py @@ -59,15 +59,16 @@ if dev is None: logger.error("GetInstance() returned None") status = 1 - elif dev.ConsumableBlocks > dev.NumberOfBlocks: - logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") - status = 1 + else: + if dev.ConsumableBlocks > dev.NumberOfBlocks: + logger.error("ConsumableBlocks should not be larger than NumberOfBlocks") + status = 1 - capacity = dev.ConsumableBlocks * dev.BlockSize / 1024 + capacity = dev.ConsumableBlocks * dev.BlockSize / 1024 - if capacity != alloc_mem: - logger.error("Capacity should be %i MB instead of %i MB", alloc_mem, capacity) - status = 1 + if capacity != alloc_mem: + logger.error("Capacity should be %i MB instead of %i MB", alloc_mem, capacity) + status = 1 if status == 0: logger.info("Checked memory capacity: %s MB", capacity) diff --git a/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py b/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py --- a/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py +++ b/suites/libvirt-cim/cimtest/SettingsDefineCapabilities/01_forward.py @@ -142,7 +142,7 @@ if dpool.InstanceID == None or mpool.InstanceID == None \ or npool.InstanceID == None or ppool.InstanceID == None: logger.error("Get pool None") - return FAIL + return FAIL, None else: pool_set = [dpool, mpool, ppool, npool] except Exception, detail: diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py @@ -175,6 +175,7 @@ nrasd_cn = get_typed_class(virt, 'NetResourceAllocationSettingData') status = FAIL + cxml = None try: rasd_list = get_rasd_list(server, virt, vsi_defaults, nrasd_cn) @@ -208,8 +209,9 @@ except Exception, details: logger.error(details) - cxml.cim_destroy(server) - cxml.undefine(server) + if cxml is not None: + cxml.cim_destroy(server) + cxml.undefine(server) return status From cvincent at linux.vnet.ibm.com Tue Jun 28 20:43:16 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 16:43:16 -0400 Subject: [Libvirt-cim] [PATCH] (#4) Add read-only support In-Reply-To: <4E0A2BDF.2090001@linux.vnet.ibm.com> References: <83f0e989145d86bc84da.1309284781@etrunko-t410.br.ibm.com> <4E0A2BDF.2090001@linux.vnet.ibm.com> Message-ID: <4E0A3CE4.4090508@linux.vnet.ibm.com> Missed some change upstream so squashed this in so everything should be in sync now. diff --git a/libvirt-cim.conf b/libvirt-cim.conf --- a/libvirt-cim.conf +++ b/libvirt-cim.conf @@ -6,7 +6,7 @@ # # readonly (boolean) -# Defines wether connection to libvirt is read-only or not +# Defines if connection to libvirt is read-only or not # Possible values: {true,false} # Default value: false # diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -66,8 +66,8 @@ ret = config_read_file(&conf, LIBVIRTCIM_CONF); if (ret == CONFIG_FALSE) { - CU_DEBUG("Error reading config file(%d): '%s'\n", - conf.error_type, conf.error_text); + CU_DEBUG("Error reading config file at liine %d: '%s'\n", + conf.error_line, conf.error_text); goto out; } On 06/28/2011 03:30 PM, Chip Vincent wrote: > According to cimtest, setting readonly = true works. I see lots of this > on RHEL 6: > > omputerSystem - 41_cs_to_settingdefinestate.py: FAIL > ERROR - Got CIM error Unauthorized with return code 0 > ERROR - Failed to define the dom: CrossClass_GuestDom > InvokeMethod(DefineSystem): Unauthorized > -------------------------------------------------------------------- > ComputerSystem - 42_cs_gi_errs.py: FAIL > ERROR - Got CIM error Unauthorized with return code 0 > ERROR - Unable to define guest ETdomain > InvokeMethod(DefineSystem): Unauthorized > -------------------------------------------------------------------- > > +1. Pushed. Thanks. > > On 06/28/2011 02:13 PM, Eduardo Lima (Etrunko) wrote: >> # HG changeset patch >> # User Eduardo Lima (Etrunko) >> # Date 1308270993 14400 >> # Node ID 83f0e989145d86bc84dac05ef371c536a9734673 >> # Parent a2f523cd39c29977ed07247a38316d44f5123874 >> Add read-only support. >> >> This patch enables a consumer of libvirt-cim to put it in read-only >> mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. >> >> Also clean-up some extra whitespace in touched files. >> >> Changes from #1: >> - Fix build error on RHEL 6 >> Changes from #2: >> - Small typo in libvirt-cim.conf >> Changes from #3: >> - Removed unecessary debug messages >> >> Signed-off-by: Chip Vincent >> Signed-off-by: Eduardo Lima (Etrunko) >> >> diff --git a/Makefile.am b/Makefile.am >> --- a/Makefile.am >> +++ b/Makefile.am >> @@ -172,6 +172,9 @@ >> >> pkgdata_SCRIPTS = provider-register.sh >> >> +libvirtcim_confdir = @sysconfdir@ >> +dist_libvirtcim_conf_DATA = @PACKAGE at .conf >> + >> EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ >> $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ >> doc/CodingStyle doc/SubmittingPatches \ >> diff --git a/acinclude.m4 b/acinclude.m4 >> --- a/acinclude.m4 >> +++ b/acinclude.m4 >> @@ -270,6 +270,15 @@ >> LDFLAGS="$LDFLAGS $LIBUUID_LIBS" >> ]) >> >> +AC_DEFUN([CHECK_LIBCONFIG], >> + [ >> + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) >> + AC_SUBST([LIBCONFIG_CFLAGS]) >> + AC_SUBST([LIBCONFIG_LIBS]) >> + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" >> + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" >> + ]) >> + >> # A convenience macro that spits out a fail message for a particular test >> # >> # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) >> diff --git a/configure.ac b/configure.ac >> --- a/configure.ac >> +++ b/configure.ac >> @@ -166,6 +166,7 @@ >> CHECK_LIBXML2 >> CHECK_LIBCU >> CHECK_LIBUUID >> +CHECK_LIBCONFIG >> >> CFLAGS_STRICT="-Werror" >> >> diff --git a/libvirt-cim.conf b/libvirt-cim.conf >> new file mode 100644 >> --- /dev/null >> +++ b/libvirt-cim.conf >> @@ -0,0 +1,13 @@ >> +# >> +# libvirt-cim config file >> +# >> +# This config file is based on the libconfig format. For more >> information, >> +# please check http://www.hyperrealm.com/libconfig/ >> +# >> + >> +# readonly (boolean) >> +# Defines if connection to libvirt is read-only or not >> +# Possible values: {true,false} >> +# Default value: false >> +# >> +# readonly = false; >> diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in >> --- a/libvirt-cim.spec.in >> +++ b/libvirt-cim.spec.in >> @@ -26,6 +26,7 @@ >> >> BuildRequires: libxml2-devel >> BuildRequires: libcmpiutil-devel >> +BuildRequires: libconfig-devel >> BuildConflicts: sblim-cmpi-devel >> >> %description >> @@ -135,6 +136,7 @@ >> %{_datadir}/libvirt-cim/*.registration >> %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip >> %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf >> +%{_sysconfdir}/libvirt-cim.conf >> >> %changelog >> * Wed Oct 28 2009 Richard Maciel - 0.1-1 >> diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am >> --- a/libxkutil/Makefile.am >> +++ b/libxkutil/Makefile.am >> @@ -1,7 +1,8 @@ >> # Copyright IBM Corp. 2007 >> SUBDIRS = tests >> >> -CFLAGS += $(CFLAGS_STRICT) >> +AM_CFLAGS = $(CFLAGS_STRICT) \ >> + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE at .conf\" >> >> noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h >> infostore.h \ >> pool_parsing.h acl_parsing.h >> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c >> --- a/libxkutil/misc_util.c >> +++ b/libxkutil/misc_util.c >> @@ -35,11 +35,12 @@ >> >> #include >> #include >> +#include >> >> #include "misc_util.h" >> #include "cs_util.h" >> >> -#include >> +#include "config.h" >> >> #define URI_ENV "HYPURI" >> >> @@ -55,6 +56,37 @@ >> return NULL; >> } >> >> +static int is_read_only(void) >> +{ >> + config_t conf; >> + int ret, readonly = 0; >> + const char *readonly_str = "readonly"; >> + >> + config_init(&conf); >> + >> + ret = config_read_file(&conf, LIBVIRTCIM_CONF); >> + if (ret == CONFIG_FALSE) { >> + CU_DEBUG("Error reading config file at line %d: '%s'\n", >> + conf.error_line, conf.error_text); >> + goto out; >> + } >> + >> + ret = config_lookup_bool(&conf, readonly_str,&readonly); >> + if (ret == CONFIG_FALSE) { >> + CU_DEBUG("Error: '%s' not found in config file\n", >> + readonly_str); >> + goto out; >> + } >> + >> + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, >> + LIBVIRTCIM_CONF, readonly); >> +out: >> + config_destroy(&conf); >> + >> + /* Default value is 0 (false) */ >> + return readonly; >> +} >> + >> virConnectPtr connect_by_classname(const CMPIBroker *broker, >> const char *classname, >> CMPIStatus *s) >> @@ -66,7 +98,7 @@ >> >> uri = cn_to_uri(classname); >> if (!uri) { >> - cu_statusf(broker, s, >> + cu_statusf(broker, s, >> CMPI_RC_ERR_FAILED, >> "Unable to generate URI from classname"); >> return NULL; >> @@ -74,7 +106,11 @@ >> >> CU_DEBUG("Connecting to libvirt with uri `%s'", uri); >> >> - conn = virConnectOpen(uri); >> + if (is_read_only()) >> + conn = virConnectOpenReadOnly(uri); >> + else >> + conn = virConnectOpen(uri); >> + >> if (!conn) { >> CU_DEBUG("Unable to connect to `%s'", uri); >> return NULL; >> @@ -258,7 +294,7 @@ >> inst = CMNewInstance(broker, op,&s); >> if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) >> goto out; >> - >> + >> CMSetProperty(inst, "CreationClassName", >> (CMPIValue *)new_cn, CMPI_chars); >> >> @@ -310,7 +346,7 @@ >> if (STREQC(pfx, "CIM")) { >> cu_statusf(broker, status, >> CMPI_RC_ERR_FAILED, >> - "Please exactly specify the class (check CIMOM behavior!): %s", >> + "Please exactly specify the class (check CIMOM behavior!): %s", >> CLASSNAME(reference)); >> rc = false; >> } >> @@ -347,7 +383,7 @@ >> >> free(pfx); >> } >> - >> + >> free(ref_pfx); >> return rc; >> } >> @@ -367,13 +403,13 @@ >> CLASSNAME(source_ref), >> assoc_classname, >> NAMESPACE(source_ref)); >> - >> + >> if (ref_inst != NULL) { >> CMPIObjectPath *target_ref; >> - >> + >> target_ref = CMGetObjectPath(target_inst, NULL); >> >> - set_reference(assoc, ref_inst, >> + set_reference(assoc, ref_inst, >> source_ref, target_ref); >> } >> >> >> _______________________________________________ >> Libvirt-cim mailing list >> Libvirt-cim at redhat.com >> https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Tue Jun 28 21:04:50 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Tue, 28 Jun 2011 18:04:50 -0300 Subject: [Libvirt-cim] [PATCH] (#2) Add write support for FilterList and NestedFilterList In-Reply-To: <2a1c7e5112590eb7157b.1309271268@oc0840652111.ibm.com> References: <2a1c7e5112590eb7157b.1309271268@oc0840652111.ibm.com> Message-ID: <4E0A41F2.8060008@linux.vnet.ibm.com> On 06/28/2011 11:27 AM, Chip Vincent wrote: > # HG changeset patch > # User Chip Vincent > # Date 1309213800 14400 > # Node ID 2a1c7e5112590eb7157b566facd61ea9fc815b85 > # Parent 75411f53df02159c3fa6ce5810c9446579e3d66d > (#2) Add write support for FilterList and NestedFilterList > > Changes since #1: > - fixed compilation issue > > This allows clients to create new filter lists and then associate them > with other filter lists to create complex filters. This patch also has some > minor bug fixes to AppliedFilterList so the new filters can be applied > to existing NetworkPort instances. The new cimtests for the create/delete > associations are still under construction, but you can easily test > FilterList create/delete (foundation) with the following commands: > > # wbemcli ci 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="",Name="",SystemCreationClassName="",SystemName=""' 'Name="test"' > > # wbemcli di 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="KVM_FilterList",Name="test",SystemCreationClassName="KVM_HostSystem",SystemName="oc0840652111.ibm.com"' > +1 Patch indeed looks fine, builds fine, and works like described. Need to create the proper cimtests for that. Best regards, Etrunko -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com From cvincent at linux.vnet.ibm.com Tue Jun 28 21:38:04 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 17:38:04 -0400 Subject: [Libvirt-cim] [PATCH] (#2) Add write support for FilterList and NestedFilterList In-Reply-To: <4E0A41F2.8060008@linux.vnet.ibm.com> References: <2a1c7e5112590eb7157b.1309271268@oc0840652111.ibm.com> <4E0A41F2.8060008@linux.vnet.ibm.com> Message-ID: <4E0A49BC.6020509@linux.vnet.ibm.com> Thanks. Pushed. On 06/28/2011 05:04 PM, Eduardo Lima (Etrunko) wrote: > On 06/28/2011 11:27 AM, Chip Vincent wrote: >> # HG changeset patch >> # User Chip Vincent >> # Date 1309213800 14400 >> # Node ID 2a1c7e5112590eb7157b566facd61ea9fc815b85 >> # Parent 75411f53df02159c3fa6ce5810c9446579e3d66d >> (#2) Add write support for FilterList and NestedFilterList >> >> Changes since #1: >> - fixed compilation issue >> >> This allows clients to create new filter lists and then associate them >> with other filter lists to create complex filters. This patch also has >> some >> minor bug fixes to AppliedFilterList so the new filters can be applied >> to existing NetworkPort instances. The new cimtests for the create/delete >> associations are still under construction, but you can easily test >> FilterList create/delete (foundation) with the following commands: >> >> # wbemcli ci >> 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="",Name="",SystemCreationClassName="",SystemName=""' >> 'Name="test"' >> >> # wbemcli di >> 'http://localhost:5988/root/virt:KVM_FilterList.CreationClassName="KVM_FilterList",Name="test",SystemCreationClassName="KVM_HostSystem",SystemName="oc0840652111.ibm.com"' >> >> > > +1 > Patch indeed looks fine, builds fine, and works like described. Need to > create the proper cimtests for that. > > Best regards, Etrunko > -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From cvincent at linux.vnet.ibm.com Tue Jun 28 22:01:07 2011 From: cvincent at linux.vnet.ibm.com (Chip Vincent) Date: Tue, 28 Jun 2011 18:01:07 -0400 Subject: [Libvirt-cim] Release of libvirt-cim-0.5.13 Message-ID: <4E0A4F23.1040602@linux.vnet.ibm.com> The new release is available at: ftp://libvirt.org/libvirt-cim/libvirt-cim-0.5.13.tar.gz libvirt-cim-0.5.13 * Add write support for FilterList (Chip Vincent) * Add read-only support (Eduardo Lima) * Fix MemoryPool.Reserved (Chip Vincent) * Check libvirt version before compiling ACL (Chip Vincent) * Fix AppliedFilterList Associators (Chip Vincent) * Libvirt dependency should be 0.6.3 (Chip Vincent) * Conditional build requirement for RPM package (Eduardo Lima) * Fill up NetworkName attribute (Eduardo Lima) * Add DCN ACL classes & providers (Chip Vincent) * Configure tweaks (Eduardo Lima) * Update RPM spec file to match Fedora (Eduardo Lima) * Migration was failing due to lost connection (Sharad Mishra) * Fix file permissions (Eduardo Lima) * Update .hgignore (Eduardo Lima) * Configure: Check for libuuid (Eduardo Lima) * Fix for VirtualSystemManagementService test (Chip Vincent) * Fix connection leaks (Sharad Mishra) * Ensure graphics devices have unique IDs (Chip Vincent) * Add support for StoragePool autostart (Sharad Mishra) * Add support for console/serial grahpics devices (Chip Vincent) * Add check to verify that sysname is not null (Sharad Mishra) * Added support for disk driver (Sharad Mishra) * Add VNC autoport support (Chip Vincent) * Add support for Pegasus OOP grouping (Chip Vincent) * Add SCCN and CCN for SwitchService (Sharad Mishra) * Fixing NullPointerException (Sharad Mishra) * Auto refresh StoragePools (Sharad Mishra) * Query switch to find its vsi capabilities (Sharad Mishra) * Set CreationClassName property in VSMS (Sharad Mishra) * Set/Reset VM autostart (Sharad Mishra) * Remove test for duplicate mac address (Sharad Mishra) * Add support for deactivation of disk caching (Sharad Mishra) * Add readonly property to disk (Sharad Mishra) -- Chip Vincent Open Virtualization IBM Linux Technology Center cvincent at linux.vnet.ibm.com From eblima at linux.vnet.ibm.com Thu Jun 30 16:04:12 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Thu, 30 Jun 2011 13:04:12 -0300 Subject: [Libvirt-cim] [PATCH 1 of 1] [TEST] Don't send commands via ssh for localhost In-Reply-To: References: Message-ID: # HG changeset patch # User Eduardo Lima (Etrunko) # Date 1306519808 10800 # Node ID fcce3eb554659cd76e020f3cb852c352e6a02218 # Parent 6397c0670c35acc78ac13d737b408bb90e30632e [TEST] Don't send commands via ssh for localhost Also changes python strings format in many other files. Some commands required double quotes to work properly when executed locally. Signed-off-by: Eduardo Lima (Etrunko) diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py --- a/lib/VirtLib/live.py +++ b/lib/VirtLib/live.py @@ -30,7 +30,7 @@ """Return a list of the available bridges in the running dom0. """ - cmd = "brctl show | grep -v 'bridge name' | awk '/^[^\t]/ { print \$1 }'" + cmd = 'brctl show | grep -v "bridge name" | awk "/^[^\\t]/ { print \$1 }"' rc, out = utils.run_remote(ip, cmd) if rc != 0: @@ -39,8 +39,8 @@ return out.splitlines() def exclude_vir_bridge(ip): - cmd = "brctl show | grep -v 'bridge name' | grep -v vir | \ - grep -v vif | awk '/^[^\t]/ { print \$1 }'" + cmd = 'brctl show | grep -v "bridge name" | grep -v vir | \ + grep -v vif | awk "/^[^\\t]/ { print \$1 }"' rc, out = utils.run_remote(ip, cmd) if rc != 0: return [] @@ -51,7 +51,7 @@ """Return a list of the available virtual bridges in the running dom0. """ - cmd = "brctl show | grep -v 'bridge name' | grep -v peth | awk '/^[^\t]/ { print \$1 }'" + cmd = 'brctl show | grep -v "bridge name" | grep -v peth | awk "/^[^\\t]/ { print \$1 }"' rc, out = utils.run_remote(ip, cmd) if rc != 0: @@ -78,14 +78,14 @@ """ xm_ret, mfm = utils.run_remote(server, - "xm info | awk -F ': ' '/max_free_memory/ {print \$2}'") + 'xm info | awk -F ": " "/max_free_memory/ {print \$2}"') if xm_ret != 0: return None return int(mfm) def fv_cap(server): - cmd = "egrep flags /proc/cpuinfo | uniq | egrep 'vmx|svm'" + cmd = 'egrep flags /proc/cpuinfo | uniq | egrep "vmx|svm"' ret, out = utils.run_remote(server, cmd) return ret == 0 diff --git a/lib/VirtLib/utils.py b/lib/VirtLib/utils.py --- a/lib/VirtLib/utils.py +++ b/lib/VirtLib/utils.py @@ -31,15 +31,24 @@ SSH_KEY = os.path.join(root_dot_ssh, 'id_rsa') AUTHED_KEYS = os.path.join(root_dot_ssh, 'authorized_keys') +localhost = ["0.0.0.0", "127.0.0.1", "localhost"] + def run_remote(ip, cmd): - cmd = 'ssh %s -i %s root@%s "%s"' % (SSH_PARMS, SSH_KEY, ip, cmd) + if ip not in localhost: + cmd = "ssh %s -i %s root@%s '%s'" % (SSH_PARMS, SSH_KEY, ip, cmd) return commands.getstatusoutput(cmd) def copy_remote(ip, local, remote='/tmp'): - cmd = 'scp -r %s -i %s %s root@%s:%s' % (SSH_PARMS, - SSH_KEY, local, ip, remote) + if ip not in localhost: + cmd = 'scp -r %s -i %s %s root@%s:%s' % (SSH_PARMS, + SSH_KEY, local, ip, remote) + else: + if local == remote: + return (0, "") + cmd = 'cp -r %s %s' % (local, remote) + return commands.getstatusoutput(cmd) def setup_ssh_key(): diff --git a/suites/libvirt-cim/lib/XenKvmLib/common_util.py b/suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py @@ -243,7 +243,7 @@ rc, out = utils.run_remote(ip, cmd) if rc == 0 : - cmd = "%s | awk '{ print \$8 }' | uniq" % cmd + cmd = '%s | awk "{ print \$8 }" | uniq' % cmd rc, out = utils.run_remote(ip, cmd) return rc, out @@ -252,7 +252,7 @@ cmd = "virsh -c %s list --all 2>/dev/null" % virt2uri(virt) ret, out = utils.run_remote(ip, cmd) if ret != 0: - return "This libvirt install does not support %s" % virt + return "The libvirt install on '%s' does not support %s" % (ip, virt) cmd = "virsh -c %s version 2>/dev/null" % virt2uri(virt) ret, out = utils.run_remote(ip, cmd) @@ -491,7 +491,7 @@ def get_nfs_bin(server): - cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'" + cmd = 'cat /etc/issue | grep -v ^$ | egrep "Red Hat|Fedora"' rc, out = utils.run_remote(server, cmd) if rc != 0: #SLES diff --git a/suites/libvirt-cim/lib/XenKvmLib/const.py b/suites/libvirt-cim/lib/XenKvmLib/const.py --- a/suites/libvirt-cim/lib/XenKvmLib/const.py +++ b/suites/libvirt-cim/lib/XenKvmLib/const.py @@ -166,7 +166,7 @@ # This is a sloppy mechanism for detecting a distro defined revision value distro = None - cmd = "cat /etc/issue | grep 'SUSE Linux Enterprise Server 11'" + cmd = 'cat /etc/issue | grep "SUSE Linux Enterprise Server 11"' rc, out = run_remote(ip, cmd) if rc == 0: distro = "sles11" diff --git a/suites/libvirt-cim/lib/XenKvmLib/pool.py b/suites/libvirt-cim/lib/XenKvmLib/pool.py --- a/suites/libvirt-cim/lib/XenKvmLib/pool.py +++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py @@ -107,7 +107,7 @@ def enum_volumes(virt, server, pooln=default_pool_name): volume = 0 - cmd = "virsh -c %s vol-list %s 2>/dev/null | sed -e '1,2 d' -e '$ d'" % \ + cmd = 'virsh -c %s vol-list %s 2>/dev/null | sed -e "1,2 d" -e "$ d"' % \ (virt2uri(virt), pooln) ret, out = run_remote(server ,cmd) if ret != 0: diff --git a/suites/libvirt-cim/lib/XenKvmLib/reporting.py b/suites/libvirt-cim/lib/XenKvmLib/reporting.py --- a/suites/libvirt-cim/lib/XenKvmLib/reporting.py +++ b/suites/libvirt-cim/lib/XenKvmLib/reporting.py @@ -87,7 +87,7 @@ def get_env_data(ip, virt): - distro = get_cmd_val("cat /etc/issue | sed '/^$/d' | awk 'NR<=1'", ip) + distro = get_cmd_val('cat /etc/issue | sed "/^$/d" | awk "NR<=1"', ip) if 'SUSE' in distro: distro = (distro.split('-'))[0].split('to')[1] diff --git a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py --- a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py +++ b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py @@ -67,7 +67,7 @@ def virdomid_list(server, virt="Xen"): """Get a list of domid from virsh""" - cmd = "virsh -c %s list 2>/dev/null | sed '1,2 d; /^$/d'" % \ + cmd = 'virsh -c %s list 2>/dev/null | sed "1,2 d; /^$/d"' % \ virt2uri(virt) ret, out = utils.run_remote(server, cmd) if ret != 0: @@ -108,7 +108,7 @@ def viruuid(name, server, virt="Xen"): """Return domain uuid given domid or domname""" - cmd = "virsh -c %s domuuid %s 2>/dev/null | sed '/^$/d'" % \ + cmd = 'virsh -c %s domuuid %s 2>/dev/null | sed "/^$/d"' % \ (virt2uri(virt), name) ret, out = utils.run_remote(server, cmd) if ret == 0: @@ -119,7 +119,7 @@ def destroy_and_undefine_domain(name, server, virt="Xen"): """Destroy and undefine a domain. name could be domid or domname""" - cmd = "virsh -c %s 'destroy %s ; undefine %s' 2>/dev/null" % \ + cmd = 'virsh -c %s "destroy %s ; undefine %s" 2>/dev/null' % \ (virt2uri(virt), name, name) utils.run_remote(server, cmd) @@ -164,7 +164,7 @@ """ Get the vcpu lists. The input is either the domid or domname. """ - cmd = "virsh -c %s vcpuinfo %s 2>/dev/null | grep '^$' | wc -l" % \ + cmd = 'virsh -c %s vcpuinfo %s 2>/dev/null | grep "^$" | wc -l' % \ (virt2uri(virt), name_id) ret, out = utils.run_remote(server, cmd) diff --git a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py +++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py @@ -50,7 +50,7 @@ specified bridge. """ - cmd = "brctl show %s | grep 'vif' | grep -v vif0.*" % bridge + cmd = 'brctl show %s | grep "vif" | grep -v vif0.*' % bridge rc, out = utils.run_remote(ip, cmd) if rc != 0: @@ -71,7 +71,7 @@ """Returns the list of disk of the specified VS """ - guest_cmd = "cat /proc/partitions | awk '/^ /{ print $4 } ' " + guest_cmd = 'cat /proc/partitions | awk "/^ /{ print $4 } " ' rc, out = run_remote_guest(ip, vs_name, guest_cmd) if rc != 0: @@ -86,7 +86,7 @@ """ xm_ret, mfm = utils.run_remote(server, - "xm info | awk -F ': ' '/max_free_memory/ {print \$2}'") + 'xm info | awk -F ": " "/max_free_memory/ {print \$2}"') if xm_ret != 0: return None @@ -108,7 +108,7 @@ if virt == "XenFV": virt = "Xen" - cmd = "virsh -c %s list --all 2>/dev/null | sed -e '1,2 d' -e '$ d'" % \ + cmd = 'virsh -c %s list --all 2>/dev/null | sed -e "1,2 d" -e "$ d"' % \ virt2uri(virt) ret, out = utils.run_remote(server, cmd) @@ -128,7 +128,7 @@ if virt == "XenFV": virt = "Xen" - cmd = "virsh -c %s list 2>/dev/null | sed -e '1,2 d' -e '$ d'" % \ + cmd = 'virsh -c %s list 2>/dev/null | sed -e "1,2 d" -e "$ d"' % \ virt2uri(virt) ret, out = utils.run_remote(server, cmd) @@ -162,7 +162,7 @@ if fv_cap(server) and gtype == 1: bootloader = "/usr/lib/xen/boot/hvmloader" else: - cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'" + cmd = 'cat /etc/issue | grep -v ^$ | egrep "Red Hat|Fedora"' ret, out = utils.run_remote(server,cmd) if ret != 0: # For SLES @@ -175,7 +175,7 @@ def net_list(server, virt="Xen"): """Function to list active network""" names = [] - cmd = "virsh -c %s net-list 2>/dev/null | sed -e '1,2 d' -e '$ d'" % \ + cmd = 'virsh -c %s net-list 2>/dev/null | sed -e "1,2 d" -e "$ d"' % \ virt2uri(virt) ret, out = utils.run_remote(server, cmd) @@ -192,8 +192,8 @@ def get_bridge_from_network_xml(network, server, virt="Xen"): """Function returns bridge name for a given virtual network""" - cmd = "virsh -c %s net-dumpxml %s 2>/dev/null | \ - awk '/bridge name/ { print $2 }'" % (virt2uri(virt), network) + cmd = 'virsh -c %s net-dumpxml %s 2>/dev/null | \ + awk "/bridge name/ { print $2 }"' % (virt2uri(virt), network) ret, out = utils.run_remote(server, cmd) if ret != 0: @@ -233,7 +233,7 @@ def diskpool_list(server, virt="KVM"): """Function to list active DiskPool list""" names = [] - cmd = "virsh -c %s pool-list 2>/dev/null | sed -e '1,2 d' -e '$ d'" % \ + cmd = 'virsh -c %s pool-list 2>/dev/null | sed -e "1,2 d" -e "$ d"' % \ virt2uri(virt) ret, out = utils.run_remote(server, cmd) @@ -251,7 +251,7 @@ def vol_list(server, virt="KVM", pool_name=None): """ Function to list the volumes of a pool""" - cmd = "virsh -c %s vol-list %s 2>/dev/null | sed -e '1,2 d' -e '$ d'" \ + cmd = 'virsh -c %s vol-list %s 2>/dev/null | sed -e "1,2 d" -e "$ d"' \ % (virt2uri(virt), pool_name) ret, out = utils.run_remote(server, cmd) if ret != 0: @@ -283,14 +283,14 @@ cmd = "virsh -c %s version 2>/dev/null" %virt2uri(virt) ret, out = utils.run_remote(server, cmd) if ret == 0: - cmd = "virsh -c %s version 2>/dev/null | grep ^Running | \ - cut -d ' ' -f 3,4" % virt2uri(virt) + cmd = 'virsh -c %s version 2>/dev/null | grep ^Running | \ + cut -d " " -f 3,4' % virt2uri(virt) # This is a workaround work for F10. # The version option does not seem to work on F10. if ret != 0 and virt == 'KVM': - cmd = "qemu-kvm --help | grep -i version | tr -s [:space:] |" \ - " cut -d ' ' -f 1,5" + cmd = 'qemu-kvm --help | grep -i version | tr -s [:space:] |' \ + ' cut -d " " -f 1,5' ret, out = utils.run_remote(server, cmd) if ret == 0: @@ -362,7 +362,7 @@ """Returns the number of processors of the specified VS """ - guest_cmd = "grep '^$' /proc/cpuinfo | wc -l" + guest_cmd = 'grep "^$" /proc/cpuinfo | wc -l' rc, out = run_remote_guest(ip, vs_name, guest_cmd) if rc != 0: From eblima at linux.vnet.ibm.com Thu Jun 30 16:04:11 2011 From: eblima at linux.vnet.ibm.com (Eduardo Lima (Etrunko)) Date: Thu, 30 Jun 2011 13:04:11 -0300 Subject: [Libvirt-cim] [PATCH 0 of 1] [TEST] Don't send commands via ssh for localhost Message-ID: Alright, this patch has been around for a while and I think the results are very similar to the version which sends all commands via ssh, except for the performance boost. I am now sending the patch for appreciation and requesting some feedback, especially if there is any specific test that was working but is now broke because of this patch. If possible, run the full cimtest suite first in a pristine checkout and save the run_report.txt file with a different name. After that, apply the patch to the tree and run the suite again. Reply to this email attaching both files so we can analyse the results. Best regards, Etrunko -- Eduardo de Barros Lima Software Engineer, Open Virtualization Linux Technology Center - IBM/Brazil eblima at br.ibm.com