simple proxmox

This commit is contained in:
2020-08-26 15:41:37 -04:00
parent f7cee0239e
commit f18967ce8b
26 changed files with 964 additions and 2504 deletions

View File

@ -3,16 +3,42 @@
const path = require('path');
const ejs = require('ejs')
const express = require('express');
const {P2PSub} = require('p2psub');
const pvejs = require('./utils/pvejs');
// Set up the express app.
const app = express();
app.onListen = [];
// Allow the express app to be exported into other files.
module.exports = app;
// Build the conf object from the conf files.
app.conf = require('./conf/conf');
app.p2p = new P2PSub(app.conf.p2p);
app.onListen.push(function(){
app.p2p.subscribe(/./g, function(data, topic){
if(data.__noSocket) return;
app.io.emit('P2PSub', { topic, data })
});
app.io.on('connection', (socket) => {
// console.log('connection io', socket)
socket.on('P2PSub', (msg) => {
msg.data.__noSocket = true;
app.p2p.publish(msg.topic, msg.data);
socket.broadcast.emit('P2PSub', msg)
});
});
});
// Hold onto the auth middleware
const middleware = require('./middleware/auth');
@ -39,8 +65,29 @@ app.use('/api/user', middleware.auth, require('./routes/user'));
app.use('/api/token', middleware.auth, require('./routes/token'));
app.use('/api/group', middleware.auth, require('./routes/group'));
(async function(){
app.api = await pvejs(app.conf.proxmox);
})()
setInterval(async function(){
try{
let res = await app.api.GET({path: '/cluster/resources'});
let types = {};
for(let item of res.json){
if(!types[item.type]){
types[item.type] = [];
}
types[item.type].push(item);
}
app.p2p.publish('proxmox-cluster', {vpnSite: app.conf.vpnSite, data: types});
}catch(error){
console.error('proxmox pub', error)
}
}, 10000);
// Catch 404 and forward to error handler. If none of the above routes are
// used, this is what will be called.