Browse Source

hybrid

master
zeus 4 years ago
parent
commit
5e4576a514
  1. 1
      .gitignore
  2. 1
      src-local/instance/swarmlab-sec
  3. 127
      src-local/llo/new.js
  4. 2
      src/components/mynetwork/availableservices.vue

1
.gitignore

@ -1,5 +1,6 @@
.DS_Store .DS_Store
node_modules node_modules
src-local/instance
vimsession vimsession
swarmlabdoc.js swarmlabdoc.js

1
src-local/instance/swarmlab-sec

@ -0,0 +1 @@
Subproject commit 1f7e6b9525bf44cb111d2bd27f3b975fd3b60828

127
src-local/llo/new.js

@ -208,13 +208,48 @@ app.get('/getservicesstatus', (req, res, next) => {
}); });
function create_project(swarmlabname,project){
var services_path = './instance/'+swarmlabname+'/'+project
fs.mkdir(services_path, { recursive: true }, (err) => {
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec create'
create = spawn(service_up, {
shell: true,
cwd: services_path,
//detached: true,
detached: false,
//stdio: [ 'ignore', logout, logerr ]
stdio: 'pipe'
});
create.stdout.on('data', function (data) {
var n = {}
n.data = data.toString()
io.emit('message_out', n);
});
create.stderr.on('data', function (data) {
var n = {}
n.data = data.toString()
io.emit('message_err', n);
});
create.on('close', function (code) {
var n = {}
n.data = code
io.emit('message_close', n);
});
});
}
let child = []; let child = [];
var ppid = '' var ppid = ''
io.on('connection', function(socket) { io.on('connection', function(socket) {
console.log('new connection'); console.log('new connection');
socket.on('start', (value) => { socket.on('start', (value) => {
console.log('start')
console.log('value '+JSON.stringify(value)) console.log('value '+JSON.stringify(value))
if(value.swarmlabname){ if(value.swarmlabname){
var service = value.swarmlabname var service = value.swarmlabname
@ -241,8 +276,11 @@ REGISTRY_ADDR=localhost
REGISTRY_PORT=5000 REGISTRY_PORT=5000
IMAGE_NAME=${service} IMAGE_NAME=${service}
SSH_PORT=${service_port} SSH_PORT=${service_port}
TEST=${service}
` `
fs.writeFileSync(ENV_service_file_path, ENV_service_file); console.log('value1 '+JSON.stringify(ENV_service_file_path))
console.log('value2 '+JSON.stringify(ENV_service_file))
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'});
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size
@ -311,12 +349,38 @@ SSH_PORT=${service_port}
socket.on('install', (value) => { socket.on('install', (value) => {
if(value.swarmlabname){ if(value.swarmlabname){
console.log('install')
var service = value.swarmlabname var service = value.swarmlabname
var service_git = value.git var service_git = value.git
var services_path = './instance/'+service var services_path = './instance/'+service
var ENV_service_dir = services_path+'/'+service var ENV_service_dir = services_path+'/'+service
var ENV_service_file_path = services_path+'/'+service+'/'.env var ENV_service_file_path = services_path+'/'+service+'/'.env
if (fs.existsSync(services_path)) { if (fs.existsSync(services_path)) {
const git = simpleGit(
{
baseDir: services_path,
maxConcurrentProcesses: 10
});
try {
git.pull()
.then((status) => {
var n = {}
n.data = 'Updated'
io.emit('message_out', n);
n.data = '...'
io.emit('message_close', n);
create_project(service,service)
}).catch((err) => {
var n = {}
n.data = err.toString()
io.emit('message_err', n);
console.log('error ' + JSON.stringify(err))
});
} catch (e) {
var n = {}
n.data = e.toString()
io.emit('message_err', n);
}
}else{ }else{
fs.mkdir(services_path, { recursive: true }, (err) => { fs.mkdir(services_path, { recursive: true }, (err) => {
if (err){ if (err){
@ -326,27 +390,28 @@ SSH_PORT=${service_port}
REGISTRY_ADDR=localhost REGISTRY_ADDR=localhost
REGISTRY_PORT=5000 REGISTRY_PORT=5000
IMAGE_NAME=${service} IMAGE_NAME=${service}
SSH_PORT=${service_port} SSH_PORT=
` `
/* const git = simpleGit(
const options: SimpleGitOptions = { {
baseDir: process.cwd(), baseDir: '.',
binary: 'git', maxConcurrentProcesses: 10
maxConcurrentProcesses: 6, });
};
*/
const git = simpleGit()
try { try {
git.init(); git.clone(service_git, services_path)
git.addRemote('origin', service_git).then(result => { .then((status) => {
var n = {} var n = {}
n.data = result.toString() n.data = 'Installed'
io.emit('message_out', n); io.emit('message_out', n);
}); n.data = '...'
git.clone(service_git, services_path).then(result => {
var n = {}
n.data = result.toString()
io.emit('message_out', n); io.emit('message_out', n);
fs.writeFileSync(ENV_service_file_path, ENV_service_file);
create_project(service,service)
}).catch((err) => {
var n = {}
n.data = err.toString()
io.emit('message_err', n);
console.log('error ' + JSON.stringify(err))
}); });
} catch (e) { } catch (e) {
var n = {} var n = {}
@ -354,37 +419,13 @@ SSH_PORT=${service_port}
io.emit('message_err', n); io.emit('message_err', n);
} }
//fs.writeFileSync(ENV_service_file_path, ENV_service_file);
} }
}); });
} }
/* }else{
var services_path = './instance/'+service+'/'+service
var containerrm = '/bin/sh ./container-stop.sh '+id
const stop = spawn(containerrm, {
stdio: 'pipe',
shell: true,
cwd: services_path
});
stop.stdout.on('data', function (data) {
var n = {}
n.data = data.toString()
io.emit('message_out', n);
});
stop.stderr.on('data', function (data) {
var n = {} var n = {}
n.data = data.toString() n.data = 'no services'
io.emit('message_err', n); io.emit('message_err', n);
});
stop.on('close', function (code) {
var n = {}
n.data = code
io.emit('message_close', n);
});
*/
}else{
} }
}); });

2
src/components/mynetwork/availableservices.vue

@ -125,7 +125,7 @@
<button <button
v-if="testactionrowindex[props.rowData.swarmlabname] != props.rowIndex && testactionrowindex[props.rowIndex] == props.rowIndex" v-if="testactionrowindex[props.rowData.swarmlabname] != props.rowIndex && testactionrowindex[props.rowIndex] == props.rowIndex"
class="ti-thumb-down btn btn-secondary btn-sm" class="ti-thumb-down btn btn-secondary btn-sm"
title="Stop Lan_Instance" title="Start Lan_Instance"
round round
@click="onAction('run-item', props.rowData, props.rowIndex)" @click="onAction('run-item', props.rowData, props.rowIndex)"
> >

Loading…
Cancel
Save