Solved

Can't Clone VM via API 3.0

  • 22 January 2021
  • 4 replies
  • 574 views

Badge +1

hi,

After login to prism , i open API Reference and login with credentions.

Then i go to VMs-->Clone Section to clone vm via API.

I get the vm uuid via two method which on i think i get same uuid

1)ssh to cvm and giving “acli vm.list”

2)While console url, using uuid=”string”

Both have same uuid. So i used to clone vm via api but i get error as “

Given input is invalid. VM UUID cannot be specified, use idempotence identifiers to get the UUID

I also tried get existing and create new idempotence identifiers but on executing it in clone vm it gives error “uuid not existed”.

Please suggest me ,i think uuid is correct but then what causing the error.

Please help.

icon

Best answer by AnishWalia20 23 January 2021, 09:40

View original

This topic has been closed for comments

4 replies

Badge +1

Hi @AnishWalia20 

This API is working but after vm cloned. It was in powered off state.

Is there any way to set power on state via API 3 (in API 2 it was there, but its old and deprecated not work)

OR

Any other way to create VM or clone so that it will be in power on state.

Badge +1

Thanks, I got it, and it works also

Userlevel 6
Badge +5

hey, @Balram here are more details about the “/idempotence_identifiers” REST API: https://www.nutanix.dev/reference/prism_central/v3/api/idempotence-identifiers/postidempotenceidentifiers/

 

Using the above POST method you can get the idempotence identifier of the VM. 

Also as the above documentation suggests It is mandatory to provide the count for how many identifiers we need and the lifetime until we can use it in the POST “/idempotence_identifiers” API. 

Below is an example with CURL:
 

anish.singhwalia@C02XF4HA:~$ curl -k -X POST --header "Content-Type: application/json" --header 

"Accept: application/json" --header "Authorization: Basic AYWtrr7y23TnV0YW5peC8" -d "{
\"count\": 1,
\"valid_duration_in_minutes\": 527040
}" "https://10.136.107.69:9440/api/nutanix/v3/idempotence_identifiers"
{"client_identifier": null, "count": 1, "expiration_time": "2020-12-23T07:59:57Z", "uuid_list": ["a1d6b81b-a76c-495c-9a71-508167f810dd"]}



We can use now the returned idempotence identifier(a1d6b81b-a76c-495c-9a71-508167f810dd) in the /clone API

anish.singhwalia@C02XF4HA::~$ curl -k -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Basic AYWtrr7y23TnV0YW5peC8" -d "{
\"metadata\": {
\"uuid\": \"a1d6b81b-a76c-495c-9a71-508167f810dd\"
}
}" "https://10.136.107.69:9440/api/nutanix/v3/vms/9276242d-34r1-69f3-dfe8-5d1cb15569k2/clone"
{"task_uuid": "9bb26a3e-18cf-4fea-941a-cfe5e542c076"}

 

Now we can check the above task details and identify the UUID of the cloned VM:


anish.singhwalia@C02XF4HA:~$ curl -k -X GET --header "Accept: application/json" --header "Authorization: Basic AYWtrr7y23TnV0YW5peC8" "https://10.136.10769:9440/api/nutanix/v3/tasks/9bb26a3e-18cf-4fea-941a-cfe5e542c076"
{"status": "SUCCEEDED", "last_update_time": "2019-12-23T08:01:31Z", "logical_timestamp": 2, "entity_reference_list": [{"kind": "vm", "uuid": "a1d6b81b-a76c-495c-9a71-508167f810dd"}], "start_time": "2019-12-23T08:01:18Z", "creation_time": "2019-12-23T08:01:18Z", "start_time_usecs": 1577088078927590, "cluster_reference": {"kind": "cluster", "uuid": "r4fd3d69-3df4-5g3d-448e-6b9312655365"}, "subtask_reference_list": [], "completion_time": "2019-12-23T08:01:31Z", "creation_time_usecs": 1577088078874113, "progress_message": "", "operation_type": "ProcessVmClone", "completion_time_usecs": 1577088091347015, "percentage_complete": 100, "api_version": "3.1", "uuid": "9bb26a3e-18cf-4fea-941a-cfe5e542c076"}

 

I hope the above clarifies the procedure and helps you @Balram .

Let me know if you need anything else.:sweat_smile:

 

Userlevel 1
Badge +2

Hi Balram, 

The /clone API expects an idempotence identifier.
To get the idempotence identifier, we can use the API idempotence_identifiers.
It is mandatory to provide the count for how many identifiers we need and the lifetime until we can use it.

Can you open a Support case if possible so that this can be looked into detail ?