mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
add retries everywhere cuz proxmox sucks, use json for iso list (for marc <3)
This commit is contained in:
parent
b658033d85
commit
8bf49a664a
5 changed files with 28 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
import psutil
|
import psutil
|
||||||
import atexit
|
import atexit
|
||||||
|
@ -157,7 +158,7 @@ def list_vms(user_view=None):
|
||||||
def isos():
|
def isos():
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
|
isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
|
||||||
return ','.join(isos)
|
return json.dumps({"isos": isos})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/hostname/<string:name>")
|
@app.route("/hostname/<string:name>")
|
||||||
|
|
|
@ -171,12 +171,11 @@ $("#change-iso").click(function(){
|
||||||
fetch(`/isos`, {
|
fetch(`/isos`, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
return response.text()
|
return response.json()
|
||||||
}).then((text) => {
|
}).then((json) => {
|
||||||
var isos = text.split(',');
|
|
||||||
var iso_list = document.createElement('select');
|
var iso_list = document.createElement('select');
|
||||||
for (i = 0; i < isos.length; i++) {
|
for (i = 0; i < json.isos.length; i++) {
|
||||||
iso_list.appendChild(new Option(isos[i], isos[i]));
|
iso_list.appendChild(new Option(json.isos[i], json.isos[i]));
|
||||||
}
|
}
|
||||||
swal({
|
swal({
|
||||||
title: 'Choose an ISO to mount:',
|
title: 'Choose an ISO to mount:',
|
||||||
|
|
|
@ -133,6 +133,9 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory):
|
||||||
ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE'])
|
ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE'])
|
||||||
register_starrs(starrs, name, app.config['STARRS_USER'], mac, ip)
|
register_starrs(starrs, name, app.config['STARRS_USER'], mac, ip)
|
||||||
get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
get_vm_expire(db, vmid, app.config['VM_EXPIRE_MONTHS'])
|
||||||
|
print("[{}] Giving Proxmox some time to finish cloning.".format(name))
|
||||||
|
job.meta['status'] = 'waiting for Proxmox'
|
||||||
|
time.sleep(15)
|
||||||
print("[{}] Setting CPU and memory.".format(name))
|
print("[{}] Setting CPU and memory.".format(name))
|
||||||
job.meta['status'] = 'setting CPU and memory'
|
job.meta['status'] = 'setting CPU and memory'
|
||||||
job.save_meta()
|
job.save_meta()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
|
from tenacity import retry, wait_fixed, stop_after_attempt
|
||||||
from proxstar import db, starrs
|
from proxstar import db, starrs
|
||||||
from proxstar.db import get_vm_expire
|
from proxstar.db import get_vm_expire
|
||||||
from proxstar.util import lazy_property
|
from proxstar.util import lazy_property
|
||||||
|
@ -43,39 +44,48 @@ class VM(object):
|
||||||
if vm['vmid'] == int(self.id):
|
if vm['vmid'] == int(self.id):
|
||||||
return vm['node']
|
return vm['node']
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def delete(self):
|
def delete(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).delete()
|
proxmox.nodes(self.node).qemu(self.id).delete()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_cpu(self, cores):
|
def set_cpu(self, cores):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).config.put(
|
proxmox.nodes(self.node).qemu(self.id).config.put(
|
||||||
cores=cores, sockets=1)
|
cores=cores, sockets=1)
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_mem(self, mem):
|
def set_mem(self, mem):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).config.put(memory=mem)
|
proxmox.nodes(self.node).qemu(self.id).config.put(memory=mem)
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def start(self):
|
def start(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.start.post()
|
proxmox.nodes(self.node).qemu(self.id).status.start.post()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def stop(self):
|
def stop(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.stop.post()
|
proxmox.nodes(self.node).qemu(self.id).status.stop.post()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.shutdown.post()
|
proxmox.nodes(self.node).qemu(self.id).status.shutdown.post()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def reset(self):
|
def reset(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.reset.post()
|
proxmox.nodes(self.node).qemu(self.id).status.reset.post()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def suspend(self):
|
def suspend(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.suspend.post()
|
proxmox.nodes(self.node).qemu(self.id).status.suspend.post()
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def resume(self):
|
def resume(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(self.id).status.resume.post()
|
proxmox.nodes(self.node).qemu(self.id).status.resume.post()
|
||||||
|
@ -108,6 +118,7 @@ class VM(object):
|
||||||
def boot_order_json(self):
|
def boot_order_json(self):
|
||||||
return json.dumps(self.boot_order)
|
return json.dumps(self.boot_order)
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_boot_order(self, boot_order):
|
def set_boot_order(self, boot_order):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
boot_order_lookup = {
|
boot_order_lookup = {
|
||||||
|
@ -184,11 +195,13 @@ class VM(object):
|
||||||
proxmox.nodes(self.node).qemu(self.id).monitor.post(
|
proxmox.nodes(self.node).qemu(self.id).monitor.post(
|
||||||
command="change vnc 127.0.0.1:{}".format(port))
|
command="change vnc 127.0.0.1:{}".format(port))
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def eject_iso(self):
|
def eject_iso(self):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(
|
proxmox.nodes(self.node).qemu(
|
||||||
self.id).config.post(ide2='none,media=cdrom')
|
self.id).config.post(ide2='none,media=cdrom')
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def mount_iso(self, iso):
|
def mount_iso(self, iso):
|
||||||
proxmox = connect_proxmox()
|
proxmox = connect_proxmox()
|
||||||
proxmox.nodes(self.node).qemu(
|
proxmox.nodes(self.node).qemu(
|
||||||
|
@ -203,15 +216,18 @@ class VM(object):
|
||||||
def expire(self):
|
def expire(self):
|
||||||
return get_vm_expire(db, self.id, app.config['VM_EXPIRE_MONTHS'])
|
return get_vm_expire(db, self.id, app.config['VM_EXPIRE_MONTHS'])
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_ci_user(self, user):
|
def set_ci_user(self, user):
|
||||||
proxmox = connect_proxmox_ssh()
|
proxmox = connect_proxmox_ssh()
|
||||||
proxmox.nodes(self.node).qemu(self.id).config.put(ciuser=user)
|
proxmox.nodes(self.node).qemu(self.id).config.put(ciuser=user)
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_ci_ssh_key(self, ssh_key):
|
def set_ci_ssh_key(self, ssh_key):
|
||||||
proxmox = connect_proxmox_ssh()
|
proxmox = connect_proxmox_ssh()
|
||||||
escaped_key = urllib.parse.quote(ssh_key, safe='')
|
escaped_key = urllib.parse.quote(ssh_key, safe='')
|
||||||
proxmox.nodes(self.node).qemu(self.id).config.put(sshkey=escaped_key)
|
proxmox.nodes(self.node).qemu(self.id).config.put(sshkey=escaped_key)
|
||||||
|
|
||||||
|
@retry(wait=wait_fixed(2), stop=stop_after_attempt(5))
|
||||||
def set_ci_network(self):
|
def set_ci_network(self):
|
||||||
proxmox = connect_proxmox_ssh()
|
proxmox = connect_proxmox_ssh()
|
||||||
proxmox.nodes(self.node).qemu(self.id).config.put(ipconfig0='ip=dhcp')
|
proxmox.nodes(self.node).qemu(self.id).config.put(ipconfig0='ip=dhcp')
|
||||||
|
@ -232,7 +248,7 @@ def create_vm(proxmox, user, name, cores, memory, disk, iso):
|
||||||
pool=user,
|
pool=user,
|
||||||
description='Managed by Proxstar')
|
description='Managed by Proxstar')
|
||||||
retry = 0
|
retry = 0
|
||||||
while retry < 5:
|
while retry < 20:
|
||||||
try:
|
try:
|
||||||
mac = VM(vmid).get_mac()
|
mac = VM(vmid).get_mac()
|
||||||
break
|
break
|
||||||
|
@ -254,7 +270,7 @@ def clone_vm(proxmox, template_id, name, pool):
|
||||||
description='Managed by Proxstar',
|
description='Managed by Proxstar',
|
||||||
target=target)
|
target=target)
|
||||||
retry = 0
|
retry = 0
|
||||||
while retry < 60:
|
while retry < 100:
|
||||||
try:
|
try:
|
||||||
mac = VM(newid).get_mac()
|
mac = VM(newid).get_mac()
|
||||||
break
|
break
|
||||||
|
|
|
@ -15,3 +15,4 @@ sshtunnel
|
||||||
psutil
|
psutil
|
||||||
requests
|
requests
|
||||||
rq_dashboard
|
rq_dashboard
|
||||||
|
tenacity
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue