Import a Template

Before creating a cloud stack with the Oracle Cloud Stack REST API, your cloud account must contain at least one stack template. A template is defined as a YAML file and is added to an account by importing the file.

Refer to the Using Oracle Cloud Stack guide for instructions on creating templates. See Creating a Template.

Note: All of the examples in this guide use the URL prefix and context path for the United States region in Oracle Cloud. For information about the context path and the URL prefixes for other regions of the world, see Send Requests.

Import

To import a template, provide the following information on the cURL command line.

  • Define the request:
    • Use the -X option to set the request method to POST.

    • Use the -H option to set the Content-Type header to multipart/form-data.

    • Use the -F option to send a form field named template, whose value is the contents of your template file.

  • For authentication, you must specify the account credentials obtained previously, as described in Obtain Account Information, on the cURL command line, as follows:
    • Use the -u option to send the user name and password for your Oracle Cloud account.

    • Use the -H option to set the X-ID-TENANT-NAME custom request header to the identity domain ID for your Oracle Cloud account.

For example:

curl -i -X POST \
-u yourUserName:yourPassword \
-H "Content-Type:multipart/form-data" \
-H "X-ID-TENANT-NAME:yourIdentityDomain" \
-F "template=@yourTemplateFile.yaml" \
https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/yourIdentityDomain/templates/cst/instances

Verify that the response includes HTTP code 201, meaning that the import was successful:

HTTP/1.1 201 Created

The response body is a JSON document with a summary of your template along with its REST endpoint. For example:

{
  "templateName":"MyTemplate",
  "latestVersion":"1.0.0",
  "description":"My first template",
  "createdOn":"2016-08-25T18:16:50.233+0000",
  "createdBy":"MyIdentityDomain",
  "links":[
    {
      "rel":"canonical","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances/MyTemplate"
    },
    {
      "rel":"self","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances"
    }
  ]
}

List

Use the same URL and set the request method to GET in order to view a list of all templates available in this account. For example:

curl -i -X GET \
-u yourUserName:yourPassword \
-H "X-ID-TENANT-NAME:yourIdentityDomain" \
https://paas.oraclecloud.com/paas/api/v1.1/instancemgmt/yourIdentityDomain/templates/cst/instances

Below is an example JSON response containing two templates:

{
  "items": [
    {
      "templateName":"MyTemplate",
      "latestVersion":"1.0.0",
      "description":"My first template",
      "createdOn":"2016-08-25T18:16:50.233+0000",
      "createdBy":"MyIdentityDomain",
      "links":[
        {
          "rel":"canonical","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances/MyTemplate"
        },
        {
          "rel":"self","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances"
        }
      ]
    },
    {
      "templateName":"MyTemplate2",
      "latestVersion":"1.0.0",
      "description":"My second template",
      "createdOn":"2016-08-25T18:20:50.233+0000",
      "createdBy":"MyIdentityDomain",
      "links":[
        {
          "rel":"canonical","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances/MyTemplate2"
        },
        {
          "rel":"self","href":"https://psm.us.oraclecloud.com/paas/api/v1.1/instancemgmt/MyIdentityDomain/templates/cst/instances"
        }
      ]
    },
  ]
}