清单 6. CIM 代理提供者的程序
static CMPIStatus InvokeMethod( CMPIMethodMI * self, const CMPIContext * context, const CMPIResult * results, const CMPIObjectPath * reference, const char * methodname, const CMPIArgs * argsin, CMPIArgs * argsout) { CMPIString *str_ok = CMNewString(_BROKER, "CMPI return ok", NULL); CMPIStatus status = {CMPI_RC_OK, str_ok}; CMPIArgs* in = CMNewArgs(_BROKER, NULL); CMPIArgs* out = CMNewArgs(_BROKER, NULL); CMPIData argdata; int r=500; if (strcmp(methodname,"RequestStateChangeAdapter")==0) { char* KName=NULL; char* KCreationClassName=NULL; argdata = CMGetArg(argsin, "Name", &status); if ((status.rc == CMPI_RC_OK) && !(CMIsNullValue(argdata)) && (argdata.type == CMPI_string) && !CMIsNullObject(argdata.value.string)) { KName = strdup(CMGetCharPtr(argdata.value.string)); }else { CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "Name is invalid"); goto exit; } argdata = CMGetArg(argsin, "CreationClassName", &status); if ((status.rc == CMPI_RC_OK) && !(CMIsNullValue(argdata)) && (argdata.type == CMPI_string) && !CMIsNullObject(argdata.value.string)) { KCreationClassName = strdup(CMGetCharPtr(argdata.value.string)); }else { CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "CreationClassName is invalid"); goto exit; } argdata = CMGetArg(argsin, "RequestedState", &status); if ((status.rc == CMPI_RC_OK) && !(CMIsNullValue(argdata)) && (argdata.type == CMPI_string) && !CMIsNullObject(argdata.value.string)) { CMPIUint16 val = sToUint16(argdata.value.string); CMAddArg(in, "RequestedState", &val, CMPI_uint16); }else { CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "RequestedState is invalid"); goto exit; } argdata = CMGetArg(argsin, "TimeoutPeriod", &status); if ((status.rc == CMPI_RC_OK) && !(CMIsNullValue(argdata)) && (argdata.type == CMPI_string) && !CMIsNullObject(argdata.value.string)) { CMPIDateTime* val = sToDateTime(_BROKER, argdata.value.string); CMAddArg(in, "TimeoutPeriod",&val, CMPI_dateTime); }else { CMSetStatusWithChars(_BROKER, &status, CMPI_RC_ERR_INVALID_PARAMETER, "TimeoutPeriod is invalid"); goto exit; } CMPIObjectPath* op = CMNewObjectPath(_BROKER, _NAMESPACE,"KVM_ComputerSystem", &status); CMAddKey(op, "CreationClassName", (CMPIValue*)KCreationClassName,CMPI_chars); CMAddKey(op, "Name",(CMPIValue*)KName,CMPI_chars); CMPIData ret = CBInvokeMethod(_BROKER, context, op, "RequestStateChange",in, out, &status); if(status.rc != CMPI_RC_OK) { goto exit; } r= ret.value.uint32; if(KCreationClassName) free(KCreationClassName); if(KName) free(KName); } CMReturnData(results, (CMPIValue*)&r, CMPI_uint32); CMReturnDone(results); exit: /* Exit point of this function */ _SBLIM_RETURNSTATUS(status); } |
验证方案
下面的步骤将验证采用 CIM 代理提供者方案能否如预期所愿实现我们希望的功能。
清单 7. Openwsman 客户端调用 CIM 代理提供者
wsman invoke "http://ovs.net/console/OVS_ComputerSystem" -B include -R – a RequestStateChangeAdapter -k Name="vmm" -k CreationClassName="KVM_ComputerSystem" – k RequestedState="2" -k TimeoutPeriod="00000000000000.000000:000" -h 9.186.96.101 -u wsman -p password -N root/virt |
可以看到 Openwsman 传递给 SFCB 的 CIM-XML 如下图所示:
图 6. 调用 CIM 代理提供者的 CIM-XML 文件
从 Openwsman 的日志窗口,我们可以看到请求被正确处理的成功信息,如下图所示:
图 7. Openwsman 报告的正确日志信息
结论
通过这篇文章,读者应该熟悉 WS-Management 协议,并且对于一种 WS-Management 协议的开源实现项目 Openwsman 有了进一步的认识。 Openwsman 是一个强大的并且非常有用的工具,它可以通过 Web service 来发布和管理系统信息资源,Openwsman 和 CIM 技术的结合,使得通用信息模型可以应用在 Web service 中,这样就可以进一步的扩展 CIM 的使用场景,增强其功能。通过本文介绍的创建代理信息提供者的方案,用户可以解决当前 Openwsman 中存在的不支持非字符串参数类型的限制,使得 Openwsman 更加具有可用性和可靠性。(责任编辑:A6)
时间:2009-06-25 16:05
来源:developerWorks 中国
作者:孙 皓
原文链接