Unable to attach disk using REST API methods.
Issue
-
Using REST API version 3 documentation to create VM backups.
-
With the REST API command, we are doing the following and it fails at step four.
- Search the VM to back up which is called DATA_VM
- Search the AGENT_VM UUID that is will perform the backup
- Create a snapshot of the DATA_VM
- Attach the snapshot disk of the DATA_VM to the AGENT_VM.
-
The following is a sample script with REST API commands.
1 HOST='ovirt-engine.example.com'
2 USER='admin'
3 DOMAIN='internal'
4 PASS='my_password'
5 DATA_VM='my_prod_vm'
6 AGENT_VM='my_backup_agent_vm'
7 DESCRIPTION='my_backup'
8
9 # Search the VM to back up which is called DATA_VM
10
11 SNAPURL=$(curl -k -u "${USER}@${DOMAIN}:${PASS}" -X GET https://${HOST}/ovirt-engine/api/v3/vms?search=${DATA_VM} | xmllint --xpath 'string(//link[@rel="snapshots"]/@href)' -)
12
13 # Search the AGENT_VM UUID that is will perform the backup
14
15 BACKUPURL=$(curl -k -u "${USER}@${DOMAIN}:${PASS}" -X GET https://${HOST}/ovirt-engine/api/v3/vms?search=${AGENT_VM} | xmllint --xpath 'string(/vms/vm/@href)' -)
16
17 # Create a snapshot of the DATA_VM
18
19 URLDISK=$(curl -k -u "${USER}@${DOMAIN}:${PASS}" -X POST -H "Accept: application/xml" -H "Content-type: application/xml" https://${HOST}${SNAPURL} --data-binary @- << EOF | xmllint --xpath 'string(//link[@rel="disks"]/@href)' -
20 <snapshot>
21 <description>${DESCRIPTION}</description>
22 </snapshot>
23 EOF)
24
25 # Attach the snapshot disk of the DATA_VM to the AGENT_VM.
26
27 curl -k -u "$USER@$DOMAIN:$PASS" -X GET https://${HOST}${URLDISK} > disktmp.xml
28
29 IDDISK=$(xmllint --xpath 'string(/disks/disk/@id)' disktmp.xml)
30 IDSNAP=$(xmllint --xpath 'string(/disks/disk/snapshot/@id)' disktmp.xml)
31
32 curl -k -u "${USER}@${DOMAIN}:${PASS}" -X POST -H "Accept: application/xml" -H "Content-type: application/xml" https://${HOST}${BACKUPURL}/disks/ --data-binary @- << EOF
33 <disk id=\"${IDDISK}\">
34 <snapshot id=\"${IDSNAP}\"/>
35 <active>true</active>
36 </disk>
37 EOF
Environment
- Red Hat Virtualization (RHV) version 4.3
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.