Browse Source

add network

master
zeus 4 years ago
parent
commit
5541176763
  1. BIN
      dist/img/dockernetwork.f3bb6fa3.png
  2. 2
      dist/index.html
  3. 2
      dist/js/app.45012763.js
  4. 1
      dist/js/app.45012763.js.map
  5. 2
      dist/js/app.77237a5d.js
  6. 1
      dist/js/app.77237a5d.js.map
  7. 183
      src-local/llo/new.js
  8. BIN
      src/assets/img/dockernetwork.png
  9. BIN
      src/assets/img/dockernetwork.xcf
  10. 2
      src/components/mynetwork/AdhocView.vue
  11. 34
      src/components/mynetwork/availableservices.vue
  12. 7
      src/components/mynetwork/dockerservices.vue
  13. 130
      src/components/mynetwork/mytable.vue
  14. 63
      src/store/modules/create_pipelineLLO.js

BIN
dist/img/dockernetwork.f3bb6fa3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

2
dist/index.html

@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue App</title><link href="/css/app.2301b4fb.css" rel="preload" as="style"><link href="/css/chunk-vendors.e469b508.css" rel="preload" as="style"><link href="/js/app.77237a5d.js" rel="preload" as="script"><link href="/js/chunk-vendors.d8d18fe6.js" rel="preload" as="script"><link href="/css/chunk-vendors.e469b508.css" rel="stylesheet"><link href="/css/app.2301b4fb.css" rel="stylesheet"></head><body><div id="app"></div><script src="/js/chunk-vendors.d8d18fe6.js"></script><script src="/js/app.77237a5d.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue App</title><link href="/css/app.2301b4fb.css" rel="preload" as="style"><link href="/css/chunk-vendors.e469b508.css" rel="preload" as="style"><link href="/js/app.45012763.js" rel="preload" as="script"><link href="/js/chunk-vendors.d8d18fe6.js" rel="preload" as="script"><link href="/css/chunk-vendors.e469b508.css" rel="stylesheet"><link href="/css/app.2301b4fb.css" rel="stylesheet"></head><body><div id="app"></div><script src="/js/chunk-vendors.d8d18fe6.js"></script><script src="/js/app.45012763.js"></script></body></html>

2
dist/js/app.45012763.js

File diff suppressed because one or more lines are too long

1
dist/js/app.45012763.js.map

File diff suppressed because one or more lines are too long

2
dist/js/app.77237a5d.js

File diff suppressed because one or more lines are too long

1
dist/js/app.77237a5d.js.map

File diff suppressed because one or more lines are too long

183
src-local/llo/new.js

@ -75,7 +75,7 @@ const io = require("socket.io")(server, {
});
const { spawn, exec } = require('child_process')
const { spawn, exec, execSync } = require('child_process')
const simpleGit = require('simple-git');
@ -811,22 +811,169 @@ app.get('/getstoragestatus', (req, res, next) => {
});
app.get('/getnetworks', (req, res, next) => {
var RES = new Object();
var instancejson = JSON.parse(req.query["instance"])
var instance = instancejson.instance
var datajson1 = ''
//console.log(JSON.stringify(instancejson))
var showexec1 = `docker inspect ${instance} --format '{{json .HostConfig.NetworkMode}}' | jq . -s`
exec(showexec1, (err1, stdout1, stderr1) => {
if (err1) {
return;
}
if (stdout1) {
var string1 = stdout1.toString()
datajson1 = JSON.parse(string1);
//console.log(JSON.stringify(datajson1))
var showexec = `docker network ls --format '{{json .}}' | jq . -s`
exec(showexec, (err, stdout, stderr) => {
if (err) {
return;
}
if (stdout) {
var string = stdout.toString()
var datajson = JSON.parse(string);
var networks = []
var extenderror = new RegExp('^hybrid-');
for(var i = 0; i < datajson.length; i++) {
var NET = {}
var servicename = datajson[i].Name
if(extenderror.test(servicename)){
NET.ID = datajson[i].ID
NET.Name = datajson[i].Name
NET.NetworkMode = datajson1
NET.Scope = datajson[i].Scope
NET.Internal = datajson[i].Internal
NET.IPv6 = datajson[i].IPv6
networks.push(NET)
}
}
var extenderror1 = new RegExp('^storage-');
for(var i = 0; i < datajson.length; i++) {
var NET = {}
var servicename1 = datajson[i].Name
if(extenderror1.test(servicename1)){
NET.ID = datajson[i].ID
NET.Name = datajson[i].Name
NET.NetworkMode = datajson1
NET.Scope = datajson[i].Scope
NET.Internal = datajson[i].Internal
NET.IPv6 = datajson[i].IPv6
networks.push(NET)
}
}
RES.error = false
RES.error_msg = "ok"
RES.data = networks;
res.json(RES)
}else{
var found = 'no'
RES.error = false
RES.error_msg = "ok"
RES.data = 'no network';
res.json(RES)
}
}); //var showexec = `docker network ls --format '{{json .}}' | jq . -s
} // if exec(showexec1
}); // exec(showexec1
});
app.post('/updatenetworks', (req, res, next) => {
var RES = new Object();
const network = req.body["network"]
const container = req.body["container"]
var defaultnetwork = req.body["defaultnetwork"]
var execerror = 0
var execerror1 = 0
//console.log(JSON.stringify(defaultnetwork))
var showexec = `docker inspect ${container} --format '{{json .NetworkSettings.Networks}}' | jq . -s`
exec(showexec, (err, stdout, stderr) => {
if (err) {
return;
}
if (stdout) {
var string = stdout.toString()
var datajson = JSON.parse(string);
var NET1 = []
for (const property in datajson[0]) {
var NET = {}
var name = property
NET1.push(NET)
if(property.trim() !== defaultnetwork.trim()){
try {
var showexecrm = `docker network disconnect ${property} ${container} -f`
//console.log(`${showexecrm}`);
execSync(showexecrm);
execerror = 1
var n = {}
n.data = `rm ${property} from ${container}`
io.emit('message_close', n);
} catch (error) {
execerror = 2
var n = {}
n.data = `rm ${error}`
io.emit('message_close', n);
}
}
//console.log(`${property}`);
}
for(var i = 0; i < network.length; i++) {
try {
var showexecadd = `docker network connect ${network[i]} ${container}`
execSync(showexecadd);
var n = {}
n.data = `add ${network[i]} to ${container}`
io.emit('message_close', n);
execerror1 = 1
} catch (error) {
var n = {}
n.data = `add ${error}`
io.emit('message_close', n);
execerror1 = 2
}
}
RES.error = false
RES.error_msg = "ok"
RES.network = NET1
RES.datarm = execerror
RES.dataadd = execerror1
res.json(RES)
}else{
RES.error = false
RES.error_msg = "ok"
RES.data = 'no network';
res.json(RES)
}
}); // exec(showexec1
});
app.get('/rm_swarmlab', (req, res, next) => {
var mypath = process.cwd()
var RES = new Object();
RES.instance = req.query["instance"]
var services_path = './instance/'+RES.instance
docker_image_rm(mypath, RES.instance);
fs.rm(services_path, {
recursive: true,
force: true
}, (error) => {
if (error) {
RES.error = true
RES.path = mypath
RES.error_msg = "no"
res.json(RES)
} else {
RES.error = false
RES.path = mypath
RES.error_msg = "ok"
res.json(RES)
}
@ -839,16 +986,19 @@ app.get('/rm_swarmlabstorage', (req, res, next) => {
var RES = new Object();
RES.instance = req.query["instance"]
var services_path = './instance/'+RES.instance
docker_image_rm(mypath, RES.instance);
fs.rm(services_path, {
recursive: true,
force: true
}, (error) => {
if (error) {
RES.error = true
RES.path = mypath
RES.error_msg = "no"
res.json(RES)
} else {
RES.error = false
RES.path = mypath
RES.error_msg = "ok"
res.json(RES)
}
@ -1090,6 +1240,37 @@ function create_project(swarmlabname,project){
});
}
function docker_image_rm(swarmlabname,project){
var services_path = swarmlabname
var service_rm = 'docker rmi $(docker images --format "{{.Repository}}#{{ .ID }}" | grep "/'+project+'#" | cut -d"#" -f2)'
console.log('docker rmi '+service_rm)
remove = spawn(service_rm, {
shell: true,
cwd: services_path,
detached: false,
stdio: 'pipe'
});
remove.stdout.on('data', function (data) {
var n = {}
n.data = data.toString()
io.emit('message_out', n);
});
remove.stderr.on('data', function (data) {
var n = {}
n.data = data.toString()
io.emit('message_err', n);
});
remove.on('close', function (code) {
var n = {}
n.data = code
io.emit('message_close', n);
});
}
function myserverStatus(){
var serverStatus = '/bin/bash ./hybrid/connect/status.sh swarmlab0';
exec(serverStatus, (err, stdout, stderr) => {

BIN
src/assets/img/dockernetwork.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
src/assets/img/dockernetwork.xcf

Binary file not shown.

2
src/components/mynetwork/AdhocView.vue

@ -192,7 +192,7 @@ export default {
cmOptions: {
tabSize: 2,
styleActiveLine: true,
lineNumbers: false,
lineNumbers: true,
lineSeparator:'\n',
line: true,
foldGutter: true,

34
src/components/mynetwork/availableservices.vue

@ -479,11 +479,43 @@ export default {
this.$wait.start('myRunInstancetutor');
var res = await store.dispatch('pipelineLLO/rmswarmlablocal', this.hybridoptions.swarmlabname)
this.$wait.end('myRunInstancetutor');
var obj = {}
obj.token = this.token
obj.instance = data.swarmlabname
//check if exists
var res2 = await store.dispatch('pipelineLLO/getservicesinfo', obj)
if(res2.data.data == 'yes'){
if(res2.data.data == 'yes'){
var winfo='<h6 class="text-warning"> swarmlab encountered a problem while deleting your labroom files. <br> This propably means that you have created some files while operating the labroom. <br> To remove those files please run the following command as root. </h6> <h5><i>Copy-and-run-command </i></h5><br> '
winfo += '<span class="text-success">sudo rm -rf '+res.data.path+'/instance/'+data.swarmlabname+' </span><br><br>'
winfo += '<span class="text-secondary"> You can back up content using: </span><br>'
winfo += '<span class="text-warning">sudo tar -zcvf /home/\$USER/swarmlabbackup_'+data.swarmlabname+'.tar.gz '+res.data.path+'/instance/'+data.swarmlabname+' </span>'
var info='<h5>Labroom remove</h5>'
this.$swal({
type: 'info',
html: info+winfo,
icon: 'info',
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
cancelButtonText: 'No, cancel!',
showCancelButton: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true,
confirmButtonText: 'Ok!'
})
console.log('inf res11111111111 '+ JSON.stringify(res.data.path))
}
}
//Vue.nextTick( () => this.$refs.vuetable.refresh())
Vue.delete(this.testactionrowindex, data.swarmlabname)
this.refreshVuetable()
this.$root.$emit('hybrid_refresh_info_deploy_local')
//console.log('inf res '+ JSON.stringify(res))
}else if(action == 'run-install' ){
this.$wait.start('myRunInstancetutor');
this.hybridoptions.swarmlabname = data.swarmlabname

7
src/components/mynetwork/dockerservices.vue

@ -233,6 +233,12 @@ export default {
}
},
mounted() {
this.$root.$on('hybrid_refresh_networktable', () => {
//this.setFilter()
//this.$refs.vuetable.refresh()
Vue.nextTick( () => this.$refs.vuetable.refresh())
this.refreshVuetable()
})
this.$root.$on('hybrid_refresh_dockerservices', () => {
//this.setFilter()
//this.$refs.vuetable.refresh()
@ -255,6 +261,7 @@ export default {
},
beforeDestroy () {
this.$root.$off('hybrid_refresh_networktable')
this.$root.$off('hybrid_refresh_dockerservices')
this.$root.$off('hybrid_refresh_table')
},

130
src/components/mynetwork/mytable.vue

@ -94,12 +94,14 @@
</div>
</div> <!-- row -->
<div class="row" >
<div class="col-2 text-info" >
Networks
Status
</div>
<div class="col-3 text-secondary" >
{{ hybridshowdata.Networks }}
{{ hybridshowdata.Status }}
</div>
<div class="col-2 text-info" >
CreatedAt
</div>
@ -108,12 +110,29 @@
</div>
</div> <!-- row -->
<div class="row" >
<div class="col-2 text-info" >
Status
<button
v-if="hybridshowdata.Networks&&addNetworkMenou==false"
class="btn btn-outline-info btn-sm"
round
type="button"
@click="addNetwork(hybridshowdata,'on')"
>
Networks</button>
<button
v-if="hybridshowdata.Networks&&addNetworkMenou==true"
class="btn btn-outline-warning btn-sm"
round
type="button"
@click="addNetwork(hybridshowdata,'off')"
>
Networks</button>
</div>
<div class="col-3 text-secondary" >
{{ hybridshowdata.Status }}
{{ hybridshowdata.Networks }}
</div>
<div class="col-2 text-info" >
Ports
</div>
@ -126,6 +145,51 @@
"Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}'
-->
</b-container>
<!-- Networks -->
<div class="card border-success bg-light mb-3" style="max-width: 100%;"
v-if="addNetworkMenou==true"
>
<div class="card-header"></div>
<div class="card-body text-info">
<div class="row">
<div class="col-6 text-info">
<h5 class="card-title">Select network</h5>
</div>
<div class="col-6 text-info">
Connect a running container to multiple networks
</div>
</div>
<div class="row">
<div class="col-6 text-info">
<b-form-select v-model="selectedNetworks" :options="localNetworkoptions" multiple :select-size="4"></b-form-select>
<div class="mt-3">Selected: <strong>{{ selectedNetworks }}</strong></div>
</div>
<div class="col-6 text-info">
<img class="border-white img-thumbnail" src="@/assets/img/dockernetwork.png" alt="...">
</div>
</div>
<div class="row">
<div class="col-6 text-info">
<button
class="btn btn-outline-warning btn-sm"
round
type="button"
@click="updateNetwork(hybridshowdata,'update')"
>
Update</button>
</div>
</div>
</div>
</div>
</card>
</template>
<script>
@ -154,6 +218,11 @@ export default {
},
data() {
return{
addNetworkMenou:false,
localNetworks:[],
selectedNetworks:[],
localNetworkoptions:[],
localNetworkdefault:'',
STATUS:{},
CONFIG:{
'status':'',
@ -194,6 +263,11 @@ export default {
this.$root.$on('hybrid_show_info', (data) => {
this.$nextTick(function () {
this.hybridshowdata = data
this.addNetworkMenou = false
this.localNetworks = []
this.selectedNetworks = []
this.localNetworkoptions = []
this.localNetworkdefault = ''
//console.log(JSON.stringify(this.hybridshowdata))
})
})
@ -285,6 +359,54 @@ export default {
},
methods: {
async updateNetwork(container,action){
console.log(JSON.stringify(container));
console.log(JSON.stringify('selected :' + this.selectedNetworks));
var log = await store.dispatch("pipelineLLO/updatenetworks",{
networks:this.selectedNetworks,
defaultnetwork:this.localNetworkdefault,
container:container.ID
})
this.$root.$emit('hybrid_refresh_networktable')
this.hybridshowdata = {}
this.addNetworkMenou = false
this.localNetworks = []
this.selectedNetworks = []
this.localNetworkoptions = []
this.localNetworkdefault = ''
console.log(JSON.stringify(log.data.data));
},
async addNetwork(container,action){
if(action == 'on'){
this.addNetworkMenou = true
var log = await store.dispatch("pipelineLLO/getnetworks",{
instance:container.ID
})
this.localNetworks = log.data.data
var searchnet = ''
this.localNetworkoptions = []
for(var i = 0; i < this.localNetworks.length; i++) {
this.localNetworkdefault = this.localNetworks[i].NetworkMode[0]
var NET = {}
NET.text = this.localNetworks[i].Name
NET.value = this.localNetworks[i].Name
searchnet = new RegExp(this.localNetworks[i].NetworkMode[0]);
//console.log(this.localNetworks[i].NetworkMode[0] +' - ' + this.localNetworks[i].Name );
if(searchnet.test(this.localNetworks[i].Name)){
NET.disabled = true
}else{
NET.disabled = false
}
this.localNetworkoptions.push(NET)
}
console.log(JSON.stringify(this.localNetworks));
}else if(action == 'off'){
this.addNetworkMenou = false
}
console.log(container);
},
async onAction(action){
if(action == 'start'){
var obj = {}

63
src/store/modules/create_pipelineLLO.js

@ -367,6 +367,69 @@ export default {
return R;
}
}
},
async getnetworks({commit,rootGetters}, value) {
//console.log('value '+JSON.stringify(value))
try {
var token = value.token
var params = {
instance: value
}
var options = {
params: params,
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
};
var sock_server_l = ApiConfig.url_80+'/getnetworks'
var p = await axios.get(sock_server_l,options);
//var p = await axios.get('https://localhost:3000/getservicesinfo',options);
return p
//console.log(JSON.stringify(p))
//console.log(value.token)
//console.log(value.swarmlabname)
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
async updatenetworks({commit,rootGetters}, value) {
//console.log('value '+JSON.stringify(value))
try {
var token = value.token
var params = {
network: value.networks,
defaultnetwork: value.defaultnetwork,
container: value.container
}
var options = {
//params: params,
headers: { 'content-type': 'application/json',Authorization: `Bearer ${token}` },
};
var sock_server_l = ApiConfig.url_80+'/updatenetworks'
var p = await axios.post(sock_server_l,params,options);
//var p = await axios.get('https://localhost:3000/get_config',options);
return p
} catch (e) {
if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){
//console.log('error '+JSON.stringify(e))
//window.location.href = 'https://api-login.swarmlab.io:8089';
}else{
var R = {
ERROR_str: e,
ERROR: 'yes'
}
return R;
}
}
},
async getserviceshybridstatus({commit,rootGetters}, value) {
//console.log('value '+JSON.stringify(value))

Loading…
Cancel
Save