1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #3951: FireEdge adjustments (#797)

For container deployment

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-02-11 18:16:27 +01:00 committed by GitHub
parent 05e6d4472a
commit c4e39c39ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 52 deletions

View File

@ -305,17 +305,21 @@ const executeCommand = (command = '', resource = '', options = {}) => {
const findRecursiveFolder = (path = '', finder = '', rtn = false) => {
if (path && finder) {
const dirs = readdirSync(path)
dirs.forEach(dir => {
const name = `${path}/${dir}`
if (statSync(name).isDirectory()) {
if (basename(name) === finder) {
rtn = name
} else {
rtn = findRecursiveFolder(name, finder, rtn)
try {
const dirs = readdirSync(path)
dirs.forEach(dir => {
const name = `${path}/${dir}`
if (statSync(name).isDirectory()) {
if (basename(name) === finder) {
rtn = name
} else {
rtn = findRecursiveFolder(name, finder, rtn)
}
}
}
})
})
} catch (error) {
messageTerminal(defaultError((error && error.message) || '', 'Error: %s'))
}
}
return rtn
}

View File

@ -14,7 +14,7 @@
/* -------------------------------------------------------------------------- */
const { Validator } = require('jsonschema')
const { tmpPath, defaultCommandProvider } = require('server/utils/constants/defaults')
const { defaultFolderTmpProvision, defaultCommandProvider } = require('server/utils/constants/defaults')
const {
ok,
@ -76,7 +76,7 @@ const createProviders = (res = {}, next = () => undefined, params = {}, userData
if (valSchema.valid) {
const content = createYMLContent(resource)
if (content) {
const file = createTemporalFile(tmpPath, 'yaml', content)
const file = createTemporalFile(`${global.CPI}/${defaultFolderTmpProvision}`, 'yaml', content)
if (file && file.name && file.path) {
const paramsCommand = ['create', file.path, ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
@ -86,11 +86,11 @@ const createProviders = (res = {}, next = () => undefined, params = {}, userData
const data = executedCommand.data
const dataInternal = data && Array.isArray(data.match('\\d+')) ? data.match('\\d+').join() : data
res.locals.httpCode = httpResponse(ok, dataInternal)
removeFile(file.path)
} else {
res.locals.httpCode = httpResponse(internalServerError, '', executedCommand.data)
}
}
removeFile(file.path)
next()
return
}
@ -119,15 +119,15 @@ const updateProviders = (res = {}, next = () => undefined, params = {}, userData
const resource = parsePostData(params.resource)
const valSchema = schemaValidator.validate(resource, providerUpdate)
if (valSchema.valid) {
const file = createTemporalFile(tmpPath, 'json', JSON.stringify(resource))
const file = createTemporalFile(`${global.CPI}/${defaultFolderTmpProvision}`, 'json', JSON.stringify(resource))
if (file && file.name && file.path) {
const paramsCommand = ['update', params.id, file.path, ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
res.locals.httpCode = httpResponse(internalServerError)
if (executedCommand && executedCommand.success) {
res.locals.httpCode = httpResponse(ok)
removeFile(file.path)
}
removeFile(file.path)
next()
return
}
@ -156,7 +156,7 @@ const deleteProvider = (res = {}, next = () => undefined, params = {}, userData
const data = executedCommand.data || ''
try {
if (executedCommand && executedCommand.success) {
if(executedCommand.data.length === 0){
if (executedCommand.data.length === 0) {
res.locals.httpCode = httpResponse(ok)
} else {
res.locals.httpCode = httpResponse(internalServerError, '', executedCommand.data)

View File

@ -26,7 +26,7 @@ const {
internalServerError
} = require('server/utils/constants/http-codes')
const { httpResponse, parsePostData, existsFile, createFile } = require('server/utils/server')
const { tmpPath, defaultCommandProvision } = require('server/utils/constants/defaults')
const { defaultFolderTmpProvision, defaultCommandProvision } = require('server/utils/constants/defaults')
const {
executeCommand,
executeCommandAsync,
@ -176,8 +176,8 @@ const getProvisionDefaults = (res = {}, next = () => undefined, params = {}, use
const authCommand = ['--user', user, '--password', password]
const directories = getDirectories(path)
let description = ''
const providers = {}
const provisions = {}
let providers = {}
let provisions = {}
const fillDescription = (content = '') => {
if (content) {
description = content
@ -248,12 +248,17 @@ const getProvisionDefaults = (res = {}, next = () => undefined, params = {}, use
(content, filePath) => fillProvisions(content, filePath, dirname(file))
)
})
if (description && !checkEmpty(providers) && !checkEmpty(provisions)) {
files[directory.filename] = {
description,
providers,
provisions
}
// clear
description = ''
providers = {}
provisions = {}
}
}
})
@ -603,21 +608,36 @@ const configureProvision = (res = {}, next = () => undefined, params = {}, userD
const configureHost = (res = {}, next = () => undefined, params = {}, userData = {}) => {
const { user, password } = userData
let rtn = httpInternalError
const rtn = httpInternalError
if (params && params.id && user && password) {
const command = 'configure'
const endpoint = getEndpoint()
const authCommand = ['--user', user, '--password', password]
const paramsCommand = ['host', 'configure', `${params.id}`.toLowerCase(), '--debug', '--fail_cleanup', '--batch', ...authCommand, ...endpoint]
const paramsCommand = ['host', command, `${params.id}`.toLowerCase(), '--debug', '--fail_cleanup', '--batch', ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
try {
const response = executedCommand.success ? ok : internalServerError
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
next()
return
} catch (error) {
rtn = httpResponse(internalServerError, '', executedCommand.data)
// get Log file
const dataLog = logData(params.id, true)
// create stream for write into file
const stream = dataLog && dataLog.fullPath && createWriteStream(dataLog.fullPath, { flags: 'a' })
// This function is performed for each command line response
const emit = (lastLine, uuid) => {
const renderLine = { id: params.id, data: lastLine, command: `host ${command}`, commandId: uuid }
stream && stream.write && stream.write(`${JSON.stringify(renderLine)}\n`)
}
const close = (success, lastLine) => {
stream && stream.end && stream.end()
}
// execute Async Command
const executedCommand = executeWithEmit(paramsCommand, { close, out: emit, err: emit }, params.id)
// response Http
res.locals.httpCode = httpResponse(executedCommand ? accepted : internalServerError, params.id)
next()
return
}
res.locals.httpCode = rtn
next()
@ -635,15 +655,15 @@ const validate = (res = {}, next = () => undefined, params = {}, userData = {})
if (valSchema.valid) {
const content = createYMLContent(resource)
if (content) {
const file = createTemporalFile(tmpPath, 'yaml', content)
const file = createTemporalFile(`${global.CPI}/${defaultFolderTmpProvision}`, 'yaml', content)
if (file && file.name && file.path) {
const paramsCommand = ['validate', '--dump', file.path, ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
let response = internalServerError
if (executedCommand && executedCommand.success) {
response = ok
removeFile(file)
}
removeFile(file)
res.locals.httpCode = httpResponse(response)
next()
return

View File

@ -14,7 +14,7 @@
/* -------------------------------------------------------------------------- */
const { Validator } = require('jsonschema')
const { tmpPath, defaultCommandProvisionTemplate } = require('server/utils/constants/defaults')
const { defaultFolderTmpProvision, defaultCommandProvisionTemplate } = require('server/utils/constants/defaults')
const {
ok,
@ -62,15 +62,15 @@ const createProvisionTemplate = (res = {}, next = () => undefined, params = {},
if (valSchema.valid) {
const content = createYMLContent(resource)
if (content) {
const file = createTemporalFile(tmpPath, 'yaml', content)
const file = createTemporalFile(`${global.CPI}/${defaultFolderTmpProvision}`, 'yaml', content)
if (file && file.name && file.path) {
const paramsCommand = ['create', file.path, ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
res.locals.httpCode = httpResponse(internalServerError)
if (executedCommand && executedCommand.success && executedCommand.data) {
res.locals.httpCode = httpResponse(ok, executedCommand.data)
removeFile(file.path)
}
removeFile(file.path)
next()
return
}
@ -122,15 +122,15 @@ const updateProvisionTemplate = (res = {}, next = () => undefined, params = {},
if (valSchema.valid) {
const content = createYMLContent(resource)
if (content) {
const file = createTemporalFile(tmpPath, 'yaml', content)
const file = createTemporalFile(`${global.CPI}/${defaultFolderTmpProvision}`, 'yaml', content)
if (file && file.name && file.path) {
const paramsCommand = ['update', params.id, file.path, ...authCommand, ...endpoint]
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
res.locals.httpCode = httpResponse(internalServerError)
if (executedCommand && executedCommand.success && executedCommand.data) {
res.locals.httpCode = httpResponse(ok, executedCommand.data)
removeFile(file.path)
}
removeFile(file.path)
next()
return
}

View File

@ -17,8 +17,6 @@ const express = require('express')
const { defaults, httpCodes, params } = require('server/utils/constants')
const { getConfig } = require('server/utils/yml')
const appConfig = getConfig()
const {
opennebulaConnect,
checkIfIsARouteFunction,
@ -50,17 +48,6 @@ const {
defaultOpennebulaZones
} = defaults
const defaultZones = defaultOpennebulaZones
if (
appConfig &&
appConfig.one_xmlrpc &&
Array.isArray(defaultOpennebulaZones) &&
defaultOpennebulaZones[0] &&
defaultOpennebulaZones[0].rpc
) {
defaultOpennebulaZones[0].rpc = appConfig.one_xmlrpc
}
const router = express.Router()
express()
@ -79,7 +66,17 @@ router.all(
const { method: httpMethod } = req
res.locals.httpCode = httpResponse(internalServerError)
const { zone } = getQueriesState()
const zoneData = getDataZone(zone, defaultZones)
// get data zones by config file
const appConfig = getConfig()
if (
appConfig.one_xmlrpc &&
Array.isArray(defaultOpennebulaZones) &&
defaultOpennebulaZones[0] &&
defaultOpennebulaZones[0].rpc
) {
defaultOpennebulaZones[0].rpc = appConfig.one_xmlrpc
}
const zoneData = getDataZone(zone, defaultOpennebulaZones)
if (zoneData) {
const { rpc } = zoneData
const connectOpennebula = (

View File

@ -26,7 +26,7 @@ const apps = {
}
}
const default2FAOpennebulaVar = 'TWO_FACTOR_AUTH_SECRET'
const defaultIp = '127.0.0.1'
const defaultIp = 'localhost'
const protocol = 'http'
const defaults = {
defaultLimit: {
@ -74,6 +74,7 @@ const defaults = {
defaultCommandProvision: 'oneprovision',
defaultCommandProvisionTemplate: 'oneprovision-template',
defaultCommandProvider: 'oneprovider',
defaultFolderTmpProvision: 'tmp',
defaultOneFlowServer: `${protocol}://${defaultIp}:2474`,
defaultEndpointWebsocket: `${appName ? '/' + appName : ''}/websocket`,
defaultConfigFile: `${appName}-server.conf`,
@ -89,7 +90,6 @@ const defaults = {
defaultKeyFilename: `${appName}_key`,
defaultVmrcTokens: 'sunstone_vmrc_tokens/',
defaultBaseURL: '',
tmpPath: '/var/tmp',
endpointVmrc: `${appName ? '/' + appName : ''}/vmrc`,
endpointGuacamole: `${appName ? '/' + appName : ''}/guacamole`,
defaultNamespace: 'one.',