1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-30 22:50:10 +03:00

F #3951: fix provision create

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2020-11-20 14:05:03 +01:00 committed by GitHub
parent 9f77261af5
commit de7661710f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 25 deletions

View File

@ -13,10 +13,10 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
const { createReadStream, generateFile } = require('fireedge-pojson');
const { createReadStream, generateFile } = require('fireedge-pojson')
const testFolder = './src/public/assets/languages';
const testFolder = './src/public/assets/languages'
createReadStream(testFolder, { exportPath: testFolder });
createReadStream(testFolder, { exportPath: testFolder })
generateFile(true);
generateFile(true)

View File

@ -204,18 +204,15 @@ const executeCommandAsync = (
const close = callbacks && callbacks.close && typeof callbacks.close === 'function' ? callbacks.close : () => undefined
const rsc = Array.isArray(resource) ? resource : [resource]
const execute = spawn(command, [...rsc])
if (execute) {
execute.stdout.on('data', (data) => {
if (out) {
out(data)
}
out(data)
})
execute.stderr.on('data', (data) => {
if (err) {
err(data)
}
err(data)
})
execute.on('error', error => {
@ -229,6 +226,7 @@ const executeCommandAsync = (
}
})
}
}
const executeCommand = (command = '', resource = '') => {
@ -247,6 +245,25 @@ const executeCommand = (command = '', resource = '') => {
return rtn
}
const findRecursiveFolder = (path = '', finder = '') => {
let rtn = false
if (path && finder) {
const dirs = readdirSync(path)
dirs.forEach(dir => {
const name = `${path}/${dir}`
if (statSync(name).isDirectory()) {
console.log('-->', name, basename(name))
if (basename(name) === finder) {
rtn = name
} else {
findRecursiveFolder(name, finder)
}
}
})
}
return rtn
}
const functionRoutes = {
createYMLContent,
executeCommand,
@ -257,6 +274,7 @@ const functionRoutes = {
moveToFolder,
getFiles,
executeCommandAsync,
findRecursiveFolder,
publish,
subscriber
}

View File

@ -31,6 +31,7 @@ const {
removeFile,
renameFolder,
moveToFolder,
findRecursiveFolder,
publish
} = require('./functions')
const { provision } = require('./schemas')
@ -117,8 +118,12 @@ const deleteProvision = (res = {}, next = () => undefined, params = {}, userData
const paramsCommand = ['delete', params.id, '--batch', '--debug', ...authCommand]
let lastLine = ''
const emit = message => {
lastLine = message.toString()
publish(command, { id: params.id, message: lastLine })
message.toString().split(/\r|\n/).map(line=>{
if(line){
lastLine = line
publish(command, { id: params.id, message: lastLine })
}
})
}
executeCommandAsync(
command,
@ -202,9 +207,13 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
let lastLine = ''
var stream = createWriteStream(log.path, { flags: 'a' })
const emit = message => {
lastLine = message.toString()
stream.write(lastLine)
publish(command, { id: files.name, message: lastLine })
message.toString().split(/\r|\n/).map(line=>{
if(line){
lastLine = line
stream.write(line)
publish(command, { id: files.name, message: line })
}
})
}
executeCommandAsync(
command,
@ -246,11 +255,39 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
next()
}
const configureProvision = (res = {}, next = () => undefined, params = {}, userData = {}) => { // falta
const configureProvision = (res = {}, next = () => undefined, params = {}, userData = {}) => {
const { user, password } = userData
const authCommand = ['--user', user, '--password', password]
const rtn = httpInternalError
res.locals.httpCode = rtn // debe de ser un websocket
if (params && params.id && user && password) {
const authCommand = ['--user', user, '--password', password]
const paramsCommand = ['configure', params.id, '--debug', '--fail_cleanup', '--batch', ...authCommand]
let lastLine = ''
const emit = message => {
message.toString().split(/\r|\n/).map(line=>{
if(line){
lastLine = line
publish(command, { id: params.id, message: lastLine })
}
})
}
executeCommandAsync(
command,
paramsCommand,
{
err: emit,
out: emit,
close: success => {
if (success) {
console.log('configurado con exito')
}
}
}
)
res.locals.httpCode = httpResponse(accepted, params.id)
next()
return
}
res.locals.httpCode = rtn
next()
}

View File

@ -100,6 +100,13 @@ const routes = {
resource: { from: fromData.postBody, front: true }
}
},
configure: {
action: configureProvision,
params: {
resource: { from: fromData.resource, name: 'method' }
},
websocket: true
},
host: {
poweroff: {
action: hostCommand,
@ -198,13 +205,6 @@ const routes = {
}
},
[PUT]: {
configure: { // configure <provisionid> //--debug, --fail_cleanup, --batch // este puede tardar Websocket //FALTA
action: configureProvision, // el comando tiene que ser asincrono
params: {
resource: { from: fromData.resource, name: 'method' }
},
websocket: true
},
host: {
action: configureHost,
params: {