作为云模板开发人员,您可以使用输入参数,以便用户可以在请求时进行自定义选择。

输入的工作原理

用户提供输入时,您不再需要保存多个仅有细微差别的模板副本。此外,输入还可以为实施后操作准备模板。请参见如何使用云模板输入进行 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}'

嵌套输入

如果要对输入进行组织或分类,则支持嵌套输入。在以下示例中,CPU 和内存都位于 level 父标题下。

注: 一组嵌套输入不同于创建和引用 正式的属性组
inputs:
  cluster:
    type: integer
    title: Cluster
    default: 1
    minimum: 1
    maximum: 4
  level:
    type: object
    properties:
      cpu:
        type: integer
        title: CPU
        default: 1
        minimum: 1
        maximum: 4
      memory:
        type: integer
        title: Memory
        default: 2048
        minimum: 2048
        maximum: 4096

resources 部分中,要引用嵌套输入,请在路径中包含父项。

resources:
  Disk_1:
    type: Cloud.vSphere.Disk
    allocatePerInstance: true
    properties:
      capacityGb: 1
      count: ${input.cluster}
  Machine_1:
    type: Cloud.vSphere.Machine
    allocatePerInstance: true
    properties:
      totalMemoryMB: ${input.level.memory}
      attachedDisks:
        - source: ${slice(resource.Disk_1[*].id, count.index, count.index + 1)[0]}
      count: ${input.cluster}
      imageRef: ubuntu
      cpuCount: ${input.level.cpu}

可选输入与必需输入

对于除布尔以外的所有类型,默认情况下用户输入均为可选项。若要求输入,请执行以下操作之一:

  • 设置默认值。
  • 如果没有嵌套输入,请添加 populateRequiredOnNonDefaultProperties 属性:
    inputs:
      cluster:
        type: integer
        populateRequiredOnNonDefaultProperties: true
        title: Cluster
        minimum: 1
        maximum: 4

    请注意,也可以在引用正式的属性组时应用此设置:

    inputs:
      pgmachine:
        type: object
        populateRequiredOnNonDefaultProperties: true
        $ref: /ref/property-groups/machine
  • 如果有嵌套输入,请添加 populateRequiredForNestedProperties 属性:
    inputs:
      cluster:
        type: integer
        title: Cluster
        default: 1
        minimum: 1
        maximum: 4
      level:
        type: object
        properties:
          cpu:
            type: integer
            populateRequiredForNestedProperties: true
            title: CPU
            minimum: 1
            maximum: 4
          memory:
            type: integer
            populateRequiredForNestedProperties: true
            title: Memory
            minimum: 2048
            maximum: 4096

    请注意,也可以在嵌套正式的属性组引用时应用此设置:

      level:
        type: object
        properties:
          cpu:
            type: integer
            populateRequiredForNestedProperties: true
            title: CPU
            minimum: 1
            maximum: 4
          memory:
            type: integer
            populateRequiredForNestedProperties: true
            title: Memory
            minimum: 2048
            maximum: 4096
          pgrequester:
            type: object
            populateRequiredForNestedProperties: true
            $ref: /ref/property-groups/requesterDetails

可选输入 - 要强制输入保持可选状态,请使用刻度标记设置空默认值:

owner:
  type: string
  minLength: 0
  maxLength: 30
  title: Owner Name
  description: Account Owner
  default: ''
可选输入

将输入发送到 vRealize Orchestrator

要为 vRealize Orchestrator 操作提供云模板输入,请执行以下步骤。对于 vRealize Orchestrator 操作,“输入”表单比直接在云模板代码中键入更易于使用。

  1. 在与 vRealize Automation 集成的 vRealize Orchestrator 实例中,验证所需操作是否存在。
  2. Cloud Assembly 的云模板设计页面中,转到输入选项卡,然后单击以添加新输入。
  3. 选择类型,然后选择外部源
  4. 在“操作”旁边,单击选择按钮。
  5. 使用“操作”搜索字段查找并选择 vRealize Orchestrator 操作。
  6. 输入或选择任何操作参数。

保存并创建输入后,该输入将作为 $dynamicDefault 输入显示在云模板代码中。例如:

inputs:
  backupnetwork:
    type: string
    $dynamicDefault: /data/vro-actions/com.insanpaolo/getBackupNetworkVLAN?network={{abcdef123456}}&tenant={{abcdef123456}}

输入属性的列表

属性 说明
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 个字符以内,请输入 maxLength: 25

maximum 数字或整数的最大允许值。
minItems 数组中可选择的最小项目数。
minLength 字符串允许使用的最小字符数。
minimum 数字或整数的最小允许值。
oneOf 允许用户输入表单为不太友好的值 (const) 显示友好名称 (title)。如果设置默认值,请设置 const,而不是 title。

适用于字符串、整数和数字类型。

pattern 正则表达式语法中字符串输入的允许字符。

例如,'[a-z]+''[a-z0-9A-Z@#$]+'

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