@@ -466,6 +466,7 @@ def start(
466
466
"""
467
467
self .require_jail_existing ()
468
468
self .require_jail_stopped ()
469
+ self .require_jail_match_hostid ()
469
470
470
471
try :
471
472
yield from self .config ["resolver" ].apply (
@@ -1430,6 +1431,8 @@ def _create_from_resource(
1430
1431
if backend is not None :
1431
1432
backend .setup (self .storage , resource )
1432
1433
1434
+ self .config ["hostid" ] = self .host .id
1435
+
1433
1436
self ._update_fstab ()
1434
1437
self .save ()
1435
1438
@@ -2012,6 +2015,26 @@ def require_jail_is_template(self, log_errors: bool=True) -> None:
2012
2015
logger = (self .logger if log_errors else None )
2013
2016
)
2014
2017
2018
+ def require_jail_match_hostid (self , log_errors : bool = True ) -> None :
2019
+ """Raise JailIsTemplate exception if the jail is a template."""
2020
+ if self .hostid_check_ok is False :
2021
+ raise libioc .errors .JailHostIdMismatch (
2022
+ jail = self ,
2023
+ host_hostid = self .host .id ,
2024
+ logger = (self .logger if log_errors else None )
2025
+ )
2026
+
2027
+ @property
2028
+ def hostid_check_ok (self ) -> bool :
2029
+ """Return true if the hostid check passes."""
2030
+ if self .config ["hostid_strict_check" ] is False :
2031
+ self .logger .spam ("hostid_strict_check is disabled" )
2032
+ return True
2033
+ jail_hostid = self .config ["hostid" ]
2034
+ if (jail_hostid is None ) or (jail_hostid == self .host .id ):
2035
+ return True
2036
+ return False
2037
+
2015
2038
def require_storage_backend (self , log_errors : bool = True ) -> None :
2016
2039
"""Raise if the jail was not initialized with a storage backend."""
2017
2040
if self .storage_backend is None :
0 commit comments