IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  WebSphere | Web development | Information Management  >

管理私有云:WebSphere CloudBurst Appliance 命令行界面简介

developerWorks
文档选项

未显示需要 JavaScript 的文档选项

英文原文

英文原文


级别: 中级

Dustin Amrhein, 软件工程师, IBM
Mike Burr, 高级软件工程师, IBM

2009 年 9 月 21 日

Journal icon IBM® WebSphere® CloudBurst™ Appliance 使您能够在一个私有云中构造、部署和维护 WebSphere Application Server 虚拟系统。为了在一个私有云中管理这些系统的完整生命周期,WebSphere CloudBurst 提供了多个管理界面,包括针对基于 GUI 的管理行为的富 Web 2.0 界面,以及一个支持脚本化、自动化管理方法的命令行界面(CLI)。本文将介绍如何利用 WebSphere CloudBurst CLI,并附带了一些示例来展示如何在您自己的 WebSphere CloudBurst 环境中使用 CLI。

来自 IBM WebSphere Developer Technical Journal

简介

云计算空间

您是否希望随时获取最新的云计算消息?是否想得到云计算相关的技术知识?developerWorks 云计算空间就是这样一个云计算信息资源的门户,在这里您可以了解来自 IBM 和业界其他媒体的最新信息,并且得到如何在云环境中使用 IBM 软件的入门知识。

IBM 在 Amazon EC2 云计算环境中提供了 DB2、Informix、Lotus、WebSphere 等方面的 AMI 镜像资源。您只需按使用量支付少量费用,就可以使用到云上的数据、门户、Web 内容管理、情景应用等服务。欢迎您随时访问 云计算空间,获取更多信息。

在深入讨论 IBM WebSphere CloudBurst Appliance 的管理功能之前,首先简要地介绍它。

WebSphere CloudBurst 是一个支持您在私有云中创建、部署和监视 WebSphere Application Server 虚拟系统的设备。实现这些操作的方法就是在 IBM WebSphere Application Server Hypervisor Edition 之上创造价值,后者是一个针对虚拟环境进行了优化的 IBM WebSphere Application Server 包。WebSphere Application Server Hypervisor Edition 是一个根据 Open Virutal Format (OVF) 标准打包的虚拟映像,它运行在受支持的管理程序之上。

虚拟映像包含一个操作系统、WebSphere Application Server 二进制文件和配置文件,以及 IBM HTTP Server,所有内容都是预安装的。预安装多个配置文件将使映像能够在激活后采用多种定制(在 WebSphere CloudBurst 之外使用)。这为由 WebSphere CloudBurst 实现的价值奠定了基础。

除了 WebSphere Application Server Hypervisor Edition 映像外,WebSphere CloudBurst 还附带了 WebSphere Application Server 配置,称为模式,这些模式构建自映像内的组件。例如,WebSphere Application Server 集群模式可能包含开发管理器组件和来自 WebSphere Application Server Hypervisor Edition 映像的两个定制的节点组件。您可以复制并修改附带的模式,并使用 WebSphere Application Server Hypervisor Edition 中的任一组件创建定制的模式。WebSphere CloudBurst 根据十年的领域经验自动对配置调优,以获得最优性能,并且所有模式都存储在设备中,使您能够在需要时重新请求这些配置。

除了极大地简化了 WebSphere Application Server 配置构建流程外,WebSphere CloudBurst 将模式分配给一个私有云,从而创建 WebSphere 虚拟系统。WebSphere CloudBurst 支持 “引入自己的云”,这意味着您可以对设备定义自己的云资源。实现方式是提供一组受支持的管理程序和可用于私有云的 IP 地址池。定义好了这些资源后,通过处理云资源的可用性(CPU、内存和磁盘空间)和高可用性等其他问题,WebSphere CloudBurst 就能够智能地将虚拟系统放到私有云中。

为了在私有云中为 WebSphere Application Server 虚拟系统提供完整的生命周期支持,WebSphere CloudBurst 提供监视和管理这些系统的功能。您可以查看由 WebSphere CloudBurst 创建的所有虚拟系统,并且可以轻松地监视它们的资源使用情况。此外,WebSphere CloudBurst 跟踪用户使用设备的情况。将跟踪每个用户的内存使用情况、CPU 情况、IP 利用情况等等,从而支持在企业内部收费。

此外,WebSphere CloudBurst 使您能够将 iFixes 和服务补丁应用到私有云中的虚拟系统。通过在应用补丁前自动创建虚拟系统的快照,WebSphere CloudBurst 大大降低了补丁应用的风险。如果需要的话,您只需单击按钮就可以回滚到先前的状态。

WebSphere CloudBurst 为管理私有云中的虚拟系统的完整生命周期提供了综合的解决方案。它针对虚拟系统生命周期中的每个组成提供了解决方案,与此同时还提供了易用性,为中间件环境的管理提供了前所未有的可消费性。

WebSphere CloudBurst 中的基本管理

WebSphere CloudBurst 对 WebSphere Application Server 虚拟系统的生命周期提供了完整的控制,这一事实暗示着健壮的管理功能。您必须能够执行许多不同的任务,包括定义您的私有云、创建定制模式、将模式部署到云中,以及监视虚拟系统的状态。为了帮助您执行这些行为,WebSphere CloudBurst 提供了一个基于 Web 2.0 的图形化界面、一个 HTTP REST 界面 和一个基于 Jython 2.2.1 的 命令行界面 (CLI)。图形化界面非常适合临时用户,或者需要用户干预的不常发生的动作。HTTP REST 界面提供了一种独立于编程语言的方法,用于设备交互。它还可以用于包含一些 WebSphere CloudBurst 管理任务作为富企业 mashup 的一部分。对于那些频繁执行的任务,或者只需要少量或不需要干预的任务,CLT 是最佳的选择。

当您登录到 WebSphere CloudBurst 控制台后,首先出现的面板类似于图 1。


图 1. WebSphere CloudBurst Administration 控制台
WebSphere CloudBurst Administration 控制台

控制台提供了一个图形化网关,从中可以对 WebSphere CloudBurst Appliance 执行所有必需的管理功能。这个富界面非常直观和引人注目,特别是如果您是第一次使用该设备的话。此外,控制台将根据当前的用户发生变化,这样用户只能看到他访问的功能的链接。例如,如果仅拥有向云部署模式的权限,那么就无法在顶部的工具栏中看到 CloudApplianceCatalog 链接。

WebSphere CloudBurst CLI 为您提供了创建一组自动化的、脚本化管理任务的能力,并且提供了一个易于使用且功能强大的 API。

本文其余部分将更进一步地介绍该 CLI 的使用。

开始使用 CLI

在开始使用 WebSphere CloudBurst CLI 之前,首先需要从 WebSphere CloudBurst 管理控制台下载该工具:

  1. 登录到控制台并单击 Use command line tools 下方的 Download now! 链接。一个包含命令行工具的 .zip 文件将下载到您的机器中。
  2. 将下载文件提取到一个目录,从而创建 cloudburst.cli 目录。这是 WebSphere CloudBurst CLI 工具的根目录。
  3. 必须在您的机器上安装 IBM Java™ Runtime Environment (JRE) Version 6(SR3 或更高版本,如果使用了由 IBM 提供的 JRE 的话)。如果需要的话,可以 下载受支持的 Linux JDK

资源和资源集合是 WebSphere CloudBurst CLI 中的核心概念:

  • 资源(resource)用于表示由 WebSphere CloudBurst Appliance 管理的各种实体。例如,每个管理程序、模式和虚拟系统都是一个资源。CloudBurst CLI 使用资源对象读取或更新有关某个实体的信息。
  • 资源集合(resource collection)指一组以某种方式关联的资源对象。例如,资源集合可以包含所有针对 WebSphere CloudBurst Appliance 定义的管理程序,或包含在给定模式中的部分内容。资源集合用于定义新的资源并列出或搜索现有资源。

WebSphere CloudBurst CLI 建立在 Jython version 2.2.1 的基础上,后者是运行在 Java 虚拟机内部的 Python 语言的实现。WebSphere CloudBurst CLI 的命令行和脚本被表示为 Python 语句和表达式。

在 Jython 环境内部,WebSphere CloudBurst CLI 提供了一个特殊的 cloudburst 模块来与设备交互。所有资源和资源集合都通过这个 cloudburst 模块访问,从而提供了一致的访问模式并减少了用户脚本出现名称空间冲突的风险。除了这个特殊的模块外,由于 CLI 环境建立在 Jython 的基础上,您可以利用 Java 语言的功能来进行管理交互。

WebSphere CloudBurst CLI 支持交互式的和 batch 式的操作模式,下面的小节将进行描述。

使用交互模式

交互模式中,您将命令输入到命令提示符中,控制台将显示结果。要开始一个交互式会话,必须提供有关 WebSphere CloudBurst Appliance 位置的信息,以及您的登录凭证。

在清单 1 中,一个交互式 CLI 会话将被启动,只要输入 cloudburst 并提供设备的以下信息:

  • 使用参数 -h 提供主机名
  • 通过 -u 选项提供用户名
  • 通过 -p 选项提供密码

在会话期间输入的所有命令都将被发送到位于 mycloudburst.com 中的 WebSphere CloudBurst Appliance 中。


清单 1. 发起 CLI 会话
				
C:\cloudburst\cloudburst.cli\bin>cloudburst -h mycloudburst.com -u cloudburstUser 
	-p password
				

WebSphere CloudBurst CLI 还支持通过环境变量传递主机名、用户 id 和密码。为此,在运行 cloudburst 命令前设置 CLOUDBURST_HOSTNAME、CLOUDBURST_USERID 和 CLOUDBURST_PASSWORD 环境变量,然后去掉如上所示的命令行参数。

在运行交互式 CLI 会话期间,普通的命令 shell 提示符将被修改为 >>>。如果命令超出了一个输入行,那么命令提示符变为 ...,表示该行是前一行中的命令的延续。(当解释交互式模式以匹配您从屏幕上看到的内容时,这些提示将在本文的示例中做演示;换而言之,不要输入这些提示字符)。要退出交互模式,输入 exit 并在 >>> 提示符处按下 Enter

清单 2 和 3 展示了命令的使用,将显示 WebSphere CloudBurst 系统上的所有用户。


清单 2. 列出所有用户 - 命令
				
>>> cloudburst.users
				


清单 3. 列出所有用户 - 输出
				
[
  {
    "currentmessage": "RM02011",
    "currentmessage_text": "Active in the last five minutes",
    "currentstatus": "RM01061",
    "currentstatus_text": "Logged in and active",
    "email": "",
    "fullname": "Administrator",
    "groups": (nested object),
    "id": 1,
    "parts": (nested object),
    "password": (write-only),
    "patterns": (nested object),
    "roles": (nested object),
    "scripts": (nested object),
    "username": "cbadmin",
    "virtualimages": (nested object),
    "virtualsystems": (nested object)
  }
]

除了查看资源和资源集合外,还可以对由 WebSphere CloudBurst 管理的项目执行操作。例如,假设您希望添加一个有权将模式部署到私有云的用户。可以通过几个不同的方式实现这点。

第一种方法是使用交互式向导创建一个新用户,如清单 4 和 5 所示。这里,将提醒您为新用户输入用户名、全名、密码和邮件地址。因此,新用户将被创建,并且用户的细节被显示出来。


清单 4. 使用向导创建一个新用户 - 命令
				
>>> cloudburst.users.create(cloudburst.wizard)
				


清单 5. 使用向导创建一个新用户 - 输出
				
Enter ?? for help using the wizard.

username: newuser
fullname: Pattern Deployer
password: password
email: newuser@mycompany.com
{
  "currentmessage": "RM02013",
  "currentmessage_text": "User has not logged in yet",
  "currentstatus": "RM01062",
  "currentstatus_text": "Inactive",
  "email": "newuser@mycompany.com",
  "fullname": "Pattern Creator",
  "groups": (nested object),
  "id": 2,
  "parts": (nested object),
  "password": (write-only),
  "patterns": (nested object),
  "roles": (nested object),
  "scripts": (nested object),
  "username": "newuser",
  "virtualimages": (nested object),
  "virtualsystems": (nested object)
}
				

使用内联 Python 对象可以获得相同的结果,如清单 6 和 7 所示。注意,<< 是上面示例中使用的 create() 方法的别名。


清单 6. 使用 JSON 创建一个新用户 - 命令
				
>>> cloudburst.users << {"username":"newuser", "fullname":"Pattern Deployer", 
... "password":"password", "email":"newuser@mycompany.com"}
    			


清单 7. 使用 JSON 创建一个新用户 - 输出
				
{
  "currentmessage": "RM02013",
  "currentmessage_text": "User has not logged in yet",
  "currentstatus": "RM01062",
  "currentstatus_text": "Inactive",
  "email": "newuser@mycompany.com",
  "fullname": "Pattern Deployer",
  "groups": (nested object),
  "id": 3,
  "parts": (nested object),
  "password": (write-only),
  "patterns": (nested object),
  "roles": (nested object),
  "scripts": (nested object),
  "username": "newuser",
  "virtualimages": (nested object),
  "virtualsystems": (nested object)
}
				

CLI 还提供了一个非常方便的 help 函数,您可以对资源、资源集合和这些项的方法调用该函数:

  • 对于资源和资源集合,help 函数提供了项的简短摘要以及可用的属性和方法。
  • 对于方法,help 提供了方法摘要和方法接受的输入。

清单 8 和 9 展示了如何使用 help 方法找到与某个管理程序资源相关的属性和方法。


清单 8. 使用 help 函数 - 命令
				
>>> help(cloudburst.hypervisors[0])
				


清单 9. 使用 help 函数 - 输出
				
A Hypervisor object represents a particular hypervisor defined on the
CloudBurst appliance.  Use the Hypervisor object to query and
manipulate the hypervisor definition on the appliance.  Attributes of
the hypervisor and relationships between the hypervisor and other
resources on the CloudBurst appliance are represented as Jython
attributes on the Hypervisor object.  Manipulate these Jython
attributes using standard Jython mechanisms to make changes to the
corresponding data on the CloudBurst appliance.

Additional help is available for the following methods:
   acceptCertificate, __contains__, __delattr__, delete, discover, __eq__,
   __hash__, isMaintenance, isStarted, isStatusTransient, maintenance,
   __nonzero__, refresh, __repr__, start, __str__, __unicode__, waitFor

Additional help is available for the following properties:
   address, certificate, certified, cloud, created, currentmessage,
   currentmessage_text, currentstatus, currentstatus_text, desiredstatus,
   desiredstatus_text, id, name, networks, password, storage, type, updated,
   userid

Remember to append an underscore to the property name when asking for
help using a specific instance of a resource rather than the class.
For example, "help(cloudburst.pattern.name)" or "help(mypattern.name_)"
will work, but "help(mypattern.name)" will resolve the name of the pattern
referenced by mypattern and attempt to provide help for the resulting
string rather than the property itself.

使用 batch 模式

除了交互模式外,另一种调用 CLI 界面的方法就是 batch 模式。batch 模式可以通过 -c-f 参数调用。-c 参数让您能够为调用提供一个命令。例如,假设您需要获得组成云的管理程序的快速列表。实现方法就是发起一个 CLI 会话并使用 -c 参数传递相应的命令。如清单 10 和 11 所示,在发起会话的同时提供了命令,因此不会启动交互式 shell。


清单 10. 为 CLI 提供命令 - 命令
				
C:\cloudburst\cloudburst.cli\bin>cloudburst -h mycloudburst.com -u cloudburstUser 
	-p password -c "cloudburst.hypervisors"
				


清单 11. 为 CLI 提供命令 - 输出
				
[
  {
    "address": "https://myhypervisor01.com/sdk",
    "certificate": (nested object),
    "certified": "T",
    "cloud": (nested object),
    "created": May 13, 2009 4:25:02 PM,
    "currentmessage": "RM03103",
    "currentmessage_text": "Started (move to maintenance mode to make changes)",

    "currentstatus": "RM01006",
    "currentstatus_text": "Started",
    "desiredstatus": "RM01006",
    "desiredstatus_text": "Started",
    "id": 1,
    "name": "Virtual WAS",
    "networks": (nested object),
    "password": "12422499021750",
    "storage": (nested object),
    "type": "ESX",
    "updated": May 13, 2009 4:25:48 PM,
    "userid": "root"
  }
]

您也可以通过传入多个 -c 参数传递多个命令。在清单 12 所示的命令中,执行了三个不同的命令:

  • 首先,创建 newuser WebSphere CloudBurst 用户。
  • newuser 电子邮件地址被修改为 newguy@mycompany.com
  • 最后,检索表示 newuser 的资源的当前状态。

通过使用多个 -c 参数,您可以构造一组有序的步骤,所有命令将按从左到右的顺序执行。


清单 12. 为 CLI 提供多个命令 - 命令
				
C:\cloudburst\cloudburst.cli>cloudburst -h wstiblade12.rtp.raleigh.ibm.com -u cb
admin -p cbadmin -c "newuser = cloudburst.users.create({'username':'newuser', 'fullname':'
Pattern Deployer', 'password':'password', 'email':'newuser@mycompany.com'})" -c
"newuser.email='newguy@mycompany.com'" -c "newuser”
				


清单 13. 为 CLI 提供多个命令 - 输出
				
{
  "currentmessage": "RM02013",
  "currentmessage_text": "User has not logged in yet",
  "currentstatus": "RM01062",
  "currentstatus_text": "Inactive",
  "email": "newuser@mycompany.com",
  "fullname": "Pattern Deployer",
  "groups": (nested object),
  "id": 7,
  "parts": (nested object),
  "password": (write-only),
  "patterns": (nested object),
  "roles": (nested object),
  "scripts": (nested object),
  "username": "newuser",
  "virtualimages": (nested object),
  "virtualsystems": (nested object)
}
{
  "currentmessage": "RM02013",
  "currentmessage_text": "User has not logged in yet",
  "currentstatus": "RM01062",
  "currentstatus_text": "Inactive",
  "email": "newguy@mycompany.com",
  "fullname": "Pattern Deployer",
  "groups": (nested object),
  "id": 7,
  "parts": (nested object),
  "password": (write-only),
  "patterns": (nested object),
  "roles": (nested object),
  "scripts": (nested object),
  "username": "newuser",
  "virtualimages": (nested object),
  "virtualsystems": (nested object)
}

使用文件模式

对交互式或 batch 模式使用 -c 参数,有利于使用 CLI 接口驱动频繁运行的任务,或是执行需要固定用户交互的任务。然而,当您需要创建围绕脚本构建的自动化管理流程时,WebSphere CloudBurst CLI 提供了文件模式,这是一种使用 -f 参数的 batch 模式。

在这种模式中,您将发起会话并通过使用 -f 参数提供一个 Jython 脚本文件。命令语法与交互模式和命令模式完全相同。

清单 14 所示的脚本将遍历所有模式并在控制台中显示所有者为 cbadmin 用户的所有模式。如果下面的脚本被命名为 findAdminPatterns.jy,那么它将按照清单 15 那样运行。


清单 14. 样例 WebSphere CloudBurst Jython 脚本
				
cbadmin = cloudburst.users.cbadmin[0]

for pattern in cloudburst.patterns:
    if pattern.owner == cbadmin:
        print pattern

				


清单 15. 使用 -f 命令调用 CLI - 命令
				
C:\cloudburst\cloudburst.cli\bin>cloudburst.bat -h mycloudburst.com -u cloudburstUser 
	-p password -f findAdminPatterns.jy
					


清单 16. 使用 -f 命令调用 CLI - 输出
				
{
  "acl": (nested object),
  "advancedoptions": (nested object),
  "created": May 13, 2009 1:29:03 PM,
  "currentmessage": None,
  "currentmessage_text": None,
  "currentstatus": "RM01028",
  "currentstatus_text": "Read-only",
  "description": "Single server is a WebSphere Application Server topology or pa
rt of a WebSphere Application Server Network Deployment topology.  The single no
de can be used for a development environment, or as part of a multiple node, pro
duction environment in which the application configuration is manually duplicate
d.",
  "id": 1,
  "name": "WebSphere single server",
  "owner": (nested object),
  "parts": (nested object),
  "updated": May 13, 2009 1:29:40 PM,
  "validationmessage": "RM10051",
  "validationmessage_text": "OK",
  "validationstatus": "RM01001",
  "validationstatus_text": "Defined",
  "virtualimage": (nested object),
  "virtualsystems": (nested object)
}
					

脚本文件还可以创建新的资源和资源集合。清单 17 所示的脚本创建了一个脚本包,附带了一个 .zip 文件,并指定了必需的运行特征。此外,脚本创建了一个新的集群模式并将脚本包放到部署管理器组件中。


清单 17. 创建新的脚本包和模式
				
#first create the new script package
newScript = cloudburst.scripts << {'name':'Install My App'}
newScript.archive.set('c:\\apps\\myapp\\installMyApp.zip')
newScript.command = '${WAS_PROFILE_ROOT}/bin/wsadmin.sh'
newScript.location = '/opt/tmp/myapp'
newScript.log = '/opt/tmp/myapp/logs'
newScript.commandargs = '-f /opt/tmp/myapp/installMyApp.jacl'

# now create the cluster pattern
patternName = 'My Cluster Pattern'
description = 'Cluster with custom application installed'
virtualImage = cloudburst.virtualimages['WebSphere Application Server 7.0.0.3'][0]
newPattern = cloudburst.patterns << {'name': patternName, 'description': description, 
'virtualimage': virtualImage}

# create Dmgr part and add script package
dmgrPart = cloudburst.parts['Deployment manager'][0]
dmgrPpart = newPattern.parts << dmgrPart
dmgrPpart.scripts << newScript

# add a script that configures the IBM HTTP Server on the same node as the Dmgr
dmgrPpart.scripts << cloudburst.scripts['AddIhsNode'][0]

# create two custom nodes for the cluster
customNodePart = cloudburst.parts['Custom node'][0]
customNodePpart = newPattern.parts << customNodePart
customNodePpart.count = 2
				

在 CLI 使用 -f 命令运行完脚本后,您应当能够检查结果:在 CLI 中查询新模式,或是登录到管理控制台。在 WebSphere CloudBurst 控制台中,您应当看到类似图 2 所示的模式。


图 2. 控制台中显示的新模式
新创建的包含脚本包的模式

结合使用 batch 模式和 -f 参数将令您发挥出 CLI 的全部力量,并能够为 WebSphere CloudBurst 建立自动化的管理流程。一定要牢记,CLI 是建立在 Jython 2.2.1 的基础上的,因此这个级别的 Jython 所支持的大部分功能都可以用于在 CLI 环境中运行的脚本。例如,可以使用 sys.argv 变量在命令行中访问传递给脚本的参数。

样例

WebSphere CloudBurst CLI 附带了一个样例目录,其中包含了可以与以上的 -f 选项结合使用的若干脚本。这些脚本为各种可通过脚本化完成的任务提供了示例,并且也可以作为编写定制脚本的起点。脚本中归档的注释提供了脚本执行的每个任务的更多信息。

结束语

WebSphere CloudBurst Appliance 包含了许多不同的资源,帮助企业构建私有的 WebSphere 云环境。为了帮助您管理这些不同的资源,该设备提供了一个图形用户界面和一个命令行界面。CLI 提供了一个 Jython 环境,让您可以查看和操作私有云中包含的资源和资源集合。可在 GUI 中完成的大多数管理任务都可以在 CLI 中完成。此外,CLI 提供了不同的操作模式,可以支持从用户驱动操作到完全自动化任务等各种行为。最妙的是,CLI 的设置非常简单。您仅需下载 WebSphere CloudBurst 提供的工具和一个受支持的 JRE。

本文分享的信息仅仅是从较高的级别对 WebSphere CloudBurst CLI 进行了回顾,但是涉及的概念可以进行扩展,从而完成系统中几乎任何类型的管理任务。通过学习如何使用 WebSphere CloudBurst CLI,它是管理私有 WebSphere 云环境的强大工具。



参考资料

学习

获得产品和技术

讨论


作者简介

Dustin Amrhein 是在德克萨斯州奥斯汀工作的一位 IBM 软件工程师。他是一位 WebSphere Application Server Web Services 组件开发人员。


Mike Burr 是 IBM Raleigh 的一位软件工程师。他在 WebSphere Technology Institute 工作,探索 IBM 的 WebSphere 系列产品未来可能的方向。




对本文的评价










回页首


IBM 公司保留在 developerWorks 网站上发表的内容的著作权。未经IBM公司或原始作者的书面明确许可,请勿转载。如果您希望转载,请通过 提交转载请求表单 联系我们的编辑团队。
    关于 IBM 隐私条约 联系 IBM 使用条款