作为云模板开发人员,您可以使用输入参数,以便用户可以在请求时进行自定义选择。
输入的工作原理
用户提供输入时,您不再需要保存多个仅有细微差别的模板副本。此外,输入还可以为实施后操作准备模板。请参见如何使用云模板输入进行 vRealize Automation 实施后操作更新。
以下输入介绍了如何为 MySQL 数据库服务器创建一个云模板,用户可以在其中将该模板部署到不同的云资源环境中,并且每次都应用不同的容量和凭据。
添加输入参数
在模板代码中添加 inputs 部分,您可以在其中设置可选择的值。
在以下示例中,可以选择计算机大小、操作系统和集群服务器数量。
inputs:
wp-size:
type: string
enum:
- small
- medium
description: Size of Nodes
title: Node Size
wp-image:
type: string
enum:
- coreos
- ubuntu
title: Select Image/OS
wp-count:
type: integer
default: 2
maximum: 5
minimum: 2
title: Wordpress Cluster Size
description: Wordpress Cluster Size (Number of nodes)
如果您不擅长编辑代码,可以单击代码编辑器的输入选项卡,然后在其中输入设置。以下示例显示了前面提到的 MySQL 数据库的一些输入。
引用输入参数
然后,在 resources 部分中,使用 ${input.property-name} 语法引用输入参数。
如果属性名称包含空格,请使用方括号和双引号分隔,而不是使用点表示形式:${input["property name"]}
input 一词。
resources:
WebTier:
type: Cloud.Machine
properties:
name: wordpress
flavor: '${input.wp-size}'
image: '${input.wp-image}'
count: '${input.wp-count}'
可选输入
输入通常是必需项,并标有星号。要将输入设置为可选项,请设置空的默认值,如下所示。
owner: type: string minLength: 0 maxLength: 30 title: Owner Name description: Account Owner default: ''
输入属性的列表
| 属性 | 说明 |
|---|---|
| const | 与 oneOf 一起使用。与友好标题关联的实际值。 |
| default | 输入的预填充值。 默认值必须为正确的类型。请勿输入单词作为整数的默认值。 |
| description | 输入的用户帮助文本。 |
| encrypted | 是否对用户键入的输入进行加密(true 或 false)。 密码通常是加密的。 此外,还可以创建可在多个云模板中重用的加密属性。请参见密钥 Cloud Assembly 属性。 |
| enum | 允许值的下拉菜单。 请使用以下示例作为格式指南。
enum:
- value 1
- value 2 |
| format | 设置所需的输入格式。例如,(25/04/19) 支持日期-时间。 允许在 Service Broker 自定义表单中使用日期选择器。 |
| items | 声明数组中的项目。支持数字、整数、字符串、布尔或对象。 |
| maxItems | 数组中可选择的最大项目数。 |
| maxLength | 字符串允许使用的最大字符数。 例如,要将字段限制在 25 个字符以内,请输入 |
| maximum | 数字或整数的最大允许值。 |
| minItems | 数组中可选择的最小项目数。 |
| minLength | 字符串允许使用的最小字符数。 |
| minimum | 数字或整数的最小允许值。 |
| oneOf | 允许用户输入表单为不太友好的值 (const) 显示友好名称 (title)。如果设置默认值,请设置 const,而不是 title。 适用于字符串、整数和数字类型。 |
| pattern | 正则表达式语法中字符串输入的允许字符。 例如, |
| properties | 声明对象的 key:value 属性块。 |
| readOnly | 仅用于提供表单标签。 |
| title | 与 oneOf 一起使用。const 值的友好名称。在部署时,标题显示在用户输入表单上。 |
| type | 数字、整数、字符串、布尔或对象的数据类型。
重要说明:
布尔类型会向请求表单添加空白复选框。使该框保持原样不会将输入设置为 False。 要将输入设置为 False,用户必须选中并清除该框。 |
| writeOnly | 在表单中隐藏星号后面的击键。不能与 enum 一起使用。在 Service Broker 自定义表单中显示为密码字段。 |
其他示例
包含枚举的字符串
image:
type: string
title: Operating System
description: The operating system version to use.
enum:
- ubuntu 16.04
- ubuntu 18.04
default: ubuntu 16.04
shell:
type: string
title: Default shell
Description: The default shell that will be configured for the created user.
enum:
- /bin/bash
- /bin/sh
包含最小值和最大值的整数
count:
type: integer
title: Machine Count
description: The number of machines that you want to deploy.
maximum: 5
minimum: 1
default: 1
对象数组
tags:
type: array
title: Tags
description: Tags that you want applied to the machines.
items:
type: object
properties:
key:
type: string
title: Key
value:
type: string
title: Value
包含友好名称的字符串
platform:
type: string
oneOf:
- title: AWS
const: platform:aws
- title: Azure
const: platform:azure
- title: vSphere
const: platform:vsphere
default: platform:aws
包含模式验证的字符串
username:
type: string
title: Username
description: The name for the user that will be created when the machine is provisioned.
pattern: ^[a-zA-Z]+$
显示为密码的字符串
password:
type: string
title: Password
description: The initial password that will be required to logon to the machine. Configured to reset on first login.
encrypted: true
writeOnly: true
显示为文本区域的字符串
ssh_public_key:
type: string
title: SSH public key
maxLength: 256
布尔
public_ip:
type: boolean
title: Assign public IP address
description: Choose whether your machine should be internet facing.
default: false
日期和时间日历选择器
leaseDate:
type: string
title: Lease Date
format: date-time