If you do not already have an Azure managed disk, create a block device to use for your snapshot. To create a block device, you make a POST request using the block device specification. The request body includes a project ID, disk capacity, persistence setting, and constraints from the Azure Storage Profile for a managed disk.

Prerequisites

Procedure

  1. Assign the project ID variable.
    project_id='<your_project_id>'
  2. Set the capacity and persistence for the disk.
    capacity_in_gb=<integer>
    persistence=<true|false>
    
  3. Deploy the block device.
    • With mandatory set to false, tags in the expression are not required to match tags in an existing storage profile for the deployment to succeed. However if tags are provided, Automation will try to match them when deploying the block device.
    • The expression is the key:value tag pair used to create the storage profile. See Create a vSphere Storage Profile for a First Class Disk.
    curl -X POST \
      $url/iaas/api/block-devices?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token" \
      -d '{
        "projectId": "'$project_id'",
        "name": "block-device-example",
        "capacityInGB": "'$capacity_in_gb'",
        "persistent" : "'$persistent'",
        "constraints": [
            {
                "mandatory": "false",
                "expression": "type:managed"
            }
        ]
    }' | jq "."
    The response includes a selfLink value.
    {
      "progress": 0,
      "status": "INPROGRESS",
      "name": "Provisioning",
      "id": "example-selfLink-alphanumeric-string",
      "selfLink": "/iaas/api/request-tracker/example-selfLink-alphanumeric-string"
    }
  4. Assign the selfLink variable.
    selfLink_id='example-selfLink-alphanumeric-string'
  5. Use the selfLink variable to track the progress of the block device creation.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/request-tracker/$selfLink_id?apiVersion=$api_version | jq "."
    
    In the list of resources, the response includes block devices with the block device ID in the path.
    {
      "progress": 100,
      "message": "success",
      "status": "FINISHED",
      "resources": [
        "/iaas/api/block-devices/example-blockdevice-alphanumeric-string"
      ],
      ...
    }
  6. (Optional) If you want to retrieve the ID of an existing block device, use an OData filter with the block device name in the request.
    block_device_name='<your_block_device_name>'
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" "$url/iaas/api/block-devices?apiVersion=$api_version&"'$filter'"=name%20eq%20$block_device_name" | jq "."
  7. Assign the block device ID variable.
    block_device_id='example-blockdevice-alphanumeric-string'

Example: Create a Block Device

With constraints from an Azure Storage Profile for a managed disk, use the block device specification to deploy a managed disk for a project ID with a two GB capacity and persistence set to false.

$ url='https://appliance.domain.com'
$ api_version='2021-07-15'
$ project_id='f5357a28-df59-47e0-b983-8a562910d0be'
$ capacity_in_gb=2
$ persistent=false

Deploy the block device.

$ curl -X POST \
  $url/iaas/api/block-devices?apiVersion=$api_version \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "projectId": "'$project_id'",
    "name": "block-device-example",
    "capacityInGB": "'$capacity_in_gb'",
    "persistent" : "'$persistent'",
    "constraints": [
        {
            "mandatory": "false",
            "expression": "type:managed"
        }
    ]
}' | jq "."

The response provides a selfLink to the request.

{
  "progress": 0,
  "status": "INPROGRESS",
  "name": "Provisioning",
  "id": "22bdaf20-ce48-4a9f-8c1f-f4e74263645f",
  "selfLink": "/iaas/api/request-tracker/22bdaf20-ce48-4a9f-8c1f-f4e74263645f",
  "deploymentId":"cf33c90e-6f6d-48ed-82dd-a6a9f0e6f700"
}

Assign the selfLink ID variable.

$ selfLink_id='22bdaf20-ce48-4a9f-8c1f-f4e74263645f'

Track the progress of the request.

$ curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" $url/iaas/api/request-tracker/$selfLink_id?apiVersion=$api_version | jq "."

After the request completes successfully, the response provides the block device ID.

{
  "progress": 100,
  "message": "success",
  "status": "FINISHED",
  "resources": [
    "/iaas/api/block-devices/41d600c2-429e-4c90-98d4-638e77724101"
  ],
  "name": "Provisioning",
  "id": "22bdaf20-ce48-4a9f-8c1f-f4e74263645f",
  "selfLink": "/iaas/api/request-tracker/22bdaf20-ce48-4a9f-8c1f-f4e74263645f",
  "deploymentId":"cf33c90e-6f6d-48ed-82dd-a6a9f0e6f700"
}

Assign the block device ID variable.

$ block_device_id='41d600c2-429e-4c90-98d4-638e77724101'

What to do next

Use the block device ID to create a snapshot. See Create and Manage Azure Disk Snapshots.