VMware Cloud Foundation APIs: Cancelling a VCF Fleet Lifecycle Task

There maybe a number scenarios where you find yourself needing to cancel a running task, this is possible using the VCF Fleet Lifecycle Service APIs. It's important to note that the running stage will continue until it reaches a terminal state, and only then subsequent steps will not be executed.

VCF Fleet Lifecycle Service APIs Used

VCF Fleet LCM Service APIs

  • POST /api/v1/identity/token
  • GET /fleet-lcm/v1/tasks
  • POST /fleet-lcm/v1/tasks/?action=cancel

Procedure

  1. Connect to a system that has access to the infrastructure and is capable of running CURL.

  2. Replace the values in the sample code with values for your VCF Fleet Lifecycle Service and paste the commands in the console. If your not sure which endpoint this FQDN should be log into VCF Operations, go to Build > Lifecycle > VCF Management and select the Components tab and locate the component named Fleet lifecycle the FQDN is shown in the FQDN column.

1export vcfFleetLifecycleFqdn='flt-fc01.rainpole.io'
2export vcfFleetLifecycleUser='[email protected]'
3export vcfFleetLifecyclePass='VMw@re1!VMw@re1!'
  1. Authenticate to the VCF Fleet Lifecycle service and obtain a token by running the following command:
1vcfFleetLifecycleToken=$(curl -k -X POST "https://$vcfFleetLifecycleFqdn/api/v1/identity/token" \
2    -H 'Content-Type: application/x-www-form-urlencoded' \
3    --data "grant_type=password" \
4    --data "username=$vcfFleetLifecycleUser" \
5    --data "password=$vcfFleetLifecyclePass" \
6    | jq -r '.access_token')
  1. Verify you successfully obtained an authentication token by running the following command:
1echo $vcfFleetLifecycleToken

Example Output:

1eyJhbGciOiJFZERTQSIsImtpZCI6Ilg4Mk5veGNJRlVCVEFiY0xPM1NUdU12UTF6Qlo4d01xeUxDTGNuOGZYdFUiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2ZsdC1mYzAxLnJhaW5wb2xlLmlvIiwic3ViIjoiYWRtaW5AdnNwLmxvY2FsIiwiYXVkIjpbInZzcCJdLCJleHAiOjE3ODUyNDk1MzIsImlhdCI6MTc4NTIzNTEzMiwianRpIjoiOThkMjE2NzYtZGRhYy00NmU2LWEyZWItMzdjNDYzNmI1NjQwIiwiYXpwIjoicGFzc3dvcmRfZ3JhbnRfY2xpZW50IiwiYWNjdCI6ImFkbWluQHZzcC5sb2NhbCIsImF1dGhvcml6YXRpb25fZGV0YWlscyI6bnVsbH0.CjyGod2F17Wz0Y4TmggHZieByeE80a6Uqe2S7trD1ycaPupzqZ19d_qLbiHjrMviV-ADDKc7RkGc27DoaChNBA
  1. Retrieve the task ID of the running task by running the following command:
1taskId=$(curl -ks -X GET "https://$vcfFleetLifecycleFqdn/fleet-lcm/v1/tasks" \
2  --header "Authorization: Bearer ${vcfFleetLifecycleToken}" \
3  --header "Accept: application/json" \
4  --header "Content-Type: application/json" \
5  | jq -r '.elements[] | select(.status == "RUNNING") | .id')
  1. Verify you successfully obtained the task ID by running the following command:
1echo $taskId

Example Output:

1019fa881-3b1f-7934-86d3-dd617eab2976
  1. Cancel the task by running the following command:
1curl -ks -X POST "https://$vcfFleetLifecycleFqdn/fleet-lcm/v1/tasks/${taskId}?action=cancel" \
2  --header "Authorization: Bearer ${vcfFleetLifecycleToken}" \
3  --header "Accept: application/json" \
4  --header "Content-Type: application/json"

Posts in this Series