Skip to content

Commit

Permalink
Virtual machine selector
Browse files Browse the repository at this point in the history
  • Loading branch information
lkiesow committed Nov 4, 2022
0 parents commit 9da69f5
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 0 deletions.
102 changes: 102 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"owner": {
"type": "text",
"hint": "Benutzerkennung"
},
"group": {
"type": "select",
"hint": "Organisationseinheit",
"options": [
"bio",
"fb1",
"fb3",
"geo",
"igb",
"ikw",
"inf",
"math",
"psycho",
"rz",
"rz-net",
"ub",
"usf",
"virtuos",
"wiwi"
]
},
"name": {
"type": "text",
"hint": "Hostname"
},
"cpus": {
"hint": "Anzahl der CPUs",
"type": "select",
"options": [
1,
2,
4,
6,
8,
12,
16,
32
]
},
"mem": {
"hint": "Hauptspeicher",
"type": "select",
"options": [
"2GiB",
"4GiB",
"6GiB",
"8GiB",
"10GiB",
"12GiB",
"16GiB",
"32GiB"
]
},
"disksize": {
"hint": "Plattengr\u00f6\u00dfe",
"type": "select",
"options": [
"32GiB",
"64GiB",
"128GiB",
"256GiB",
"512GiB",
"1024GiB"
]
},
"net": {
"type": "select",
"hint": "Netzanschluss",
"options": [
"131.173.22.0/23",
"172.17.22.0/23"
]
},
"os": {
"hint": "Betriebssystem",
"type": "select",
"options": [
"bionic",
"bullseye",
"buster",
"centos",
"cs8",
"cs9",
"debian",
"debian-10",
"debian-11",
"focal",
"jammy",
"other",
"sl7",
"ubuntu",
"ubuntu-18",
"ubuntu-20",
"ubuntu-22"
]
}
}
86 changes: 86 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
owner:
type: text
hint: Benutzerkennung
group:
type: select
hint: Organisationseinheit
options:
- bio
- fb1
- fb3
- geo
- igb
- ikw
- inf
- math
- psycho
- rz
- rz-net
- ub
- usf
- virtuos
- wiwi
name:
type: text
hint: Hostname
cpus:
hint: Anzahl der CPUs
type: select
options:
- 1
- 2
- 4
- 6
- 8
- 12
- 16
- 32
mem:
hint: Hauptspeicher
type: select
options:
- 2GiB
- 4GiB
- 6GiB
- 8GiB
- 10GiB
- 12GiB
- 16GiB
- 32GiB
disksize:
hint: Plattengröße
type: select
options:
- 32GiB
- 64GiB
- 128GiB
- 256GiB
- 512GiB
- 1024GiB
net:
type: select
hint: Netzanschluss
options:
- 131.173.22.0/23
- 172.17.22.0/23
os:
hint: Betriebssystem
type: select
options:
- bionic
- bullseye
- buster
- centos
- cs8
- cs9
- debian
- debian-10
- debian-11
- focal
- jammy
- other
- sl7
- ubuntu
- ubuntu-18
- ubuntu-20
- ubuntu-22
22 changes: 22 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
body {
font-family: sans;
width: 750px;
margin: 0 auto;
}

.buttons {
text-align: right;
margin: 15px 0;
}

#selector {
display: grid;
grid-template-columns: 200px auto;
}

#order {
background-color: #ddd;
border: 1px solid #666;
border-radius: 5px;
padding: 10px;
}
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang=en>
<head>
<meta http-equiv=content-type content="text/html; charset=utf-8" />
<meta name=author content="Lars Kiesow" />
<meta name=viewport content="width=device-width, initial-scale=1">
<link rel=stylesheet type=text/css href=index.css />
<script type=application/javascript src=index.js></script>

<title>Lars Kiesow :: Home</title>
</head>
<body onload="load_config()">

<header>
<h1>VM Selector</h1>
</header>

<div id=selector>
</div>

<div class=buttons>
<button onclick="add_vm()">Hinzufügen</button>
</div>

<pre id=order>
</pre>

<div class=buttons>
<button onclick="copy()">🗎 Kopieren</button>
</div>

</body>
</html>
56 changes: 56 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
fields = []

function load_config() {
fetch('config.json')
.then((response) => response.json())
.then((data) => build_ui(data));
}

function build_ui(config) {
const selector = document.getElementById('selector');
for (const key in config) {
const field = config[key];
fields.push(key);
const label = document.createElement('label');
label.setAttribute('for', key);
label.innerText = field.hint;
selector.appendChild(label);
if (field.type === 'text') {
const input = document.createElement('input');
input.setAttribute('type', field.type);
input.setAttribute('id', key);
input.setAttribute('name', key);
selector.appendChild(input);
} else if (field.type === 'select') {
const input = document.createElement('select');
input.setAttribute('id', key);
input.setAttribute('name', key);
for (const value of field.options) {
const option = document.createElement('option');
option.setAttribute('value', value);
option.innerText = value;
input.appendChild(option);
}
selector.appendChild(input);
}
}
}

function add_vm() {
let args = '';
for (field of fields) {
const value = document.getElementById(field).value;
if (!value) {
alert(`${field} must not be empty`);
return;
}
args += `${value} `;
}
const order = document.getElementById('order');
order.innerText = `${order.innerText}\n${args}`.trim();
}

function copy() {
const order = document.getElementById('order');
navigator.clipboard.writeText(order.innerText);
}

0 comments on commit 9da69f5

Please sign in to comment.