Skip to content

Commit 39ec49b

Browse files
committed
ksushy bootonce: force boot order
1 parent 980b594 commit 39ec49b

File tree

9 files changed

+17
-105
lines changed

9 files changed

+17
-105
lines changed

docs/index.md

-5
Original file line numberDiff line numberDiff line change
@@ -2386,11 +2386,6 @@ For plugging an iso, only virtualization providers can be used.
23862386

23872387
When deploying the service, an username and password can be specified for securing access through basic authentication
23882388

2389-
## Using Bootonce with ksushy
2390-
2391-
Since virtualization providers don't provide a way to restart in a given iso only one time (and because in kcli design, we don't want to mess with boot orders), the `bootonce` overcomes this by running a side process which monitors vms getting rebooted, and restart them instead after removing their iso to make sure they boot from OS.
2392-
2393-
# Using kcli as a library
23942389

23952390
You can use kvirt library directly, without the client or to embed it into your own application.
23962391

docs/index.rst

-8
Original file line numberDiff line numberDiff line change
@@ -2533,14 +2533,6 @@ Restricting ksushy access
25332533

25342534
When deploying the service, an username and password can be specified for securing access through basic authentication
25352535

2536-
Using Bootonce with ksushy
2537-
--------------------------
2538-
2539-
Since virtualization providers don’t provide a way to restart in a given iso only one time (and because in kcli design, we don’t want to mess with boot orders), the ``bootonce`` overcomes this by running a side process which monitors vms getting rebooted, and restart them instead after removing their iso to make sure they boot from OS.
2540-
2541-
Using kcli as a library
2542-
=======================
2543-
25442536
You can use kvirt library directly, without the client or to embed it into your own application.
25452537

25462538
Here’s a sample:

kcli.spec

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ rm -rf %{buildroot}
5353
%attr(0755,root,root) %{_bindir}/kweb
5454
%attr(0755,root,root) %{_bindir}/klist.py
5555
%attr(0755,root,root) %{_bindir}/ksushy
56-
%attr(0755,root,root) %{_bindir}/ksushy-isoremover
5756
%attr(0755,root,root) %{_bindir}/ignitionmerger
5857
%attr(0755,root,root) %{_bindir}/ekstoken
5958
%attr(0755,root,root) %{_bindir}/gketoken

kvirt/baseconfig.py

-14
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,6 @@ def deploy_ksushy_service(self, port=9000, ssl=False, ipv6=False, user=None, pas
14541454
os.makedirs(os.path.dirname(service_file))
14551455
update = os.path.exists(service_file)
14561456
home = os.environ.get('HOME', '/root')
1457-
iso_remover = bootonce
14581457
executable = which('ksushy')
14591458
port = f"Environment=KSUSHY_PORT={port}\n" if port != 9000 else ''
14601459
ssl = "Environment=KSUSHY_SSL=true\n" if ssl else ''
@@ -1469,19 +1468,6 @@ def deploy_ksushy_service(self, port=9000, ssl=False, ipv6=False, user=None, pas
14691468
user_space = "--user" if not root else ""
14701469
cmd = f"systemctl {user_space} restart ksushy" if update else f"systemctl {user_space} enable --now ksushy"
14711470
call(cmd, shell=True)
1472-
if iso_remover:
1473-
executable = which('ksushy-isoremover')
1474-
plan = f"Environment=KSUSHY_PLAN={plan}\n" if plan is not None else ''
1475-
isoremoverdata = kdefaults.ISOSERVICE.format(home=home, executable=executable, plan=plan)
1476-
if root:
1477-
service_file = "/etc/systemd/system/ksushy-isoremover.service"
1478-
else:
1479-
service_file = f"{os.environ.get('HOME')}/.config/systemd/user/ksushy-isoremover.service"
1480-
with open(service_file, "w") as f:
1481-
f.write(isoremoverdata)
1482-
cmd = f"systemctl {user_space} restart" if update else f"systemctl {user_space} enable --now"
1483-
cmd += " ksushy-isoremover"
1484-
call(cmd, shell=True)
14851471

14861472
def deploy_web_service(self, port=8000, ssl=False, ipv6=False):
14871473
update = os.path.exists("/usr/lib/systemd/system/kweb.service")

kvirt/defaults.py

-13
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,6 @@
229229
[Install]
230230
WantedBy=multi-user.target"""
231231

232-
ISOSERVICE = """[Unit]
233-
Description=Ksushy iso remover service
234-
After=syslog.target
235-
[Service]
236-
Type=simple
237-
ExecStart={executable}
238-
StandardOutput=journal
239-
StandardError=journal
240-
Environment=HOME={home}
241-
Environment=PYTHONUNBUFFERED=true
242-
[Install]
243-
WantedBy=multi-user.target"""
244-
245232
WEBSERVICE = """[Unit]
246233
Description=Kweb service
247234
After=syslog.target

kvirt/ksushy/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ def system_reset_action(client, name):
200200
if reset_type in ['On', 'ForceRestart']:
201201
try:
202202
pprint(f"Starting vm {name}")
203-
k.start_from_cd(name) if self.bootonce and config.type == 'kvm' else k.start(name)
203+
if config.type == 'kvm' and self.bootonce:
204+
pprint(f"Forcing boot from cdrom for vm {name}")
205+
k.force_cdrom(name)
206+
k.start(name)
204207
except subprocess.CalledProcessError as e:
205208
error(e)
206209
response.status = 400

kvirt/ksushy/isoremover.py

-49
This file was deleted.

kvirt/providers/kvm/__init__.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1439,29 +1439,29 @@ def start(self, name):
14391439
return {'result': 'failure', 'reason': e}
14401440
return {'result': 'success'}
14411441

1442-
def start_from_cd(self, name):
1442+
def force_cdrom(self, name):
14431443
self.stop(name)
14441444
conn = self.conn
14451445
vm = conn.lookupByName(name)
14461446
xml = vm.XMLDesc(0)
14471447
root = ET.fromstring(xml)
1448+
for _os in list(root.iter('os')):
1449+
if list(_os.iter('boot'))[0].get('dev') == 'cdrom':
1450+
return {'result': 'success'}
14481451
newxml = ET.tostring(root).decode("utf-8")
1452+
newxml = newxml.replace('dev="cdrom"', 'dev="TEMP"')
14491453
newxml = newxml.replace('dev="hd"', 'dev="cdrom"')
1450-
newxml = newxml.replace('dev="network"', 'dev="hd"')
1454+
newxml = newxml.replace('dev="TEMP"', 'dev="hd"')
14511455
for element in list(root.iter('disk')):
14521456
if element.get('device') == 'cdrom':
1453-
iso_file = element.find('source').get('file') if element.find('source') is not None else None
1454-
if iso_file is None or iso_file.endswith(f'{name}.ISO'):
1455-
warning(f"No iso found in VM {name}, starting normally")
1456-
return self.start(name)
1457-
boot = element.find('boot') or {}
1458-
cd_order = boot.get('order')
1459-
if cd_order is not None:
1460-
newxml = newxml.replace("<boot order='1'/>", "<boot order='XX'/>")
1461-
newxml = newxml.replace(f"<boot order='{cd_order}'/>", "<boot order='1'/>")
1462-
newxml = newxml.replace("<boot order='XX'/>", f"<boot order='{cd_order}'/>")
1457+
boot = element.find('boot')
1458+
if boot is not None:
1459+
cd_order = boot.get('order')
1460+
newxml = newxml.replace('<boot order="1"/> ', '<boot order="TEMP" />')
1461+
newxml = newxml.replace(f'<boot order="{cd_order}" />', '<boot order="1" />')
1462+
newxml = newxml.replace('<boot order="TEMP"/> ', f'<boot order="{cd_order}" />')
14631463
break
1464-
conn.createXML(newxml)
1464+
conn.defineXML(newxml)
14651465
return {'result': 'success'}
14661466

14671467
def stop(self, name, soft=False):

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
kweb=kvirt.web.main:run
5959
klist.py=kvirt.klist:main
6060
ksushy=kvirt.ksushy.main:run
61-
ksushy-isoremover=kvirt.ksushy.isoremover:run
6261
ignitionmerger=kvirt.ignitionmerger:cli
6362
ekstoken=kvirt.ekstoken:cli
6463
gketoken=kvirt.gketoken:cli

0 commit comments

Comments
 (0)