add pool selection to instance create,
allow multiple pools per user
This commit is contained in:
parent
848eb5d1d1
commit
1c41d55ceb
@ -145,6 +145,7 @@ router.post(`${basePath}/create`, async (req, res) => {
|
|||||||
vmid: req.params.vmid,
|
vmid: req.params.vmid,
|
||||||
hostname: req.body.hostname,
|
hostname: req.body.hostname,
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
|
pool: req.body.pool,
|
||||||
cores: req.body.cores,
|
cores: req.body.cores,
|
||||||
memory: req.body.memory,
|
memory: req.body.memory,
|
||||||
swap: req.body.swap,
|
swap: req.body.swap,
|
||||||
@ -206,7 +207,7 @@ router.post(`${basePath}/create`, async (req, res) => {
|
|||||||
vmid: params.vmid,
|
vmid: params.vmid,
|
||||||
cores: Number(params.cores),
|
cores: Number(params.cores),
|
||||||
memory: Number(params.memory),
|
memory: Number(params.memory),
|
||||||
pool: user.cluster.pool
|
pool: params.pool // TODO allow user to select pool to assign VM
|
||||||
};
|
};
|
||||||
for (const key of Object.keys(user.templates.instances[params.type])) {
|
for (const key of Object.keys(user.templates.instances[params.type])) {
|
||||||
action[key] = user.templates.instances[params.type][key].value;
|
action[key] = user.templates.instances[params.type][key].value;
|
||||||
|
@ -63,7 +63,7 @@ if (schemes.hash.enabled) {
|
|||||||
// setup interupt scheme
|
// setup interupt scheme
|
||||||
if (schemes.interrupt.enabled) {
|
if (schemes.interrupt.enabled) {
|
||||||
const wsServer = new WebSocketServer({ noServer: true, path: "/api/sync/interrupt" });
|
const wsServer = new WebSocketServer({ noServer: true, path: "/api/sync/interrupt" });
|
||||||
wsServer.on("connection", (socket, username, pool) => {
|
wsServer.on("connection", (socket, username, pools) => {
|
||||||
// add new socket to userSocketmap
|
// add new socket to userSocketmap
|
||||||
if (userSocketMap[username]) {
|
if (userSocketMap[username]) {
|
||||||
const index = Object.keys(userSocketMap[username]).length;
|
const index = Object.keys(userSocketMap[username]).length;
|
||||||
@ -74,13 +74,15 @@ if (schemes.interrupt.enabled) {
|
|||||||
userSocketMap[username] = { 0: socket };
|
userSocketMap[username] = { 0: socket };
|
||||||
socket.userIndex = 0;
|
socket.userIndex = 0;
|
||||||
}
|
}
|
||||||
// add user to associated pool in poolUserMap
|
// for each pool, add user to associated pool in poolUserMap
|
||||||
if (poolUserMap[pool]) {
|
for (const pool of pools) {
|
||||||
poolUserMap[pool][username] = true;
|
if (poolUserMap[pool]) {
|
||||||
}
|
poolUserMap[pool][username] = true;
|
||||||
else {
|
}
|
||||||
poolUserMap[pool] = {};
|
else {
|
||||||
poolUserMap[pool][username] = true;
|
poolUserMap[pool] = {};
|
||||||
|
poolUserMap[pool][username] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// add socket entry into requestedRates
|
// add socket entry into requestedRates
|
||||||
const index = Object.keys(requestedRates).length;
|
const index = Object.keys(requestedRates).length;
|
||||||
@ -96,11 +98,13 @@ if (schemes.interrupt.enabled) {
|
|||||||
if (Object.keys(userSocketMap[username]).length === 0) {
|
if (Object.keys(userSocketMap[username]).length === 0) {
|
||||||
// delete the user entry
|
// delete the user entry
|
||||||
delete userSocketMap[username];
|
delete userSocketMap[username];
|
||||||
// remove user from poolUserMap pool entry
|
// remove user from poolUserMap entry for each pool
|
||||||
delete poolUserMap[pool][username];
|
for (const pool of pools) {
|
||||||
// if the poolUserMap pool entry is empty, delete the entry
|
delete poolUserMap[pool][username];
|
||||||
if (Object.keys(poolUserMap[pool]).length === 0) {
|
// if the poolUserMap pool entry is empty, delete the entry
|
||||||
delete poolUserMap[pool];
|
if (Object.keys(poolUserMap[pool]).length === 0) {
|
||||||
|
delete poolUserMap[pool];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// remove socket entry from requestedRates
|
// remove socket entry from requestedRates
|
||||||
@ -154,6 +158,7 @@ if (schemes.interrupt.enabled) {
|
|||||||
});
|
});
|
||||||
// handle the wss upgrade request
|
// handle the wss upgrade request
|
||||||
global.server.on("upgrade", async (req, socket, head) => {
|
global.server.on("upgrade", async (req, socket, head) => {
|
||||||
|
// basic auth validation
|
||||||
const cookies = cookie.parse(req.headers.cookie || "");
|
const cookies = cookie.parse(req.headers.cookie || "");
|
||||||
const auth = (await global.pve.requestPVE("/version", "GET", { cookies })).status === 200;
|
const auth = (await global.pve.requestPVE("/version", "GET", { cookies })).status === 200;
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
@ -161,8 +166,10 @@ if (schemes.interrupt.enabled) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wsServer.handleUpgrade(req, socket, head, (socket) => {
|
wsServer.handleUpgrade(req, socket, head, (socket) => {
|
||||||
const pool = global.db.getUser(cookies.username).cluster.pool;
|
// get the user pools
|
||||||
wsServer.emit("connection", socket, cookies.username, pool);
|
const pools = global.db.getUser(cookies.username).cluster.pools;
|
||||||
|
// emit the connection to initialize socket
|
||||||
|
wsServer.emit("connection", socket, cookies.username, pools);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -81,7 +81,10 @@
|
|||||||
"min": 100,
|
"min": 100,
|
||||||
"max": 199
|
"max": 199
|
||||||
},
|
},
|
||||||
"pool": "examplepool"
|
"pools": [
|
||||||
|
"examplepool1",
|
||||||
|
"examplepool2"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"templates": {
|
"templates": {
|
||||||
"instances": {
|
"instances": {
|
||||||
|
Loading…
Reference in New Issue
Block a user