improve db format for templates,
add additional per user customization for instance network interfaces, update tempalte localdb
This commit is contained in:
parent
7719911d5a
commit
81d2841b79
@ -88,31 +88,32 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"users": {
|
"users": {
|
||||||
"exampleuser@authrealm": {
|
"exampleuser@examplepool": {
|
||||||
"resources": {
|
"resources": {
|
||||||
"max": {
|
"max": {
|
||||||
"cpu": ["kvm64", "host"],
|
"cpu": ["kvm64", "host"],
|
||||||
"cores": 0,
|
"cores": 128,
|
||||||
"memory": 0,
|
"memory": 131072,
|
||||||
"swap": 0,
|
"swap": 131072,
|
||||||
"local": 0,
|
"local": 1099511627776,
|
||||||
"cephpl": 0,
|
"cephpl": 1099511627776,
|
||||||
"network": 0,
|
"network": 100000,
|
||||||
"pci": ["[GeForce GTX 1070]", "[GeForce GTX 1080 Ti]"]
|
"pci": ["Device Name Matcher 1", "Device Name Matcher 2"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nodes": [
|
"nodes": [
|
||||||
"node1",
|
"examplenode1",
|
||||||
"node2"
|
"examplenode2"
|
||||||
],
|
],
|
||||||
"instances": {
|
"cluster": {
|
||||||
"vmid": {
|
"vmid": {
|
||||||
"min": 100,
|
"min": 200,
|
||||||
"max": 199
|
"max": 299
|
||||||
|
},
|
||||||
|
"pool": "examplepool"
|
||||||
},
|
},
|
||||||
"pool": "exampleuserpool",
|
|
||||||
"vlan": "10",
|
|
||||||
"templates": {
|
"templates": {
|
||||||
|
"instances": {
|
||||||
"lxc": {
|
"lxc": {
|
||||||
"net0": {
|
"net0": {
|
||||||
"value": "name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,tag=10,type=veth,rate=1000",
|
"value": "name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,tag=10,type=veth,rate=1000",
|
||||||
@ -123,6 +124,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"qemu": {
|
"qemu": {
|
||||||
|
"cpu": {
|
||||||
|
"value": "host",
|
||||||
|
"resource": null
|
||||||
|
},
|
||||||
"net0": {
|
"net0": {
|
||||||
"value": "virtio,bridge=vmbr0,tag=10,rate=1000",
|
"value": "virtio,bridge=vmbr0,tag=10,rate=1000",
|
||||||
"resource": {
|
"resource": {
|
||||||
@ -131,6 +136,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"network": {
|
||||||
|
"lxc": {
|
||||||
|
"type": "veth",
|
||||||
|
"bridge": "vmbr0",
|
||||||
|
"vlan": 10,
|
||||||
|
"ip": "dhcp",
|
||||||
|
"ip6": "dhcp"
|
||||||
|
},
|
||||||
|
"qemu": {
|
||||||
|
"type": "virtio",
|
||||||
|
"bridge": "vmbr0",
|
||||||
|
"vlan": 10
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
src/main.js
26
src/main.js
@ -148,17 +148,17 @@ app.get("/api/user/config/resources", async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET - get db user instance configuration
|
* GET - get db user cluster configuration
|
||||||
* responses:
|
* responses:
|
||||||
* - 200: {pool: String, templates: {lxc: Object, qemu: Object}, vmid: {min: Number, max: Number}}
|
* - 200: {pool: String, templates: {lxc: Object, qemu: Object}, vmid: {min: Number, max: Number}}
|
||||||
* - 401: {auth: false, path: String}
|
* - 401: {auth: false, path: String}
|
||||||
*/
|
*/
|
||||||
app.get("/api/user/config/instances", async (req, res) => {
|
app.get("/api/user/config/cluster", async (req, res) => {
|
||||||
// check auth
|
// check auth
|
||||||
let auth = await checkAuth(req.cookies, res);
|
let auth = await checkAuth(req.cookies, res);
|
||||||
if (!auth) { return; }
|
if (!auth) { return; }
|
||||||
let config = db.getUserConfig(req.cookies.username);
|
let config = db.getUserConfig(req.cookies.username);
|
||||||
res.status(200).send(config.instances)
|
res.status(200).send(config.cluster)
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -510,13 +510,13 @@ app.post("/api/instance/network/create", async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// setup action
|
// setup action
|
||||||
let vlan = db.getUserConfig(req.cookies.username).instances.vlan;
|
let nc = db.getUserConfig(req.cookies.username).templates.network[req.body.type];
|
||||||
let action = {};
|
let action = {};
|
||||||
if (req.body.type === "lxc") {
|
if (req.body.type === "lxc") {
|
||||||
action[`net${req.body.netid}`] = `name=${req.body.name},bridge=vmbr0,ip=dhcp,ip6=dhcp,tag=${vlan},type=veth,rate=${req.body.rate}`;
|
action[`net${req.body.netid}`] = `name=${req.body.name},bridge=${nc.bridge},ip=${nc.ip},ip6=${nc.ip6},tag=${nc.vlan},type=${nc.type},rate=${req.body.rate}`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
action[`net${req.body.netid}`] = `virtio,bridge=vmbr0,tag=${vlan},rate=${req.body.rate}`;
|
action[`net${req.body.netid}`] = `${nc.type},bridge=${nc.bridge},tag=${nc.vlan},rate=${req.body.rate}`;
|
||||||
}
|
}
|
||||||
action = JSON.stringify(action);
|
action = JSON.stringify(action);
|
||||||
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
||||||
@ -943,8 +943,8 @@ app.post("/api/instance", async (req, res) => {
|
|||||||
// get user db config
|
// get user db config
|
||||||
let user = await db.getUserConfig(req.cookies.username);
|
let user = await db.getUserConfig(req.cookies.username);
|
||||||
let vmid = Number.parseInt(req.body.vmid);
|
let vmid = Number.parseInt(req.body.vmid);
|
||||||
let vmid_min = user.instances.vmid.min;
|
let vmid_min = user.cluster.vmid.min;
|
||||||
let vmid_max = user.instances.vmid.max;
|
let vmid_max = user.cluster.vmid.max;
|
||||||
// check vmid is within allowed range
|
// check vmid is within allowed range
|
||||||
if (vmid < vmid_min || vmid > vmid_max) {
|
if (vmid < vmid_min || vmid > vmid_max) {
|
||||||
res.status(500).send({ error: `Requested vmid ${vmid} is out of allowed range [${vmid_min},${vmid_max}].` });
|
res.status(500).send({ error: `Requested vmid ${vmid} is out of allowed range [${vmid_min},${vmid_max}].` });
|
||||||
@ -966,8 +966,8 @@ app.post("/api/instance", async (req, res) => {
|
|||||||
request.swap = req.body.swap;
|
request.swap = req.body.swap;
|
||||||
request[req.body.rootfslocation] = req.body.rootfssize;
|
request[req.body.rootfslocation] = req.body.rootfssize;
|
||||||
}
|
}
|
||||||
for (let key of Object.keys(user.instances.templates[req.body.type])) {
|
for (let key of Object.keys(user.templates.instances[req.body.type])) {
|
||||||
let item = user.instances.templates[req.body.type][key];
|
let item = user.templates.instances[req.body.type][key];
|
||||||
if (item.resource) {
|
if (item.resource) {
|
||||||
if (request[item.resource.name]) {
|
if (request[item.resource.name]) {
|
||||||
request[item.resource.name] += item.resource.amount;
|
request[item.resource.name] += item.resource.amount;
|
||||||
@ -988,10 +988,10 @@ app.post("/api/instance", async (req, res) => {
|
|||||||
vmid: req.body.vmid,
|
vmid: req.body.vmid,
|
||||||
cores: Number(req.body.cores),
|
cores: Number(req.body.cores),
|
||||||
memory: Number(req.body.memory),
|
memory: Number(req.body.memory),
|
||||||
pool: user.instances.pool
|
pool: user.cluster.pool
|
||||||
};
|
};
|
||||||
for (let key of Object.keys(user.instances.templates[req.body.type])) {
|
for (let key of Object.keys(user.templates.instances[req.body.type])) {
|
||||||
action[key] = user.instances.templates[req.body.type][key].value;
|
action[key] = user.templates.instances[req.body.type][key].value;
|
||||||
}
|
}
|
||||||
if (req.body.type === "lxc") {
|
if (req.body.type === "lxc") {
|
||||||
action.hostname = req.body.name;
|
action.hostname = req.body.name;
|
||||||
|
Loading…
Reference in New Issue
Block a user