add servicelist

This commit is contained in:
2021-02-21 19:48:30 +01:00
parent c149d7c38d
commit e6afef6a81
144 changed files with 505 additions and 204 deletions

View File

@ -70,10 +70,21 @@ class ServiceAnnotator:
self.objectspace.space.services.doc = 'services'
self.objectspace.space.services.path = 'services'
for service_name, service in self.objectspace.space.services.service.items():
if not service.manage:
service.information = self.objectspace.information(service.xmlfiles)
service.information.manage = service.manage
activate_obj = self._generate_element('boolean',
None,
None,
'activate',
True,
service,
'.'.join(['services', normalize_family(service_name), 'activate']),
)
for elttype, values in dict(vars(service)).items():
if elttype == 'servicelist':
self.objectspace.list_conditions.setdefault('servicelist',
{}).setdefault(
values,
[]).append(activate_obj)
continue
if not isinstance(values, (dict, list)) or elttype in ERASED_ATTRIBUTES:
continue
if not service.manage and elttype not in ALLOW_ATTRIBUT_NOT_MANAGE:
@ -96,6 +107,15 @@ class ServiceAnnotator:
path,
)
setattr(service, elttype, family)
manage = self._generate_element('boolean',
None,
None,
'manage',
service.manage,
service,
'.'.join(['services', normalize_family(service_name), 'manage']),
)
service.variable = [activate_obj, manage]
service.doc = service.name
def make_group_from_elts(self,

View File

@ -49,6 +49,7 @@
<!ELEMENT service ((ip*|file*|override*)*)>
<!ATTLIST service name CDATA #REQUIRED>
<!ATTLIST service manage (True|False) "True">
<!ATTLIST service servicelist CDATA #IMPLIED>
<!ELEMENT ip (#PCDATA)>
<!ATTLIST ip iplist CDATA #IMPLIED>
@ -126,7 +127,7 @@
<!ATTLIST param optional (True|False) "False">
<!ELEMENT target (#PCDATA)>
<!ATTLIST target type (variable|family|filelist|iplist) "variable">
<!ATTLIST target type (variable|family|servicelist|filelist|iplist) "variable">
<!ATTLIST target optional (True|False) "False">
<!ELEMENT group (follower+)>

View File

@ -289,7 +289,11 @@ class RougailBaseTemplate:
for included in (True, False):
for service_obj in await self.config.option('services').list('all'):
service_name = await service_obj.option.name()
for fills in await service_obj.list('all'):
if await service_obj.option('activate').value.get() is False:
if included is False:
self.desactive_service(service_name)
continue
for fills in await service_obj.list('optiondescription'):
type_ = await fills.option.name()
for fill_obj in await fills.list('all'):
fill = await fill_obj.value.dict()
@ -306,6 +310,11 @@ class RougailBaseTemplate:
self.post_instance()
chdir(ori_dir)
def desactive_service(self,
service_name: str,
):
raise NotImplementedError(_('cannot desactivate a service'))
def post_instance(self): # pragma: no cover
pass

View File

@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from typing import Dict
from os import makedirs
from os import makedirs, symlink
from os.path import dirname, isfile, join
from ipaddress import ip_network
@ -45,9 +45,9 @@ z %%filename - - - - -
%end if
%end def
%for %%service in %%services
%if %%hasattr(%%service, 'files')
%if %%service.activate is True and %%hasattr(%%service, 'files')
%for %%file in %%service.files
%if %%file.activate == True and %%file.included != 'content'
%if %%file.activate is True and %%file.included != 'content'
%if %%isinstance(%%file.name, list)
%for %%filename in %%file.name
%%display(%%file, %%filename)%slurp
@ -93,7 +93,6 @@ class RougailSystemdTemplate(RougailBaseTemplate):
service_name = filevar['name']
return tmp_file, None, f'/systemd/system/{service_name}.service.d/rougail.conf', None
def _instance_ip(self,
filevar: Dict,
destfile,
@ -116,6 +115,13 @@ class RougailSystemdTemplate(RougailBaseTemplate):
filevar['engine'] = 'creole'
return None, ROUGAIL_IP_TEMPLATE, f'/systemd/system/{service_name}.service.d/rougail_ip.conf', variable
def desactive_service(self,
service_name: str,
):
filename = f'{self.destinations_dir}/systemd/system/{service_name}.service'
makedirs(dirname(filename), exist_ok=True)
symlink('/dev/null', filename)
def post_instance(self):
destfile = '/tmpfiles.d/rougail.conf'
destfilename = join(self.destinations_dir, destfile[1:])