级别: 中级 Sun Hao, 软件工程师, IBM
2009 年 7 月 27 日 在本文中,介绍 WS-Management 和 Common Information Model (CIM) 的概念。通过研究几个 SOAP 消息示例,学习如何通过 WS-Management SOAP 消息转换 CIM 操作。
为了满足多个计算机资源之间日益增长的互操作性需求,Common Information Model (CIM) 得到了广泛使用。它为系统、网络、应用程序和服务的管理信息提供统一的定义,并允许厂商扩展。WS-Management 是一个基于 SOAP 的 Web 服务协议,允许系统以独立于系统类型或平台的方式使用管理信息。WS-Management 让系统能够发送和接收事件和性能信息,以及在受管理系统上执行任务。
当前,DMTF 定义的与 WS-Management 和 WS-CIM 相关的规范已经把 CIM 操作映射到 Web 服务了。标准规范已经定稿,一些实现项目(比如 Openwsman)仍然在开发过程中。因此,还没有完整的技术文档介绍把来自 Web 的 CIM 操作传递给 CIMOM 的 SOAP 消息。在本文中,向读者介绍 CIM 和 WS-Management,然后讨论把 WS-Management 功能映射到 CIM 操作的完整 SOAP 消息。这会帮助从事这个领域的读者,对于对 CIM 和 Web 服务感兴趣的读者也有价值。
WBEM 和 CIM
Web-Based Enterprise Management (WBEM) 是 Distributed Management Task Force (DMTF) 开发的一套管理和 Internet 标准技术,它用于统一分布式计算环境的管理。WBEM 能够提供一套集成的基于标准的管理工具,促进在不同的技术和平台之间交换数据。
CIM 为系统、网络、应用程序和服务的管理信息提供统一的定义,并允许厂商扩展。厂商可以使用 CIM 的定义在网络上的系统之间交换语义丰富的管理信息。
Web 服务中的 WS-Management
WS-Management 是一个基于 SOAP 的协议,允许系统以独立于系统类型或平台的方式使用管理信息。WS-Management 让系统能够发送和接收事件和性能信息,以及在受管理系统上执行任务。
WS-Management 提供一种统一的跨整个 IT 基础结构访问和交换管理信息的方法,这会降低 IT 管理的成本和复杂性。通过使用 Web 服务管理 IT 系统,IT 管理员可以使用支持 WS-Management 的部署远程访问网络上的设备 —— 包括从电子组件和手持设备到 PC、服务器和大型数据中心的所有设备。
图 1. WS-Management 规范
DMTF 发布的 WS-Management 规范的当前版本包括几个子规范:
- WS-Addressing:WS-Management 依靠 WS-Addressing 定义其他 Web 组件的引用和在 SOAP 消息中使用的一些消息头。
- WS-Transfer:它作为简单的一元资源访问的基础:Get、Put、Delete 和 Create。
- WS-Enumeration:它作为遍历成员集合的基础。
- WS-Eventing:WS-Management 通过 WS-Eventing 规范提供事件功能。
- WS-Security:这是在任何 SOAP 消息处理之前实施的安全机制,有助于防御攻击。
WBEM/CIM 和 WS-Management 之间的关系
简单地说,WBEM/CIM 描述和管理对象模型中定义的硬件和软件资源。而 WS-Management 决定用于访问资源的传输。
图 2. CIM 和 WS-Management 层次结构
图 2 显示 WS-Management 中 CIM 的层次结构。CIM 对象由 WS-CIM 表示,由 WS-Management WSDL 描述。通过基于 HTTP 的 SOAP 消息传输,WS-Management 应用程序可以以多种模式交付 CIM 对象,比如传输、枚举和事件。当前,已经出现了几个 WS-Management 实现项目,例如 Openwsman 和 Wiseman。
从 WS-Management 映射到 WBEM/CIM
DMTF specification DSP0227 描述了用于 WS-Management 的 CIM 绑定,描述如何把 WS-CIM 规范指定的 CIM 资源映射到 WS-Management 操作和 WSDL 定义。
图 3. 从 WS-Management 映射到 CIM
在下面几节中,通过一些示例介绍这种映射。同时,介绍详细的规则和语法。
CIM 操作消息流
对于本文的示例,整个系统的构造如图 4 所示。为了能够通过 Common Information Model 使用 Web 服务,需要四个组件:CIMOM、WS-Management 实现、Web 服务器和 Web 页面。CIM 用户通过 Web 页面访问受管理系统中的 CIM 对象。这个过程如下:
图 4. CIM 操作消息流
整个操作过程包含以下步骤:
- CIM 用户在 Web 页面上发送 CIM 请求并获得 CIM 响应。
- Web 页面通过 SOAP 消息向 Web 服务器发送请求,消息包含经过转换的 CIM 操作和 CIM 对象。
- Web 服务器依靠 WS-Management 实现处理与 CIM 相关的 SOAP 消息。
- WS-Management 实现把 SOAP 消息转换为 CIM-XML 并与 CIM object manager (CIMOM) 通信,例如 SFCB 或 OpenPegasus。
- CIMOM 依靠 CIM 提供者查询和访问受管理系统中的 CIM 对象。
在本文中,我们主要关注第 2 步中处理的 SOAP 消息。我们要讨论用于枚举实例、获取实例、关联、调用方法和预订通知 CIM 操作的 SOAP 消息(包括请求和响应)。我们使用 Openwsman 作为 WS-Management 实现。
枚举实例操作
这个操作允许客户机枚举指定的 CIM 类或其子类的所有 CIM 实例。
清单 1. 用于枚举实例的请求 SOAP 消息
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration"
xmlns:wsmb="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate
</wsa:Action>
<wsa:To s:mustUnderstand="true">
http://localhost:8889/wsman
</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_OperatingSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:c9a366aa-59f5-19f5-8002-7ec0ed251100
</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
</s:Header>
<s:Body>
<wsen:Enumerate>
<wsmb:PolymorphismMode>IncludeSubClassProperties</wsmb:PolymorphismMode>
</wsen:Enumerate>
</s:Body>
</s:Envelope>
|
解释:
- Wsa:Action —— 表示对资源执行哪种操作。
- Wsa:To —— 服务的传输地址。
- Wsman:ResourceURI —— 资源类或实例表示的 URI。
- Wsa:MessageID —— 惟一地标识这个消息,用于跟踪和关联。常常使用 RFC 4122 中定义的格式。
- Wsa:ReplyTo —— 标识响应地址。在这个示例中,通过与请求相同的连接交付代表响应的字符串。
- Wsen:enumerate —— 指出这个操作是枚举。
- Wsmb:PolymorphismMode —— 这个选项指定是否应该返回子类。
清单 2. 用于枚举实例的响应 SOAP 消息
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration">
<s:Header>
<wsa:To>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse
</wsa:Action>
<wsa:RelatesTo>
uuid:c9a366aa-59f5-19f5-8002-7ec0ed251100
</wsa:RelatesTo>
<wsa:MessageID>
uuid:c9b353c8-59f5-19f5-8003-7ec0ed251100
</wsa:MessageID>
</s:Header>
<s:Body>
<wsen:EnumerateResponse>
<wsen:EnumerationContext>c9b2ca21-59f5-19f5-8002-7ec0ed251100
</wsen:EnumerationContext>
</wsen:EnumerateResponse>
</s:Body>
</s:Envelope>
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://localhost:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_OperatingSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:c9b3577f-59f5-19f5-8003-7ec0ed251100
</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
</s:Header>
<s:Body>
<wsen:Pull>
<wsen:EnumerationContext>
c9b2ca21-59f5-19f5-8002-7ec0ed251100
</wsen:EnumerationContext>
</wsen:Pull>
</s:Body>
</s:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration"
xmlns:n1=http://sblim.sf.net/wbem/wscim/1/cim-schema/2/Linux_OperatingSystem
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header>
<wsa:To>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponse
</wsa:Action>
<wsa:RelatesTo>uuid:c9b3577f-59f5-19f5-8003-7ec0ed251100</wsa:RelatesTo>
<wsa:MessageID>uuid:c9b36201-59f5-19f5-8004-7ec0ed251100</wsa:MessageID>
</s:Header>
<s:Body>
<wsen:PullResponse>
<wsen:Items>
<n1:Linux_OperatingSystem>
<n1:CSCreationClassName>Linux_ComputerSystem</n1:CSCreationClassName>
<n1:CSName>sles101-hao.site</n1:CSName>
…
<n1:CreationClassName>Linux_OperatingSystem</n1:CreationClassName>
<n1:CurrentTimeZone>480</n1:CurrentTimeZone>
</n1:Linux_OperatingSystem>
</wsen:Items>
<wsen:EndOfSequence/>
</wsen:PullResponse>
</s:Body>
</s:Envelope>
|
解释:
- 这个响应包含几个 SOAP 消息,它们按以下次序组成一个完整的响应:Enumeration、Pull 和 Pull response。Enumeration 返回 Pull 操作的枚举上下文,Pull response 返回 CIM 对象。
- Wsa:RelatesTo —— 标识与它相关的请求操作消息 ID。
- Wsen:EnumerateResponse —— 返回一个上下文对象,它代表引用的枚举。这用于后面的 Pull 操作。
- Wsen:Pull —— 在枚举之后,从最初的枚举消息获取结果。
- Wsen:PullResponse —— 它后面跟着 wsen:Items,以类名和属性名-值对的形式表示获得的 CIM 对象。在这个示例中,Linux_OperatingSystem 是 CIM 实例的类,还列出它的属性。
获取实例操作
这个操作允许客户机按标识符获取指定的 CIM 实例。
清单 3. 用于获取实例的请求 SOAP 消息
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/09/transfer/Get
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://localhost:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_OperatingSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:099a84d8-59f6-19f6-8002-7ec0ed251100</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
<wsman:SelectorSet>
<wsman:Selector Name="CSName">sles101-hao.site</wsman:Selector>
<wsman:Selector Name="Name">sles101-hao.site</wsman:Selector>
<wsman:Selector Name="CSCreationClassName">Linux_ComputerSystem</wsman:Selector>
<wsman:Selector Name="CreationClassName">Linux_OperatingSystem</wsman:Selector>
</wsman:SelectorSet>
</s:Header>
<s:Body/>
</s:Envelope>
|
解释:
- Wsman:SelectorSet —— 标识或选择要访问的具有特定属性名和值的资源实例。只返回匹配的实例。
清单 4. 用于获取实例的响应 SOAP 消息
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:n1=http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_OperatingSystem
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse
</wsa:Action>
<wsa:RelatesTo>uuid:099a84d8-59f6-19f6-8002-7ec0ed251100</wsa:RelatesTo>
<wsa:MessageID>uuid:09aab9b8-59f6-19f6-8006-7ec0ed251100</wsa:MessageID>
</s:Header>
<s:Body>
<n1:CIM_OperatingSystem>
<n1:CSCreationClassName>Linux_ComputerSystem</n1:CSCreationClassName>
<n1:CSName>sles101-hao.site</n1:CSName>
<n1:Caption>Operating System</n1:Caption>
<n1:CodeSet>ANSI_X3.4-1968</n1:CodeSet>
…
<n1:CurrentTimeZone>480</n1:CurrentTimeZone>
<n1:RequestedState>2</n1:RequestedState>
<n1:SizeStoredInPagingFiles>2104444</n1:SizeStoredInPagingFiles>
<n1:Status>NULL</n1:Status>
</n1:CIM_OperatingSystem>
</s:Body>
</s:Envelope>
|
解释:
- Wsa:Action —— 注意,action 部分因 CIM 操作而异。
关联操作
这个操作允许客户机枚举所有通过特定的 CIM 关联类与源对象相关联的 CIM 实例。
清单 5. 用于关联实例的请求 SOAP 消息
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:wsen=http://schemas.xmlsoap.org/ws/2004/09/enumeration
xmlns:wsmb="http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://9.123.253.83:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/KVM_HostSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:4fa307cb-58b5-18b5-8002-402497251100</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
</s:Header>
<s:Body>
<wsen:Enumerate>
<wsman:Filter
Dialect="http://schemas.dmtf.org/wbem/wsman/1/cimbinding/associationFilter">
<wsmb:AssociatedInstances>
<wsmb:Object>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
<wsa:ReferenceParameters>
<wsman:ResourceURI>
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/KVM_HostSystem
</wsman:ResourceURI>
<wsman:SelectorSet>
<wsman:Selector Name="__cimnamespace">root/virt</wsman:Selector>
<wsman:Selector Name="Name">zeit</wsman:Selector>
<wsman:Selector Name="CreationClassName">KVM_HostSystem</wsman:Selector>
</wsman:SelectorSet>
</wsa:ReferenceParameters>
</wsmb:Object>
<wsmb:AssociationClassName>CIM_HostedResourcePool</wsmb:AssociationClassName>
<wsmb:ResultClassName>CIM_ResourcePool</wsmb:ResultClassName>
</wsmb:AssociatedInstances>
</wsman:Filter>
</wsen:Enumerate>
</s:Body>
</s:Envelope>
|
解释:
- Wsman:Filter Dialect —— 允许使用现有查询语言(比如 SQL 和 CQL)执行枚举,可以用相同的语法组合谓词和投影信息。
- Wsmb:AssociatedInstances —— 在 WS-CIM 中定义,表示通过关联类与源对象相关联的实例。
- Wsa:ReferenceParameters —— 与 wsman:SelectorSet 相同。如果资源 URI 标识一个多实例目标,可以用这些值选择实例。
- Wsmb:AssociationClassName —— 在 WS-CIM 中定义,表示关联类的名称。
- Wsmb:ResultClassName —— 标识目标对象的 CIM 类名。
清单 6. 用于关联实例的响应 SOAP 消息
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration">
<s:Header>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/09/enumeration/EnumerateResponse
</wsa:Action>
<wsa:RelatesTo>uuid:4fa307cb-58b5-18b5-8002-402497251100</wsa:RelatesTo>
<wsa:MessageID>uuid:4fc2b63b-58b5-18b5-8008-402497251100</wsa:MessageID>
</s:Header>
<s:Body>
<wsen:EnumerateResponse>
<wsen:EnumerationContext>
4fc1ef2e-58b5-18b5-8007-402497251100
</wsen:EnumerationContext>
</wsen:EnumerateResponse>
</s:Body>
</s:Envelope>
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://9.123.253.83:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/KVM_HostSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:4fc2bb41-58b5-18b5-8003-402497251100
</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
</s:Header>
<s:Body>
<wsen:Pull>
<wsen:EnumerationContext>
4fc1ef2e-58b5-18b5-8007-402497251100
</wsen:EnumerationContext>
</wsen:Pull>
</s:Body>
</s:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration"
xmlns:n1=http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/KVM_ProcessorPool
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/09/enumeration/PullResponse
</wsa:Action>
<wsa:RelatesTo>uuid:4fc2bb41-58b5-18b5-8003-402497251100</wsa:RelatesTo>
<wsa:MessageID>uuid:4fc2c806-58b5-18b5-8009-402497251100</wsa:MessageID>
</s:Header>
<s:Body>
<wsen:PullResponse>
<wsen:Items>
<n1:KVM_ProcessorPool>
<n1:AllocationUnits>Processors</n1:AllocationUnits>
<n1:Capacity>2</n1:Capacity>
…
<n1:ResourceSubType xsi:nil="true"/>
<n1:ResourceType>3</n1:ResourceType>
<n1:Status xsi:nil="true"/>
</n1:KVM_ProcessorPool>
</wsen:Items>
<wsen:EnumerationContext>
4fc1ef2e-58b5-18b5-8007-402497251100
</wsen:EnumerationContext>
</wsen:PullResponse>
</s:Body>
</s:Envelope>
|
解释:
- Wsen:PullResponse —— 通过 Enumeration 和 Pull 操作返回关联的实例。
调用方法操作
这个操作允许客户机调用 CIM 实例的公开方法。
清单 7. 用于调用方法的请求 SOAP 消息
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:n1="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem/mymethod
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://9.123.251.94:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:a9d78e51-5943-1943-8002-7ec0ed251100
</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
<wsman:SelectorSet>
<wsman:Selector Name="Name">sunhaodemethod</wsman:Selector>
<wsman:Selector Name="CreationClassName">SUN_method</wsman:Selector>
<wsman:Selector Name="__cimnamespace">root/cimv2</wsman:Selector>
</wsman:SelectorSet>
</s:Header>
<s:Body>
<n1:mymethod_INPUT>
<n1:name>myName</n1:name>
</n1:mymethod_INPUT>
</s:Body>
</s:Envelope>
|
解释:
- Wsa:Action —— 因方法名而异。格式是方法名后面加上 CIM 类名。在这个示例中,我们调用 CIM_ComputerSystem 实例的 “mymethod” 方法。
- Wsman:SelectorSet —— 标识负责调用公开方法的实例。
- Mymethod_INPUT —— 包含 “mymethod” 方法的所有输入参数。在这个标记后面列出参数名和值,比如这个示例中的参数 “name”。
清单 8. 用于调用方法的响应 SOAP 消息
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:n1="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem">
<s:Header>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action>
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem/mymethodResponse
<wsa:Action>
<wsa:RelatesTo>uuid:a9d78e51-5943-1943-8002-7ec0ed251100</wsa:RelatesTo>
<wsa:MessageID>uuid:a9f66c80-5943-1943-8002-7ec0ed251100</wsa:MessageID>
</s:Header>
<s:Body>
<n1:mymethod_OUTPUT>
<n1:ReturnValue>called method</n1:ReturnValue>
<n1:out>this is out parameter</n1:out>
</n1:mymethod_OUTPUT>
</s:Body>
</s:Envelope>
|
解释:
- Mymethod_OUTPUT —— 这个标记包含方法调用的返回值和输出参数。返回值放在 “ReturnValue” 标记中,每个输出参数表示为单独的名-值对。
预订通知操作
这个操作允许客户机预订受管理系统中的某些事件通知。具体地说,CIM 用户在受管理系统中创建必需的 CIM 实例,从而注册事件通知,然后等待 CIM 通知实例。
清单 9. 用于预订通知的请求 SOAP 消息
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsman="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd"
xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing">
<s:Header>
<wsa:Action s:mustUnderstand="true">
http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe
</wsa:Action>
<wsa:To s:mustUnderstand="true">http://localhost:8889/wsman</wsa:To>
<wsman:ResourceURI s:mustUnderstand="true">
http://schemas.dmtf.org/wbem/wscim/1/*
</wsman:ResourceURI>
<wsa:MessageID s:mustUnderstand="true">
uuid:e48c7154-59d2-19d2-8002-7ec0ed251100
</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
</wsa:Address>
</wsa:ReplyTo>
<wsman:SelectorSet>
<wsman:Selector Name="__cimnamespace">root/interop</wsman:Selector>
</wsman:SelectorSet>
</s:Header>
<s:Body>
<wse:Subscribe>
<wse:Delivery Mode="http://schemas.dmtf.org/wbem/wsman/1/wsman/Pull">
<wse:NotifyTo>
<wsa:Address>http://127.0.0.1:80/eventsink</wsa:Address>
</wse:NotifyTo>
</wse:Delivery>
<wse:Expires>PT120.000000S</wse:Expires>
<wsman:Filter Dialect="http://schemas.microsoft.com/wbem/wsman/1/WQL">
SELECT * FROM CIM_ProcessIndication
</wsman:Filter>
</wse:Subscribe>
</s:Body>
</s:Envelope>
|
解释:
- Wsa:Action —— 对于预订通知操作,action 标记应该是 “/eventing/Subscribe”。
- Wsman:ResourceURI —— 这与其他 SOAP 消息不同,它不提供指定的 CIM 类名,而是指定 “*”,这表示域中的所有 CIM 类。
- Name= “_cimnamespace” —— 代表发出事件通知的 CIM 名称空间。
- Wse:Subscribe —— 包含交付模式、通知接收者和筛选器等信息。
- Wse:Delivery Mode —— 包含 Push、Pull 和 PushWithAck,表示向预订者交付通知的方式。
- Wse:NotifyTo —— 表示预订者。
- Wsman:Filter —— 这个示例使用 WQL 作为方言选择 CIM_ProcessIndication 类的所有通知。
清单 10. 用于预订通知的响应 SOAP 消息
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing"
xmlns:wsen="http://schemas.xmlsoap.org/ws/2004/09/enumeration">
<s:Header>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsa:Action>
http://schemas.xmlsoap.org/ws/2004/08/eventing/SubscribeResponse
</wsa:Action>
<wsa:RelatesTo>uuid:e48c7154-59d2-19d2-8002-7ec0ed251100</wsa:RelatesTo>
<wsa:MessageID>uuid:e49d431d-59d2-19d2-8004-7ec0ed251100</wsa:MessageID>
</s:Header>
<s:Body>
<wse:SubscribeResponse>
<wse:SubscriptionManager>
<wsa:Address>http://localhost:8889/wsman</wsa:Address>
<wsa:ReferenceParameters>
<wse:Identifier>uuid:e49bdf13-59d2-19d2-8003-7ec0ed251100</wse:Identifier>
</wsa:ReferenceParameters>
</wse:SubscriptionManager>
<wse:Expires>PT120.000000S</wse:Expires>
<wsen:EnumerationContext>
uuid:e49bdf13-59d2-19d2-8003-7ec0ed251100
</wsen:EnumerationContext>
</wse:SubscribeResponse>
</s:Body>
</s:Envelope>
|
解释:
- Wse:SubscriptionManager —— 返回与服务有关的任何引用参数,供 CIM 客户机在发出其他事件请求时使用。
- 可以使用枚举上下文通过 Pull 操作获取通知实例。
结束语
在本文中,学习了 WS-Management 和 CIM 的概念。通过绑定 WS-Management 和 CIM,可以为 Web 服务启用 Common Information Model 功能,这会带来许多方面的好处。本文解释的 SOAP 消息演示了如何成功地映射 CIM 操作和 WS-Management 操作。
参考资料 学习
获得产品和技术
-
Openwsman 项目提供 Web Services Management specification (WS-Management) 的开放源码实现并使用 WS-Management 协议在 Linux 操作系统上提供系统管理信息。
-
Wiseman 项目 是针对 Java SE 平台的 WS-Management 规范实现。
讨论
关于作者  | 
|  | Sun Hao 是上海 IBM China Systems and Technology Laboratories 的软件工程师。他当前从事与嵌入式系统管理程序相关的项目,在 CIM 和 Web 服务方面具有丰富经验。他还对 Linux 非常感兴趣。 |
对本文的评价
|