1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-13 13:17:39 +03:00

F #5422: Add lock and unlock requests (#1511)

This commit is contained in:
Sergio Betanzos 2021-10-07 16:08:55 +02:00 committed by GitHub
parent 292b62d7ce
commit 22f5a6ef14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 2 deletions

View File

@ -86,6 +86,8 @@ export const addScheduledAction = createAction(`${VM}/add/scheduled-action`, vmS
export const updateScheduledAction = createAction(`${VM}/update/scheduled-action`, vmService.updateScheduledAction)
export const deleteScheduledAction = createAction(`${VM}/delete/scheduled-action`, vmService.deleteScheduledAction)
export const recover = createAction(`${VM}/recover`, vmService.recover)
export const lock = createAction(`${VM}/lock`, vmService.lock)
export const unlock = createAction(`${VM}/unlock`, vmService.unlock)
export const deploy = createAction(`${VM}/deploy`, vmService.deploy)
export const migrate = createAction(`${VM}/migrate`, vmService.migrate)
export const migrateLive = createAction(`${VM}/migrate-live`, vmService.migrate)

View File

@ -86,6 +86,8 @@ export const useVmApi = () => {
deleteScheduledAction: (id, data) =>
unwrapDispatch(actions.deleteScheduledAction({ id, ...data })),
recover: (id, operation) => unwrapDispatch(actions.recover({ id, operation })),
lock: (id, data) => unwrapDispatch(actions.lock({ id, ...data })),
unlock: id => unwrapDispatch(actions.unlock({ id })),
deploy: (id, data) => unwrapDispatch(actions.deploy({ id, ...data })),
migrate: (id, data) => unwrapDispatch(actions.migrate({ id, ...data, live: false })),
migrateLive: (id, data) => unwrapDispatch(actions.migrate({ id, ...data, live: true }))

View File

@ -597,6 +597,53 @@ export const vmService = ({
return res?.data
},
/**
* Locks a virtual machine. Lock certain actions depending on blocking level.
*
* @param {object} params - Request parameters
* @param {string|number} params.id - Virtual machine id
* @param {1|2|3|4} params.level
* - Lock level:
* ``1``: Use
* ``2``: Manage
* ``3``: Admin
* ``4``: All
* @param {boolean} params.test - Check if the object is already locked to return an error
* @returns {number} Virtual machine id
* @throws Fails when response isn't code 200
*/
lock: async params => {
const name = Actions.VM_LOCK
const command = { name, ...Commands[name] }
const config = requestConfig(params, command)
const res = await RestClient.request(config)
if (!res?.id || res?.id !== httpCodes.ok.id) throw res?.data
return res?.data
},
/**
* Unlocks a virtual machine.
*
* @param {object} params - Request parameters
* @param {string|number} params.id - Virtual machine id
* @returns {number} Virtual machine id
* @throws Fails when response isn't code 200
*/
unlock: async params => {
const name = Actions.VM_UNLOCK
const command = { name, ...Commands[name] }
const config = requestConfig(params, command)
const res = await RestClient.request(config)
if (!res?.id || res?.id !== httpCodes.ok.id) throw res?.data
return res?.data
},
/**
* Initiates the instance of the given VM id on the target host.
*

View File

@ -234,7 +234,7 @@ export const vmTemplateService = ({
*
* @param {object} params - Request parameters
* @param {string|number} params.id - Template id
* @param {1|2|3|4} params.lock
* @param {1|2|3|4} params.level
* - Lock level:
* ``1``: Use
* ``2``: Manage

View File

@ -226,7 +226,7 @@ module.exports = {
from: resource,
default: 0
},
lock: {
level: {
from: postBody,
default: 4
},

View File

@ -575,6 +575,10 @@ module.exports = {
level: {
from: postBody,
default: 4
},
test: {
from: postBody,
default: false
}
}
},