mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
(cherry picked from commit cd533b685c65b6371f5ceb61b523eca575e269ba)
This commit is contained in:
parent
500219e637
commit
bf06efd1a1
@ -15,6 +15,7 @@
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
// INFORMATION
|
||||
export const REFRESH = 'refresh'
|
||||
export const RENAME = 'rename'
|
||||
|
||||
// ATTRIBUTES
|
||||
|
@ -14,6 +14,7 @@
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
import * as STATES from 'client/constants/states'
|
||||
import * as ACTIONS from 'client/constants/actions'
|
||||
import COLOR from 'client/constants/color'
|
||||
|
||||
/**
|
||||
@ -80,3 +81,15 @@ export const HOST_STATES = [
|
||||
color: COLOR.error.dark,
|
||||
},
|
||||
]
|
||||
|
||||
/** @enum {string} Host actions */
|
||||
export const HOST_ACTIONS = {
|
||||
REFRESH: ACTIONS.REFRESH,
|
||||
CREATE_DIALOG: 'create_dialog',
|
||||
RENAME: ACTIONS.RENAME,
|
||||
ADD_TO_CLUSTER: 'addtocluster',
|
||||
ENABLE: 'enable',
|
||||
DISABLE: 'disable',
|
||||
OFFLINE: 'offline',
|
||||
DELETE: 'delete',
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ export const VM_LCM_STATES = [
|
||||
|
||||
/** @enum {string} Virtual machine actions */
|
||||
export const VM_ACTIONS = {
|
||||
REFRESH: 'refresh',
|
||||
REFRESH: ACTIONS.REFRESH,
|
||||
CREATE_DIALOG: 'create_dialog',
|
||||
CREATE_APP_DIALOG: 'create_app_dialog',
|
||||
DEPLOY: 'deploy',
|
||||
|
@ -16,7 +16,7 @@
|
||||
import * as ACTIONS from 'client/constants/actions'
|
||||
|
||||
export const VM_TEMPLATE_ACTIONS = {
|
||||
REFRESH: 'refresh',
|
||||
REFRESH: ACTIONS.REFRESH,
|
||||
CREATE_DIALOG: 'create_dialog',
|
||||
IMPORT_DIALOG: 'import_dialog',
|
||||
UPDATE_DIALOG: 'update_dialog',
|
||||
|
@ -27,3 +27,19 @@ export const getHosts = createAction(
|
||||
hostService.getHosts,
|
||||
(response) => ({ [RESOURCES.host]: response })
|
||||
)
|
||||
|
||||
export const allocate = createAction(`${HOST}/allocate`, hostService.allocate)
|
||||
export const remove = createAction(`${HOST}/delete`, hostService.delete)
|
||||
export const enable = createAction(`${HOST}/enable`, hostService.enable)
|
||||
export const disable = createAction(`${HOST}/disable`, hostService.disable)
|
||||
export const offline = createAction(`${HOST}/offline`, hostService.offline)
|
||||
export const update = createAction(`${HOST}/update`, hostService.update)
|
||||
export const rename = createAction(`${HOST}/rename`, hostService.rename)
|
||||
export const monitoring = createAction(
|
||||
`${HOST}/monitoring`,
|
||||
hostService.monitoring
|
||||
)
|
||||
export const monitoringPool = createAction(
|
||||
`${HOST}/monitoring-pool`, // ends with "-pool" to differentiate with resource pool
|
||||
hostService.monitoringPool
|
||||
)
|
||||
|
@ -35,5 +35,17 @@ export const useHostApi = () => {
|
||||
return {
|
||||
getHost: (id) => unwrapDispatch(actions.getHost({ id })),
|
||||
getHosts: (options) => unwrapDispatch(actions.getHosts(options)),
|
||||
allocate: (data) => unwrapDispatch(actions.allocate(data)),
|
||||
remove: (id) => unwrapDispatch(actions.remove({ id })),
|
||||
enable: (id) => unwrapDispatch(actions.enable({ id })),
|
||||
disable: (id) => unwrapDispatch(actions.disable({ id })),
|
||||
offline: (id) => unwrapDispatch(actions.offline({ id })),
|
||||
update: (id, template, replace) =>
|
||||
unwrapDispatch(actions.update({ id, template, replace })),
|
||||
rename: (id, newName) =>
|
||||
unwrapDispatch(actions.rename({ id, name: newName })),
|
||||
getMonitoring: (id) => unwrapDispatch(actions.monitoring({ id })),
|
||||
getMonitoringPool: (seconds) =>
|
||||
unwrapDispatch(actions.monitoringPool({ seconds })),
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,199 @@ export const hostService = {
|
||||
|
||||
return [res?.data?.HOST_POOL?.HOST ?? []].flat()
|
||||
},
|
||||
/**
|
||||
* Allocates a new host in OpenNebula.
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {string} params.hostname - Hostname of the machine we want to add
|
||||
* @param {string} params.imMad
|
||||
* - The name of the information manager (im_mad_name),
|
||||
* this values are taken from the oned.conf with the tag name IM_MAD (name)
|
||||
* @param {string} params.vmmMad
|
||||
* - The name of the virtual machine manager mad name (vmm_mad_name),
|
||||
* this values are taken from the oned.conf with the tag name VM_MAD (name)
|
||||
* @param {string|number} [params.cluster] - The cluster ID
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
allocate: async (params) => {
|
||||
const name = Actions.HOST_ALLOCATE
|
||||
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
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes the given host from the pool.
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Host id
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
delete: async (params) => {
|
||||
const name = Actions.HOST_DELETE
|
||||
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
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the status of the host to enabled.
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Host id
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
enable: async (params) => {
|
||||
const name = Actions.HOST_STATUS
|
||||
const command = { name, ...Commands[name] }
|
||||
const config = requestConfig({ ...params, status: 0 }, command)
|
||||
|
||||
const res = await RestClient.request(config)
|
||||
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the status of the host to disabled.
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Host id
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
disable: async (params) => {
|
||||
const name = Actions.HOST_STATUS
|
||||
const command = { name, ...Commands[name] }
|
||||
const config = requestConfig({ ...params, status: 1 }, command)
|
||||
|
||||
const res = await RestClient.request(config)
|
||||
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the status of the host to offline.
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Host id
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
offline: async (params) => {
|
||||
const name = Actions.HOST_STATUS
|
||||
const command = { name, ...Commands[name] }
|
||||
const config = requestConfig({ ...params, status: 2 }, command)
|
||||
|
||||
const res = await RestClient.request(config)
|
||||
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Replaces the host’s template contents..
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Host id
|
||||
* @param {string} params.template - The new template contents
|
||||
* @param {0|1} params.replace
|
||||
* - Update type:
|
||||
* ``0``: Replace the whole template.
|
||||
* ``1``: Merge new template with the existing one.
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
update: async (params) => {
|
||||
const name = Actions.HOST_UPDATE
|
||||
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
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Renames a host.
|
||||
*
|
||||
* @param {object} params - Request parameters
|
||||
* @param {string|number} params.id - Host id
|
||||
* @param {string} params.name - New name
|
||||
* @returns {number} Host id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
rename: async (params) => {
|
||||
const name = Actions.HOST_RENAME
|
||||
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
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the host monitoring records.
|
||||
*
|
||||
* @param {object} params - Request parameters
|
||||
* @param {string|number} params.id - Host id
|
||||
* @returns {string} The monitoring information string / The error string
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
monitoring: async (params) => {
|
||||
const name = Actions.HOST_MONITORING
|
||||
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
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns all the host monitoring records.
|
||||
*
|
||||
* @param {object} params - Request parameters
|
||||
* @param {string|number} [params.seconds]
|
||||
* - Retrieve monitor records in the last num seconds.
|
||||
* ``0``: Only the last record.
|
||||
* ``-1``: All records.
|
||||
* @returns {string} The monitoring information string / The error string
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
monitoringPool: async (params) => {
|
||||
const name = Actions.HOST_POOL_MONITORING
|
||||
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
|
||||
},
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ export const vmTemplateService = {
|
||||
*
|
||||
* @param {object} params - Request params
|
||||
* @param {number|string} params.id - Template id
|
||||
* @param {boolean} params.template - The new template contents
|
||||
* @param {string} params.template - The new template contents
|
||||
* @param {0|1} params.replace
|
||||
* - Update type:
|
||||
* ``0``: Replace the whole template.
|
||||
|
@ -52,11 +52,11 @@ module.exports = {
|
||||
from: postBody,
|
||||
default: '',
|
||||
},
|
||||
information: {
|
||||
imMad: {
|
||||
from: postBody,
|
||||
default: '',
|
||||
},
|
||||
manager: {
|
||||
vmmMad: {
|
||||
from: postBody,
|
||||
default: '',
|
||||
},
|
||||
@ -154,7 +154,12 @@ module.exports = {
|
||||
[HOST_POOL_MONITORING]: {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {},
|
||||
params: {
|
||||
seconds: {
|
||||
from: query,
|
||||
default: -1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user