Create and Deploy a Machine Resource

To create a new resource such as a VM, you can use the resources API to make a POST request with a project ID. The deployment creates a new resource without using a cloud template.

This procedure shows how to provision a VM with a project and a cloud zone assigned to the project. The flavor and image for the VM must exist in your cloud account.

Prerequisites

Procedure

  1. Assign the cloud account ID variable.
    cloud_account_id='<your_cloud_account_id>'
  2. Assign the project ID variable.
    project_id='<your_project_id>'
  3. List all cloud zones.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" "$url/iaas/api/zones?apiVersion=$api_version"  | jq "."
  4. Examine the response for the zone where you want to place your VM.
    You use the externalRegionId to filter for fabric flavor and fabric image. You use the cloud zone ID for VM placement.
  5. Assign the external region ID variable.
    external_region_id='<your_external_region_id>'
  6. Assign the cloud zone placement variable.
    placement_name='/iaas/api/zone/<your_cloud_zone_id>'
  7. To list the fabric images in your cloud account and zone, specify the cloud account ID and external region ID in the request.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" \
        "$url/iaas/api/fabric-images/?apiVersion=$api_version&"\
        '$filter'="(((externalRegionId eq '') or (externalRegionId eq '$external_region_id')) \
        and ((cloudAccountId ne '*') or cloudAccountId eq '$cloud_account_id')))" | jq "."
  8. Examine the response to select a fabric image.
  9. Assign the fabric image variable.
    image_name='<your_image_name>'
  10. To list the fabric flavors in your cloud account and zone, specify the cloud account ID and external region ID in the request.
    curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" \ 
        "$url/iaas/api/fabric-flavors/?apiVersion=$api_version&"\
        '$filter'="(((externalRegionId eq '') or (externalRegionId eq '$external_region_id')) \
        and ((cloudAccountId ne '*') or cloudAccountId eq '$cloud_account_id')))" | jq "."
  11. Examine the response to select a fabric flavor.
  12. Assign the fabric flavor variable.
    flavor_name='<your_flavor_name>'
  13. Assign the resource type variable.
    resource_type='<your_resource_type>'
  14. Create and deploy the VM.
    curl -X POST \
      $url/deployment/api/resources?apiVersion=$api_version_deployment \
      -H "Authorization: Bearer $access_token" \
      -H "Content-Type: application/json" \
      -d '{
        "name":"<your_resource_name>",
        "projectId": "'$project_id'",
        "type":"'$resource_type'",
        "properties":{
            "imageRef": "'$image_name'",
            "flavor": "'$flavor_name'",
            "placement": "'$placement_name'"  
      },
    }' | jq "."
  15. Examine the response for the request ID.
  16. Assign the request ID.
  17. Get the status of the deployment.
    curl -X GET \
      $url/deployment/api/deployments/$deployment_id?apiVersion=$api_version_deployment \
      -H "Authorization: Bearer $access_token" | jq "."
    When the status shows CREATE_SUCCESSFUL the VM is deployed.

Example: Create and deploy a VM

With a cloud account ID and cloud zone in the cloud account, create and deploy an AWS machine named cloud_machine_1 using the Cloud.AWS.EC2.Instance resource type.

Assign variables.

$ url='https://appliance.domain.com'
$ api_version='2021-07-15'
$ api_version_deployment='2020-08-25'
$ cloud_account_id='14e6b70c-0e76-4c5e-bb61-e6d70a5b43ef'
$ project_id='394a4ccb-22c6-4ef0-8c75-8b77efbefb51'

List all cloud zones.

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

A snippet of the response shows the cloud account ID with the external region ID and cloud zone ID.

...
      "externalRegionId": "eu-west-1",
      "cloudAccountId": "14e6b70c-0e76-4c5e-bb61-e6d70a5b43ef",
      "name": "AWS / eu-west-1-changed",
      "description": "test description",
      "id": "f32a30fd-67ac-43e3-9512-60cf6ef7bee8"
...

Assign the external region ID variable.

$ external_region_id='eu-west-1'

Assign the cloud zone placement variable.

$ placement_name='/iaas/api/zone/f32a30fd-67ac-43e3-9512-60cf6ef7bee8'

To list the fabric images in your cloud account and zone, specify the cloud account ID and external region ID in the request.

curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" \
    "$url/iaas/api/fabric-images/?apiVersion=$api_version&"\
    '$filter'="(((externalRegionId eq '') or (externalRegionId eq '$external_region_id')) \
    and ((cloudAccountId ne '*') or cloudAccountId eq '$cloud_account_id')))" | jq "."

Examine the response to find the image ID that you want.

...      
      "externalRegionId": "eu-west-1",
      "isPrivate": false,
      "externalId": "ami-9a9012e9",
...

To list the fabric flavors in your cloud account and zone, specify the cloud account ID and external region ID in the request.

curl -X GET -H 'Content-Type: application/json' -H "Authorization: Bearer $access_token" \ 
    "$url/iaas/api/fabric-flavors/?apiVersion=$api_version&"\
    '$filter'="(((externalRegionId eq '') or (externalRegionId eq '$external_region_id')) \
    and ((cloudAccountId ne '*') or cloudAccountId eq '$cloud_account_id')))" | jq "."

Examine the response to find the flavor ID that you want.

...          {
      "id": "x1e.xlarge",
      "name": "x1e.xlarge",
      "cpuCount": 4,
      "memoryInMB": 124928,
      "storageType": "ssd",
      "dataDiskSizeInMB": 122880,
      "dataDiskMaxCount": 1,
      "networkType": "Up to 10 Gigabit"
    },
...

Assign the resource type for the VM.

$ resource_type = 'Cloud.AWS.EC2.Instance'

To deploy the VM, assign variables for image and flavor.

$ image_name='ami-9a9012e9'
$ flavor_name='x1e.xlarge'

Create and deploy the VM.

curl -X POST \
  $url/deployment/api/resources?apiVersion=$api_version_deployment \
  -H "Authorization: Bearer $access_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name":"cloud_machine_1",
    "projectId": "'$project_id'",
    "type":"'$resource_type'",
    "properties":{
        "imageRef": "'$image_name",
        "flavor": "'$flavor_name",
        "placement": "'$placement_name'"
  },
}' | jq "."

The response shows the deployment ID.

{
    "deploymentId": "fccd2081-fd44-44c8-878c-f962ef71969a",
    "projectId": "394a4ccb-22c6-4ef0-8c75-8b77efbefb51",
    "requestId": "1f8f2e4f-0b2e-448d-8439-f1a05b1e90c1",
    "resourceId": "9a510ccb-0543-47e8-a2f2-f1f65fcd0b0a"
}

Assign the deployment ID variable.

$ deployment_id='fccd2081-fd44-44c8-878c-f962ef71969a'

Get the status of the deployment.

$ curl -X GET \
  $url/deployment/api/deployments/$deployment_id?apiVersion=$api_version" 
  -H "Authorization: Bearer $access_token" | jq "."

A snippet of the response shows the deployment status.

...
  ],
  "status": "CREATE_SUCCESSFUL"
}