
add the class Net_VirtualEthernetSwitchSystemDevice. Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- schema/SystemDevice.mof | 18 +++++- schema/SystemDevice.registration | 3 +- src/Virt_SystemDevice.c | 126 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 2 deletions(-) diff --git a/schema/SystemDevice.mof b/schema/SystemDevice.mof index e13b265..13f45ae 100644 --- a/schema/SystemDevice.mof +++ b/schema/SystemDevice.mof @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2007 +// Copyright IBM Corp. 2011 [Association, Description ( @@ -47,3 +47,19 @@ class LXC_SystemDevice : CIM_SystemDevice CIM_LogicalDevice REF PartComponent; }; + +[Association, + Description ( + "A class to associate switch system." ), + Provider("cmpi::Virt_SwitchSystemDevice") +] +class Net_VirtualEthernetSwitchSystemDevice : CIM_SystemDevice +{ + + [Override ( "GroupComponent" )] + Net_VirtualEthernetSwitchSystem REF GroupComponent; + + [Override ( "PartComponent" )] + Net_EthernetPort REF PartComponent; + +}; diff --git a/schema/SystemDevice.registration b/schema/SystemDevice.registration index d6c331d..83dcbc6 100644 --- a/schema/SystemDevice.registration +++ b/schema/SystemDevice.registration @@ -1,5 +1,6 @@ -# Copyright IBM Corp. 2007 +# Copyright IBM Corp. 2011 # Classname Namespace ProviderName ProviderModule ProviderTypes Xen_SystemDevice root/virt Virt_SystemDevice Virt_SystemDevice association KVM_SystemDevice root/virt Virt_SystemDevice Virt_SystemDevice association LXC_SystemDevice root/virt Virt_SystemDevice Virt_SystemDevice association +Net_VirtualEthernetSwitchSystemDevice root/virt Virt_SystemDevice Virt_SystemDevice association diff --git a/src/Virt_SystemDevice.c b/src/Virt_SystemDevice.c index 31d6b61..0b166fa 100644 --- a/src/Virt_SystemDevice.c +++ b/src/Virt_SystemDevice.c @@ -6,6 +6,9 @@ * Jay Gagnon <grendel@linux.vnet.ibm.com> * Zhengang Li <lizg@cn.ibm.com> * + * Modified by: + * Wenchao Xia <xiawenc@cn.ibm.com> + * * 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 @@ -37,6 +40,8 @@ #include "Virt_ComputerSystem.h" #include "Virt_Device.h" +#include "Virt_VirtualEthernetSwitchSystem.h" +#include "Virt_EthernetPort.h" /* Associate an XXX_ComputerSystem to the proper XXX_LogicalDisk * and XXX_NetworkPort instances. @@ -44,6 +49,11 @@ * -- or -- * * Associate an XXX_LogicalDevice to the proper XXX_ComputerSystem + * + * -- or -- + * + * Virtual Ethernet Switch System with Ethernet Port + * */ const static CMPIBroker *_BROKER; @@ -120,6 +130,79 @@ static CMPIStatus dev_to_sys(const CMPIObjectPath *ref, return s; } +static CMPIStatus vess_to_ep(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + const char *host = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (!match_hypervisor_prefix(ref, info)) { + return s; + } + + /* the step of creating a vess instance is skipped to make it fast */ + if (cu_get_str_path(ref, "Name", &host) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing Name"); + goto out; + } + + s = enum_eps(_BROKER, + host, + ref, + info->properties, + list); + + + out: + return s; +} + +static CMPIStatus ep_to_vess(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + const char *devid = NULL; + char *host = NULL; + char *dev = NULL; + CMPIInstance *inst = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (!match_hypervisor_prefix(ref, info)) { + return s; + } + + /* the step of creating a ep instance is skipped to make it fast */ + + if (cu_get_str_path(ref, "DeviceID", &devid) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing DeviceID"); + goto out; + } + + if (!parse_fq_devid(devid, &host, &dev)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Invalid DeviceID"); + goto out; + } + + s = get_switch_by_name(_BROKER, host, ref, &inst); + if (s.rc != CMPI_RC_OK) { + goto out; + } + + inst_list_add(list, inst); + + out: + free(host); + free(dev); + return s; +} + LIBVIRT_CIM_DEFAULT_MAKEREF() static char* group_component[] = { @@ -158,6 +241,21 @@ static char* assoc_classname[] = { NULL }; +static char *vess_group_component[] = { + "Net_VirtualEthernetSwitchSystem", + NULL +}; + +static char *vess_part_component[] = { + "Net_EthernetPort", + NULL +}; + +static char *vess_assoc_classname[] = { + "Net_VirtualEthernetSwitchSystemDevice", + NULL +}; + static struct std_assoc forward = { .source_class = (char**)&group_component, .source_prop = "GroupComponent", @@ -184,9 +282,37 @@ static struct std_assoc backward = { .make_ref = make_ref }; +static struct std_assoc assoc_vess_to_ep = { + .source_class = (char **)&vess_group_component, + .source_prop = "GroupComponent", + + .target_class = (char **)&vess_part_component, + .target_prop = "PartComponent", + + .assoc_class = (char **)&vess_assoc_classname, + + .handler = vess_to_ep, + .make_ref = make_ref +}; + +static struct std_assoc assoc_ep_to_vess = { + .source_class = (char **)&vess_part_component, + .source_prop = "PartComponent", + + .target_class = (char **)&vess_group_component, + .target_prop = "GroupComponent", + + .assoc_class = (char **)&vess_assoc_classname, + + .handler = ep_to_vess, + .make_ref = make_ref +}; + static struct std_assoc *assoc_handlers[] = { &forward, &backward, + &assoc_vess_to_ep, + &assoc_ep_to_vess, NULL }; -- 1.7.6