首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

WebSphere CloudBurst Appliance 命令行界面简介-5

WebSphere CloudBurst Appliance 命令行界面简介-5

使用文件模式对交互式或 batch 模式使用 -c 参数,有利于使用 CLI 接口驱动频繁运行的任务,或是执行需要固定用户交互的任务。然而,当您需要创建围绕脚本构建的自动化管理流程时,WebSphere CloudBurst CLI 提供了文件模式,这是一种使用 -f 参数的 batch 模式。
在这种模式中,您将发起会话并通过使用 -f 参数提供一个 Jython 脚本文件。命令语法与交互模式和命令模式完全相同。
清单 14 所示的脚本将遍历所有模式并在控制台中显示所有者为 cbadmin 用户的所有模式。如果下面的脚本被命名为 findAdminPatterns.jy,那么它将按照清单 15 那样运行。
清单 14. 样例 WebSphere CloudBurst Jython 脚本
1
2
3
4
5
cbadmin = cloudburst.users.cbadmin[0]

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




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




清单 16. 使用 -f 命令调用 CLI - 输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
  "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. 创建新的脚本包和模式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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 变量在命令行中访问传递给脚本的参数。
返回列表