mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Merge branch 'f-3951'
This commit is contained in:
commit
6f84f59a04
@ -4,10 +4,10 @@ plain:
|
||||
image: 'AWS.webp'
|
||||
|
||||
connection:
|
||||
acces_key: "Encrypted aws access key"
|
||||
access_key: "Encrypted aws access key"
|
||||
secret_key: "Encrypted aws secret key"
|
||||
|
||||
location_key: 'aws_region'
|
||||
location_key: 'region'
|
||||
|
||||
locations:
|
||||
us-east-1:
|
||||
|
@ -25,6 +25,9 @@ limit_token:
|
||||
# VMRC: use it for connect to vmrc. Its is a URL for the ESX server
|
||||
vmrc: 'http://opennebula.io'
|
||||
|
||||
# Prepend for oneprovision command
|
||||
oneprovision_prepend_command: ''
|
||||
|
||||
# Guacamole: use it if you have the Guacd in other server or port
|
||||
# guacd:
|
||||
# port: 4822
|
||||
|
@ -32,6 +32,9 @@ const { getConfig } = require('server/utils/yml')
|
||||
const { spawnSync, spawn } = require('child_process')
|
||||
const { messageTerminal } = require('server/utils/general')
|
||||
|
||||
const appConfig = getConfig()
|
||||
const prependCommand = appConfig.oneprovision_prepend_command || ''
|
||||
|
||||
const eventsEmitter = new events.EventEmitter()
|
||||
const defaultError = (err = '', message = 'Error: %s') => ({
|
||||
color: 'red',
|
||||
@ -197,6 +200,25 @@ const moveToFolder = (path = '', relative = '/../') => {
|
||||
return rtn
|
||||
}
|
||||
|
||||
const addPrependCommand = (command="", resource='') => {
|
||||
const rsc = Array.isArray(resource) ? resource : [resource]
|
||||
|
||||
let newCommand = command
|
||||
let newRsc = rsc
|
||||
|
||||
if(prependCommand){
|
||||
let splitPrepend = prependCommand.split(" ")
|
||||
newCommand = splitPrepend[0]
|
||||
splitPrepend = splitPrepend.splice(1);
|
||||
newRsc = [...splitPrepend, command, ...rsc].filter(el => el !== "")
|
||||
}
|
||||
|
||||
return {
|
||||
cmd: newCommand,
|
||||
rsc: newRsc
|
||||
}
|
||||
}
|
||||
|
||||
const executeCommandAsync = (
|
||||
command = '',
|
||||
resource = '',
|
||||
@ -210,9 +232,9 @@ const executeCommandAsync = (
|
||||
const out = callbacks && callbacks.out && typeof callbacks.out === 'function' ? callbacks.out : () => undefined
|
||||
const close = callbacks && callbacks.close && typeof callbacks.close === 'function' ? callbacks.close : () => undefined
|
||||
|
||||
const rsc = Array.isArray(resource) ? resource : [resource]
|
||||
const {cmd, rsc} = addPrependCommand(command, resource)
|
||||
|
||||
const execute = spawn(command, [...rsc])
|
||||
const execute = spawn(cmd, rsc)
|
||||
if (execute) {
|
||||
execute.stderr.on('data', (data) => {
|
||||
err(data)
|
||||
@ -236,9 +258,9 @@ const executeCommandAsync = (
|
||||
}
|
||||
|
||||
const executeCommand = (command = '', resource = '', options = {}) => {
|
||||
const rsc = Array.isArray(resource) ? resource : [resource]
|
||||
let rtn = { success: false, data: null }
|
||||
const execute = spawnSync(command, [...rsc], options)
|
||||
const {cmd, rsc} = addPrependCommand(command, resource)
|
||||
const execute = spawnSync(cmd, rsc, options)
|
||||
if (execute) {
|
||||
if (execute.stdout) {
|
||||
rtn = { success: true, data: execute.stdout.toString() }
|
||||
@ -269,7 +291,6 @@ const findRecursiveFolder = (path = '', finder = '', rtn = false) => {
|
||||
}
|
||||
|
||||
const getEndpoint = () => {
|
||||
const appConfig = getConfig()
|
||||
let rtn = []
|
||||
if (appConfig && appConfig.one_xmlrpc) {
|
||||
const parseUrl = parse(appConfig.one_xmlrpc)
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
const { parse } = require('yaml')
|
||||
const { Validator } = require('jsonschema')
|
||||
const { tmpPath } = require('server/utils/constants/defaults')
|
||||
const { tmpPath, defaultCommandProvider } = require('server/utils/constants/defaults')
|
||||
|
||||
const {
|
||||
ok,
|
||||
@ -28,8 +28,6 @@ const { provider, providerUpdate } = require('./schemas')
|
||||
|
||||
const httpInternalError = httpResponse(internalServerError, '', '')
|
||||
|
||||
const command = 'oneprovider'
|
||||
|
||||
const getListProviders = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
@ -40,7 +38,7 @@ const getListProviders = (res = {}, next = () => undefined, params = {}, userDat
|
||||
if (params && params.id) {
|
||||
paramsCommand = ['show', `${params.id}`.toLowerCase(), ...authCommand, '--json']
|
||||
}
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
@ -108,7 +106,8 @@ const createProviders = (res = {}, next = () => undefined, params = {}, userData
|
||||
const file = createTemporalFile(tmpPath, 'yaml', content)
|
||||
if (file && file.name && file.path) {
|
||||
const paramsCommand = ['create', file.path, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
|
||||
console.log("JORGE: ", executeCommand)
|
||||
res.locals.httpCode = httpResponse(internalServerError)
|
||||
if (executedCommand && executedCommand.data) {
|
||||
if (executedCommand.success) {
|
||||
@ -151,7 +150,7 @@ const updateProviders = (res = {}, next = () => undefined, params = {}, userData
|
||||
const file = createTemporalFile(tmpPath, 'json', JSON.stringify(resource))
|
||||
if (file && file.name && file.path) {
|
||||
const paramsCommand = ['update', params.id, file.path, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
|
||||
res.locals.httpCode = httpResponse(internalServerError)
|
||||
if (executedCommand && executedCommand.success) {
|
||||
res.locals.httpCode = httpResponse(ok)
|
||||
@ -181,7 +180,7 @@ const deleteProvider = (res = {}, next = () => undefined, params = {}, userData
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const paramsCommand = ['delete', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvider, paramsCommand)
|
||||
const data = executedCommand.data || ''
|
||||
try {
|
||||
if (executedCommand) {
|
||||
|
@ -24,7 +24,7 @@ const {
|
||||
internalServerError
|
||||
} = require('server/utils/constants/http-codes')
|
||||
const { httpResponse, parsePostData, existsFile, createFile } = require('server/utils/server')
|
||||
const { tmpPath } = require('server/utils/constants/defaults')
|
||||
const { tmpPath, defaultCommandProvision } = require('server/utils/constants/defaults')
|
||||
const {
|
||||
executeCommand,
|
||||
executeCommandAsync,
|
||||
@ -43,7 +43,6 @@ const { provision } = require('./schemas')
|
||||
|
||||
const httpInternalError = httpResponse(internalServerError, '', '')
|
||||
|
||||
const command = 'oneprovision'
|
||||
const logFile = {
|
||||
name: 'stdouterr',
|
||||
ext: 'log'
|
||||
@ -70,7 +69,7 @@ const getProvisionDefaults = (res = {}, next = () => undefined, params = {}, use
|
||||
const fillData = (content = '', filePath = '') => {
|
||||
try {
|
||||
const paramsCommand = ['validate', '--dump', filePath, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand, { cwd: path })
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand, { cwd: path })
|
||||
if (executedCommand && executedCommand.success) {
|
||||
files.push(parse(executedCommand.data))
|
||||
}
|
||||
@ -109,7 +108,7 @@ const getList = (res = {}, next = () => undefined, params = {}, userData = {}) =
|
||||
if (params && params.resource && user && password) {
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const executedCommand = executeCommand(command, [`${params.resource}`.toLowerCase(), 'list', ...authCommand, ...endpoint, '--json'])
|
||||
const executedCommand = executeCommand(defaultCommandProvision, [`${params.resource}`.toLowerCase(), 'list', ...authCommand, ...endpoint, '--json'])
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
@ -133,7 +132,7 @@ const getListProvisions = (res = {}, next = () => undefined, params = {}, userDa
|
||||
if (params && params.id) {
|
||||
paramsCommand = ['show', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint, '--json']
|
||||
}
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
let data = JSON.parse(executedCommand.data)
|
||||
@ -163,7 +162,7 @@ const deleteResource = (res = {}, next = () => undefined, params = {}, userData
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const paramsCommand = [`${params.resource}`.toLowerCase(), 'delete', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
rtn = httpResponse(response, executedCommand.data ? JSON.parse(executedCommand.data) : params.id)
|
||||
@ -191,12 +190,12 @@ const deleteProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
message.toString().split(/\r|\n/).map(line => {
|
||||
if (line) {
|
||||
lastLine = line
|
||||
publish(command, { id: params.id, message: lastLine })
|
||||
publish(defaultCommandProvision, { id: params.id, message: lastLine })
|
||||
}
|
||||
})
|
||||
}
|
||||
executeCommandAsync(
|
||||
command,
|
||||
defaultCommandProvision,
|
||||
paramsCommand,
|
||||
{
|
||||
err: emit,
|
||||
@ -255,7 +254,7 @@ const hostCommand = (res = {}, next = () => undefined, params = {}, userData = {
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const paramsCommand = ['host', `${params.action}`.toLowerCase(), `${params.id}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, executedCommand.data ? JSON.parse(executedCommand.data) : params.id)
|
||||
@ -276,7 +275,7 @@ const hostCommandSSH = (res = {}, next = () => undefined, params = {}, userData
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const paramsCommand = ['host', `${params.action}`.toLowerCase(), `${params.id}`.toLowerCase(), `${params.command}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, executedCommand.data ? JSON.parse(executedCommand.data) : params.id)
|
||||
@ -329,12 +328,12 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
|
||||
}
|
||||
lastLine = line
|
||||
stream.write(`${line}\n`)
|
||||
publish(command, { id: files.name, message: line })
|
||||
publish(defaultCommandProvision, { id: files.name, message: line })
|
||||
}
|
||||
})
|
||||
}
|
||||
executeCommandAsync(
|
||||
command,
|
||||
defaultCommandProvision,
|
||||
paramsCommand,
|
||||
{
|
||||
err: emit,
|
||||
@ -413,12 +412,12 @@ const configureProvision = (res = {}, next = () => undefined, params = {}, userD
|
||||
message.toString().split(/\r|\n/).map(line => {
|
||||
if (line) {
|
||||
lastLine = line
|
||||
publish(command, { id: params.id, message: lastLine })
|
||||
publish(defaultCommandProvision, { id: params.id, message: lastLine })
|
||||
}
|
||||
})
|
||||
}
|
||||
executeCommandAsync(
|
||||
command,
|
||||
defaultCommandProvision,
|
||||
paramsCommand,
|
||||
{
|
||||
err: emit,
|
||||
@ -440,7 +439,7 @@ const configureHost = (res = {}, next = () => undefined, params = {}, userData =
|
||||
const endpoint = getEndpoint()
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const paramsCommand = ['host', 'configure', `${params.id}`.toLowerCase(), '--debug', '--fail_cleanup', '--batch', ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
@ -469,7 +468,7 @@ const validate = (res = {}, next = () => undefined, params = {}, userData = {})
|
||||
const file = createTemporalFile(tmpPath, 'yaml', content)
|
||||
if (file && file.name && file.path) {
|
||||
const paramsCommand = ['validate', '--dump', file.path, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvision, paramsCommand)
|
||||
let response = internalServerError
|
||||
if (executedCommand && executedCommand.success) {
|
||||
response = ok
|
||||
|
@ -14,7 +14,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const { Validator } = require('jsonschema')
|
||||
const { tmpPath } = require('server/utils/constants/defaults')
|
||||
const { tmpPath, defaultCommandProvisionTemplate } = require('server/utils/constants/defaults')
|
||||
|
||||
const {
|
||||
ok,
|
||||
@ -26,8 +26,6 @@ const { provider } = require('./schemas')
|
||||
|
||||
const httpInternalError = httpResponse(internalServerError, '', '')
|
||||
|
||||
const command = 'oneprovision-template'
|
||||
|
||||
const getListProvisionTemplates = (res = {}, next = () => undefined, params = {}, userData = {}) => {
|
||||
const { user, password } = userData
|
||||
let rtn = httpInternalError
|
||||
@ -38,7 +36,7 @@ const getListProvisionTemplates = (res = {}, next = () => undefined, params = {}
|
||||
if (params && params.id) {
|
||||
paramsCommand = ['show', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint, '--json']
|
||||
}
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
@ -67,7 +65,7 @@ const createProvisionTemplate = (res = {}, next = () => undefined, params = {},
|
||||
const file = createTemporalFile(tmpPath, 'yaml', content)
|
||||
if (file && file.name && file.path) {
|
||||
const paramsCommand = ['create', file.path, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
|
||||
res.locals.httpCode = httpResponse(internalServerError)
|
||||
if (executedCommand && executedCommand.success && executedCommand.data) {
|
||||
res.locals.httpCode = httpResponse(ok, executedCommand.data)
|
||||
@ -98,7 +96,7 @@ const instantiateProvisionTemplate = (res = {}, next = () => undefined, params =
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const endpoint = getEndpoint()
|
||||
const paramsCommand = ['instantiate', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
@ -127,7 +125,7 @@ const updateProvisionTemplate = (res = {}, next = () => undefined, params = {},
|
||||
const file = createTemporalFile(tmpPath, 'yaml', content)
|
||||
if (file && file.name && file.path) {
|
||||
const paramsCommand = ['update', params.id, file.path, ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
|
||||
res.locals.httpCode = httpResponse(internalServerError)
|
||||
if (executedCommand && executedCommand.success && executedCommand.data) {
|
||||
res.locals.httpCode = httpResponse(ok, executedCommand.data)
|
||||
@ -158,7 +156,7 @@ const deleteProvisionTemplate = (res = {}, next = () => undefined, params = {},
|
||||
const authCommand = ['--user', user, '--password', password]
|
||||
const endpoint = getEndpoint()
|
||||
const paramsCommand = ['delete', `${params.id}`.toLowerCase(), ...authCommand, ...endpoint]
|
||||
const executedCommand = executeCommand(command, paramsCommand)
|
||||
const executedCommand = executeCommand(defaultCommandProvisionTemplate, paramsCommand)
|
||||
try {
|
||||
const response = executedCommand.success ? ok : internalServerError
|
||||
res.locals.httpCode = httpResponse(response, JSON.parse(executedCommand.data))
|
||||
|
@ -69,6 +69,9 @@ const defaults = {
|
||||
zeromq: `tcp://${defaultIp}:2101`
|
||||
}
|
||||
],
|
||||
defaultCommandProvision: 'oneprovision',
|
||||
defaultCommandProvisionTemplate: 'oneprovision-template',
|
||||
defaultCommandProvider: 'oneprovider',
|
||||
defaultOneFlowServer: `${protocol}://${defaultIp}:2474`,
|
||||
defaultEndpointWebsocket: `${appName ? '/' + appName : ''}/websocket`,
|
||||
defaultConfigFile: `${appName}-server.conf`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user