mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
M #-: Alert Error when delete provision (#1287)
(cherry picked from commit 0cd57ac3ec1a8d1e96caefe3f713e3a31719be13)
This commit is contained in:
parent
f3843fa2d3
commit
29ef52b896
@ -32,8 +32,8 @@ const fillPrivateRoutes = (methods = {}, path = '', action = () => undefined) =>
|
||||
Object.keys(methods).forEach((method) => {
|
||||
privateRoutes.push(
|
||||
fillRoute(method, path,
|
||||
(req, res, next, conection, userId, user) => {
|
||||
action(req, res, next, methods[method], user)
|
||||
(req, res, next, connection, userId, user) => {
|
||||
action(req, res, next, methods[method], user, connection)
|
||||
})
|
||||
)
|
||||
})
|
||||
|
@ -12,7 +12,7 @@
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
const { from: fromData } = require('server/utils/constants/defaults')
|
||||
const { from: fromData, defaultEmptyFunction } = require('server/utils/constants/defaults')
|
||||
const { getParamsForObject } = require('server/utils/server')
|
||||
const {
|
||||
getListProviders,
|
||||
@ -67,7 +67,7 @@ const routes = {
|
||||
}
|
||||
}
|
||||
|
||||
const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}, index = 0) => {
|
||||
const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}, oneConnection = defaultEmptyFunction, index = 0) => {
|
||||
const resources = Object.keys(req[fromData.resource])
|
||||
if (req && res && next && routes) {
|
||||
const route = routes[`${req[fromData.resource][resources[index]]}`.toLowerCase()]
|
||||
|
@ -19,6 +19,9 @@ const { Validator } = require('jsonschema')
|
||||
const { createWriteStream } = require('fs-extra')
|
||||
const { lockSync, checkSync, unlockSync } = require('lockfile')
|
||||
const { basename, dirname } = require('path')
|
||||
const { sprintf } = require('sprintf-js')
|
||||
|
||||
const { Actions } = require('server/utils/constants/commands/document')
|
||||
const {
|
||||
ok,
|
||||
notFound,
|
||||
@ -26,7 +29,7 @@ const {
|
||||
internalServerError
|
||||
} = require('server/utils/constants/http-codes')
|
||||
const { httpResponse, parsePostData, existsFile, createFile } = require('server/utils/server')
|
||||
const { defaultFolderTmpProvision, defaultCommandProvision } = require('server/utils/constants/defaults')
|
||||
const { defaultFolderTmpProvision, defaultCommandProvision, defaultEmptyFunction, defaultErrorTemplate } = require('server/utils/constants/defaults')
|
||||
const {
|
||||
executeCommand,
|
||||
executeCommandAsync,
|
||||
@ -72,9 +75,9 @@ const executeWithEmit = (command = [], actions = {}, dataForLog = {}) => {
|
||||
actions &&
|
||||
dataForLog
|
||||
) {
|
||||
const err = actions.err && typeof actions.err === 'function' ? actions.err : () => undefined
|
||||
const out = actions.out && typeof actions.out === 'function' ? actions.out : () => undefined
|
||||
const close = actions.close && typeof actions.close === 'function' ? actions.close : () => undefined
|
||||
const err = actions.err && typeof actions.err === 'function' ? actions.err : defaultEmptyFunction
|
||||
const out = actions.out && typeof actions.out === 'function' ? actions.out : defaultEmptyFunction
|
||||
const close = actions.close && typeof actions.close === 'function' ? actions.close : defaultEmptyFunction
|
||||
|
||||
// data for log
|
||||
const id = (dataForLog && dataForLog.id) || ''
|
||||
@ -86,7 +89,7 @@ const executeWithEmit = (command = [], actions = {}, dataForLog = {}) => {
|
||||
let pendingMessages = ''
|
||||
|
||||
// send data of command
|
||||
const emit = (message, callback = () => undefined) => {
|
||||
const emit = (message, callback = defaultEmptyFunction) => {
|
||||
const publisher = (line = '') => {
|
||||
const resposeData = callback(line, uuid) || { id, data: line, command: commandName, commandId: uuid }
|
||||
publish(defaultCommandProvision, resposeData)
|
||||
@ -189,7 +192,7 @@ const logData = (id, fullPath = false) => {
|
||||
return rtn
|
||||
}
|
||||
|
||||
const getProvisionDefaults = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const getProvisionDefaults = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const extFiles = 'yml'
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
@ -295,7 +298,7 @@ const getProvisionDefaults = (res = {}, next = () => undefined, params = {}, use
|
||||
next()
|
||||
}
|
||||
|
||||
const getList = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const getList = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (params && params.resource && user && password) {
|
||||
@ -315,7 +318,7 @@ const getList = (res = {}, next = () => undefined, params = {}, userData = {}) =
|
||||
next()
|
||||
}
|
||||
|
||||
const getListProvisions = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const getListProvisions = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (user && password) {
|
||||
@ -348,7 +351,7 @@ const getListProvisions = (res = {}, next = () => undefined, params = {}, userDa
|
||||
next()
|
||||
}
|
||||
|
||||
const deleteResource = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const deleteResource = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (params && params.resource && params.id && user && password) {
|
||||
@ -367,7 +370,7 @@ const deleteResource = (res = {}, next = () => undefined, params = {}, userData
|
||||
next()
|
||||
}
|
||||
|
||||
const deleteProvision = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const deleteProvision = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}, oneConnection = defaultEmptyFunction) => {
|
||||
const basePath = `${global.CPI}/provision`
|
||||
const relFile = `${basePath}/${relName}`
|
||||
const relFileYML = `${relFile}.${ext}`
|
||||
@ -393,7 +396,7 @@ const deleteProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
}
|
||||
|
||||
// This function is only executed if the command is completed
|
||||
const close = success => {
|
||||
const close = (success, lastLine) => {
|
||||
if (success) {
|
||||
stream && stream.end && stream.end()
|
||||
existsFile(
|
||||
@ -429,6 +432,9 @@ const deleteProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
)
|
||||
const findFolder = findRecursiveFolder(`${global.CPI}/provision`, params.id)
|
||||
findFolder && removeFile(findFolder)
|
||||
} else {
|
||||
const connect = oneConnection(user, password)
|
||||
connect(Actions.DOCUMENT_UPDATE, [parseInt(params.id, 10), sprintf(defaultErrorTemplate, lastLine), 1], defaultEmptyFunction)
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,7 +454,7 @@ const deleteProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
next()
|
||||
}
|
||||
|
||||
const hostCommand = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const hostCommand = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (params && params.action && params.id && user && password) {
|
||||
@ -469,7 +475,7 @@ const hostCommand = (res = {}, next = () => undefined, params = {}, userData = {
|
||||
next()
|
||||
}
|
||||
|
||||
const hostCommandSSH = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const hostCommandSSH = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (params && params.action && params.id && params.command && user && password) {
|
||||
@ -490,7 +496,7 @@ const hostCommandSSH = (res = {}, next = () => undefined, params = {}, userData
|
||||
next()
|
||||
}
|
||||
|
||||
const createProvision = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const createProvision = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}, oneConnection = defaultEmptyFunction) => {
|
||||
const basePath = `${global.CPI}/provision`
|
||||
const relFile = `${basePath}/${relName}`
|
||||
const relFileYML = `${relFile}.${ext}`
|
||||
@ -603,7 +609,7 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
next()
|
||||
}
|
||||
|
||||
const configureProvision = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const configureProvision = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
const rtn = httpInternalError
|
||||
if (params && params.id && user && password) {
|
||||
@ -644,7 +650,7 @@ const configureProvision = (res = {}, next = () => undefined, params = {}, userD
|
||||
next()
|
||||
}
|
||||
|
||||
const configureHost = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const configureHost = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
const rtn = httpInternalError
|
||||
if (params && params.id && user && password) {
|
||||
@ -685,7 +691,7 @@ const configureHost = (res = {}, next = () => undefined, params = {}, userData =
|
||||
next()
|
||||
}
|
||||
|
||||
const validate = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const validate = (res = {}, next = defaultEmptyFunction, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
if (params && params.resource && user && password) {
|
||||
@ -725,7 +731,7 @@ const validate = (res = {}, next = () => undefined, params = {}, userData = {})
|
||||
next()
|
||||
}
|
||||
|
||||
const getLogProvisions = (res = {}, next = () => undefined, params = {}) => {
|
||||
const getLogProvisions = (res = {}, next = defaultEmptyFunction, params = {}) => {
|
||||
let rtn = httpInternalError
|
||||
if (params && params.id) {
|
||||
const foundLogs = logData(params.id)
|
||||
|
@ -12,7 +12,7 @@
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
const { httpMethod, from: fromData } = require('server/utils/constants/defaults')
|
||||
const { httpMethod, from: fromData, defaultEmptyFunction } = require('server/utils/constants/defaults')
|
||||
const { getParamsForObject } = require('server/utils/server')
|
||||
const {
|
||||
getList,
|
||||
@ -219,7 +219,7 @@ const routes = {
|
||||
}
|
||||
}
|
||||
|
||||
const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}, index = 0) => {
|
||||
const main = (req = {}, res = {}, next = defaultEmptyFunction, routes = {}, user = {}, oneConnection = defaultEmptyFunction, index = 0) => {
|
||||
const resources = Object.keys(req[fromData.resource])
|
||||
if (req && res && next && routes) {
|
||||
const route = routes[`${req[fromData.resource][resources[index]]}`.toLowerCase()]
|
||||
@ -227,9 +227,9 @@ const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}
|
||||
if (Object.keys(route).length > 0 && route.constructor === Object) {
|
||||
if (route.action && route.params && typeof route.action === 'function') {
|
||||
const params = getParamsForObject(route.params, req)
|
||||
route.action(res, next, params, user)
|
||||
route.action(res, next, params, user, oneConnection)
|
||||
} else {
|
||||
main(req, res, next, route, user, index + 1)
|
||||
main(req, res, next, route, user, oneConnection, index + 1)
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
|
@ -12,7 +12,7 @@
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
const { from: fromData } = require('server/utils/constants/defaults')
|
||||
const { from: fromData, defaultEmptyFunction } = require('server/utils/constants/defaults')
|
||||
const { getParamsForObject } = require('server/utils/server')
|
||||
const {
|
||||
getListProvisionTemplates,
|
||||
@ -67,7 +67,7 @@ const routes = {
|
||||
}
|
||||
}
|
||||
|
||||
const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}, index = 0) => {
|
||||
const main = (req = {}, res = {}, next = defaultEmptyFunction, routes = {}, user = {}, oneConnection = defaultEmptyFunction, index = 0) => {
|
||||
const resources = Object.keys(req[fromData.resource])
|
||||
if (req && res && next && routes) {
|
||||
const route = routes[`${req[fromData.resource][resources[index]]}`.toLowerCase()]
|
||||
|
@ -83,6 +83,7 @@ router.all(
|
||||
user = getUserOpennebula(),
|
||||
pass = getPassOpennebula()
|
||||
) => opennebulaConnect(user, pass, rpc)
|
||||
|
||||
const { resource } = req.params
|
||||
const routeFunction = checkIfIsARouteFunction(resource, httpMethod)
|
||||
res.locals.httpCode = httpResponse(methodNotAllowed)
|
||||
@ -92,6 +93,7 @@ router.all(
|
||||
[fromData.postBody]: req.body
|
||||
}
|
||||
if (routeFunction) {
|
||||
// this execute functions
|
||||
const valRouteFunction = checkMethodRouteFunction(
|
||||
routeFunction,
|
||||
httpMethod
|
||||
@ -110,6 +112,7 @@ router.all(
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
// this execute a XMLRPC commands
|
||||
const { method } = getParamsState()
|
||||
const command = commandXML(
|
||||
resource,
|
||||
@ -140,11 +143,7 @@ router.all(
|
||||
res.locals.httpCode = code
|
||||
}
|
||||
}
|
||||
const connect = connectOpennebula(
|
||||
getUserOpennebula(),
|
||||
getPassOpennebula(),
|
||||
rpc
|
||||
)
|
||||
const connect = connectOpennebula()
|
||||
connect(command, getOpennebulaMethod(dataSources), (err, value) =>
|
||||
responseOpennebula(updaterResponse, err, value, response, next)
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ const {
|
||||
getIdUserOpennebula,
|
||||
getUserOpennebula,
|
||||
getPassOpennebula
|
||||
} = require('./api');
|
||||
} = require('./api')
|
||||
|
||||
module.exports = {
|
||||
validateResourceAndSession,
|
||||
@ -34,4 +34,4 @@ module.exports = {
|
||||
getIdUserOpennebula,
|
||||
getUserOpennebula,
|
||||
getPassOpennebula
|
||||
};
|
||||
}
|
||||
|
@ -16,17 +16,17 @@
|
||||
const {
|
||||
from: { resource, postBody, query },
|
||||
httpMethod: { GET, POST, PUT, DELETE }
|
||||
} = require('../defaults');
|
||||
} = require('../defaults')
|
||||
|
||||
const DATASTORE_ALLOCATE = 'datastore.allocate';
|
||||
const DATASTORE_DELETE = 'datastore.delete';
|
||||
const DATASTORE_UPDATE = 'datastore.update';
|
||||
const DATASTORE_CHMOD = 'datastore.chmod';
|
||||
const DATASTORE_CHOWN = 'datastore.chown';
|
||||
const DATASTORE_RENAME = 'datastore.rename';
|
||||
const DATASTORE_ENABLE = 'datastore.enable';
|
||||
const DATASTORE_INFO = 'datastore.info';
|
||||
const DATASTORE_POOL_INFO = 'datastorepool.info';
|
||||
const DATASTORE_ALLOCATE = 'datastore.allocate'
|
||||
const DATASTORE_DELETE = 'datastore.delete'
|
||||
const DATASTORE_UPDATE = 'datastore.update'
|
||||
const DATASTORE_CHMOD = 'datastore.chmod'
|
||||
const DATASTORE_CHOWN = 'datastore.chown'
|
||||
const DATASTORE_RENAME = 'datastore.rename'
|
||||
const DATASTORE_ENABLE = 'datastore.enable'
|
||||
const DATASTORE_INFO = 'datastore.info'
|
||||
const DATASTORE_POOL_INFO = 'datastorepool.info'
|
||||
|
||||
const Actions = {
|
||||
DATASTORE_ALLOCATE,
|
||||
@ -38,7 +38,7 @@ const Actions = {
|
||||
DATASTORE_ENABLE,
|
||||
DATASTORE_INFO,
|
||||
DATASTORE_POOL_INFO
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Actions,
|
||||
@ -197,4 +197,4 @@ module.exports = {
|
||||
params: {}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -16,19 +16,19 @@
|
||||
const {
|
||||
from: { resource, postBody, query },
|
||||
httpMethod: { GET, POST, PUT, DELETE }
|
||||
} = require('../defaults');
|
||||
} = require('../defaults')
|
||||
|
||||
const DOCUMENT_ALLOCATE = 'document.allocate';
|
||||
const DOCUMENT_CLONE = 'document.clone';
|
||||
const DOCUMENT_DELETE = 'document.delete';
|
||||
const DOCUMENT_UPDATE = 'document.update';
|
||||
const DOCUMENT_CHMOD = 'document.chmod';
|
||||
const DOCUMENT_CHOWN = 'document.chown';
|
||||
const DOCUMENT_RENAME = 'document.rename';
|
||||
const DOCUMENT_INFO = 'document.info';
|
||||
const DOCUMENT_LOCK = 'document.lock';
|
||||
const DOCUMENT_UNLOCK = 'document.unlock';
|
||||
const DOCUMENT_POOL_INFO = 'documentpool.info';
|
||||
const DOCUMENT_ALLOCATE = 'document.allocate'
|
||||
const DOCUMENT_CLONE = 'document.clone'
|
||||
const DOCUMENT_DELETE = 'document.delete'
|
||||
const DOCUMENT_UPDATE = 'document.update'
|
||||
const DOCUMENT_CHMOD = 'document.chmod'
|
||||
const DOCUMENT_CHOWN = 'document.chown'
|
||||
const DOCUMENT_RENAME = 'document.rename'
|
||||
const DOCUMENT_INFO = 'document.info'
|
||||
const DOCUMENT_LOCK = 'document.lock'
|
||||
const DOCUMENT_UNLOCK = 'document.unlock'
|
||||
const DOCUMENT_POOL_INFO = 'documentpool.info'
|
||||
|
||||
const Actions = {
|
||||
DOCUMENT_ALLOCATE,
|
||||
@ -42,7 +42,7 @@ const Actions = {
|
||||
DOCUMENT_LOCK,
|
||||
DOCUMENT_UNLOCK,
|
||||
DOCUMENT_POOL_INFO
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Actions,
|
||||
@ -223,10 +223,6 @@ module.exports = {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
@ -241,9 +237,9 @@ module.exports = {
|
||||
},
|
||||
type: {
|
||||
from: query,
|
||||
default: 0
|
||||
default: 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ const default2FAOpennebulaVar = 'TWO_FACTOR_AUTH_SECRET'
|
||||
const defaultIp = 'localhost'
|
||||
const protocol = 'http'
|
||||
const defaults = {
|
||||
defaultEmptyFunction: () => undefined,
|
||||
defaultErrorTemplate: 'ERROR_FIREEDGE="%1$s"',
|
||||
defaultOpennebulaExpiration: 180,
|
||||
defaultOpennebulaMinimumExpiration: 30,
|
||||
defaultAppName: appName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user