removed service load methids, since they are no longer used, added way for custom service load code to facilitate the unique docker service case
This commit is contained in:
parent
73eea80f51
commit
f3863ead73
11 changed files with 26 additions and 117 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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'<none>' in image['RepoTags'][0]:
|
||||
continue
|
||||
for repo in image['RepoTags']:
|
||||
if u':core' not in repo:
|
||||
for image in images:
|
||||
if u"<none>" 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue