To create a cloud template, you make a POST request. The request body includes the name of the new cloud template and the project ID of an existing project. To update a cloud template, you make a PUT request that changes one of the properties of the cloud template.

Before creating a cloud template, you get a list of cloud templates to verify that the cloud template you plan to create does not already exist. After a cloud template is created, you can update it to change the cloud template definition.

Prerequisites

Procedure

  1. Assign the project ID variable.
    project_id='<your_project_id>'
  2. Assign your cloud template name variable.
    cloud_template_name='<your_cloud_template_name>'

    your_cloud_template_name is a name that you choose.

  3. Get a list of cloud templates.
    curl -X GET $url/blueprint/api/blueprints -H "Authorization: Bearer $access_token"  | jq "."
  4. To verify that the cloud template you plan to create is not already listed, examine the response.
  5. Validate the cloud template before creating it.
    curl -X POST \
      $url/blueprint/api/blueprint-validation?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token"  \
      -d '{
        "name" : "'"$cloud_template_name"'",
        "description" : "Basic Cloud Machine cloud template",
        "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''",
        "projectId" : "'"$project_id"'",
        "requestScopeOrg": false
    }' | jq "."
  6. Examine the response to confirm that you see "valid":true.
  7. Create a new cloud template.
    curl -X POST \
      $url/blueprint/api/blueprints?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token"  \
      -d '{
        "name" : "'"$cloud_template_name"'",
        "description" : "Basic Cloud Machine cloud template",
        "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''",
        "projectId" : "'"$project_id"'",
        "requestScopeOrg": false
    }' | jq "."
  8. Examine the response and record the ID of your newly created cloud template.
  9. Assign the cloud template ID variable.
    cloud_template_id='<your_cloud_template_id>'

    your_cloud_template_id is the ID of the new cloud template that you created.

  10. To verify that the cloud template has been created, get a list of cloud templates and filter for your_cloud_template_name.
    curl -X GET $url/blueprint/api/blueprints?name=$cloud_template_name -H "Authorization: Bearer $access_token"  | jq "."
  11. (Optional) To update the cloud template, use a PUT request and specify your_cloud_template_id.
    curl -X PUT \
      $url/blueprint/api/blueprints/$cloud_template_id?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token"  \
      -d '{
        "name" : "'"$cloud_template_name"'",
        "description" : "Basic Cloud Machine cloud template",
        "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''\n      tags: [\n        {\n          \"key\": \"env\",\n          \"value\": \"prod\"\n        }\n      ]\n",
        "projectId" : "'"$project_id"'",
        "requestScopeOrg": false
    }' | jq "."

Example: Create a Cloud Template and Update it

Create a cloud template named MyExampleCloudTemplate. This example assumes that MyExampleCloudTemplate does not already exist.

Assign variables.

$ url='https://appliance.domain.com'
$ api_version='2019-09-12'
$ project_id='394a4ccb-22c6-4ef0-8c75-8b77efbefb51'
$ cloud_template_name='MyExampleCloudTemplate'

Validate the cloud template.

$ curl -X POST \
  $url/blueprint/api/blueprint-validation?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token"  \
  -d '{
    "name" : "'"$cloud_template_name"'",
    "description" : "Basic cloud machine cloud template",
    "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''",
    "projectId" : "'"$project_id"'",
    "requestScopeOrg": false
}' | jq "."

Examine the response to confirm that "valid":true.

{
  "valid": true,
  "validationMessages": []
}

Create the cloud template.

$ curl -X POST \
  $url/blueprint/api/blueprints?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token"  \
  -d '{
    "name" : "'"$cloud_template_name"'",
    "description" : "Basic cloud machine cloud template",
    "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''",
    "projectId" : "'"$project_id"'",
    "requestScopeOrg": false
}' | jq "."

The response from your request to create the cloud template shows the cloud template ID.

{
  "id": "1f170637-81a3-4257-b1cd-b2219ee8034c",
  "createdAt": "2019-10-10T23:43:27.001Z",
  ...
  "selfLink": "/blueprint/api/blueprints/1f170637-81a3-4257-b1cd-b2219ee8034c"
  ...
}

Assign the cloud template ID variable.

$ cloud_template_id='1f170637-81a3-4257-b1cd-b2219ee8034c'

Update the cloud template to set a tag on the machine properties in the cloud template.

$ curl -X PUT \
  $url/blueprint/api/blueprints/$cloud_template_id?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token"  \
  -d '{
    "name" : "'"$cloud_template_name"'",
    "description" : "Basic cloud machine cloud template",
    "content" : "formatVersion: 1\ninputs:\n  flavor:\n    type: string\n    title: Flavor\n    description: Flavor Mapping Name\n  image:\n    type: string\n    title: Image\n    description: Image Mapping Name\n  count:\n    type: integer\n    minimum: 1\n    default: 1\n    maximum: 2\n    title: Number of Instances\nresources:\n  BasicCloudMachine:\n    type: Cloud.Machine\n    properties:\n      name: BasicCloudMachine\n      flavor: '\''${input.flavor}'\''      \n      image: '\''${input.image}'\''\n      count: '\''${input.count}'\''\n      tags: [\n        {\n          \"key\": \"env\",\n          \"value\": \"prod\"\n        }\n      ]\n",
    "projectId" : "'"$project_id"'",
    "requestScopeOrg": false
}' | jq "."

What to do next

Use the cloud template ID to version and release the cloud template to a catalog.