Skip to content

Commit

Permalink
kvm: remove kernel and initrd parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Oct 1, 2024
1 parent c0fe46b commit b73fc3e
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 129 deletions.
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1571,8 +1571,6 @@ parameters:
|*sharedfolders*|[]|List of paths to share between hypervisor and vm. You will also need to make sure that the path is accessible as qemu user (typically with id 107) and use an hypervisor and a guest with 9p support (centos/rhel lack it for instance)|
|*yamlinventory*|false|Ansible generated inventory for single vms or for plans containing ansible entries will be yaml based.|
|*autostart*|false|Autostarts vm (Libvirt specific)|
|*kernel*|None|Kernel location to pass to the vm. Needs to be local to the hypervisor|
|*initrd*|None|Initrd location to pass to the vm. Needs to be local to the hypervisor|
|*cmdline*|None|Cmdline to pass to the vm|
|*pcidevices*|[]|array of pcidevices to passthrough to the first worker only. Check [here](https://github.com/karmab/kcli-plan-samples/blob/main/pcipassthrough/pci.yml) for an example|
|*tpm*|false|Enables a TPM device in the vm, using emulator mode. Requires swtpm in the host|
Expand Down
2 changes: 0 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,6 @@ Parameter Default Value Comments
*sharedfolders* [] List of paths to share between hypervisor and vm. You will also need to make sure that the path is accessible as qemu user (typically with id 107) and use an hypervisor and a guest with 9p support (centos/rhel lack it for instance)
*yamlinventory* false Ansible generated inventory for single vms or for plans containing ansible entries will be yaml based.
*autostart* false Autostarts vm (Libvirt specific)
*kernel* None Kernel location to pass to the vm. Needs to be local to the hypervisor
*initrd* None Initrd location to pass to the vm. Needs to be local to the hypervisor
*cmdline* None Cmdline to pass to the vm
*pcidevices* [] array of pcidevices to passthrough to the first worker only. Check `here <https://github.com/karmab/kcli-plan-samples/blob/main/pcipassthrough/pci.yml>`__ for an example
*tpm* false Enables a TPM device in the vm, using emulator mode. Requires swtpm in the host
Expand Down
4 changes: 0 additions & 4 deletions kvirt/baseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ def __init__(self, client=None, containerclient=None, debug=False, quiet=False,
defaults['mailfrom'] = default.get('mailfrom', kdefaults.MAILFROM)
defaults['mailto'] = default.get('mailto', kdefaults.MAILTO)
defaults['sharedfolders'] = default.get('sharedfolders', kdefaults.SHAREDFOLDERS)
defaults['kernel'] = default.get('kernel', kdefaults.KERNEL)
defaults['initrd'] = default.get('initrd', kdefaults.INITRD)
defaults['cmdline'] = default.get('cmdline', kdefaults.CMDLINE)
defaults['placement'] = default.get('placement', kdefaults.PLACEMENT)
defaults['cpuhotplug'] = bool(default.get('cpuhotplug', kdefaults.CPUHOTPLUG))
Expand Down Expand Up @@ -423,8 +421,6 @@ def __init__(self, client=None, containerclient=None, debug=False, quiet=False,
self.mailserver = options.get('mailserver')
self.mailfrom = options.get('mailfrom')
self.mailto = options.get('mailto')
self.kernel = options.get('kernel')
self.initrd = options.get('initrd')
self.cmdline = options.get('cmdline')
self.placement = options.get('placement')
self.cpuhotplug = options.get('cpuhotplug')
Expand Down
11 changes: 3 additions & 8 deletions kvirt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,6 @@ def create_vm(self, name, profile=None, overrides={}, customprofile={}, k=None,
default_pushbullettoken = father.get('pushbullettoken', self.pushbullettoken)
default_slacktoken = father.get('slacktoken', self.slacktoken)
default_sharedfolders = father.get('sharedfolders', self.sharedfolders)
default_kernel = father.get('kernel', self.kernel)
default_initrd = father.get('initrd', self.initrd)
default_cmdline = father.get('cmdline', self.cmdline)
default_placement = father.get('placement', self.placement)
default_cpuhotplug = father.get('cpuhotplug', self.cpuhotplug)
Expand Down Expand Up @@ -696,8 +694,6 @@ def create_vm(self, name, profile=None, overrides={}, customprofile={}, k=None,
mailfrom = profile.get('mailfrom', default_mailfrom)
mailto = profile.get('mailto', default_mailto)
sharedfolders = profile.get('sharedfolders', default_sharedfolders)
kernel = profile.get('kernel', default_kernel)
initrd = profile.get('initrd', default_initrd)
cmdline = profile.get('cmdline', default_cmdline)
placement = profile.get('placement', default_placement)
cpuhotplug = profile.get('cpuhotplug', default_cpuhotplug)
Expand Down Expand Up @@ -981,10 +977,9 @@ def create_vm(self, name, profile=None, overrides={}, customprofile={}, k=None,
start=bool(start), keys=keys, cmds=cmds, ips=ips, netmasks=netmasks, gateway=gateway, dns=dns,
domain=domain, nested=bool(nested), tunnel=tunnel, files=files, enableroot=enableroot,
overrides=overrides, tags=tags, storemetadata=storemetadata,
sharedfolders=sharedfolders, kernel=kernel, initrd=initrd, cmdline=cmdline,
placement=placement, autostart=autostart, cpuhotplug=cpuhotplug, memoryhotplug=memoryhotplug,
pcidevices=pcidevices, tpm=tpm, rng=rng, metadata=metadata, securitygroups=securitygroups,
vmuser=vmuser, guestagent=guestagent)
sharedfolders=sharedfolders, cmdline=cmdline, placement=placement, autostart=autostart,
cpuhotplug=cpuhotplug, memoryhotplug=memoryhotplug, pcidevices=pcidevices, tpm=tpm, rng=rng,
metadata=metadata, securitygroups=securitygroups, vmuser=vmuser, guestagent=guestagent)
if result['result'] != 'success':
return result
if reservedns and dnsclient is not None and domain is not None:
Expand Down
2 changes: 0 additions & 2 deletions kvirt/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@
SLACKCHANNEL = None
NOTIFYMETHODS = ['pushbullet']
SHAREDFOLDERS = []
KERNEL = None
INITRD = None
CMDLINE = None
PLACEMENT = []
YAMLINVENTORY = False
Expand Down
2 changes: 1 addition & 1 deletion kvirt/providers/aws/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
vnc=True, cloudinit=True, reserveip=False, reservedns=False, reservehost=False, start=True, keys=[],
cmds=[], ips=None, netmasks=None, gateway=None, nested=True, dns=None, domain=None, tunnel=False,
files=[], enableroot=True, alias=[], overrides={}, tags=[], storemetadata=False,
sharedfolders=[], kernel=None, initrd=None, cmdline=None, placement=[], autostart=False,
sharedfolders=[], cmdline=None, placement=[], autostart=False,
cpuhotplug=False, memoryhotplug=False, numamode=None, numa=[], pcidevices=[], tpm=False, rng=False,
metadata={}, securitygroups=[], vmuser=None, guestagent=True):
conn = self.conn
Expand Down
7 changes: 3 additions & 4 deletions kvirt/providers/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
disks=[{'size': 10}], disksize=10, diskthin=True, diskinterface='virtio', nets=['default'], iso=None,
vnc=True, cloudinit=True, reserveip=False, reservedns=False, reservehost=False, start=True, keys=[],
cmds=[], ips=None, netmasks=None, gateway=None, nested=True, dns=None, domain=None, tunnel=False,
files=[], enableroot=True, overrides={}, tags=[], storemetadata=False, sharedfolders=[], kernel=None,
initrd=None, cmdline=None, placement=[], autostart=False, cpuhotplug=False, memoryhotplug=False,
numamode=None, numa=[], pcidevices=[], tpm=False, rng=False, metadata={}, securitygroups=[],
vmuser=None, guestagent=True):
files=[], enableroot=True, overrides={}, tags=[], storemetadata=False, sharedfolders=[], cmdline=None,
placement=[], autostart=False, cpuhotplug=False, memoryhotplug=False, numamode=None, numa=[],
pcidevices=[], tpm=False, rng=False, metadata={}, securitygroups=[], vmuser=None, guestagent=True):
if self.exists(name):
return {'result': 'failure', 'reason': f"VM {name} already exists"}
if flavor is None:
Expand Down
6 changes: 3 additions & 3 deletions kvirt/providers/gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
vnc=True, cloudinit=True, reserveip=False, reservedns=False, reservehost=False, start=True, keys=[],
cmds=[], ips=None, netmasks=None, gateway=None, nested=True, dns=None, domain=None, tunnel=False,
files=[], enableroot=True, alias=[], overrides={}, tags=[], storemetadata=False,
sharedfolders=[], kernel=None, initrd=None, cmdline=None, placement=[], autostart=False,
cpuhotplug=False, memoryhotplug=False, numamode=None, numa=[], pcidevices=[], tpm=False, rng=False,
metadata={}, securitygroups=[], vmuser=None, guestagent=True):
sharedfolders=[], cmdline=None, placement=[], autostart=False, cpuhotplug=False, memoryhotplug=False,
numamode=None, numa=[], pcidevices=[], tpm=False, rng=False, metadata={}, securitygroups=[],
vmuser=None, guestagent=True):
conn = self.conn
project = self.project
region = self.region
Expand Down
6 changes: 3 additions & 3 deletions kvirt/providers/ibm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt',
reservehost=False, start=True, keys=[], cmds=[], ips=None,
netmasks=None, gateway=None, nested=True, dns=None, domain=None,
tunnel=False, files=[], enableroot=True, alias=[], overrides={},
tags=[], storemetadata=False, sharedfolders=[], kernel=None, initrd=None, cmdline=None,
cpuhotplug=False, memoryhotplug=False, numamode=None, numa=[], pcidevices=[], tpm=False,
placement=[], autostart=False, rng=False, metadata={}, securitygroups=[], vmuser=None, guestagent=True):
tags=[], storemetadata=False, sharedfolders=[], cmdline=None, cpuhotplug=False, memoryhotplug=False,
numamode=None, numa=[], pcidevices=[], tpm=False, placement=[], autostart=False, rng=False, metadata={},
securitygroups=[], vmuser=None, guestagent=True):
try:
vpcs = self.conn.list_vpcs().result['vpcs']
for vpc in vpcs:
Expand Down
6 changes: 3 additions & 3 deletions kvirt/providers/kubevirt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
vnc=True, cloudinit=True, reserveip=False, reservedns=False, reservehost=False, start=True, keys=[],
cmds=[], ips=None, netmasks=None, gateway=None, nested=True, dns=None, domain=None, tunnel=False,
files=[], enableroot=True, alias=[], overrides={}, tags=[], storemetadata=False,
sharedfolders=[], kernel=None, initrd=None, cmdline=None, placement=[], autostart=False,
cpuhotplug=False, memoryhotplug=False, numamode=None, numa=[], pcidevices=[], tpm=False, rng=False,
metadata={}, securitygroups=[], vmuser=None, guestagent=True):
sharedfolders=[], cmdline=None, placement=[], autostart=False, cpuhotplug=False, memoryhotplug=False,
numamode=None, numa=[], pcidevices=[], tpm=False, rng=False, metadata={}, securitygroups=[],
vmuser=None, guestagent=True):
kubectl = self.kubectl
owners = []
container_disk = overrides.get('container_disk', False)
Expand Down
78 changes: 2 additions & 76 deletions kvirt/providers/kvm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-

from getpass import getuser
# from urllib.request import urlopen, urlretrieve
from urllib.request import urlopen
from kvirt.defaults import IMAGES
from kvirt.defaults import UBUNTUS, METADATA_FIELDS
from kvirt import common
Expand Down Expand Up @@ -216,7 +214,7 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
vnc=True, cloudinit=True, reserveip=False, reservedns=False, reservehost=False, start=True, keys=[],
cmds=[], ips=None, netmasks=None, gateway=None, nested=True, dns=None, domain=None, tunnel=False,
files=[], enableroot=True, overrides={}, tags=[], storemetadata=False, sharedfolders=[],
kernel=None, initrd=None, cmdline=None, placement=[], autostart=False, cpuhotplug=False,
cmdline=None, placement=[], autostart=False, cpuhotplug=False,
memoryhotplug=False, numamode=None, numa=[], pcidevices=[], tpm=False, rng=False, metadata={},
securitygroups=[], vmuser=None, guestagent=True):
bootdev = 1
Expand Down Expand Up @@ -1154,77 +1152,6 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
foldercmd = 'ssh %s -p %s %s@%s "test -d %s || (%s)"' % (self.identitycommand, self.port,
self.user, self.host, folder, foldercmd)
code = os.system(foldercmd)
kernelxml = ""
if kernel is not None:
existing_kernel = os.path.basename(kernel) in [os.path.basename(v) for v in self.volumes()]
locationdir = os.path.basename(kernel)
locationdir = f"{default_poolpath}/{locationdir}"
if existing_kernel:
pass
elif self.host == 'localhost' or self.host == '127.0.0.1':
os.mkdir(locationdir)
elif self.protocol == 'ssh':
locationcmd = 'ssh %s -p %s %s@%s "mkdir %s"' % (self.identitycommand, self.port, self.user,
self.host, locationdir)
code = os.system(locationcmd)
else:
return {'result': 'failure', 'reason': "Couldn't create dir to hold kernel and initrd"}
if kernel.startswith('http') or kernel.startswith('ftp'):
if existing_kernel:
pass
elif 'rhcos' in kernel:
if self.host == 'localhost' or self.host == '127.0.0.1':
kernelcmd = f"curl -Lo {locationdir}/vmlinuz -f '{kernel}'"
initrdcmd = f"curl -Lo {locationdir}/initrd.img -f '{initrd}'"
elif self.protocol == 'ssh':
kernelcmd = 'ssh %s -p %s %s@%s "curl -Lo %s/vmlinuz -f \'%s\'"' % (self.identitycommand,
self.port, self.user,
self.host, locationdir,
kernel)
initrdcmd = 'ssh %s -p %s %s@%s "curl -Lo %s/initrd.img -f \'%s\'"' % (self.identitycommand,
self.port, self.user,
self.host, locationdir,
initrd)
code = os.system(kernelcmd)
code = os.system(initrdcmd)
else:
try:
location = urlopen(kernel).readlines()
except Exception as e:
return {'result': 'failure', 'reason': e}
for line in location:
if 'init' in str(line):
p = re.compile(r'.*<a href="(.*)">\1.*')
m = p.match(str(line))
if m is not None and initrd is None:
initrdfile = m.group(1)
initrdurl = f"{kernel}/{initrdfile}"
initrd = f"{locationdir}/initrd"
if self.host == 'localhost' or self.host == '127.0.0.1':
initrdcmd = f"curl -Lo {initrd} -f '{initrdurl}'"
elif self.protocol == 'ssh':
initrdcmd = 'ssh %s -p %s %s@%s "curl -Lo %s -f \'%s\'"' % (self.identitycommand,
self.port, self.user,
self.host, initrd,
initrdurl)
code = os.system(initrdcmd)
kernelurl = f'{kernel}/vmlinuz'
kernel = f"{locationdir}/vmlinuz"
if self.host == 'localhost' or self.host == '127.0.0.1':
kernelcmd = f"curl -Lo {kernel} -f '{kernelurl}'"
elif self.protocol == 'ssh':
kernelcmd = 'ssh %s -p %s %s@%s "curl -Lo %s -f \'%s\'"' % (self.identitycommand,
self.port, self.user, self.host,
kernel, kernelurl)
code = os.system(kernelcmd)
elif initrd is None:
return {'result': 'failure', 'reason': "Missing initrd"}
warning("kernel and initrd will only be available during first boot")
kernel = f"{locationdir}/vmlinuz"
initrd = f"{locationdir}/initrd.img"
kernelxml = f"<kernel>{kernel}</kernel><initrd>{initrd}</initrd>"
if cmdline is not None:
kernelxml += f"<cmdline>{cmdline}</cmdline>"
memoryhotplugxml = "<maxMemory slots='16' unit='MiB'>1524288</maxMemory>" if memoryhotplug else ""
videoxml = ""
firmwarexml = ""
Expand Down Expand Up @@ -1340,7 +1267,6 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
{ramxml}
{firmwarexml}
{bootxml}
{kernelxml}
<bootmenu enable="yes" timeout="60"/>
</os>
<features>
Expand Down Expand Up @@ -1379,7 +1305,7 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
</domain>""".format(virttype=virttype, namespace=namespace, name=name, uuidxml=uuidxml, metadataxml=metadataxml,
memoryhotplugxml=memoryhotplugxml, cpupinningxml=cpupinningxml, numatunexml=numatunexml,
hugepagesxml=hugepagesxml, memory=memory, vcpuxml=vcpuxml, osfirmware=osfirmware, arch=arch,
machine=machine, ramxml=ramxml, firmwarexml=firmwarexml, bootxml=bootxml, kernelxml=kernelxml,
machine=machine, ramxml=ramxml, firmwarexml=firmwarexml, bootxml=bootxml,
smmxml=smmxml, emulatorxml=emulatorxml, disksxml=disksxml, busxml=busxml, netxml=netxml,
isoxml=isoxml, extraisoxml=extraisoxml, floppyxml=floppyxml, displayxml=displayxml,
serialxml=serialxml, sharedxml=sharedxml, guestxml=guestxml, videoxml=videoxml,
Expand Down
Loading

0 comments on commit b73fc3e

Please sign in to comment.