From f3863ead73c113435e64441e1eda275c644c6582 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Mon, 7 Aug 2017 16:40:39 -0700 Subject: [PATCH] removed service load methids, since they are no longer used, added way for custom service load code to facilitate the unique docker service case --- daemon/core/service.py | 8 ++++++- daemon/core/services/bird.py | 13 ---------- daemon/core/services/dockersvc.py | 40 +++++++++++++++---------------- daemon/core/services/nrl.py | 14 ----------- daemon/core/services/quagga.py | 13 ---------- daemon/core/services/sdn.py | 6 ----- daemon/core/services/security.py | 9 ------- daemon/core/services/startup.py | 5 ---- daemon/core/services/ucarp.py | 5 ---- daemon/core/services/utility.py | 17 ------------- daemon/core/services/xorp.py | 13 ---------- 11 files changed, 26 insertions(+), 117 deletions(-) diff --git a/daemon/core/service.py b/daemon/core/service.py index 1f7f513f..66d45bf9 100644 --- a/daemon/core/service.py +++ b/daemon/core/service.py @@ -138,7 +138,9 @@ class ServiceManager(object): module = importlib.import_module(import_statement) members = inspect.getmembers(module, lambda x: _is_service(module, x)) for member in members: - cls.add(member[1]) + clazz = member[1] + clazz.on_load() + cls.add(clazz) class CoreServices(ConfigurableManager): @@ -943,6 +945,10 @@ class CoreService(object): """ self._custom = True + @classmethod + def on_load(cls): + pass + @classmethod def getconfigfilenames(cls, nodenum, services): """ diff --git a/daemon/core/services/bird.py b/daemon/core/services/bird.py index c24fe341..34884e51 100644 --- a/daemon/core/services/bird.py +++ b/daemon/core/services/bird.py @@ -3,7 +3,6 @@ bird.py: defines routing services provided by the BIRD Internet Routing Daemon. """ from core.service import CoreService -from core.service import ServiceManager class Bird(CoreService): @@ -238,21 +237,9 @@ class BirdStatic(BirdService): @classmethod def generatebirdconfig(cls, node): cfg = '/* This is a sample config that must be customized */\n' - cfg += 'protocol static {\n' cfg += '# route 0.0.0.0/0 via 198.51.100.130; # Default route. Do NOT advertise on BGP !\n' cfg += '# route 203.0.113.0/24 reject; # Sink route\n' cfg += '# route 10.2.0.0/24 via "arc0"; # Secondary network\n' cfg += '}\n\n' - return cfg - - -def load_services(): - # Register all protocols - ServiceManager.add(Bird) - ServiceManager.add(BirdOspf) - ServiceManager.add(BirdBgp) - # ServiceManager.add(BirdRadv) # untested - ServiceManager.add(BirdRip) - ServiceManager.add(BirdStatic) diff --git a/daemon/core/services/dockersvc.py b/daemon/core/services/dockersvc.py index 0e65a42f..1733f04b 100644 --- a/daemon/core/services/dockersvc.py +++ b/daemon/core/services/dockersvc.py @@ -153,27 +153,25 @@ done """ % (cls._image,) return cfg + @classmethod + def on_load(cls): + logger.debug("loading custom docker services") -def load_services(): - ServiceManager.add(DockerService) + if "Client" in globals(): + client = Client(version="1.10") + images = client.images() + del client + else: + images = [] - # This auto-loads Docker images having a :core tag, adding them to the list - # of services under the "Docker" group. - # TODO: change this logic, should be a proper configurable, or docker needs to be a required library - # TODO: also should make this call possible real time for reloading removing "magic" auto loading on import - if 'Client' in globals(): - client = Client(version='1.10') - images = client.images() - del client - else: - images = [] - for image in images: - if u'' in image['RepoTags'][0]: - continue - for repo in image['RepoTags']: - if u':core' not in repo: + for image in images: + if u"" in image["RepoTags"][0]: continue - dockerid = repo.encode('ascii', 'ignore').split(':')[0] - sub_class = type('SubClass', (DockerService,), {'_name': dockerid, '_image': dockerid}) - ServiceManager.add(sub_class) - del images + for repo in image["RepoTags"]: + if u":core" not in repo: + continue + dockerid = repo.encode("ascii", "ignore").split(":")[0] + sub_class = type("SubClass", (DockerService,), {"_name": dockerid, "_image": dockerid}) + ServiceManager.add(sub_class) + + del images diff --git a/daemon/core/services/nrl.py b/daemon/core/services/nrl.py index 5187d788..a6a416ea 100644 --- a/daemon/core/services/nrl.py +++ b/daemon/core/services/nrl.py @@ -6,7 +6,6 @@ nrl.py: defines services provided by NRL protolib tools hosted here: from core.misc import utils from core.misc.ipaddress import Ipv4Prefix from core.service import CoreService -from core.service import ServiceManager class NrlService(CoreService): @@ -651,16 +650,3 @@ done cfg += " stability 10" cfg += " 2>&1 > /var/log/arouted.log &\n\n" return cfg - - -def load_services(): - ServiceManager.add(MgenSinkService) - ServiceManager.add(NrlNhdp) - ServiceManager.add(NrlSmf) - ServiceManager.add(NrlOlsr) - ServiceManager.add(NrlOlsrv2) - ServiceManager.add(OlsrOrg) - # this line is required to add the above class to the list of available services - ServiceManager.add(MgenActor) - # experimental - # ServiceManager.add(Arouted) diff --git a/daemon/core/services/quagga.py b/daemon/core/services/quagga.py index 70d919d6..ca6f0ad8 100644 --- a/daemon/core/services/quagga.py +++ b/daemon/core/services/quagga.py @@ -7,7 +7,6 @@ from core.enumerations import LinkTypes, NodeTypes from core.misc import ipaddress from core.misc import nodeutils from core.service import CoreService -from core.service import ServiceManager class Zebra(CoreService): @@ -593,15 +592,3 @@ class Xpimd(QuaggaService): @classmethod def generatequaggaifcconfig(cls, node, ifc): return ' ip mfea\n ip igmp\n ip pim\n' - - -def load_services(): - ServiceManager.add(Zebra) - ServiceManager.add(Ospfv2) - ServiceManager.add(Ospfv3) - ServiceManager.add(Ospfv3mdr) - ServiceManager.add(Bgp) - ServiceManager.add(Rip) - ServiceManager.add(Ripng) - ServiceManager.add(Babel) - ServiceManager.add(Xpimd) diff --git a/daemon/core/services/sdn.py b/daemon/core/services/sdn.py index 28cdc097..63ca610a 100644 --- a/daemon/core/services/sdn.py +++ b/daemon/core/services/sdn.py @@ -5,7 +5,6 @@ sdn.py defines services to start Open vSwitch and the Ryu SDN Controller. import re from core.service import CoreService -from core.service import ServiceManager class SdnService(CoreService): @@ -121,8 +120,3 @@ class RyuService(SdnService): cfg += "# auto-generated by ryuService (ryuService.py)\n" cfg += '/usr/local/bin/ryu-manager --observe-links %s/ofctl_rest.py %s/rest_topology.py' % (app_path, app_path) return cfg - - -def load_services(): - ServiceManager.add(OvsService) - ServiceManager.add(RyuService) diff --git a/daemon/core/services/security.py b/daemon/core/services/security.py index 27478368..34a37624 100644 --- a/daemon/core/services/security.py +++ b/daemon/core/services/security.py @@ -6,7 +6,6 @@ firewall) from core import constants from core import logger from core.service import CoreService -from core.service import ServiceManager class VPNClient(CoreService): @@ -115,11 +114,3 @@ class Firewall(CoreService): logger.exception("Error opening Firewall configuration template (%s)", fname) return cfg - - -def load_services(): - # this line is required to add the above class to the list of available services - ServiceManager.add(VPNClient) - ServiceManager.add(VPNServer) - ServiceManager.add(IPsec) - ServiceManager.add(Firewall) diff --git a/daemon/core/services/startup.py b/daemon/core/services/startup.py index 0e749bcd..a26cd6f4 100644 --- a/daemon/core/services/startup.py +++ b/daemon/core/services/startup.py @@ -2,7 +2,6 @@ from inspect import isclass from sys import maxint from core.service import CoreService -from core.service import ServiceManager class Startup(CoreService): @@ -37,7 +36,3 @@ class Startup(CoreService): if start: script += start + '\n' return script - - -def load_services(): - ServiceManager.add(Startup) diff --git a/daemon/core/services/ucarp.py b/daemon/core/services/ucarp.py index 4a8fb2ea..ee73e7ca 100644 --- a/daemon/core/services/ucarp.py +++ b/daemon/core/services/ucarp.py @@ -3,7 +3,6 @@ ucarp.py: defines high-availability IP address controlled by ucarp """ from core.service import CoreService -from core.service import ServiceManager UCARP_ETC = "/usr/local/etc/ucarp" @@ -179,7 +178,3 @@ fi """ - - -def load_services(): - ServiceManager.add(Ucarp) diff --git a/daemon/core/services/utility.py b/daemon/core/services/utility.py index 2c64492a..912a9c1f 100644 --- a/daemon/core/services/utility.py +++ b/daemon/core/services/utility.py @@ -10,7 +10,6 @@ from core.misc import utils from core.misc.ipaddress import Ipv4Prefix from core.misc.ipaddress import Ipv6Prefix from core.service import CoreService -from core.service import ServiceManager class UtilService(CoreService): @@ -724,19 +723,3 @@ class UserDefinedService(UtilService): _name = "UserDefined" _startindex = 50 _meta = "Customize this service to do anything upon startup." - - -def load_services(): - ServiceManager.add(IPForwardService) - ServiceManager.add(DefaultRouteService) - ServiceManager.add(DefaultMulticastRouteService) - ServiceManager.add(StaticRouteService) - ServiceManager.add(SshService) - ServiceManager.add(DhcpService) - ServiceManager.add(DhcpClientService) - ServiceManager.add(FtpService) - ServiceManager.add(HttpService) - ServiceManager.add(PcapService) - ServiceManager.add(RadvdService) - ServiceManager.add(AtdService) - ServiceManager.add(UserDefinedService) diff --git a/daemon/core/services/xorp.py b/daemon/core/services/xorp.py index a626b0af..fff574ea 100644 --- a/daemon/core/services/xorp.py +++ b/daemon/core/services/xorp.py @@ -4,7 +4,6 @@ xorp.py: defines routing services provided by the XORP routing suite. from core import logger from core.service import CoreService -from core.service import ServiceManager class XorpRtrmgr(CoreService): @@ -468,15 +467,3 @@ class XorpOlsr(XorpService): cfg += " }\n" cfg += "}\n" return cfg - - -def load_services(): - ServiceManager.add(XorpRtrmgr) - ServiceManager.add(XorpOspfv2) - ServiceManager.add(XorpOspfv3) - ServiceManager.add(XorpBgp) - ServiceManager.add(XorpRip) - ServiceManager.add(XorpRipng) - ServiceManager.add(XorpPimSm4) - ServiceManager.add(XorpPimSm6) - ServiceManager.add(XorpOlsr)