diff --git a/lib/aquilon/worker/commands/cat_instance.py b/lib/aquilon/worker/commands/cat_instance.py index a7fca6a5d..2378a0199 100644 --- a/lib/aquilon/worker/commands/cat_instance.py +++ b/lib/aquilon/worker/commands/cat_instance.py @@ -18,7 +18,7 @@ from aquilon.aqdb.model import Service, ServiceInstance from aquilon.worker.broker import BrokerCommand -from aquilon.worker.templates.service import (PlenaryServiceInstanceToplevel, +from aquilon.worker.templates.service import (PlenaryServiceInstanceData, PlenaryServiceInstanceClientDefault, PlenaryServiceInstanceServer, PlenaryServiceInstanceServerDefault) @@ -45,7 +45,7 @@ def render(self, session, logger, service, instance, default, server, if server: cls = PlenaryServiceInstanceServer else: - cls = PlenaryServiceInstanceToplevel + cls = PlenaryServiceInstanceData plenary_info = cls.get_plenary(dbsi, logger=logger) diff --git a/lib/aquilon/worker/commands/cat_service.py b/lib/aquilon/worker/commands/cat_service.py index d745fe1cd..e7707b6a2 100644 --- a/lib/aquilon/worker/commands/cat_service.py +++ b/lib/aquilon/worker/commands/cat_service.py @@ -18,7 +18,7 @@ from aquilon.aqdb.model import Service from aquilon.worker.broker import BrokerCommand -from aquilon.worker.templates.service import (PlenaryServiceToplevel, +from aquilon.worker.templates.service import (PlenaryServiceData, PlenaryServiceClientDefault, PlenaryServiceServerDefault) @@ -38,7 +38,7 @@ def render(self, session, logger, service, server, default, generate, **_): else: cls = PlenaryServiceClientDefault else: - cls = PlenaryServiceToplevel + cls = PlenaryServiceData plenary_info = cls.get_plenary(dbservice, logger=logger) diff --git a/lib/aquilon/worker/commands/update_machine.py b/lib/aquilon/worker/commands/update_machine.py index be75a5b4a..c2656878b 100755 --- a/lib/aquilon/worker/commands/update_machine.py +++ b/lib/aquilon/worker/commands/update_machine.py @@ -29,7 +29,7 @@ from aquilon.worker.dbwrappers.resources import (find_resource, get_resource_holder) from aquilon.worker.templates import (PlenaryHostData, - PlenaryServiceInstanceToplevel) + PlenaryServiceInstanceData) from aquilon.worker.processes import DSDBRunner from aquilon.worker.dbwrappers.change_management import ChangeManagement @@ -325,7 +325,7 @@ def render(self, session, logger, plenaries, machine, model, vendor, serial, uui if dbmachine.host: for srv in dbmachine.host.services_provided: si = srv.service_instance - plenaries.add(si, cls=PlenaryServiceInstanceToplevel) + plenaries.add(si, cls=PlenaryServiceInstanceData) update_primary_ip(session, logger, dbmachine, ip) if dbmachine.location != old_location and dbmachine.host: diff --git a/lib/aquilon/worker/templates/__init__.py b/lib/aquilon/worker/templates/__init__.py index b3fbd0e1a..06d9b250e 100644 --- a/lib/aquilon/worker/templates/__init__.py +++ b/lib/aquilon/worker/templates/__init__.py @@ -26,11 +26,11 @@ from aquilon.worker.templates.network import PlenaryNetwork from aquilon.worker.templates.resource import PlenaryResource from aquilon.worker.templates.service import (PlenaryService, - PlenaryServiceToplevel, + PlenaryServiceData, PlenaryServiceClientDefault, PlenaryServiceServerDefault, PlenaryServiceInstance, - PlenaryServiceInstanceToplevel, + PlenaryServiceInstanceData, PlenaryServiceInstanceClientDefault, PlenaryServiceInstanceServer, PlenaryServiceInstanceServerDefault) diff --git a/lib/aquilon/worker/templates/cluster.py b/lib/aquilon/worker/templates/cluster.py index 077172fa8..0288818d6 100755 --- a/lib/aquilon/worker/templates/cluster.py +++ b/lib/aquilon/worker/templates/cluster.py @@ -25,6 +25,7 @@ from aquilon.worker.templates import (Plenary, ObjectPlenary, StructurePlenary, PlenaryCollection, PlenaryResource, PlenaryServiceInstanceClientDefault, + PlenaryServiceInstanceData, PlenaryServiceInstanceServerDefault, PlenaryPersonalityBase, add_location_info) from aquilon.worker.templates.panutils import (StructureTemplate, PanValue, @@ -188,6 +189,14 @@ def get_key(self, exclusive=True): return CompileKey.merge(keylist) def body(self, lines): + # Collect configuration of used services + services = [] + services_data = {} + for si in self.dbobj.services_used: + services.append(PlenaryServiceInstanceClientDefault.template_name(si)) + services_data[si.service.name] = PlenaryServiceInstanceData.template_name(si) + services.sort() + # Allow settings such as loadpath to be modified by the archetype before anything else happens # Included only if object_declarations_template option is true # It the option is true, the template MUST exist @@ -203,6 +212,12 @@ def body(self, lines): pan_assign(lines, "/", StructureTemplate(path, {"metadata": PanValue("/metadata")})) + + # Include service data + for service_name in sorted(services_data.keys()): + pan_assign(lines, "/system/services/%s" % service_name, + StructureTemplate(services_data[service_name])) + pan_include(lines, "archetype/base") for servinst in sorted(self.dbobj.services_used, diff --git a/lib/aquilon/worker/templates/host.py b/lib/aquilon/worker/templates/host.py index c6c381fdd..bf380bda7 100755 --- a/lib/aquilon/worker/templates/host.py +++ b/lib/aquilon/worker/templates/host.py @@ -34,6 +34,7 @@ PlenaryCollection, PlenaryClusterClient, PlenaryResource, PlenaryPersonalityBase, PlenaryServiceInstanceClientDefault, + PlenaryServiceInstanceData, PlenaryServiceInstanceServerDefault) from aquilon.worker.templates.personality import get_parameters_by_feature from aquilon.worker.templates.panutils import (StructureTemplate, PanValue, @@ -354,11 +355,13 @@ def body(self, lines): continue services = [] + services_data = {} required_services = self.dbobj.required_services for si in self.dbobj.services_used: required_services.pop(si.service, None) services.append(PlenaryServiceInstanceClientDefault.template_name(si)) + services_data[si.service.name] = PlenaryServiceInstanceData.template_name(si) if required_services: missing = ", ".join(sorted(srv.name for srv in required_services)) raise IncompleteError("{0} is missing the following required " @@ -389,6 +392,12 @@ def body(self, lines): pan_assign(lines, "/", StructureTemplate(path, {"metadata": PanValue("/metadata")})) + + # Include service data + for service_name in sorted(services_data.keys()): + pan_assign(lines, "/system/services/%s" % service_name, + StructureTemplate(services_data[service_name])) + pan_include(lines, "archetype/base") dbos = self.dbobj.operating_system diff --git a/lib/aquilon/worker/templates/metacluster.py b/lib/aquilon/worker/templates/metacluster.py index 9b7331770..da133c339 100755 --- a/lib/aquilon/worker/templates/metacluster.py +++ b/lib/aquilon/worker/templates/metacluster.py @@ -25,6 +25,7 @@ PlenaryCollection, PlenaryPersonalityBase, PlenaryResource, PlenaryServiceInstanceClientDefault, + PlenaryServiceInstanceData, add_location_info) from aquilon.worker.templates.panutils import (StructureTemplate, PanValue, pan_assign, pan_include, @@ -117,6 +118,14 @@ def get_key(self, exclusive=True): return CompileKey.merge(keylist) def body(self, lines): + # Collect configuration of used services + services = [] + services_data = {} + for si in self.dbobj.services_used: + services.append(PlenaryServiceInstanceClientDefault.template_name(si)) + services_data[si.service.name] = PlenaryServiceInstanceData.template_name(si) + services.sort() + # Allow settings such as loadpath to be modified by the archetype before anything else happens # Included only if object_declarations_template option is true # It the option is true, the template MUST exist @@ -131,6 +140,12 @@ def body(self, lines): pan_assign(lines, "/", StructureTemplate("clusterdata/%s" % self.dbobj.name, {"metadata": PanValue("/metadata")})) + + # Include service data + for service_name in sorted(services_data.keys()): + pan_assign(lines, "/system/services/%s" % service_name, + StructureTemplate(services_data[service_name])) + pan_include(lines, "archetype/base") for servinst in sorted(self.dbobj.services_used): diff --git a/lib/aquilon/worker/templates/service.py b/lib/aquilon/worker/templates/service.py index e0c32016f..89dc42878 100644 --- a/lib/aquilon/worker/templates/service.py +++ b/lib/aquilon/worker/templates/service.py @@ -37,8 +37,8 @@ def __init__(self, dbservice, logger=LOGGER, allow_incomplete=True): super(PlenaryService, self).__init__(logger=logger, allow_incomplete=allow_incomplete) - self.append(PlenaryServiceToplevel.get_plenary(dbservice, - allow_incomplete=allow_incomplete)) + self.append(PlenaryServiceData.get_plenary(dbservice, + allow_incomplete=allow_incomplete)) self.append(PlenaryServiceClientDefault.get_plenary(dbservice, allow_incomplete=allow_incomplete)) self.append(PlenaryServiceServerDefault.get_plenary(dbservice, @@ -48,7 +48,7 @@ def __init__(self, dbservice, logger=LOGGER, allow_incomplete=True): Plenary.handlers[Service] = PlenaryService -class PlenaryServiceToplevel(StructurePlenary): +class PlenaryServiceData(StructurePlenary): """ The top-level service template does nothing. It is really a placeholder which can be overridden by the library @@ -128,8 +128,8 @@ def __init__(self, dbinstance, logger=LOGGER, allow_incomplete=True): allow_incomplete=allow_incomplete) self.dbobj = dbinstance - self.append(PlenaryServiceInstanceToplevel.get_plenary(dbinstance, - allow_incomplete=allow_incomplete)) + self.append(PlenaryServiceInstanceData.get_plenary(dbinstance, + allow_incomplete=allow_incomplete)) self.append(PlenaryServiceInstanceClientDefault.get_plenary(dbinstance, allow_incomplete=allow_incomplete)) self.append(PlenaryServiceInstanceServer.get_plenary(dbinstance, @@ -140,7 +140,7 @@ def __init__(self, dbinstance, logger=LOGGER, allow_incomplete=True): Plenary.handlers[ServiceInstance] = PlenaryServiceInstance -class PlenaryServiceInstanceToplevel(SIHelperMixin, StructurePlenary): +class PlenaryServiceInstanceData(SIHelperMixin, StructurePlenary): """ This structure template provides information for the template specific to the service instance and for use by the client. @@ -159,7 +159,7 @@ def template_name(cls, dbinstance): def body(self, lines): pan_include(lines, - PlenaryServiceToplevel.template_name(self.dbobj.service)) + PlenaryServiceData.template_name(self.dbobj.service)) lines.append("") pan_assign(lines, "instance", self.dbobj.name) @@ -201,8 +201,9 @@ class PlenaryServiceInstanceClientDefault(SIHelperMixin, Plenary): included from within the host.tpl. This may be overridden within the template library, but this plenary should typically be sufficient without override. - This template defines configuration for clients only, and - is specific to the instance. + This template defines configuration specific to the instance + for clients only but the instance data has to be loaded before + (the broker does it earlier in host object template). """ prefix = "service" @@ -213,10 +214,6 @@ def template_name(cls, dbinstance): dbinstance.name) def body(self, lines): - path = PlenaryServiceInstanceToplevel.template_name(self.dbobj) - pan_assign(lines, "/system/services/%s" % self.dbobj.service, - StructureTemplate(path)) - path = PlenaryServiceClientDefault.template_name(self.dbobj.service) pan_include(lines, path)