feat(xo-server/rest-api): support to destroy VMs/VDIs
This commit is contained in:
@@ -121,6 +121,28 @@ Content-Type: application/x-ndjson
|
||||
{"name_label":"Debian 10 Cloudinit self-service","power_state":"Halted","url":"/rest/v0/vms/5019156b-f40d-bc57-835b-4a259b177be1"}
|
||||
```
|
||||
|
||||
## VM and VDI destruction
|
||||
|
||||
For a VM:
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X DELETE \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.example.org/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac' \
|
||||
| cat
|
||||
```
|
||||
|
||||
For a VDI:
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X DELETE \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.example.org/rest/v0/vdis/1a269782-ea93-4c4c-897a-475365f7b674' \
|
||||
| cat
|
||||
```
|
||||
|
||||
## VM and VDI export
|
||||
|
||||
VDI export and VM export are supported by the API. Below is a simple example to export a VM with `zstd` compression into a `myVM.xva` file:
|
||||
|
||||
@@ -111,6 +111,16 @@ Content-Type: application/x-ndjson
|
||||
{"name_label":"Debian 10 Cloudinit self-service","power_state":"Halted","url":"/rest/v0/vms/5019156b-f40d-bc57-835b-4a259b177be1"}
|
||||
```
|
||||
|
||||
## VM destruction
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X DELETE \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.company.lan/rest/v0/vms/770aa52a-fd42-8faf-f167-8c5c4a237cac' \
|
||||
| cat
|
||||
```
|
||||
|
||||
## VM Export
|
||||
|
||||
A VM can be exported as an XVA at `/rest/v0/vms/<uuid>.xva`.
|
||||
@@ -127,6 +137,16 @@ curl \
|
||||
> myVM.xva
|
||||
```
|
||||
|
||||
## VDI destruction
|
||||
|
||||
```bash
|
||||
curl \
|
||||
-X DELETE \
|
||||
-b authenticationToken=KQxQdm2vMiv7jBIK0hgkmgxKzemd8wSJ7ugFGKFkTbs \
|
||||
'https://xo.company.lan/rest/v0/vdis/1a269782-ea93-4c4c-897a-475365f7b674' \
|
||||
| cat
|
||||
```
|
||||
|
||||
## VDI Export
|
||||
|
||||
A VM can be exported as an VHD at `/rest/v0/vdis/<uuid>.vhd`.
|
||||
|
||||
@@ -149,6 +149,20 @@ export default class RestApi {
|
||||
}
|
||||
})
|
||||
|
||||
api.delete('/vdi:subtype(|-snapshot)s/:uuid', async (req, res, next) => {
|
||||
try {
|
||||
const { subtype, uuid } = req.params
|
||||
const vdi = app.getXapiObject(uuid, 'VDI' + subtype)
|
||||
await vdi.$destroy()
|
||||
res.sendStatus(200)
|
||||
} catch (error) {
|
||||
if (noSuchObject.is(error)) {
|
||||
next()
|
||||
} else {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
api.get('/vdi:subtype(|-snapshot)s/:uuid.vhd', async (req, res, next) => {
|
||||
try {
|
||||
const { subtype, uuid } = req.params
|
||||
@@ -168,6 +182,20 @@ export default class RestApi {
|
||||
}
|
||||
})
|
||||
|
||||
api.delete('/vm:subtype(|-snapshot|-template)s/:uuid', async (req, res, next) => {
|
||||
try {
|
||||
const { subtype, uuid } = req.params
|
||||
const vm = app.getXapiObject(uuid, 'VM' + subtype)
|
||||
await vm.$destroy()
|
||||
res.sendStatus(200)
|
||||
} catch (error) {
|
||||
if (noSuchObject.is(error)) {
|
||||
next()
|
||||
} else {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
api.get('/vm:subtype(|-snapshot|-template)s/:uuid.xva', async (req, res, next) => {
|
||||
try {
|
||||
const { subtype, uuid } = req.params
|
||||
|
||||
Reference in New Issue
Block a user