[PATCH 0/2] ComputerSystem: Make reboot/shutdown work as a job
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
This code is based on the VSMigrationService for the job creation and on
ComputerSystemIndication for the job thread, which will listen for the
respective domain event to mark the job as finished.
Unfortunately I could not make it work properly. In this case I need a help
from more experienced people to help on the debug. The call in line 1318 will
fail with status code 100. I am sending a simple python test program as a
reply to this email so everyone can reproduce.
Eduardo Lima (Etrunko) (2):
VSMigrationService: Move job state definitions to svpc_types.h
ComputerSystem: Reboot/Shutdown state changes as jobs
schema/ComputerSystem.mof | 9 ++
src/Virt_ComputerSystem.c | 300 +++++++++++++++++++++++++++++++++++++++--
src/Virt_VSMigrationService.c | 14 +--
src/svpc_types.h | 13 ++
4 files changed, 317 insertions(+), 19 deletions(-)
--
1.7.7.6
12 years, 9 months
[PATCH 0/3] ComputerSystemIndication: code cleanups
by Eduardo Lima (Etrunko)
From: "Eduardo Lima (Etrunko)" <eblima(a)br.ibm.com>
Simple series of patches that fix some minor issues found in the CSI code.
Eduardo Lima (Etrunko) (3):
CSI: Only execute callback if indications are enabled
CSI: Cleanup code
CSI: Fix log messages
src/Virt_ComputerSystemIndication.c | 76 ++++++++++++++++++----------------
1 files changed, 40 insertions(+), 36 deletions(-)
--
1.7.7.6
12 years, 9 months
[PATCH] Pool Refresh Patch2
by Gareth S Bestor
From: Gareth S. Bestor <bestor(a)us.ibm.com>
This patches earlier patch (from Sharad) that added pool refresh function to
libvirt-cim. Previously, a pool refresh would be initiated whenever the pool's
CIM instance was retreived; this turns out to be too expensive for some
consumers. This patch removes that, and instead makes pool refresh an
explicit CIM operation that a CIM client can request on the
KVM_ResourcePoolConfigurationService (eg when pool resources are added or
removed or changes outside of CIM). The previous patch also initiated a
refresh whenever libvirt-cim was used to add or remove a pool resource; this
fuction has been kept, because it makes sense for the CIM pool to immediately
reflect any changes when resources are added/removed via CIM.
The new extrinsic method is called RefreshResourcesInPool[<pool>]
Signed-off-by: Gareth S. Bestor <bestor(a)us.ibm.com>
---
schema/ResourcePoolConfigurationService.mof | 12 ++++
src/Virt_DevicePool.c | 4 -
src/Virt_ResourcePoolConfigurationService.c | 93 +++++++++++++++++++++++++++
3 files changed, 105 insertions(+), 4 deletions(-)
diff --git a/schema/ResourcePoolConfigurationService.mof b/schema/ResourcePoolConfigurationService.mof
index 9199f08..7fd1cbd 100644
--- a/schema/ResourcePoolConfigurationService.mof
+++ b/schema/ResourcePoolConfigurationService.mof
@@ -76,6 +76,18 @@ class KVM_ResourcePoolConfigurationService : CIM_ResourcePoolConfigurationServic
CIM_ConcreteJob REF Job
);
+ [Description ( "Refresh the list of resource within a specified pool to "
+ "reflect any external changes. If 0 is returned, the "
+ "function completed successfully." )]
+ uint32 RefreshResourcesInPool(
+ [IN, Description ( "The pool to refresh the resource in." )]
+ CIM_ResourcePool REF Pool,
+
+ [IN ( false ), OUT, Description ( "Reference to the job (may be null "
+ "if job completed)." )]
+ CIM_ConcreteJob REF Job
+ );
+
};
[Provider("cmpi::Virt_ResourcePoolConfigurationService")]
diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c
index fe5573f..def8454 100644
--- a/src/Virt_DevicePool.c
+++ b/src/Virt_DevicePool.c
@@ -186,10 +186,6 @@ static bool diskpool_set_capacity(virConnectPtr conn,
goto out;
}
- if ((virStoragePoolRefresh(pool, 0)) == -1)
- CU_DEBUG("Unable to refresh storage pool");
-
-
if (virStoragePoolGetInfo(pool, &info) == -1) {
CU_DEBUG("Failed to get info for pool `%s'", _pool->tag);
goto out;
diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c
index 7e76032..751d016 100644
--- a/src/Virt_ResourcePoolConfigurationService.c
+++ b/src/Virt_ResourcePoolConfigurationService.c
@@ -1075,6 +1075,90 @@ static CMPIStatus delete_resource_in_pool(CMPIMethodMI *self,
return s;
}
+static CMPIStatus refresh_resources_parse_args(const CMPIArgs *argsin,
+ CMPIObjectPath **pool)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+
+ if (cu_get_ref_arg(argsin, "Pool", pool) != CMPI_RC_OK) {
+ CU_DEBUG("Failed to get Pool reference arg");
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "Missing argument `Pool'");
+ goto out;
+ }
+
+ out:
+ return s;
+}
+
+static CMPIStatus refresh_resources_in_pool(CMPIMethodMI *self,
+ const CMPIContext *context,
+ const CMPIResult *results,
+ const CMPIObjectPath *reference,
+ const CMPIArgs *argsin,
+ CMPIArgs *argsout)
+{
+ uint32_t rc = CIM_SVPC_RETURN_FAILED;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIObjectPath *pool;
+ virStoragePoolPtr poolPtr;
+ char *pool_id = NULL;
+ const char *id = NULL;
+ virConnectPtr conn = NULL;
+
+ CU_DEBUG("RefreshResourcesInPool");
+
+ s = refresh_resources_parse_args(argsin, &pool);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (cu_get_str_path(pool, "InstanceID", &id) != CMPI_RC_OK) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Missing InstanceID in resource pool");
+ goto out;
+ }
+
+ pool_id = name_from_pool_id(id);
+ if (pool_id == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_INVALID_PARAMETER,
+ "Pool has invalid InstanceID");
+ goto out;
+ }
+
+ conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
+ if (conn == NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to connect to hypervisor");
+ goto out;
+ }
+
+ poolPtr = virStoragePoolLookupByName(conn, pool_id);
+ if (poolPtr == NULL) {
+ CU_DEBUG("Failed to lookup storage pool `%s'", pool_id);
+ goto out;
+ }
+
+ if ((virStoragePoolRefresh(poolPtr, 0)) == -1) {
+ CU_DEBUG("Unable to refresh storage pool");
+ }
+ else
+ CU_DEBUG("Refreshed resources in storage pool `%s'", pool_id);
+ virStoragePoolFree(poolPtr);
+
+ out:
+ free(pool_id);
+
+ if (s.rc == CMPI_RC_OK)
+ rc = CIM_SVPC_RETURN_COMPLETED;
+ CMReturnData(results, &rc, CMPI_uint32);
+
+ return s;
+}
+
static CMPIStatus dummy_handler(CMPIMethodMI *self,
const CMPIContext *context,
const CMPIResult *results,
@@ -1139,6 +1223,14 @@ static struct method_handler DeleteResourceInPool = {
}
};
+static struct method_handler RefreshResourcesInPool = {
+ .name = "RefreshResourcesInPool",
+ .handler = refresh_resources_in_pool,
+ .args = {{"Pool", CMPI_ref, true},
+ ARG_END
+ }
+};
+
static struct method_handler *my_handlers[] = {
&CreateResourcePool,
&CreateChildResourcePool,
@@ -1147,6 +1239,7 @@ static struct method_handler *my_handlers[] = {
&DeleteResourcePool,
&CreateResourceInPool,
&DeleteResourceInPool,
+ &RefreshResourcesInPool,
NULL,
};
--
1.7.1
12 years, 9 months
[PATCH] Plan9fs (aka 9pfs, VirtFS) support for QEMU/KVM environment
by Deepak C Shetty
VirtFS is virtualization aware file system pass-through which provides the
functionality to share host file system inside the guest. Its supported in
libvirt via the <filesystem> xml node/tag. This patch introduces the
filesystem support in KVM_DiskRASD and its associated changes needed to
support VirtFS in libvirt-cim.
For further details...
Virtfs home page/wiki : http://v9fs.sourceforge.net/
Virtfs setup for QEMU : http://wiki.qemu.org/Documentation/9psetup
Virtfs support in libvirt :
http://libvirt.org/formatdomain.html#elementsFilesystems
An example of the <filesystem> node in libvirt, supporting VirtFS...
<filesystem type='mount' accessmode='passthrough'>
<driver type='path'/>
<source dir='/export/to/guest'/>
<target dir='/import/from/host'/>
<readonly/>
</filesystem>
Signed-off-by: Deepak C Shetty <deepakcs(a)linux.vnet.ibm.com>
---
libxkutil/device_parsing.c | 8 ++++++++
libxkutil/device_parsing.h | 1 +
libxkutil/xmlgen.c | 15 +++++++++++++++
schema/ResourceAllocationSettingData.mof | 7 +++++--
src/Virt_RASD.c | 6 ++++++
src/Virt_RASD.h | 1 +
src/Virt_VirtualSystemManagementService.c | 8 ++++++++
7 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c
index 371838f..6a09e7d 100644
--- a/libxkutil/device_parsing.c
+++ b/libxkutil/device_parsing.c
@@ -65,6 +65,7 @@ static void cleanup_disk_device(struct disk_device *dev)
free(dev->source);
free(dev->virtual_dev);
free(dev->bus_type);
+ free(dev->access_mode);
}
static void cleanup_vsi_device(struct vsi_device *dev)
@@ -220,6 +221,8 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
goto err;
}
+ ddev->access_mode = get_attr_value(dnode, "accessmode");
+
for (child = dnode->children; child != NULL; child = child->next) {
if (XSTREQ(child->name, "source")) {
ddev->source = get_attr_value(child, "dir");
@@ -233,6 +236,8 @@ static int parse_fs_device(xmlNode *dnode, struct virt_device **vdevs)
CU_DEBUG("No target dir");
goto err;
}
+ } else if (XSTREQ(child->name, "driver")) {
+ ddev->driver_type = get_attr_value(child, "type");
}
}
@@ -870,6 +875,7 @@ struct virt_device *virt_device_dup(struct virt_device *_dev)
DUP_FIELD(dev, _dev, dev.disk.source);
DUP_FIELD(dev, _dev, dev.disk.virtual_dev);
DUP_FIELD(dev, _dev, dev.disk.bus_type);
+ DUP_FIELD(dev, _dev, dev.disk.access_mode);
dev->dev.disk.disk_type = _dev->dev.disk.disk_type;
dev->dev.disk.readonly = _dev->dev.disk.readonly;
dev->dev.disk.shareable = _dev->dev.disk.shareable;
@@ -1436,6 +1442,8 @@ int disk_type_from_file(const char *path)
return DISK_PHY;
else if (S_ISREG(s.st_mode))
return DISK_FILE;
+ else if (S_ISDIR(s.st_mode))
+ return DISK_FS;
else
return DISK_UNKNOWN;
}
diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h
index ab104d9..6bed040 100644
--- a/libxkutil/device_parsing.h
+++ b/libxkutil/device_parsing.h
@@ -55,6 +55,7 @@ struct disk_device {
bool shareable;
char *bus_type;
char *cache;
+ char *access_mode; /* access modes for DISK_FS (filesystem) type */
};
struct net_device {
diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c
index 4cca75b..44a6158 100644
--- a/libxkutil/xmlgen.c
+++ b/libxkutil/xmlgen.c
@@ -152,6 +152,21 @@ static const char *disk_fs_xml(xmlNodePtr root, struct disk_device *dev)
if (fs == NULL)
return XML_ERROR;
+ /* filesystem prop 'type' not needed to be generated, as it defaults
+ to 'mount' in libvirt, the only supported value for now. */
+
+ /* filesystem prop 'accessmode' defaults to 'passthrough' in libvirt.
+ So generate here if specified by user, else leave it to libvirt. */
+
+ if (dev->access_mode) {
+ xmlNewProp(fs, BAD_CAST "accessmode", BAD_CAST dev->access_mode);
+ }
+
+ if(dev->driver_type) {
+ tmp = xmlNewChild(fs, NULL, BAD_CAST "driver", NULL);
+ xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->driver_type);
+ }
+
tmp = xmlNewChild(fs, NULL, BAD_CAST "source", NULL);
if (tmp == NULL)
return XML_ERROR;
diff --git a/schema/ResourceAllocationSettingData.mof b/schema/ResourceAllocationSettingData.mof
index 3da503d..108dff7 100644
--- a/schema/ResourceAllocationSettingData.mof
+++ b/schema/ResourceAllocationSettingData.mof
@@ -40,8 +40,8 @@ class KVM_DiskResourceAllocationSettingData : KVM_ResourceAllocationSettingData
string VirtualDevice;
[Description ("Device emulation type"),
- ValueMap {"0", "1", "2"},
- Values {"Disk", "CDROM", "floppy"}]
+ ValueMap {"0", "1", "2", "3"},
+ Values {"Disk", "CDROM", "floppy", "filesystem"}]
uint16 EmulatedType;
[Description ("Bus type of the device")]
@@ -58,6 +58,9 @@ class KVM_DiskResourceAllocationSettingData : KVM_ResourceAllocationSettingData
[Description ("cache setting for device")]
string DriverCache;
+
+ [Description ("filesystem access mode")]
+ string AccessMode;
};
[Description ("LXC virtual disk configuration"),
diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c
index 9305c8d..29bf10d 100644
--- a/src/Virt_RASD.c
+++ b/src/Virt_RASD.c
@@ -397,6 +397,12 @@ static CMPIStatus set_disk_rasd_params(const CMPIBroker *broker,
(CMPIValue *)dev->dev.disk.cache,
CMPI_chars);
+ if(dev->dev.disk.access_mode)
+ CMSetProperty(inst,
+ "AccessMode",
+ (CMPIValue *)dev->dev.disk.access_mode,
+ CMPI_chars);
+
virStoragePoolFree(pool);
virStorageVolFree(vol);
virConnectClose(conn);
diff --git a/src/Virt_RASD.h b/src/Virt_RASD.h
index 550543a..cef4224 100644
--- a/src/Virt_RASD.h
+++ b/src/Virt_RASD.h
@@ -26,6 +26,7 @@
#define VIRT_DISK_TYPE_DISK 0
#define VIRT_DISK_TYPE_CDROM 1
#define VIRT_DISK_TYPE_FLOPPY 2
+#define VIRT_DISK_TYPE_FS 3
char *rasd_to_xml(CMPIInstance *rasd);
diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c
index 21979c3..3cdca86 100644
--- a/src/Virt_VirtualSystemManagementService.c
+++ b/src/Virt_VirtualSystemManagementService.c
@@ -1022,6 +1022,8 @@ static const char *disk_rasd_to_vdev(CMPIInstance *inst,
}
else if (type == VIRT_DISK_TYPE_FLOPPY)
dev->dev.disk.device = strdup("floppy");
+ else if (type == VIRT_DISK_TYPE_FS)
+ dev->dev.disk.device = strdup("filesystem");
else
return "Invalid value for EmulatedType";
@@ -1056,6 +1058,12 @@ static const char *disk_rasd_to_vdev(CMPIInstance *inst,
else
dev->dev.disk.cache = strdup(val);
+ free(dev->dev.disk.access_mode);
+ if (cu_get_str_prop(inst, "AccessMode", &val) != CMPI_RC_OK)
+ dev->dev.disk.access_mode = NULL;
+ else
+ dev->dev.disk.access_mode = strdup(val);
+
free(dev->id);
dev->id = strdup(dev->dev.disk.virtual_dev);
12 years, 9 months
SELinux support in libvirt-cim
by Sharad Mishra
Using my imap account to send this email. Hopefully, it will make it
this time.
-Sharad
>
> Hi,
>
> In order to add support for selinux in libvirt-cim. I created the
> following policy -
>
>
> ***********************************************
> module mypolicy 1.0;
>
> require {
> type pegasus_var_run_t;
> type pegasus_t;
> class sock_file write;
> class unix_stream_socket connectto;
> }
>
> #============= pegasus_t ==============
> allow pegasus_t pegasus_var_run_t:sock_file write;
> allow pegasus_t self:unix_stream_socket connectto;
>
> *****************************************
>
> To create this policy -
>
> 1. Turn on selinux in permissive mode
>
> # sestatus
> SELinux status: enabled
> SELinuxfs mount: /selinux
> Current mode: permissive
> Mode from config file: enforcing
> Policy version: 24
> Policy from config file: targeted
>
> 2. Verified that /var/log/audit/audit.log was empty
>
> 3. Ran entire cimtest suite
>
> 4. ran 'audit2allow -M newpolicy < /var/log/audit/audit.log
>
> I am not familiar with selinux. Is this the right approach? Did I miss
> anything?
>
> Regards,
> Sharad Mishra
> Open Virtualization
> Linux Technology Center
> IBM
>
12 years, 10 months
[PATCH V6 0/7] vlan extention - readonly
by xiaxia347work@163.com
From: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
These patches add readonly portion of host network.
v6: code changes according to v5 comments, added CIM model code. Added DHCP
property in CIM model and EthIface structure.
Wenchao Xia (7):
vlan extention - readonly function libarary
vlan extention - CIM model helper
vlan extention - CIM model Makefile change
vlan extention - CIM model add VESS
vlan extention - CIM model add VESSSD
vlan extention - CIM model add EthernetPort
vlan extention - CIM model add EASD
Makefile.am | 14 +-
libxkutil/Makefile.am | 12 +-
libxkutil/misc_util.c | 48 ++
libxkutil/misc_util.h | 3 +
libxkutil/network_model_helper.c | 473 ++++++++++++
libxkutil/network_model_helper.h | 101 +++
libxkutil/network_parsing.c | 762 ++++++++++++++++++++
libxkutil/network_parsing.h | 176 +++++
libxkutil/network_parsing_test.c | 70 ++
libxkutil/xmlgen.c | 4 +-
libxkutil/xmlgen.h | 4 +
schema/EthernetPort.mof | 4 +
schema/EthernetPort.registration | 3 +
schema/EthernetPortAllocationSettingData.mof | 22 +
.../EthernetPortAllocationSettingData.registration | 3 +
schema/VirtualEthernetSwitchSystem.mof | 10 +
schema/VirtualEthernetSwitchSystem.registration | 3 +
schema/VirtualEthernetSwitchSystemSettingData.mof | 31 +
...ualEthernetSwitchSystemSettingData.registration | 3 +
src/Makefile.am | 23 +-
src/Virt_EASD.c | 709 ++++++++++++++++++
src/Virt_EASD.h | 59 ++
src/Virt_EthernetPort.c | 561 ++++++++++++++
src/Virt_EthernetPort.h | 58 ++
src/Virt_VESSSD.c | 382 ++++++++++
src/Virt_VESSSD.h | 39 +
src/Virt_VirtualEthernetSwitchSystem.c | 478 ++++++++++++
src/Virt_VirtualEthernetSwitchSystem.h | 52 ++
28 files changed, 4097 insertions(+), 10 deletions(-)
create mode 100644 libxkutil/network_model_helper.c
create mode 100644 libxkutil/network_model_helper.h
create mode 100644 libxkutil/network_parsing.c
create mode 100644 libxkutil/network_parsing.h
create mode 100644 libxkutil/network_parsing_test.c
create mode 100644 schema/EthernetPort.mof
create mode 100644 schema/EthernetPort.registration
create mode 100644 schema/EthernetPortAllocationSettingData.mof
create mode 100644 schema/EthernetPortAllocationSettingData.registration
create mode 100644 schema/VirtualEthernetSwitchSystem.mof
create mode 100644 schema/VirtualEthernetSwitchSystem.registration
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.mof
create mode 100644 schema/VirtualEthernetSwitchSystemSettingData.registration
create mode 100644 src/Virt_EASD.c
create mode 100644 src/Virt_EASD.h
create mode 100644 src/Virt_EthernetPort.c
create mode 100644 src/Virt_EthernetPort.h
create mode 100644 src/Virt_VESSSD.c
create mode 100644 src/Virt_VESSSD.h
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.c
create mode 100644 src/Virt_VirtualEthernetSwitchSystem.h
12 years, 10 months
[PATCH V2 4/4] cimtest - vlan extention - connection
by Wenchao Xia
This test case trys: define a bridge, create a 802.1.q port, connect
the port to the bridge, bring down the bridge, bring up the bridge. This case
is very similiar to 802.1.q usage, except that bridge have no DHCP set in this
case, for that it need external device support DHCP.
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
.../cimtest/HostNetwork/03_VESSMS_EASD_EC.py | 113 ++++++++++++++++++++
1 files changed, 113 insertions(+), 0 deletions(-)
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py
diff --git a/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py b/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py
new file mode 100644
index 0000000..ece07cd
--- /dev/null
+++ b/suites/libvirt-cim/cimtest/HostNetwork/03_VESSMS_EASD_EC.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2012 IBM Corp.
+#
+# Authors:
+# Wenchao Xia (Wayne) <xiawenc(a)cn.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU 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
+#
+
+#
+# try connect two CIM switch by attaching one eth to another bridge
+#
+#
+
+import sys
+import os
+import pywbem
+
+from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+from XenKvmLib import host_network
+
+cim = None
+sys_mgmt_service = None
+supported = ['KVM',]
+
+
+@do_main(supported)
+def main():
+ options = main.options
+ server = options.ip
+ server_url = "http://%s" % server
+ #get cim
+ cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS)
+
+ sys_mgmt_service = host_network.get_vessms(cim)
+ pNIC = host_network.FoundOnePNIC(cim)
+ if pNIC == None :
+ logger.error("Failed to find any pNIC on the host.")
+ return XFAIL
+
+ #add the bridge
+ inst_br = {'VirtualSystemIdentifier':host_network.bridge_name, 'Name': host_network.bridge_name, 'STP': host_network.bridge_stp, 'Delay': host_network.bridge_delay, 'DHCP': 0, 'AutoStart': host_network.bridge_autostart}
+
+ ret = host_network.try_create_vs(cim, sys_mgmt_service, inst_br)
+ if ret != 1:
+ logger.error("Failed to add cim bridge")
+ return FAIL
+
+ inst_ea = {'Parent': pNIC, 'VLanID':10, 'DHCP': 0, 'AutoStart': 0}
+ ret = host_network.try_add_ea(cim, sys_mgmt_service, inst_ea)
+ if ret != 1:
+ logger.error("Failed to add 802.1.q ea")
+ return FAIL
+
+ EthPort = """%s.%d""" % (inst_ea["Parent"], inst_ea["VLanID"])
+ inst_ec = {'ParentBridge': pNIC, 'EthPort':EthPort, 'TargetBridge': host_network.bridge_pNIC}
+ ret = host_network.try_add_ec(cim, sys_mgmt_service, inst_ec)
+ if ret != 1:
+ logger.error("Failed to add connection")
+ return FAIL
+
+ #bring down the iface
+ ret = host_network.try_chang_vess_state(cim, inst_br, 3)
+ if ret != 1:
+ logger.error("Failed to bring down these ifaces.")
+ return FAIL
+
+ #bring up the iface
+ ret = host_network.try_chang_vess_state(cim, inst_br, 2)
+ if ret != 1:
+ logger.error("Failed to bring up these ifaces.")
+ return FAIL
+
+ ret = host_network.try_del_ec(cim, sys_mgmt_service, inst_ec)
+ if ret != 1:
+ logger.error("Failed to add connection")
+ return FAIL
+
+ ret = host_network.try_del_ea(cim, sys_mgmt_service, inst_ea)
+ if ret != 1:
+ logger.error("Failed to remove 802.1.q ea")
+ return FAIL
+
+ ret = host_network.try_delete_vs(cim, sys_mgmt_service, inst_br)
+ if ret != 1:
+ logger.error("Failed to delete cim bridge")
+ return FAIL
+
+ return PASS
+
+# main()
+
+if __name__ == "__main__":
+ ret = main()
+ sys.exit(ret)
--
1.7.1
12 years, 10 months
[PATCH V2 3/4] cimtest - vlan extention - vlan 802.1.q
by Wenchao Xia
This case covers 802.1.q port allocation via EASD-EA.
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
.../cimtest/HostNetwork/02_VESSMS_EASD_EA.py | 83 ++++++++++++++++++++
1 files changed, 83 insertions(+), 0 deletions(-)
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py
diff --git a/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py b/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py
new file mode 100644
index 0000000..964e0e0
--- /dev/null
+++ b/suites/libvirt-cim/cimtest/HostNetwork/02_VESSMS_EASD_EA.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2012 IBM Corp.
+#
+# Authors:
+# Wenchao Xia (Wayne) <xiawenc(a)cn.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU 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
+#
+
+#
+# Create, Modify, Delete IEEE802.1.q child port
+#
+#
+
+import sys
+import os
+import pywbem
+
+from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+from XenKvmLib import host_network
+
+cim = None
+sys_mgmt_service = None
+supported = ['KVM',]
+
+
+@do_main(supported)
+def main():
+ options = main.options
+ server = options.ip
+ server_url = "http://%s" % server
+ #get cim
+ cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS)
+
+ sys_mgmt_service = host_network.get_vessms(cim)
+ pNIC = host_network.FoundOnePNIC(cim)
+ if pNIC == None :
+ logger.error("Failed to find any pNIC on the host.")
+ return XFAIL
+
+ inst = {'Parent': pNIC, 'VLanID':10, 'DHCP': 0, 'AutoStart': 0}
+ ret = host_network.try_add_ea(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to add 802.1.q ea")
+ return FAIL
+
+ inst['DHCP'] = 1
+ inst['AutoStart'] = 1
+ ret = host_network.try_mod_ea(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to mod 802.1.q ea")
+ return FAIL
+
+ ret = host_network.try_del_ea(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to remove 802.1.q ea")
+ return FAIL
+
+ return PASS
+
+# main()
+
+if __name__ == "__main__":
+ ret = main()
+ sys.exit(ret)
--
1.7.1
12 years, 10 months
[PATCH V2 2/4] cimtest - vlan extention - bridge
by Wenchao Xia
This case try add, modify, delete host bridge.
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
.../cimtest/HostNetwork/01_VESSMS_Bridge.py | 78 ++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
create mode 100644 suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py
diff --git a/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py b/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py
new file mode 100644
index 0000000..0d4dd11
--- /dev/null
+++ b/suites/libvirt-cim/cimtest/HostNetwork/01_VESSMS_Bridge.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2012 IBM Corp.
+#
+# Authors:
+# Wenchao Xia (Wayne) <xiawenc(a)cn.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU 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
+#
+
+#
+# Create ,modify, delete a soft virtual switch system
+#
+#
+
+import sys
+import os
+import pywbem
+
+from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+from XenKvmLib import host_network
+
+cim = None
+sys_mgmt_service = None
+supported = ['KVM',]
+
+@do_main(supported)
+def main():
+ options = main.options
+ server = options.ip
+ server_url = "http://%s" % server
+ #get cim
+ cim = pywbem.WBEMConnection(server_url, (CIM_USER, CIM_PASS), CIM_NS)
+
+ sys_mgmt_service = host_network.get_vessms(cim)
+
+ #add the bridge
+ inst = {'VirtualSystemIdentifier':host_network.bridge_name, 'Name': host_network.bridge_name, 'STP': host_network.bridge_stp, 'Delay': host_network.bridge_delay, 'DHCP': host_network.bridge_dhcp, 'AutoStart': host_network.bridge_autostart}
+
+ ret = host_network.try_create_vs(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to add cim bridge")
+ return FAIL
+
+ inst["STP"] = host_network.bridge_stp_modify
+ ret = host_network.try_modify_vs(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to modify cim bridge")
+ return FAIL
+
+ ret = host_network.try_delete_vs(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ logger.error("Failed to delete cim bridge")
+ return FAIL
+ return PASS
+
+# main()
+
+if __name__ == "__main__":
+ ret = main()
+ sys.exit(ret)
--
1.7.1
12 years, 10 months
[PATCH V2 1/4] cimtest - vlan extention - helper
by Wenchao Xia
This patch added core functions as test units. Generaly, the test process
is: Modify it, Enum it to check the result. All operation were done by
libvirt-cim. In adding a network device, it would automatically delete it if
it exist, before call libvirt-cim.
Signed-off-by: Wenchao Xia <xiawenc(a)linux.vnet.ibm.com>
---
suites/libvirt-cim/lib/XenKvmLib/host_network.py | 455 ++++++++++++++++++++++
1 files changed, 455 insertions(+), 0 deletions(-)
create mode 100644 suites/libvirt-cim/lib/XenKvmLib/host_network.py
diff --git a/suites/libvirt-cim/lib/XenKvmLib/host_network.py b/suites/libvirt-cim/lib/XenKvmLib/host_network.py
new file mode 100644
index 0000000..cb17f55
--- /dev/null
+++ b/suites/libvirt-cim/lib/XenKvmLib/host_network.py
@@ -0,0 +1,455 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2012 IBM Corp.
+#
+# Authors:
+# Wenchao Xia (Wayne) <xiawenc(a)cn.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU 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
+#
+
+# This file have basic functions for testing of host network in libvirt-cim
+
+
+import sys
+import os
+import pywbem
+
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+
+network_clas_prefix = "Net_"
+vesssd_parent = "Virt"
+vs_prefix = "VS_"
+ea_prefix = "EA_"
+ec_prefix = "EC_"
+delimiter_System = """:"""
+delimiter_Device = """/"""
+
+vess_cls_name = network_clas_prefix + "VirtualEthernetSwitchSystem"
+vessms_cls_name = network_clas_prefix + "VirtualEthernetSwitchSystemManagementService"
+vesssd_cls_name = network_clas_prefix + "VirtualEthernetSwitchSystemSettingData"
+easd_cls_name = network_clas_prefix + "EthernetPortAllocationSettingData"
+
+vlan_8021q_type = 1
+
+bridge_pNIC = "test_br1"
+bridge_name = """%s%s""" % (vs_prefix, bridge_pNIC)
+bridge_stp = 0
+bridge_delay = 0
+bridge_autostart = 0
+bridge_dhcp = 0
+
+bridge_stp_modify = 1
+
+
+def set_vs_define(inst):
+ return """
+instance of %s {
+ VirtualSystemIdentifier="%s";
+ STP=%d;
+ Delay=%d;
+ AutoStart=%d;
+ DHCP=%d;
+};""" % (vesssd_cls_name,
+ inst["VirtualSystemIdentifier"],
+ inst["STP"],
+ inst["Delay"],
+ inst["AutoStart"],
+ inst["DHCP"],)
+
+def set_vs_modify(inst):
+ return """
+instance of %s {
+ VirtualSystemIdentifier="%s";
+ STP=%d;
+};""" % (vesssd_cls_name,
+ inst["VirtualSystemIdentifier"],
+ inst["STP"],)
+
+
+def set_vs_destroy(inst):
+ inst = pywbem.CIMInstanceName(classname=vess_cls_name, keybindings=pywbem.NocaseDict({'CreationClassName': vess_cls_name, 'Name': inst["Name"]}))
+ return inst
+
+def get_vessms(cim):
+ _class = vessms_cls_name
+ sys_mgmt_service = cim.EnumerateInstanceNames(_class)[0]
+ #it is not supposed to fail here, the enum of VESSMS is very simple
+ logger.info("got vessms as: %s.", sys_mgmt_service)
+ return sys_mgmt_service
+
+def get_vess(cim, targetInst, name_only):
+ _class = vess_cls_name
+ if name_only == 1:
+ vess_list = cim.EnumerateInstanceNames(_class)
+ else :
+ vess_list = cim.EnumerateInstances(_class)
+ targetID = targetInst["Name"]
+ instanceList = ""
+ for inst in vess_list:
+ items = inst.items()
+ instanceList += str(items)+ "\n"
+ cmp_ret = cmp(inst["Name"], targetInst["Name"])
+ if cmp_ret == 0:
+ logger.info("found the device., it is :\n %s", str(items))
+ return inst
+ return None
+
+def try_chang_vess_state(cim, targetInst, state):
+ vess_inst = get_vess(cim, targetInst, 1)
+ if vess_inst == None :
+ logger.error("vess %s not found.", targetInst["Name"])
+ val = pywbem.cim_types.Uint16(state)
+ method = "RequestStateChange"
+ par_name = "RequestedState"
+ param = {par_name: val}
+ logger.info("trying method %s of %s with parameter:\n %s", method, vess_inst, param)
+ ret = cim.InvokeMethod(method, vess_inst, **param)
+ vess_inst = get_vess(cim, targetInst, 0)
+ logger.info("result state is %d, requested is %d.", vess_inst["EnabledState"], state)
+ if vess_inst["EnabledState"] == state :
+ return 1
+ else :
+ return 0
+
+def check_vesssd(cim, targetInst, compareAll = False):
+ #check the result
+ _class = vesssd_cls_name
+ vesssd = cim.EnumerateInstances(_class)
+ targetID = targetInst["Name"]
+ instanceList = ""
+ found = 0
+ for inst in vesssd:
+ items = inst.items()
+ instanceList += str(items)+ "\n"
+ (prefix, ID) = inst["InstanceID"].split(":",1)
+ cmp_ret = cmp(ID, targetID) or cmp(prefix, vesssd_parent)
+ if cmp_ret == 0:
+ logger.info("found the device., it is :\n %s", str(items))
+ if compareAll == False :
+ found = 1
+ else :
+ found = 1
+ if inst["STP"] != targetInst["STP"]:
+ found = 0
+ if inst["Delay"] != targetInst["Delay"]:
+ found = 0
+ if inst["AutoStart"] != targetInst["AutoStart"]:
+ found = 0
+ if inst["DHCP"] != targetInst["DHCP"]:
+ found = 0
+ #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList)
+ logger.info("target vesssd searching result is %d.", found)
+ return found
+
+def try_delete_vs(cim, sys_mgmt_service, inst):
+ #delete the bridge
+ val = set_vs_destroy(inst)
+ method = "DestroySystem"
+ par_name = "AffectedSystem"
+ param = {par_name: val}
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_vesssd(cim, inst)
+ if found == 1 :
+ return 0
+ else :
+ return 1
+
+def try_create_vs(cim, sys_mgmt_service, inst):
+ #Check the Env
+ found = check_vesssd(cim, inst)
+ if found == 1:
+ logger.info("device exist, trying delete it");
+ ret = try_delete_vs(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ return 0
+
+ #add the bridge
+ val = set_vs_define(inst)
+ method = "DefineSystem"
+ logger.info("try method %s of %s with parameter %s", method, sys_mgmt_service, val)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **{"SystemSettings": val})
+ found = check_vesssd(cim, inst)
+ if found == 1 :
+ return 1
+ else :
+ return 0
+
+def try_modify_vs(cim, sys_mgmt_service, inst):
+ #modify the bridge
+ val = set_vs_modify(inst)
+ method = "ModifySystemSettings"
+ par_name = "SystemSettings"
+ param = {par_name: val}
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_vesssd(cim, inst, True)
+ if found == 1 :
+ return 1
+ else :
+ return 0
+
+
+#inst should be:
+#{'Parent': "eth0", 'VLanID':10, 'ReorderHdr':1, 'Ingress':"1:2 2:3", 'Egress':'2:4'}
+def set_ea_add_8021q(inst):
+ ParentSystem = """%s%s""" % (vs_prefix, inst['Parent'])
+ AffectedID = """%s%s%s""" % (vesssd_parent, delimiter_System, ParentSystem)
+ AffectedConfiguration = pywbem.CIMInstanceName(classname= vesssd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': AffectedID}))
+ EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID'])
+ InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID)
+ ea1 = """
+instance of %s {
+ InstanceID ="%s";
+ VLANType = %d;
+ Connection = {"VLAN%d"};
+ AutoStart=%d;
+ DHCP=%d;
+};""" % (easd_cls_name,
+ InstanceID_EA,
+ vlan_8021q_type,
+ inst["VLanID"],
+ inst["AutoStart"],
+ inst["DHCP"])
+ final_param = {"AffectedConfiguration" : AffectedConfiguration, "ResourceSettings" : [ea1,]}
+ return final_param
+
+def set_ea_mod_8021q(inst):
+ ParentSystem = """%s%s""" % (vs_prefix, inst['Parent'])
+ EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID'])
+ InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID)
+ ea1 = """
+instance of %s {
+ InstanceID ="%s";
+ VLANType = %d;
+ Connection = {"VLAN%d"};
+ AutoStart=%d;
+ DHCP=%d;
+};""" % (easd_cls_name,
+ InstanceID_EA,
+ vlan_8021q_type,
+ inst["VLanID"],
+ inst["AutoStart"],
+ inst["DHCP"])
+ final_param = {"ResourceSettings" : [ea1,]}
+ return final_param
+
+def set_ea_del_8021q(inst):
+ ParentSystem = """%s%s""" % (vs_prefix, inst['Parent'])
+ EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID'])
+ InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID)
+ del_ref = pywbem.CIMInstanceName(classname= easd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': InstanceID_EA}))
+ final_param = {"ResourceSettings" : [del_ref,],}
+ return final_param
+
+
+def check_easd_ea(cim, targetInst, compareAll = False):
+ #check the result
+ _class = easd_cls_name
+ easds = cim.EnumerateInstances(_class)
+
+ inst = targetInst
+ ParentSystem = """%s%s""" % (vs_prefix, inst['Parent'])
+ EA_ID = """%s%s.%d""" % (ea_prefix, inst['Parent'], inst['VLanID'])
+ InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID)
+ vlanstr = """VLAN%d""" % (inst['VLanID'])
+
+ instanceList = ""
+ found = 0
+ for inst in easds:
+ items = inst.items()
+ instanceList += str(items)+ "\n"
+ cmp_ret = cmp(inst["InstanceID"], InstanceID_EA)
+ if cmp_ret == 0:
+ logger.info("found the device., it is :\n %s", str(items))
+ cmp_ret = cmp(inst["Connection"][0], vlanstr)
+ if cmp_ret == 0:
+ found = 1
+ else :
+ found = 0
+ if compareAll == False :
+ pass
+ else :
+ if inst["AutoStart"] != targetInst["AutoStart"]:
+ found = 0
+ if inst["DHCP"] != targetInst["DHCP"]:
+ found = 0
+ break
+ #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList)
+ logger.info("target easd searching result is %d.", found)
+ return found
+
+def try_del_ea(cim, sys_mgmt_service, inst):
+ param = set_ea_del_8021q(inst)
+ method = "RemoveResourceSettings"
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_easd_ea(cim, inst)
+ if found == 1 :
+ return 0
+ else :
+ return 1
+
+def try_mod_ea(cim, sys_mgmt_service, inst):
+ param = set_ea_mod_8021q(inst)
+ method = "ModifyResourceSettings"
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_easd_ea(cim, inst, True)
+ if found == 1 :
+ return 1
+ else :
+ return 0
+
+
+def try_add_ea(cim, sys_mgmt_service, inst):
+ #Check the Env
+ found = check_easd_ea(cim, inst)
+ if found == 1:
+ logger.info("device exist, trying delete it");
+ ret = try_del_ea(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ return 0
+
+ param = set_ea_add_8021q(inst)
+ method = "AddResourceSettings"
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_easd_ea(cim, inst)
+ if found == 1 :
+ return 1
+ else :
+ return 0
+
+
+#inst should be:
+#{'ParentBridge': "eth0", 'EthPort':eth0.10, 'TargetBridge': "test_br"}
+def set_ec_add(inst):
+ ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge'])
+ TargetSystem = """%s%s""" % (vs_prefix, inst['TargetBridge'])
+ AffectedID = """%s%s%s""" % (vesssd_parent, delimiter_System, ParentSystem)
+ AffectedConfiguration = pywbem.CIMInstanceName(classname= vesssd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': AffectedID}))
+ EA_ID = """%s%s""" % (ea_prefix, inst['EthPort'])
+ EC_ID = """%s%s""" % (ec_prefix, inst['EthPort'])
+ InstanceID_EA = """%s%s%s""" % (ParentSystem, delimiter_Device, EA_ID)
+ InstanceID_EC = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID)
+ ea1 = """
+instance of %s {
+ InstanceID ="%s";
+ HostResource = {"%s"};
+ Parent = "%s";
+};""" % (easd_cls_name,
+ InstanceID_EC,
+ TargetSystem,
+ InstanceID_EA)
+ final_param = {"AffectedConfiguration" : AffectedConfiguration, "ResourceSettings" : [ea1,]}
+ return final_param
+
+def set_ec_del(inst):
+ ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge'])
+ EC_ID = """%s%s""" % (ec_prefix, inst['EthPort'])
+ InstanceID_EC = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID)
+ del_ref = pywbem.CIMInstanceName(classname= easd_cls_name, keybindings=pywbem.NocaseDict({'InstanceID': InstanceID_EC}))
+ final_param = {"ResourceSettings" : [del_ref,],}
+ return final_param
+
+def check_easd_ec(cim, targetInst, compareAll = False):
+ #check the result
+ _class = easd_cls_name
+ easds = cim.EnumerateInstances(_class)
+
+ inst = targetInst
+ ParentSystem = """%s%s""" % (vs_prefix, inst['ParentBridge'])
+ TargetSystem = """%s%s""" % (vs_prefix, inst['TargetBridge'])
+ EC_ID = """%s%s""" % (ec_prefix, inst['EthPort'])
+ InstanceID_EC0 = """%s%s%s""" % (ParentSystem, delimiter_Device, EC_ID)
+ InstanceID_EC1 = """%s%s%s""" % (TargetSystem, delimiter_Device, EC_ID)
+
+ instanceList = ""
+ EC0_found = 0
+ EC1_found = 0
+ for inst in easds:
+ items = inst.items()
+ instanceList += str(items)+ "\n"
+ cmp_ret = cmp(inst["InstanceID"], InstanceID_EC0)
+ if cmp_ret == 0:
+ logger.info("found the ec0., it is :\n %s", str(items))
+ EC0_found = 1
+ else :
+ cmp_ret = cmp(inst["InstanceID"], InstanceID_EC1)
+ if cmp_ret == 0:
+ logger.info("found the ec1., it is :\n %s", str(items))
+ EC1_found = 1
+ #logger.info("search for %s, list is: \n%s", _class, instanceList)
+ found = EC0_found and EC1_found
+ logger.info("target easd_ec searching result is %d and %d.", EC0_found, EC1_found)
+ if EC0_found != EC1_found :
+ logger.info("not all ec found as expected.")
+ found = -1
+ return found
+
+def try_del_ec(cim, sys_mgmt_service, inst):
+ param = set_ec_del(inst)
+ method = "RemoveResourceSettings"
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_easd_ec(cim, inst)
+ if found == 0 :
+ return 1
+ else :
+ return 0
+
+def try_add_ec(cim, sys_mgmt_service, inst):
+ #Check the Env
+ found = check_easd_ec(cim, inst)
+ if found != 0:
+ logger.info("device exist, trying delete it");
+ ret = try_del_ec(cim, sys_mgmt_service, inst)
+ if ret != 1:
+ return 0
+
+ param = set_ec_add(inst)
+ method = "AddResourceSettings"
+ logger.info("trying method %s of %s with parameter:\n %s", method, sys_mgmt_service, param)
+ ret = cim.InvokeMethod(method, sys_mgmt_service, **param)
+ found = check_easd_ec(cim, inst)
+ if found == 1 :
+ return 1
+ else :
+ return 0
+
+def FoundOnePNIC(cim):
+ #check the result
+ _class = vesssd_cls_name
+ vesssd = cim.EnumerateInstances(_class)
+ EthList = []
+ found = 0
+ for inst in vesssd:
+ (prefix, ID) = inst["InstanceID"].split(":",1)
+ if ID.find(vs_prefix) == 0 :
+ realname = ID[len(vs_prefix):]
+ if realname.find("eth") == 0 and realname.find(".") == -1 :
+ found = 1
+ EthList.append(realname)
+ #logger.info("search for %s, found is %d, list is: \n%s", _class, found, instanceList)
+ ret_name = None
+ if found == 1 :
+ ret_name = EthList[0]
+ logger.info("pNIC searching result is %d, list %s, ret is %s.", found, EthList, ret_name)
+ return ret_name
--
1.7.1
12 years, 10 months