mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
can delete vms with confirmation
This commit is contained in:
parent
568f242010
commit
a78529f2b1
5 changed files with 68 additions and 14 deletions
26
app.py
26
app.py
|
@ -16,13 +16,9 @@ config = os.path.join(app.config.get('ROOT_DIR', os.getcwd()), "config.py")
|
|||
app.config.from_pyfile(config)
|
||||
|
||||
|
||||
user = 'ram'
|
||||
user = 'proxstar'
|
||||
proxmox = connect_proxmox(app.config['PROXMOX_HOST'], app.config['PROXMOX_USER'], app.config['PROXMOX_PASS'])
|
||||
starrs = connect_starrs(app.config['STARRS_DB_NAME'], app.config['STARRS_DB_USER'], app.config['STARRS_DB_HOST'], app.config['STARRS_DB_PASS'])
|
||||
#print(get_vms_for_user(user))
|
||||
#vmid = create_vm(proxmox, starrs, user, name)
|
||||
#time.sleep(10)
|
||||
#delete_vm(proxmox, starrs, vmid, name)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
|
@ -31,6 +27,7 @@ def get_vms():
|
|||
for vm in vms:
|
||||
vm['config'] = get_vm_config(proxmox, vm['vmid'])
|
||||
vm['disk_size'] = get_vm_disk_size(proxmox, vm['vmid'], config=vm['config'])
|
||||
print(vm)
|
||||
return render_template('get_vms.html', vms=vms)
|
||||
|
||||
|
||||
|
@ -46,10 +43,27 @@ def get_create():
|
|||
memory = request.form['memory']
|
||||
disk = request.form['disk']
|
||||
print(name, cores, memory, disk)
|
||||
vmid = create_vm(proxmox, starrs, user, name, cores, memory, disk)
|
||||
vmid, mac = create_vm(proxmox, starrs, user, name, cores, memory, disk)
|
||||
print(register_starrs(starrs, name, user, mac, get_next_ip(starrs, '49net Public Fixed')[0][0]))
|
||||
print(vmid)
|
||||
return vmid
|
||||
|
||||
|
||||
@app.route("/delete", methods=['POST'])
|
||||
def delete():
|
||||
vmid = request.form['delete']
|
||||
vmname = get_vm_config(proxmox, vmid)['name']
|
||||
return render_template('confirm_delete.html', vmid=vmid, vmname=vmname)
|
||||
|
||||
|
||||
@app.route("/confirm_delete", methods=['POST'])
|
||||
def confirm_delete():
|
||||
vmid = request.form['delete']
|
||||
vmname = get_vm_config(proxmox, vmid)['name']
|
||||
delete_vm(proxmox, starrs, vmid)
|
||||
print(delete_starrs(starrs, vmname))
|
||||
return 'SUCCESS'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
|
|
|
@ -64,12 +64,10 @@ def create_vm(proxmox, starrs, user, name, cores, memory, disk):
|
|||
node.qemu.create(vmid=vmid, name=name, cores=cores, memory=memory, storage='ceph', virtio0='ceph:10', net0='virtio,bridge=vmbr0', pool=user)
|
||||
time.sleep(3)
|
||||
mac = get_vm_mac(proxmox, vmid)
|
||||
register_starrs(starrs, name, user, mac, get_next_ip(starrs, '49net Public Fixed')[0][0])
|
||||
return vmid
|
||||
return vmid, mac
|
||||
|
||||
def delete_vm(proxmox, starrs, vmid, name):
|
||||
def delete_vm(proxmox, starrs, vmid):
|
||||
print(vmid)
|
||||
print(get_vm_node(proxmox, vmid))
|
||||
node = proxmox.nodes(get_vm_node(proxmox, vmid))
|
||||
node.qemu(vmid).delete()
|
||||
delete_starrs(starrs, name)
|
||||
|
|
20
templates/confirm_delete.html
Normal file
20
templates/confirm_delete.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a href="/proxstar/create">Create VM</a>
|
||||
|
||||
<br><br>
|
||||
|
||||
Are you sure you want to delete "{{ vmname }}"?
|
||||
|
||||
<form action="/proxstar/confirm_delete" method="post">
|
||||
<button type="submit" name="delete" value="{{ vmid }}">CONFIRM</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -11,15 +11,27 @@ table, th, td {
|
|||
|
||||
<a href="/proxstar/">VM List</a>
|
||||
|
||||
<br><br>
|
||||
|
||||
Create VM
|
||||
|
||||
<br><br>
|
||||
|
||||
<form action="get_create" method="post">
|
||||
<label for="name">VM Name</label>
|
||||
<input type="text" name="name">
|
||||
<label for="cores">Cores</label>
|
||||
<input type="text" name="cores">
|
||||
<select name="cores">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="4">4</option>
|
||||
</select>
|
||||
<label for="memory">Memory</label>
|
||||
<input type="text" name="memory">
|
||||
<select name="memory">
|
||||
<option value="1024">1GB</option>
|
||||
<option value="2048">2GB</option>
|
||||
<option value="4096">4GB</option>
|
||||
</select>
|
||||
<label for="disk">Disk</label>
|
||||
<input type="text" name="disk">
|
||||
<input type="submit">
|
||||
|
|
|
@ -11,6 +11,8 @@ table, th, td {
|
|||
|
||||
<a href="/proxstar/create">Create VM</a>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th> Name </th>
|
||||
|
@ -18,18 +20,26 @@ table, th, td {
|
|||
<th> Cores </th>
|
||||
<th> Memory </th>
|
||||
<th> Disk Size </th>
|
||||
<th> Delete </th>
|
||||
</tr>
|
||||
{% for vm in vms %}
|
||||
<tr>
|
||||
<td> {{ vm['name'] }} </td>
|
||||
<td> {{ vm['status'] }} </td>
|
||||
<td> {{ vm['config']['cores'] * vm['config']['sockets'] }} </td>
|
||||
<td> {{ vm['config']['cores'] * vm['config'].get(sockets, 1) }} </td>
|
||||
<td> {{ vm['config']['memory'] }} MB </td>
|
||||
<td> {{ vm['disk_size'] }} </td>
|
||||
<td>
|
||||
<form action="/proxstar/delete" method="post">
|
||||
<button type="submit" name="delete" value="{{ vm['vmid'] }}">DELETE</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
{{ vms }}
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue