Skip to content

Commit a2a5654

Browse files
committed
cli-lib communication draft with generators
1 parent 7f0e47c commit a2a5654

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

libiocage/cli/start.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ def cli(ctx, rc, jails, log_level):
4949
for jail in ioc_jails.list(filters=jails):
5050
logger.log(f"Starting {jail.humanreadable_name}")
5151
try:
52-
jail.start()
52+
for i in jail.start(yields=True):
53+
print(f"[+] {i.action} OK")
54+
5355
except Exception:
56+
raise
5457
exit(1)
5558

5659
logger.log(f"{jail.humanreadable_name} running as JID {jail.jid}")

libiocage/lib/Jail.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import libiocage.lib.ZFSShareStorage
1515
import libiocage.lib.DevfsRules
1616
import libiocage.lib.errors
17+
import libiocage.lib.events
1718
import libiocage.lib.helpers
1819

1920

@@ -133,7 +134,7 @@ def rc_conf(self):
133134
)
134135
return self._rc_conf
135136

136-
def start(self):
137+
def start(self, yields=False):
137138
"""
138139
Start the jail.
139140
"""
@@ -158,16 +159,33 @@ def start(self):
158159
self.config.fstab.save_with_basedirs()
159160
self._launch_jail()
160161

162+
if yields is True:
163+
yield libiocage.lib.events.JailStarted(jail=self)
164+
161165
if self.config["vnet"]:
162166
self._start_vimage_network()
163167
self._configure_routes()
168+
if yields is True:
169+
yield libiocage.lib.events.JailVnetConfigured(jail=self)
164170

165171
self._configure_nameserver()
166172

167173
if self.config["jail_zfs"] is True:
168174
libiocage.lib.ZFSShareStorage.ZFSShareStorage.mount_zfs_shares(
169175
self.storage
170176
)
177+
if yields is True:
178+
yield libiocage.lib.events.JailZfsSharesMounted(jail=self)
179+
180+
if self.config["exec_start"] is not None:
181+
self._start_services()
182+
if yields is True:
183+
yield libiocage.lib.events.JailServicesStarted(jail=self)
184+
185+
def _start_services(self):
186+
command = self.config["exec_start"].strip().split()
187+
self.logger.debug(f"Running exec_start on {self.humanreadable_name}")
188+
self.exec(command)
171189

172190
def stop(self, force=False):
173191
"""
@@ -472,7 +490,7 @@ def _launch_jail(self):
472490
f"exec.prestart={self.config['exec_prestart']}",
473491
f"exec.poststart={self.config['exec_poststart']}",
474492
f"exec.prestop={self.config['exec_prestop']}",
475-
f"exec.start={self.config['exec_start']}",
493+
#f"exec.start={self.config['exec_start']}",
476494
f"exec.stop={self.config['exec_stop']}",
477495
f"exec.clean={self.config['exec_clean']}",
478496
f"exec.timeout={self.config['exec_timeout']}",
@@ -511,7 +529,7 @@ def _launch_jail(self):
511529

512530
def _start_vimage_network(self):
513531

514-
self.logger.log("Starting VNET/VIMAGE", jail=self)
532+
self.logger.debug("Starting VNET/VIMAGE", jail=self)
515533

516534
nics = self.config["interfaces"]
517535
for nic in nics:

libiocage/lib/events.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
EVENT_STATUS = (
2+
"pending",
3+
"done",
4+
"failed"
5+
)
6+
7+
8+
class Iocage:
9+
"""
10+
IocageEvent
11+
12+
Base class for all other iocage events
13+
"""
14+
15+
def __init__(self, action, *args, **kwargs):
16+
self.action = action
17+
#self.status = EVENT_STATUS.index(status)
18+
#self.data = kwargs
19+
20+
21+
class Jail(Iocage):
22+
23+
def __init__(self, action, jail, *args, **kwargs):
24+
super().__init__(action=action, jail=jail, *args, **kwargs)
25+
26+
27+
class JailStarted(Jail):
28+
29+
def __init__(self, jail, *args, **kwargs):
30+
super().__init__("Started", jail, *args, **kwargs)
31+
32+
33+
class JailVnetConfigured(Jail):
34+
35+
def __init__(self, jail, *args, **kwargs):
36+
super().__init__("Configuring VNET", jail, *args, **kwargs)
37+
38+
39+
class JailZfsShareMounted(Jail):
40+
41+
def __init__(self, jail, *args, **kwargs):
42+
super().__init__("Mounting ZFS shares", jail, *args, **kwargs)
43+
44+
45+
class JailServicesStarted(Jail):
46+
47+
def __init__(self, jail, *args, **kwargs):
48+
super().__init__("Starting services", jail, *args, **kwargs)

0 commit comments

Comments
 (0)