Go to main content
Oracle® ZFS Storage Appliance 管理ガイド、Release OS8.7.0

印刷ビューの終了

更新: 2017 年 3 月
 
 

ワークフローの入力の検証

ワークフローは、そのワークフローのパラメータがメンバーとして含まれているオブジェクトをパラメータとして受け取る validate メンバーを追加することによって、オプションでその入力を検証できます。validate 関数からは、各メンバーの名前が検証に失敗したパラメータの名前であり、各メンバーの値がユーザーに表示される検証失敗メッセージであるオブジェクトが返されます。

使用例 23  ワークフローの入力の検証

前の例を拡張して、ユーザーがすでに存在するシェアを作成しようとした場合に明確なエラーを表示するには、次のようにします。

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' ],
		}
	},
	validate: function (params) {
		try {
			run('shares select ' + params.unit);
			run('select ' + params.name);
		} catch (err) {
			if (err.code == EAKSH_ENTITY_BADSELECT)
				return;
		}

		return ({ name: 'share already exists' });
	},
	execute: function (params) {
		try {
			run('shares select ' + params.unit);
		} catch (err) {
			if (err.code != EAKSH_ENTITY_BADSELECT)
				throw (err);

			/*
			 * We haven't yet created a project that corresponds to
			 * this business unit; create it now.
			 */
			run('shares project ' + params.unit);
			set('mountpoint', '/export/' + params.unit);
			run('commit');
			run('shares select ' + params.unit);
		}

		run('filesystem ' + params.name);
		run('commit');
		return ('Created new share "' + params.name + '"');
	}
};