Go to main content

Oracle® ZFS Storage Appliance 管理指南,发行版 OS8.8.0

退出打印视图

更新时间: 2018 年 11 月
 
 

约束工作流参数

对于某些参数,有人不希望允许使用任意字符串,而是希望将输入限制为少量备选选项之一。这些参数应该指定为 ChooseOne 类型,包含参数的对象必须具有另外两个成员:

表 143  约束参数的必要成员
必要成员
类型
说明
options
数组
一个字符串数组,指定有效的选项
optionlabels
数组
一个字符串数组,指定与在 options 中所指定的选项相关联的标签
示例 21  使用工作流 ChooseOne 参数

使用 ChooseOne 参数类型,我们可以强化前面的示例,将业务部门限制为少量预定义的值之一:

var workflow = {
	name: 'Create share',
	description: 'Creates a new share in a business unit',
	parameters: {
		name: {
			label: 'Name of new share',
			type: 'String'
		},
		unit: {
			label: 'Business unit',
			type: 'ChooseOne',
			options: [ 'development', 'finance', 'qa', 'sales' ],
			optionlabels: [ 'Development', 'Finance',
			    'Quality Assurance', 'Sales/Administrative' ],
		}
	},
	execute: function (params) {
		run('shares select ' + params.unit);
		run('filesystem ' + params.name);
		run('commit');
		return ('Created new share "' + params.name + '"');
	}
};

当执行此工作流时,unit 参数不能手动输入-它将从指定的可用选项列表中进行选择。