Storage reviewed

main
root 2024-03-18 11:03:26 +01:00
parent 2f113ad01b
commit 93f2a5379f
4 changed files with 67 additions and 27 deletions

View File

@ -10,6 +10,22 @@ Please refer to the README file, all install steps are described.
Not refered in the install, but you can pipx for you install.
# Storage
The server storage are in *{HYPE}/storage/*
You will find a folder *win* for the virtio image, *disks* for the VM images (qcow2) and iso for iso install images.
You can change these storage in *config.py* file.
For the *disks*,if you prefer to use the default libvirt pool storage (*/var/lib/libvirt/images*)
You can modify :
*--disk path='+str(disk_path)+str(nom)+'.qcow2,size='+str(disk)+',bus=virtio*
by
*--disk pool=default,size='+str(disk)+',bus=virtio,format=qcow2*
# Virtual Server Creation
## Linux
@ -24,7 +40,7 @@ For the moment, no issue with tested distribution:
## Other install
Tested succeffully :
- Pfsense,Dynfi,Open
- Pfsense,Dynfi,Opnsense
## Windows
@ -56,6 +72,16 @@ Failed with :
Never Tested :
- Win 7 and Vista
#OTHER
Please report your bugs to improve this dev.
#SOURCES
https://libvirt.gitlab.io/libvirt-appdev-guide-python/index.html
https://libvirt-python.readthedocs.io/
https://linuxcontainers.org/lxc/documentation/
# ERROR and SOLUTION
@ -63,8 +89,13 @@ You may incounter some error in specific case, please report them if they are no
They will be consider on nexts releases.
ERROR: Error destroying Requested operation is not valid: cannot undefine domain with nvram :
SOLUTION (on CLI): virsh undefine --nvram VM_NAME
ERROR: Error stoping NOM_VM:Requested operation is not valid: domain is not running
SOLUTION 1 (on CLI): virsh reset VM_NAME
SOLUTION 2 (on CLI): virsh destroy VM_NAME (destroy the VM)

View File

@ -1,7 +1,8 @@
# Hype²
Now compatible with Windows Install, just take care to launch the driver before scanning disks.
##News
- Now compatible with Windows Install, just take care to launch the driver before scanning disks.
- Screenshot and VM live edition (RAM and vCPU) added
```mermaid
graph LR

51
app.py
View File

@ -17,7 +17,6 @@ from functions.fvnc import *
from functions.fbackup import *
from functions.fpool import *
from functions.fedit import *
from functions.fscreen import *
app = Flask(__name__,static_url_path='',static_folder='static',template_folder='templates')
@ -263,7 +262,6 @@ def get_users():
list_users.append(single)
return list_users
@app.route('/param',methods=['GET'])
@login_required
def param():
@ -293,28 +291,36 @@ def edit():
vm_name = request.form['edit']
state, maxmem, mem, cpus, cput = get_info_vm(vm_name)
#Memory in MB
return render_template('edit.html', vm_name=vm_name, max_Mermory=conn.getInfo()[1],max_vCPU= conn.getMaxVcpus(None),actual_vCPU=cpus, actual_ram=int(mem/1024),screen_64=get_screenshot(vm_name).decode('ASCII'))
return render_template('edit.html', vm_name=vm_name, max_Mermory=conn.getInfo()[1],max_vCPU= conn.getMaxVcpus(None),actual_vCPU=cpus, actual_ram=int(mem/1024),screen_64=get_screenshot(vm_name).decode('ASCII'),actual_autostart=get_autostart(vm_name))
@app.route('/editressources',methods=['POST'])
@login_required
def editressources():
vm_name = request.form['vm_name']
new_ram = int(request.form['new_mem'])
new_cpu = int(request.form['new_cpu'])
print("vm:"+vm_name)
print("ram:"+str(new_ram))
print("vcpu:"+str(new_cpu))
try:
set_memory(vm_name,int(new_ram*1024))
except Exception as e:
flash('Error editing '+vm_name+': '+str(e), category='danger')
try:
set_vcpu(vm_name,new_cpu)
except Exception as e:
flash('Error editing '+vm_name+': '+str(e), category='danger')
return redirect(url_for('state'))
vm_name = request.form['vm_name']
new_ram = int(request.form['new_mem'])
new_cpu = int(request.form['new_cpu'])
new_autostart = request.form.get('new_autostart')
try:
set_memory(vm_name,int(new_ram*1024))
except Exception as e:
flash('Error editing Memory for '+vm_name+': '+str(e), category='danger')
try:
set_vcpu(vm_name,new_cpu)
except Exception as e:
flash('Error editing CPU for '+vm_name+': '+str(e), category='danger')
#Autostart
if request.form.get('new_autostart')=='auto_check':
try:
set_autostart(vm_name)
except Exception as e:
flash('Error editing Autostart for '+vm_name+': '+str(e), category='danger')
else:
try:
unset_autostart(vm_name)
except Exception as e:
flash('Error editing Autostart for '+vm_name+': '+str(e), category='danger')
return redirect(url_for('state'))
############################
## ISO ##
@ -509,17 +515,16 @@ def create_VM():
####################################
if ose.startswith('win'):
try:
cmd = "qemu-img create -f qcow2 "+str(virtuo_path)+str(nom)+".qcow2 "+str(disk)+"G"
cmd = "qemu-img create -f qcow2 "+str(disk_path)+str(nom)+".qcow2 "+str(disk)+"G"
subprocess.call(cmd, shell=True)
except Exception as e:
flash('Error on creating '+str(nom)+':'+str(e),category='danger')
return redirect(url_for('state'))
opt = " --disk path="+virtuo_path+virtuo_file+",device=cdrom"
ostype = 'windows'
diskpath = " --disk path="+str(virtuo_path)+str(nom)+".qcow2,size="+str(disk)+",bus=virtio"
creationcmd='--name '+str(nom)+' --ram '+str(ram)+' --disk path='+str(virtuo_path)+str(nom)+'.qcow2,bus=virtio,format=qcow2 --vcpus '+str(cpu)+' --os-type '+str(ostype)+' --os-variant '+str(ose)+' --network network:bridged --graphics vnc,listen=0.0.0.0 --noautoconsole --console pty,target_type=serial '+opt+' --cdrom '+str(iso)+' --force --debug '
creationcmd='--name '+str(nom)+' --ram '+str(ram)+' --disk path='+str(disk_path)+str(nom)+'.qcow2,bus=virtio,format=qcow2 --vcpus '+str(cpu)+' --os-type '+str(ostype)+' --os-variant '+str(ose)+' --network network:bridged --graphics vnc,listen=0.0.0.0 --noautoconsole --console pty,target_type=serial '+opt+' --cdrom '+str(iso)+' --force --debug '
else:
creationcmd='--name '+str(nom)+' --ram '+str(ram)+' --disk pool=default,size='+str(disk)+',bus=virtio,format=qcow2 --vcpus '+str(cpu)+' --os-type '+str(ostype)+' --os-variant '+str(ose)+' --network network:bridged --graphics vnc,listen=0.0.0.0 --noautoconsole --console pty,target_type=serial '+opt+' --cdrom '+str(iso)+' --force --debug '
creationcmd='--name '+str(nom)+' --ram '+str(ram)+' --disk path='+str(disk_path)+str(nom)+'.qcow2,size='+str(disk)+',bus=virtio --vcpus '+str(cpu)+' --os-type '+str(ostype)+' --os-variant '+str(ose)+' --network network:bridged --graphics vnc,listen=0.0.0.0 --noautoconsole --console pty,target_type=serial '+opt+' --cdrom '+str(iso)+' --force --debug '
try:
os.system('virt-install '+creationcmd+' ')
flash(str(nom)+' created', category='success')

View File

@ -2,6 +2,7 @@ import os
import libvirt
import math
hype_version = '2.7'
#Flask config
class flask_config:
port=5007
@ -12,7 +13,9 @@ class flask_config:
#Path
path = os.path.abspath(os.path.dirname(__file__))
iso_path= path+'/storage/iso/'
disk_path = path+'/storage/disks/'
virtuo_path= path+'/storage/win/'
virtuo_file='virtio-win-0.1.229.iso'
#Qemu connection
try:
conn = libvirt.open("qemu:///system")