mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
allow selection of ISO during creation and display ISO on vm details page
This commit is contained in:
parent
a2278f59db
commit
ba36af7dd5
5 changed files with 47 additions and 4 deletions
10
app.py
10
app.py
|
@ -42,6 +42,7 @@ def vm_details(vmid):
|
|||
vm['vmid'] = vmid
|
||||
vm['config'] = get_vm_config(proxmox, vmid)
|
||||
vm['disks'] = get_vm_disks(proxmox, vmid, config=vm['config'])
|
||||
vm['isos'] = get_vm_isos(proxmox, vmid, config=vm['config'])
|
||||
vm['interfaces'] = get_vm_interfaces(
|
||||
proxmox, vm['vmid'], config=vm['config'])
|
||||
return render_template('vm_details.html', username='com6056', vm=vm)
|
||||
|
@ -76,24 +77,29 @@ def create():
|
|||
limits = get_user_usage_limits(user)
|
||||
full_limits = check_user_limit(proxmox, user, usage, limits)
|
||||
percents = get_user_usage_percent(proxmox, usage, limits)
|
||||
isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE'])
|
||||
return render_template(
|
||||
'create.html',
|
||||
username='com6056',
|
||||
usage=usage,
|
||||
limits=limits,
|
||||
full_limits=full_limits,
|
||||
percents=percents)
|
||||
percents=percents,
|
||||
isos=isos)
|
||||
elif request.method == 'POST':
|
||||
name = request.form['name']
|
||||
cores = request.form['cores']
|
||||
memory = request.form['memory']
|
||||
disk = request.form['disk']
|
||||
iso = request.form['iso']
|
||||
if iso != 'none':
|
||||
iso = "{}:iso/{}".format(app.config['PROXMOX_ISO_STORAGE'], iso)
|
||||
usage_check = check_user_usage(proxmox, user, cores, memory, disk)
|
||||
if usage_check:
|
||||
return usage_check
|
||||
else:
|
||||
vmid, mac = create_vm(proxmox, starrs, user, name, cores, memory,
|
||||
disk)
|
||||
disk, iso)
|
||||
register_starrs(starrs, name, user, mac,
|
||||
get_next_ip(starrs,
|
||||
app.config['STARRS_IP_RANGE'])[0][0])
|
||||
|
|
27
proxmox.py
27
proxmox.py
|
@ -106,6 +106,23 @@ def get_vm_disks(proxmox, vmid, config=None):
|
|||
return disks
|
||||
|
||||
|
||||
def get_vm_isos(proxmox, vmid, config=None):
|
||||
if not config:
|
||||
config = get_vm_config(proxmox, vmid)
|
||||
drives = []
|
||||
for key, val in config.items():
|
||||
valid_drive_types = ['ide', 'sata', 'scsi']
|
||||
if any(drive_type in key for drive_type in valid_drive_types):
|
||||
if 'cdrom' in val:
|
||||
if val.split(',')[0] == 'none':
|
||||
iso = 'None'
|
||||
else:
|
||||
iso = val.split(',')[0].split('/')[1]
|
||||
drives.append([key, iso])
|
||||
drives = sorted(drives, key=lambda x: x[0])
|
||||
return drives
|
||||
|
||||
|
||||
def get_user_usage_limits(user):
|
||||
limits = dict()
|
||||
limits['cpu'] = 4
|
||||
|
@ -169,7 +186,7 @@ def get_user_usage_percent(proxmox, usage=None, limits=None):
|
|||
return percents
|
||||
|
||||
|
||||
def create_vm(proxmox, starrs, user, name, cores, memory, disk):
|
||||
def create_vm(proxmox, starrs, user, name, cores, memory, disk, iso):
|
||||
node = proxmox.nodes(get_node_least_mem(proxmox))
|
||||
vmid = get_free_vmid(proxmox)
|
||||
node.qemu.create(
|
||||
|
@ -179,6 +196,7 @@ def create_vm(proxmox, starrs, user, name, cores, memory, disk):
|
|||
memory=memory,
|
||||
storage='ceph',
|
||||
virtio0="ceph:{}".format(disk),
|
||||
ide2="{},media=cdrom".format(iso),
|
||||
net0='virtio,bridge=vmbr0',
|
||||
pool=user)
|
||||
time.sleep(3)
|
||||
|
@ -205,3 +223,10 @@ def change_vm_power(proxmox, vmid, action):
|
|||
node.qemu(vmid).status.suspend.post()
|
||||
elif action == 'resume':
|
||||
node.qemu(vmid).status.resume.post()
|
||||
|
||||
|
||||
def get_isos(proxmox, storage):
|
||||
isos = []
|
||||
for iso in proxmox.nodes('proxmox01').storage(storage).content.get():
|
||||
isos.append(iso['volid'].split('/')[1])
|
||||
return isos
|
||||
|
|
|
@ -55,7 +55,6 @@ table, th, td {
|
|||
font-weight: bold;
|
||||
line-height: 18px;
|
||||
color: #999999;
|
||||
text-transform: uppercase;
|
||||
margin-left: -15px;
|
||||
margin-right: -15px;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,15 @@
|
|||
<label for="disk">Disk</label>
|
||||
<input type="text" name="disk" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="iso">ISO</label>
|
||||
<select name="iso" class="form-control">
|
||||
<option value="none"></option>
|
||||
{% for iso in isos %}
|
||||
<option value="{{ iso }}">{{ iso }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-success" type="submit" value="Create">Create</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
{% for disk in vm['disks'] %}
|
||||
<li>{{ disk[0] }}: {{ disk[1] }}</li>
|
||||
{% endfor %}
|
||||
<li class="nav-header">ISO</li>
|
||||
{% for iso in vm['isos'] %}
|
||||
<li>{{ iso[1] }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue