WEB开发网
开发学院服务器云计算 管理私有云,第 2 部分: 使用 WebSphere CloudBur... 阅读

管理私有云,第 2 部分: 使用 WebSphere CloudBurst REST API 接口

 2010-05-12 00:00:00 来源:WEB开发网   
核心提示:简介IBM WebSphere CloudBurst Appliance 向您提供在一个私有云中管理 WebSphere Application Server 虚拟系统的完整生命周期的能力,其中包括创建、部署和管理这种虚拟系统的能力,管理私有云,第 2 部分: 使用 WebSphere CloudBurst REST

简介

IBM WebSphere CloudBurst Appliance 向您提供在一个私有云中管理 WebSphere Application Server 虚拟系统的完整生命周期的能力,其中包括创建、部署和管理这种虚拟系统的能力。

有 3 个用户界面可用于支持您利用这个设备的功能:

Web 2.0 图形用户界面(GUI)通常适用于很少执行的操作或向新用户介绍这个设备的功能。

第 1 部分 介绍过的命令行界面提供了一个 Jython 界面,用于自动化经常执行的任务。

REST API 是将这个设备集成到现有应用程序和用户界面的理想选择。使用 REST API 并不意味着在客户机上使用某种技术或编程语言。实际上,由于这个 API 通过发送 HTTP URL 请求使用,该接口可以从 Java™、C++、PHP、JavaScript™、Groovy 和其他多种环境访问。

WebSphere CloudBurst REST API 向您提供一种和一个设备交互的方法,该设备既是独立于语言的,又是独立于编程模型的。使用 REST API 时,您通过定义良好的 HTTP URL 和相关 HTTP 动词(GET、POST、PUT 和 DELETE)与该设备的资源(系统管理程序[hypervisor]、模式、脚本包等)进行充分地交互。通过使用这个简单的接口,您可以执行这个设备的许多功能,从而在一个私有云中管理 WebSphere Application Server 环境。

准备使用 REST API

在开始使用 WebSphere CloudBurst REST API 之前,应该先花点时间来理解关于这个接口的一些基本知识。

第一,每个 WebSphere CloudBurst Appliance 提供开箱即用的 WebSphere CloudBurst REST API,使用该 API 不需要任何支持特性。这个 API 与该设备位于同一个主机上,但是所有 API 请求必须使用 HTTPS 协议发送,而且必须发送到端口 443。这个设备使用自签名 SSL 证书,因此相应地配置您的客户机很重要。客户机可以选择接受,也可以选择忽略该证书。

使用 REST API 时,您还要注意每个请求中都需要的某些 HTTP 头部(header)。表 1 提供了这些头部的列表及其用法的简单说明。

表 1. 需要的 HTTP 请求头部

头部名称说明
Accept这个设备通常在所有响应中返回以 JSON (Java Script Object Notation) 编码的数据。客户机应该将所有请求的 Accept 值设置为 application/json。
Accept-Language这个参数表明生成响应时使用的语言和地区。
AuthorizationREST API 支持基本验证,将请求发送到 REST API 时要使用在该设备中为用户配置的用户 ID 和密码。无论使用什么界面,授予该设备的用户的权限和访问权都是一样的。
Content-Type通过 REST API 发送的所有数据都必须是 JSON 编码的。因此,在请求中发送数据的客户机应该将 Content-Type 值设置为 application/json。
X-CloudBurst-API-Version这个参数指定正在使用的 WebSphere CloudBurst REST API 的版本。本文发表时惟一有效的值是 1.0。

本文剩余部分展示的示例将解释如何使用 WebSphere CloudBurst REST API,特别是以下内容:

设置一个私有云:对这个设备定义一个系统管理程序,关联 IP 地址和这个系统管理程序,创建包含这个系统管理程序的云组,确保该系统管理程序适当初始化并准备好进行部署。

检索一个模式:检索可用于部署的所有模式并将一个选定模式部署到一个已定义云组。

将模式部署到云:查询虚拟系统以收集关于已通过一个特殊的 WebSphere CloudBurst Appliance 部署的 WebSphere Application Server 虚拟系统(单元)的信息。

本文阐释如何通过发送 HTTP 请求使用 WebSphere CloudBurst REST API。这个 API 的组成部分包括一个 URL、一个 HTTP 方法和多个 HTTP 请求头部,有时还包括一个 HTTP 请求主体。这些组件如下面展示 REST API 请求的清单所标识的一样。另外,本文还提供了几个清单来展示您将从这样的请求中返回的响应。在这些 HTTP 响应中,只有返回的响应的主体显示出来,使用的是 JSON 为格式。HTTP 头部省略掉了,原因是在很多情况下,它们对于显示的内容并不重要。当 HTTP 响应头部比较重要时,它将出现在文本中。

本文不会要求使用任何特殊的 HTTP 客户机来发出这些请求。事实上,能够使用本文指定的头部和主体格式发送 HTTP 请求的任何客户机(编程的或非编程的)都能够用于通过 REST API 和 WebSphere CloudBurst Appliance 通信。

为了阐释这里显示的 HTTP 请求的结果,有时也呈现图形用户界面的屏幕截图。而且,这些示例假定这个设备可以通过 mycloudburst.com 主机名使用。

设置一个私有云

在这个示例中,REST API 将用于设置这个设备使用的私有云。这涉及:

创建一个系统管理程序。

将系统管理程序添加到一个云组。

定义一个 IP 组供系统管理程序使用。

要使用 REST API 执行这些操作,您必须是一个至少拥有 Cloud Administration 角色权限的用户。

第一步是创建一个包含在 Functional Test Cloud 云组中的系统管理程序资源(见清单 1a 和 1b)。

清单 1a. 添加一个系统管理程序资源 - 请求

URL: https://mycloudburst.com:443/resources/hypervisors 
HTTP Method: POST 
 
HTTP request headers: 
HTTP Body: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
"address": "ftchypervisor-1.com", 
"name": "Functional test hypervisor - 1", 
"password": "ftpassword", 
"type": "ESX", 
"userid": "ftuser" 
}


清单 1b. 添加一个系统管理程序资源 - 响应

{ 
  "desiredstatus_text": "Maintenance mode", 
  "currentstatus_text": "Maintenance mode", 
  "networks": [ 
  ], 
  "userid": "root", 
  "certified": "I", 
  "created": 1251407372817, 
  "name": "Functional test hypervisor - 1", 
  "currentstatus": "RM01025", 
  "desiredstatus": "RM01025", 
  "currentmessage": "RM03106", 
  "address": "https://ftchypervisor-1.com/sdk", 
  "cloud": null, 
  "type": "ESX", 
  "storage": [ 
  ], 
  "updated": 1251407372817, 
  "id": 5, 
  "password": "125140737281455", 
  "currentmessage_text": "Maintenance mode (must add to a cloud group to start)" 
  }

当这个设备基于主机名自动配置地址时,记下地址属性的值。所有 VMware ESX 或 ESXi 系统管理程序地址都遵循以下模式:https://<hypervisor_host>/sdk。尽管 HTTP 响应头部没有显示在清单 1b 中(这种情况对于 HTTP POST 请求很正常),但一个 HTTP Location 头部将在响应中返回(我们的示例中是 resources/hypervisors/5)。这是您刚才创建的系统管理程序资源的 URI,这个值将在某些后续请求中使用。

下一步,您需要接受您刚才创建的系统管理程序的 SSL 证书。为此,您需要发送一个 HTTP GET 请求到 resources/hypervisors/<hypervisor_id>certificate URL。对于上面的系统管理程序,您可以通过发送一个 GET 请求到 https://mycloudburst.com:443/resources/hypervisors/5/certificate URL 来接受该证书。这个 SSL 证书的内容在作为这个 GET 请求的结果返回的 HTTP 响应的响应主体中返回。发出这个请求后,发送一个 PUT 请求到该系统管理程序,将认证属性从 I 更新到 T(见清单 2)。这个 PUT 请求表明这个系统管理程序资源的 SSL 证书已经被接受。

清单 2. 接受 SSL 证书 - 请求

URL: https://mycloudburst.com:443/resources/hypervisors/5 
HTTP Method: PUT 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
  "desiredstatus_text": "Maintenance mode", 
  "currentstatus_text": "Maintenance mode", 
  "networks": [ 
  ], 
  "userid": "root", 
  "certified": "T", 
  "created": 1251408002475, 
  "name": "Functional test hypervisor - 1", 
  "currentstatus": "RM01025", 
  "desiredstatus": "RM01025", 
  "currentmessage": "RM03106", 
  "address": "https://ftchypervisor-1.com/sdk", 
  "cloud": null, 
  "type": "ESX", 
  "storage": [ 
  ], 
  "updated": 1251408002475, 
  "id": 5, 
  "password": "125140800247456", 
  "currentmessage_text": "Maintenance mode (must add to a cloud group to start)" 
}

现在您已经接受与系统管理程序关联的 SSL 证书,并更改了该系统管理程序资源的状态来表明这一点,WebSphere CloudBurst 将开始为这个系统管理程序自动探测存储器和网络。一旦存储器和网络被检测到,系统管理程序资源上的适当属性将自动更新。

设置您的私有云的下一步是将您新创建的系统管理程序添加到一个云组。为此,您需要先创建一个代表该云组的资源(见清单 3a 和 3b)。

清单 3a. 创建一个新的云组 - 请求

URL: https://mycloudburst.com:443/resources/clouds 
HTTP Method: POST 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
"defaultcloud": "F", 
"description": "Functional Test Cloud", 
"name": "FTC", 
"vendor": "ESX" 
}


清单 3b. 创建一个新的云组 - 响应

{ 
  "defaultcloud": "F", 
  "created": 1251409447905, 
  "vendor": "ESX", 
  "updated": 1251409447905, 
  "name": "FTC", 
  "id": 4, 
  "hypervisors": [ 
  ], 
  "description": "Functional Test Cloud" 
}

下一步,使用一个是这个云组一部分的,表明这个新的,系统管理程序的 PUT 请求来跟进这个 POST 请求。操作方法是在这个云组资源的系统管理程序属性中指定系统管理程序的 URI(见清单 4)。

清单 4. 将一个系统管理程序添加到一个云组 - 请求

URL: https://mycloudburst.com:443/resources/clouds/4 
HTTP Method: PUT 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
  "defaultcloud": "F", 
  "created": 1251409447905, 
  "vendor": "ESX", 
  "updated": 1251409447905, 
  "name": "FTC", 
  "id": 4, 
  "hypervisors": [“/resources/hypervisors/5”], 
  "description": "Functional Test Cloud" 
}

进行上述 PUT 请求之后,Functional test hypervisor - 1 将属于 FTC 云组。

要完全初始化您的私有云,创建可以被您的系统管理程序利用的一个 IP 组和一组 IP 地址。要创建一个 IP 组,发送清单 5a 和 5b 所示的 POST 请求。

清单 5a. 创建一个 IP 组资源 - 请求

URL: https://mycloudburst.com:443/resources/ipGroups 
HTTP Method: POST 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
  "gateway": "10.42.132.1", 
  "name": "FT IP Group", 
  "netmask": " 255.0.0.0", 
  "primarydns": " 10.16.15.253", 
  "secondarydns": " 10.16.15.253", 
  "subnetaddress": " 10.16.8.0" 
}


清单 5b. 创建一个 IP 组资源 - 响应

{ 
  "gateway": "10.42.132.1", 
  "networks": [ 
  ], 
  "secondarydns": "10.16.15.253", 
  "subnetaddress": "10.16.8.0", 
  "primarydns": "10.16.15.253", 
  "created": 1251410587296, 
  "netmask": "255.0.0.0", 
  "updated": 1251410587296, 
  "name": "FT IP Group", 
  "id": 2 
}

下一步,您需要添加一个与这个 IP 组关联的 IP 地址池,操作方法是发送一个包含这些 IP 地址的 POST 请求(见清单 6)。

清单 6. 将 IP 地址添加到一个 IP 组 - 请求

URL: https://mycloudburst.com:443/resources/ipGroups/2/ips 
HTTP Method: POST 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
"addresses": ["10.1.2.3", "10.1.2.4"] 
}

IP 地址被添加到 IP 组资源后,下一步是更新您的 IP 组上的网络属性以指向您的系统管理程序上的相关网络。首先,检查系统管理程序资源,确保在接受系统管理程序的 SSL 证书后已检测到相应的网络,操作方法是发送一个 GET 请求到该系统管理程序资源(见清单 7a 和 7b)。

清单 7a. 为系统管理程序验证网络发现 - 请求

URL: https://mycloudburst.com:443/resources/hypervisors/5 
HTTP Method: GET 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0


清单 7b. 为系统管理程序验证网络发现 - 响应

{ 
  "desiredstatus_text": "Maintenance mode", 
  "currentstatus_text": "Maintenance mode", 
  "networks": [ 
   "/resources/networks/5", 
   "/resources/networks/6" 
  ], 
  "userid": "root", 
  "certified": "T", 
  "created": 1251408002475, 
  "name": "Functional test hypervisor - 1", 
  "currentstatus": "RM01025", 
  "desiredstatus": "RM01025", 
  "currentmessage": "RM03109", 
  "address": "https://ftchypervisor-1.com/sdk", 
  "cloud": "/resources/clouds/4", 
  "type": "ESX", 
  "storage": [ 
   "/resources/storage/5", 
   "/resources/storage/6" 
  ], 
  "updated": 1251409727403, 
  "id": 5, 
  "password": "125140800247456", 
  "currentmessage_text": "Maintenance mode (must set an IP group 
 for a network to start)" 
}

注意,网络属性表明两个不同的资源 URI。如果您想找到关于网络资源的更多信息,一个到 https://mycloudburst.com:443/resources/networks/<network_id> 的 GET 请求将返回相关信息。在本例中,您将通过发送如清单 8 所示的 PUT 请求把 /resources/networks/6 URI 表示的网络资源和这个 IP 组关联起来。


清单 8. 关联 IP 组和网络 - 请求

URL: https://mycloudburst.com:443/resources/ipGroups/2 
HTTP Method: PUT 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
  "gateway": "10.42.132.1", 
  "networks": [“resources/networks/6”], 
  "secondarydns": "10.16.15.253", 
  "subnetaddress": "10.16.8.0", 
  "primarydns": "10.16.15.253", 
  "created": 1251410587296, 
  "netmask": "255.0.0.0", 
  "updated": 1251410587296, 
  "name": "FT IP Group", 
  "id": 2 
  }

这个 PUT 请求有效地将这个 IP 组和包含 resources/networks/6 网络资源的系统管理程序关联起来,这意味着在这个系统管理程序上启动的虚拟机将利用包含在这个 IP 组中的 IP 地址。

进行上述 PUT 请求后,可以通过更新该资源上的 desiredstatus 状态将 Functional test hypervisor - 1 的状态从 Maintenance Mode 更新到 Started(见清单 9a 和 9b)

清单 9a. 更新系统管理程序的状态 - 请求

URL: https://mycloudburst.com:443/resources/hypervisors/5 
HTTP Method: PUT 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0


清单 9b. 更新系统管理程序的状态 - 响应

{ 
  "desiredstatus_text": "Maintenance mode", 
  "currentstatus_text": "Maintenance mode", 
  "networks": [ 
   "/resources/networks/5", 
   "/resources/networks/6" 
  ], 
  "userid": "root", 
  "certified": "T", 
  "created": 1251408002475, 
  "name": "Functional test hypervisor - 1", 
  "currentstatus": "RM01025", 
  "desiredstatus": "RM01006", 
  "currentmessage": "RM03109", 
  "address": "https://ftchypervisor-1.com/sdk", 
  "cloud": "/resources/clouds/4", 
  "type": "ESX", 
  "storage": [ 
   "/resources/storage/5", 
   "/resources/storage/6" 
  ], 
  "updated": 1251409727403, 
  "id": 5, 
  "password": "125140800247456", 
  "currentmessage_text": "Maintenance mode (must set an IP group 
 for a network to start)" 
}

代码 RM1006 表明 Started 状态,这意味着系统管理程序由于这个 PUT 请求而启动。可以通过两种方法来确认这一点:通过一个 GET 请求来检索这个资源,或者登录到 WebSphere CloudBurst 管理控制台并查看这个系统管理程序。如果您采用第二种方法,您将看到当前状态为 Started,如图 1 所示。

图 1. WebSphere CloudBurst 控制台中的系统管理程序
管理私有云,第 2 部分: 使用 WebSphere CloudBurst REST API 接口

查看原图(大图)

检索一个模式

WebSphere CloudBurst Appliance 中的模式是一个 WebSphere Application Server 环境的完整表示,它包含的组件代表不同的 WebSphere Application Server 节点(如部署管理器、自定义节点、独立服务器等)和允许用户定制中间件环境的脚本包。这些脚本包可以用于包含任意对服务器配置的定制,甚至包含用户应用程序在环境中的安装。这些模式保存在这个设备上,可以被共享和重用以生成一致的,可重复的 WebSphere Application Server 部署。

WebSphere CloudBurst 提供可以直接使用的预加载模式,您也可以复制并定制这些预加载模式来创建更适合您的环境的新模式。例如,WebSphere Application Server 集群模式是用于大规模开发和生产环境的 WebSphere Application Server 拓扑,包含一个部署管理器、两个自定义节点和一个 IBM HTTP 服务器,这些部分都驻留在它们各自的虚拟机内。

与其他 WebSphere CloudBurst 资源一样,您可以使用 REST API 与存储在该设备上的模式交互或在这些模式上执行操作。

使用 REST API 来检索集群模式(见清单 10a)。清单 10b 中的响应表示 WebSphere CloudBurst 返回的属性和值。

清单 10a. 检索预加载模式 - 请求

URL: https://mycloudburst.com:443/resources/patterns/2 
HTTP Method: GET 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0

清单 10b. 检索预加载模式 - 响应

{ 
"created": 1242965377749, 
"currentmessage": null, 
"currentmessage_text": null, 
"currentstatus": "RM01028", 
"currentstatus_text": "Read-only", 
"description": "Cluster is a WebSphere Application Server Network Deployment 
topology for larger scale development or production environments. The IBM HTTP 
Server resides in a dedicated virtual machine (in an unmanaged node).", 
"id": 2, 
"name": "WebSphere cluster", 
"owner": "/resources/users/1", 
"properties": { 
"part-1.HWAttributes.numvcpus": "1", 
"part-1.HWAttributes.memsize": "2048", 
"part-1.ConfigWAS.cell_name": "CloudBurstCell", 
"part-1.ConfigWAS.node_name": "CloudBurstNode", 
"part-1.ConfigWAS.augment_list": "none", 
"part-1.ConfigPWD_ROOT.password": null, 
"part-1.ConfigPWD_USER.password": null, 
"part-2.HWAttributes.numvcpus": "1", 
"part-2.HWAttributes.memsize": "2048", 
"part-2.ConfigWAS.cell_name": "CloudBurstCell", 
"part-2.ConfigWAS.node_name": "CloudBurstNode", 
"part-2.ConfigPWD_ROOT.password": null, 
"part-2.ConfigPWD_USER.password": null, 
"part-3.HWAttributes.numvcpus": "1", 
"part-3.HWAttributes.memsize": "2048", 
"part-3.ConfigWAS.cell_name": "CloudBurstCell", 
"part-3.ConfigWAS.node_name": "CloudBurstNode", 
"part-3.ConfigWAS.augment_list": "none", 
"part-3.ConfigPWD_ROOT.password": null, 
"part-3.ConfigPWD_USER.password": null, 
"part-4.HWAttributes.numvcpus": "1", 
"part-4.HWAttributes.memsize": "2048", 
"part-4.ConfigWAS.cell_name": "CloudBurstCell", 
"part-4.ConfigWAS.node_name": "CloudBurstNode", 
"part-4.ConfigWAS.augment_list": "none", 
"part-4.ConfigPWD_ROOT.password": null, 
"part-4.ConfigPWD_USER.password": null, 
 
}, 
"updated": 1242965394499, 
"virtualsystems": [ 
] 
}

清单 10b 中的响应描述前面提到的 WebSphere Application Server 集群拓扑:

id、name 和 owner 值指定模式的 ID 和显示名称,以及拥有该模式的用户的 URI。

properties 指定这个模式的 part 属性和脚本参数的映射。part 属性拥有的键的格式是 part-n.pclass.key,脚本参数拥有的键的格式为 part-n.script-m.key。返回的映射中的值将包含这些属性和参数的默认值(没有默认值的属性和参数的值为 null)。

virtualsystems 值指定从这个模式创建的虚拟系统的 URI 列表。从响应可以看出,当前没有虚拟系统根据这个集群模式进行部署。

至此,您已经创建了一个私有云并获取了一个预加载模式。下一小节将展示如何使用 WebSphere CloudBurst REST API 来将这个模式部署到云。

将模式部署到云

有了一个完全初始化的私有云和一个或多个模式,您现在可以将这些模式部署到您的私有云中。当然,您也可以使用 REST API 完成这个任务。

使用 REST API 将模式部署到私用云时,您需要首先创建一个虚拟系统资源。在创建这个资源的 POST 请求(见清单 11a)中,您需要指明要部署的模式,托管虚拟系统的云,虚拟系统的名称以及其他部署信息,如密码信息和 WebSphere Application Server 配置数据。

清单 11a. 将集群模式部署到云 - 请求

URL: https://mycloudburst.com:443/resources/virtualSystems 
HTTP Method: POST 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
Content-Type: application/json 
X-CloudBurst-API-Version: 1.0 
 
HTTP request body: 
{ 
"cloud": "/resources/clouds/1", 
"name": "Sample Virtual Systems - WebSphere cluster (1Dmgr+2nodes+1IHS)", 
"pattern": "/resources/patterns/2", 
"properties": { 
"*.*.memsize": "1024", 
"*.*.password": "password123" 
} 
} 


清单 11b. 将集群模式部署到云 - 响应

{ 
"created": 1242965394588, 
"currentmessage": null, 
"currentmessage_text": null, 
"currentstatus": "RM01036", 
"currentstatus_text": "Queued", 
"desiredstatus": "", 
"desiredstatus_text": null, 
"id": 14, 
"name": " Sample Virtual Systems - WebSphere cluster (1Dmgr+2nodes+1IHS)", 
"owner": "/resources/users/1", 
"pattern": "/resources/patterns/2", 
"updated": 1242965394588 
}

属性值指定新的虚拟系统将要使用的 part 属性和脚本参数的值(如果该模式中已包含脚本包的话)。当一个模式被检索到时,它包含一个必须指定的属性和参数的映射。在创建虚拟系统时给出的映射必须为任何缺失的属性和参数提供值,并能另外提供值以覆盖默认值。

在上面的示例中,通配符用于提供属性值。在内存大小和密码参数中使用 *.* 表示那些值应用到模式中的每个部分。这样,在模式部署中创建的每个虚拟机将被分配 1024 MB 的虚拟内存,每个虚拟机的密码将是 password123。

发出 POST 请求后,登录 WebSphere CloudBurst 管理控制台以查看您的部署(见图 2)。


图 2. 新部署的虚拟系统
管理私有云,第 2 部分: 使用 WebSphere CloudBurst REST API 接口

查看原图(大图)

您将看到,部署过程中创建了 4 个虚拟机,WebSphere Application Server 集群模式中包含的每个部分都对应一个虚拟机。

经过一段时间后,一个针对在 POST 请求中创建的虚拟系统资源的 GET 请求将显示所有虚拟机已经启动,WebSphere Application Server 环境已就绪。在清单 12a 中,您使用 ID 14 发出一个 GET 请求以获取虚拟资源,使用这个 ID 的原因是该 ID 是在创建虚拟系统资源时发出的 POST 请求的响应中返回的(见清单 12b)。

清单 12a. 查询一个虚拟系统 - 请求

URL: https://mycloudburst.com:443/resources/virtualSystems/14 
HTTP Method: GET 
 
HTTP request headers: 
Accept: application/json 
Accept-Language: en 
Authorization: Basic <base64encode(userid:password)> 
X-CloudBurst-API-Version: 1.0


清单 12b. 查询一个虚拟系统 - 响应

{ 
  "desiredstatus_text": null, 
  "currentstatus_text": "Started", 
  "created": 1242965394588, 
  "name": "WebSphere Cluster", 
  "currentstatus": "RM01006", 
  "desiredstatus": "", 
  "currentmessage": "RM07045", 
  "pattern": "/resources/patterns/2", 
  "owner": "/resources/users/1", 
  "updated": 1255027495806, 
  "id": 2, 
  "currentmessage_text": "The virtual system has been deployed and is   
                ready to use" 
}

您可以通过在 WebSphere CloudBurst 管理控制台中查看虚拟系统进一步验证该虚拟系统已经启动(见图 3)。


图 3. 活动虚拟系统
管理私有云,第 2 部分: 使用 WebSphere CloudBurst REST API 接口

查看原图(大图)

结束语

IBM WebSphere CloudBurst Appliance 提供 3 个接口来管理和利用其功能。HTTP REST 接口提供一种语言独立的、编程模型不可知的设备交互方式。本文介绍如何使用 REST 接口来构建一个私有云,定义一个 WebSphere CloudBurst 模式并将该模式部署到您的云。当然,这只是少数几个 REST 接口的应用场景,您可以在 WebSphere CloudBurst REST API Reference 进一步探索该接口的功能,了解如何发挥它的最大价值。

Tags:管理 私有 部分

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接