mirror of
https://git.56k.es/fanta/q.git
synced 2024-06-11 00:45:26 +02:00
cambios en el readme y script python
This commit is contained in:
parent
462fac61d7
commit
79bfd839d2
58
README.md
58
README.md
|
@ -6,63 +6,11 @@
|
|||
|
||||
<pre>
|
||||
$ git clone http://git.56k.es/fanta/q ; cd q
|
||||
$ chmod +x q
|
||||
# cp -pRv q /bin/q
|
||||
$ chmod +x q.py
|
||||
# cp -pRv q.py /bin/q
|
||||
</pre>
|
||||
|
||||
**Dependencies:**
|
||||
|
||||
- qemu-system-x86_64
|
||||
- qemu-system-i386
|
||||
- qemu-system-sparc
|
||||
- wget
|
||||
|
||||
|
||||
**Run first time:**
|
||||
|
||||
The first time we run "q" it will download the isos from a large list of different GNU+Linux distributions.
|
||||
It may take a long time to download the files. Please be patient.
|
||||
Note: Right now u can choice the iso to download.
|
||||
|
||||
<img src="imgs/first_time.png" alt="run script first time" width="100%"/>
|
||||
|
||||
|
||||
**Example: Install and run a Rocky Linux 8.6 distro**
|
||||
|
||||
Install virtual machine:
|
||||
<pre>
|
||||
$ cd ~/vms/rocky-8.6-x86_64
|
||||
$ bash install.sh
|
||||
</pre>
|
||||
|
||||
Start virtual machine:
|
||||
<pre>
|
||||
$ bash start.sh
|
||||
</pre>
|
||||
|
||||
Actual distro list:
|
||||
<pre>
|
||||
1 openSUSELeap 15.4
|
||||
2 RHEL 5.11
|
||||
3 RHEL 6.10
|
||||
4 RHEL 7.9
|
||||
5 RHEL 8.6
|
||||
6 Rocky 8.5
|
||||
7 Rocky 8.6
|
||||
8 Debian 9.13.0
|
||||
9 Debian 10.12.0
|
||||
10 Debian 11.4.0
|
||||
11 RouterOS 7.3.1
|
||||
12 AlmaLinux 8.6
|
||||
13 AlmaLinux 9.0
|
||||
14 Centos 5.11
|
||||
15 Centos 6.10
|
||||
16 Centos 7.9.2009
|
||||
17 Ubuntu 20.04.4
|
||||
18 Ubuntu 22.04.1
|
||||
19 Mint 21
|
||||
</pre>
|
||||
|
||||
Enjoy !
|
||||
|
||||
Kind regards.
|
||||
- libguestfs-tools
|
||||
|
|
87
q.py
Normal file
87
q.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Debian Lab - Máquinas virtuales con Debian levantadas rápidamente
|
||||
|
||||
import os
|
||||
import requests
|
||||
import shutil
|
||||
|
||||
dirVms=os.path.expanduser('~')+"/vms"
|
||||
dirVmsTemp=dirVms+"/templates"
|
||||
dirVmsImgs=dirVms+"/images"
|
||||
cloudImgs=["https://cloud.debian.org/images/cloud/buster/latest/debian-10-nocloud-amd64.qcow2", "https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-nocloud-amd64.qcow2", "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2"]
|
||||
vmMemory=4096 # En Megas
|
||||
|
||||
def main():
|
||||
createDirs() # Comprobamos si existen los directorios y si no es así se crean.
|
||||
downloadTemplates() # Comprobamos si ya están bajadas las imagenes cloud y si no es así se bajan.
|
||||
choice() # Elegir entre Crear una nueva máquina virtual, ejecutar una ya existente o borrarla.
|
||||
|
||||
def createDirs():
|
||||
if not os.path.exists(dirVms):
|
||||
os.makedirs(dirVms)
|
||||
os.makedirs(dirVmsTemp)
|
||||
os.makedirs(dirVmsImgs)
|
||||
|
||||
def downloadTemplates():
|
||||
qcowTemplates = os.listdir(dirVmsTemp)
|
||||
if len(qcowTemplates) == 0:
|
||||
for i in range(len(cloudImgs)):
|
||||
localFilename = cloudImgs[i].split('/')[-1]
|
||||
session = requests.Session()
|
||||
response = session.get(cloudImgs[i],allow_redirects=True,stream=True)
|
||||
if response.status_code == 200:
|
||||
print("[+] Downloading \t"+cloudImgs[i]+"\t[200]")
|
||||
downloadQcow = session.get(cloudImgs[i], allow_redirects=True)
|
||||
open(dirVmsTemp+"/"+localFilename, 'wb').write(downloadQcow.content)
|
||||
|
||||
def choice():
|
||||
print("[1] New VM\n[2] Run VM\n[3] Del VM\n[4] Exit")
|
||||
option=input("\nOption: ")
|
||||
if option == "1": createVms()
|
||||
if option == "2": runVms()
|
||||
if option == "3": delVms()
|
||||
if option == "4": return 0
|
||||
|
||||
|
||||
def createVms():
|
||||
qcowFiles = os.listdir(dirVmsTemp)
|
||||
qcowFiles.sort()
|
||||
vmName=input("\nVM Name: ")
|
||||
print("\nSeleccione una versión de Debian\n")
|
||||
for i in range(len(qcowFiles)):
|
||||
print("["+str(i)+"] - Debian "+qcowFiles[i].split('-')[-3]+" ("+qcowFiles[i].split('-')[-1]+")")
|
||||
vmVersion=input("\nVersion: ")
|
||||
shutil.copyfile(dirVmsTemp+"/"+qcowFiles[int(vmVersion)], dirVmsImgs+"/"+vmName+".qcow2")
|
||||
print("\nTamaño del disco en Gigas")
|
||||
vmSize=input("\nSize: ")
|
||||
os.system("qemu-img resize "+dirVmsImgs+"/"+vmName+".qcow2 "+vmSize+"G")
|
||||
print("\nPassword de root")
|
||||
vmPasswd=input("\nPassword: ")
|
||||
os.system("virt-customize -a "+dirVmsImgs+"/"+vmName+".qcow2 --root-password password:"+vmPasswd)
|
||||
os.system("virt-customize -a "+dirVmsImgs+"/"+vmName+".qcow2 --hostname "+vmName)
|
||||
choice()
|
||||
|
||||
def runVms():
|
||||
qcowFiles = os.listdir(dirVmsImgs)
|
||||
qcowFiles.sort()
|
||||
if len(qcowFiles) != 0:
|
||||
print("\nSeleccione una máquina para ejecutarla\n")
|
||||
for i in range(len(qcowFiles)):
|
||||
print("["+str(i)+"] - "+qcowFiles[i])
|
||||
vmRun=input("\nMachine: ")
|
||||
os.system("qemu-system-x86_64 -machine type=q35,accel=kvm -enable-kvm -smp $(nproc) --boot c -nographic -monitor telnet::45454,server,nowait -serial mon:stdio -m "+str(vmMemory)+" -hda "+dirVmsImgs+"/"+qcowFiles[int(vmRun)])
|
||||
choice()
|
||||
|
||||
def delVms():
|
||||
qcowFiles = os.listdir(dirVmsImgs)
|
||||
qcowFiles.sort()
|
||||
if len(qcowFiles) != 0:
|
||||
print("\nSeleccione una máquina para borrarla\n")
|
||||
for i in range(len(qcowFiles)):
|
||||
print("["+str(i)+"] - "+qcowFiles[i])
|
||||
vmDel=input("\nMachine: ")
|
||||
os.system("rm -rf "+dirVmsImgs+"/"+qcowFiles[int(vmDel)])
|
||||
choice()
|
||||
|
||||
main()
|
Loading…
Reference in New Issue
Block a user