refactored service interaction use names with a _, and cleanup up some of the CoreServices methods

This commit is contained in:
Blake J. Harnden 2018-06-15 14:03:27 -07:00
parent 0bf9c99910
commit e80736061f
27 changed files with 958 additions and 885 deletions

View file

@ -9,22 +9,22 @@ class Bird(CoreService):
"""
Bird router support
"""
_name = "bird"
_group = "BIRD"
_depends = ()
_dirs = ("/etc/bird",)
_configs = ("/etc/bird/bird.conf",)
_startindex = 35
_startup = ("bird -c %s" % (_configs[0]),)
_shutdown = ("killall bird",)
_validate = ("pidof bird",)
name = "bird"
group = "BIRD"
depends = ()
dirs = ("/etc/bird",)
configs = ("/etc/bird/bird.conf",)
startindex = 35
startup = ("bird -c %s" % (configs[0]),)
shutdown = ("killall bird",)
validate = ("pidof bird",)
@classmethod
def generateconfig(cls, node, filename, services):
"""
Return the bird.conf file contents.
"""
if filename == cls._configs[0]:
if filename == cls.configs[0]:
return cls.generateBirdConf(node, services)
else:
raise ValueError
@ -35,7 +35,7 @@ class Bird(CoreService):
Helper to return the first IPv4 address of a node as its router ID.
"""
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
@ -73,11 +73,11 @@ protocol device {
scan time 10; # Scan interfaces every 10 seconds
}
""" % (cls._name, cls.routerid(node))
""" % (cls.name, cls.routerid(node))
# Generate protocol specific configurations
for s in services:
if cls._name not in s._depends:
if cls.name not in s.depends:
continue
cfg += s.generatebirdconfig(node)
@ -90,15 +90,15 @@ class BirdService(CoreService):
common to Bird's routing daemons.
"""
_name = None
_group = "BIRD"
_depends = ("bird",)
_dirs = ()
_configs = ()
_startindex = 40
_startup = ()
_shutdown = ()
_meta = "The config file for this service can be found in the bird service."
name = None
group = "BIRD"
depends = ("bird",)
dirs = ()
configs = ()
startindex = 40
startup = ()
shutdown = ()
meta = "The config file for this service can be found in the bird service."
@classmethod
def generatebirdconfig(cls, node):
@ -106,14 +106,15 @@ class BirdService(CoreService):
@classmethod
def generatebirdifcconfig(cls, node):
''' Use only bare interfaces descriptions in generated protocol
"""
Use only bare interfaces descriptions in generated protocol
configurations. This has the slight advantage of being the same
everywhere.
'''
"""
cfg = ""
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
cfg += ' interface "%s";\n' % ifc.name
@ -125,8 +126,8 @@ class BirdBgp(BirdService):
BGP BIRD Service (configuration generation)
"""
_name = "BIRD_BGP"
_custom_needed = True
name = "BIRD_BGP"
custom_needed = True
@classmethod
def generatebirdconfig(cls, node):
@ -156,7 +157,7 @@ class BirdOspf(BirdService):
OSPF BIRD Service (configuration generation)
"""
_name = "BIRD_OSPFv2"
name = "BIRD_OSPFv2"
@classmethod
def generatebirdconfig(cls, node):
@ -181,7 +182,7 @@ class BirdRadv(BirdService):
RADV BIRD Service (configuration generation)
"""
_name = "BIRD_RADV"
name = "BIRD_RADV"
@classmethod
def generatebirdconfig(cls, node):
@ -209,7 +210,7 @@ class BirdRip(BirdService):
RIP BIRD Service (configuration generation)
"""
_name = "BIRD_RIP"
name = "BIRD_RIP"
@classmethod
def generatebirdconfig(cls, node):
@ -231,8 +232,8 @@ class BirdStatic(BirdService):
Static Bird Service (configuration generation)
"""
_name = "BIRD_static"
_custom_needed = True
name = "BIRD_static"
custom_needed = True
@classmethod
def generatebirdconfig(cls, node):

View file

@ -112,16 +112,16 @@ class DockerService(CoreService):
This is a service which will allow running docker containers in a CORE
node.
"""
_name = "Docker"
_group = "Docker"
_depends = ()
_dirs = ('/var/lib/docker/containers/', '/run/shm', '/run/resolvconf',)
_configs = ('docker.sh',)
_startindex = 50
_startup = ('sh docker.sh',)
_shutdown = ('service docker stop',)
name = "Docker"
group = "Docker"
depends = ()
dirs = ('/var/lib/docker/containers/', '/run/shm', '/run/resolvconf',)
configs = ('docker.sh',)
startindex = 50
startup = ('sh docker.sh',)
shutdown = ('service docker stop',)
# Container image to start
_image = ""
image = ""
@classmethod
def generateconfig(cls, node, filename, services):
@ -139,7 +139,7 @@ class DockerService(CoreService):
# distros may just be docker
cfg += 'service docker start\n'
cfg += "# you could add a command to start a image here eg:\n"
if not cls._image:
if not cls.image:
cfg += "# docker run -d --net host --name coreDock <imagename>\n"
else:
cfg += """\
@ -150,7 +150,7 @@ until [ $result -eq 0 ]; do
# this is to alleviate contention to docker's SQLite database
sleep 0.3
done
""" % (cls._image,)
""" % (cls.image,)
return cfg
@classmethod

View file

@ -13,14 +13,14 @@ class NrlService(CoreService):
Parent class for NRL services. Defines properties and methods
common to NRL's routing daemons.
"""""
_name = None
_group = "ProtoSvc"
_depends = ()
_dirs = ()
_configs = ()
_startindex = 45
_startup = ()
_shutdown = ()
name = None
group = "ProtoSvc"
depends = ()
dirs = ()
configs = ()
startindex = 45
startup = ()
shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
@ -34,7 +34,7 @@ class NrlService(CoreService):
interface's prefix length, so e.g. '/32' can turn into '/24'.
"""
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
@ -46,12 +46,12 @@ class NrlService(CoreService):
class MgenSinkService(NrlService):
_name = "MGEN_Sink"
_configs = ("sink.mgen",)
_startindex = 5
_startup = ("mgen input sink.mgen",)
_validate = ("pidof mgen",)
_shutdown = ("killall mgen",)
name = "MGEN_Sink"
configs = ("sink.mgen",)
startindex = 5
startup = ("mgen input sink.mgen",)
validate = ("pidof mgen",)
shutdown = ("killall mgen",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -63,7 +63,7 @@ class MgenSinkService(NrlService):
@classmethod
def getstartup(cls, node, services):
cmd = cls._startup[0]
cmd = cls.startup[0]
cmd += " output /tmp/mgen_%s.log" % node.name
return cmd,
@ -72,27 +72,26 @@ class NrlNhdp(NrlService):
"""
NeighborHood Discovery Protocol for MANET networks.
"""
_name = "NHDP"
_startup = ("nrlnhdp",)
_shutdown = ("killall nrlnhdp",)
_validate = ("pidof nrlnhdp",)
name = "NHDP"
startup = ("nrlnhdp",)
shutdown = ("killall nrlnhdp",)
validate = ("pidof nrlnhdp",)
@classmethod
def getstartup(cls, node, services):
"""
Generate the appropriate command-line based on node interfaces.
"""
cmd = cls._startup[0]
cmd = cls.startup[0]
cmd += " -l /var/log/nrlnhdp.log"
cmd += " -rpipe %s_nhdp" % node.name
servicenames = map(lambda x: x._name, services)
servicenames = map(lambda x: x.name, services)
if "SMF" in servicenames:
cmd += " -flooding ecds"
cmd += " -smfClient %s_smf" % node.name
netifs = filter(lambda x: not getattr(x, 'control', False), \
node.netifs())
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())
if len(netifs) > 0:
interfacenames = map(lambda x: x.name, netifs)
cmd += " -i "
@ -105,11 +104,11 @@ class NrlSmf(NrlService):
"""
Simplified Multicast Forwarding for MANET networks.
"""
_name = "SMF"
_startup = ("sh startsmf.sh",)
_shutdown = ("killall nrlsmf",)
_validate = ("pidof nrlsmf",)
_configs = ("startsmf.sh",)
name = "SMF"
startup = ("sh startsmf.sh",)
shutdown = ("killall nrlsmf",)
validate = ("pidof nrlsmf",)
configs = ("startsmf.sh",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -123,7 +122,7 @@ class NrlSmf(NrlService):
comments = ""
cmd = "nrlsmf instance %s_smf" % node.name
servicenames = map(lambda x: x._name, services)
servicenames = map(lambda x: x.name, services)
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())
if len(netifs) == 0:
return ""
@ -156,17 +155,17 @@ class NrlOlsr(NrlService):
"""
Optimized Link State Routing protocol for MANET networks.
"""
_name = "OLSR"
_startup = ("nrlolsrd",)
_shutdown = ("killall nrlolsrd",)
_validate = ("pidof nrlolsrd",)
name = "OLSR"
startup = ("nrlolsrd",)
shutdown = ("killall nrlolsrd",)
validate = ("pidof nrlolsrd",)
@classmethod
def getstartup(cls, node, services):
"""
Generate the appropriate command-line based on node interfaces.
"""
cmd = cls._startup[0]
cmd = cls.startup[0]
# are multiple interfaces supported? No.
netifs = list(node.netifs())
if len(netifs) > 0:
@ -175,7 +174,7 @@ class NrlOlsr(NrlService):
cmd += " -l /var/log/nrlolsrd.log"
cmd += " -rpipe %s_olsr" % node.name
servicenames = map(lambda x: x._name, services)
servicenames = map(lambda x: x.name, services)
if "SMF" in servicenames and not "NHDP" in servicenames:
cmd += " -flooding s-mpr"
cmd += " -smfClient %s_smf" % node.name
@ -189,21 +188,21 @@ class NrlOlsrv2(NrlService):
"""
Optimized Link State Routing protocol version 2 for MANET networks.
"""
_name = "OLSRv2"
_startup = ("nrlolsrv2",)
_shutdown = ("killall nrlolsrv2",)
_validate = ("pidof nrlolsrv2",)
name = "OLSRv2"
startup = ("nrlolsrv2",)
shutdown = ("killall nrlolsrv2",)
validate = ("pidof nrlolsrv2",)
@classmethod
def getstartup(cls, node, services):
"""
Generate the appropriate command-line based on node interfaces.
"""
cmd = cls._startup[0]
cmd = cls.startup[0]
cmd += " -l /var/log/nrlolsrv2.log"
cmd += " -rpipe %s_olsrv2" % node.name
servicenames = map(lambda x: x._name, services)
servicenames = map(lambda x: x.name, services)
if "SMF" in servicenames:
cmd += " -flooding ecds"
cmd += " -smfClient %s_smf" % node.name
@ -223,19 +222,19 @@ class OlsrOrg(NrlService):
"""
Optimized Link State Routing protocol from olsr.org for MANET networks.
"""
_name = "OLSRORG"
_configs = ("/etc/olsrd/olsrd.conf",)
_dirs = ("/etc/olsrd",)
_startup = ("olsrd",)
_shutdown = ("killall olsrd",)
_validate = ("pidof olsrd",)
name = "OLSRORG"
configs = ("/etc/olsrd/olsrd.conf",)
dirs = ("/etc/olsrd",)
startup = ("olsrd",)
shutdown = ("killall olsrd",)
validate = ("pidof olsrd",)
@classmethod
def getstartup(cls, node, services):
"""
Generate the appropriate command-line based on node interfaces.
"""
cmd = cls._startup[0]
cmd = cls.startup[0]
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())
if len(netifs) > 0:
interfacenames = map(lambda x: x.name, netifs)
@ -572,24 +571,24 @@ class MgenActor(NrlService):
"""
# a unique name is required, without spaces
_name = "MgenActor"
name = "MgenActor"
# you can create your own group here
_group = "ProtoSvc"
group = "ProtoSvc"
# list of other services this service depends on
_depends = ()
depends = ()
# per-node directories
_dirs = ()
dirs = ()
# generated files (without a full path this file goes in the node's dir,
# e.g. /tmp/pycore.12345/n1.conf/)
_configs = ('start_mgen_actor.sh',)
configs = ('start_mgen_actor.sh',)
# this controls the starting order vs other enabled services
_startindex = 50
startindex = 50
# list of startup commands, also may be generated during startup
_startup = ("sh start_mgen_actor.sh",)
startup = ("sh start_mgen_actor.sh",)
# list of validation commands
_validate = ("pidof mgen",)
validate = ("pidof mgen",)
# list of shutdown commands
_shutdown = ("killall mgen",)
shutdown = ("killall mgen",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -603,7 +602,7 @@ class MgenActor(NrlService):
comments = ""
cmd = "mgenBasicActor.py -n %s -a 0.0.0.0" % node.name
servicenames = map(lambda x: x._name, services)
servicenames = map(lambda x: x.name, services)
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())
if len(netifs) == 0:
return ""
@ -616,12 +615,12 @@ class Arouted(NrlService):
"""
Adaptive Routing
"""
_name = "arouted"
_configs = ("startarouted.sh",)
_startindex = NrlService._startindex + 10
_startup = ("sh startarouted.sh",)
_shutdown = ("pkill arouted",)
_validate = ("pidof arouted",)
name = "arouted"
configs = ("startarouted.sh",)
startindex = NrlService.startindex + 10
startup = ("sh startarouted.sh",)
shutdown = ("pkill arouted",)
validate = ("pidof arouted",)
@classmethod
def generateconfig(cls, node, filename, services):

View file

@ -10,33 +10,33 @@ from core.service import CoreService
class Zebra(CoreService):
_name = "zebra"
_group = "Quagga"
_dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
_configs = (
name = "zebra"
group = "Quagga"
dirs = ("/usr/local/etc/quagga", "/var/run/quagga")
configs = (
"/usr/local/etc/quagga/Quagga.conf",
"quaggaboot.sh",
"/usr/local/etc/quagga/vtysh.conf"
)
_startindex = 35
_startup = ("sh quaggaboot.sh zebra",)
_shutdown = ("killall zebra",)
_validate = ("pidof zebra",)
startindex = 35
startup = ("sh quaggaboot.sh zebra",)
shutdown = ("killall zebra",)
validate = ("pidof zebra",)
@classmethod
def generateconfig(cls, node, filename, services):
"""
Return the Quagga.conf or quaggaboot.sh file contents.
"""
if filename == cls._configs[0]:
if filename == cls.configs[0]:
return cls.generateQuaggaConf(node, services)
elif filename == cls._configs[1]:
elif filename == cls.configs[1]:
return cls.generateQuaggaBoot(node, services)
elif filename == cls._configs[2]:
elif filename == cls.configs[2]:
return cls.generateVtyshConf(node, services)
else:
raise ValueError("file name (%s) is not a known configuration: %s",
filename, cls._configs)
filename, cls.configs)
@classmethod
def generateVtyshConf(cls, node, services):
@ -67,12 +67,12 @@ class Zebra(CoreService):
want_ipv4 = False
want_ipv6 = False
for s in services:
if cls._name not in s._depends:
if cls.name not in s.depends:
continue
ifccfg = s.generatequaggaifcconfig(node, ifc)
if s._ipv4_routing:
if s.ipv4_routing:
want_ipv4 = True
if s._ipv6_routing:
if s.ipv6_routing:
want_ipv6 = True
cfgv6 += ifccfg
else:
@ -93,7 +93,7 @@ class Zebra(CoreService):
cfg += "!\n"
for s in services:
if cls._name not in s._depends:
if cls.name not in s.depends:
continue
cfg += s.generatequaggaconfig(node)
return cfg
@ -212,7 +212,7 @@ if [ "$1" != "zebra" ]; then
fi
confcheck
bootquagga
""" % (cls._configs[0], quagga_sbin_search, quagga_bin_search, constants.QUAGGA_STATE_DIR)
""" % (cls.configs[0], quagga_sbin_search, quagga_bin_search, constants.QUAGGA_STATE_DIR)
class QuaggaService(CoreService):
@ -220,18 +220,18 @@ class QuaggaService(CoreService):
Parent class for Quagga services. Defines properties and methods
common to Quagga's routing daemons.
"""
_name = None
_group = "Quagga"
_depends = ("zebra",)
_dirs = ()
_configs = ()
_startindex = 40
_startup = ()
_shutdown = ()
_meta = "The config file for this service can be found in the Zebra service."
name = None
group = "Quagga"
depends = ("zebra",)
dirs = ()
configs = ()
startindex = 40
startup = ()
shutdown = ()
meta = "The config file for this service can be found in the Zebra service."
_ipv4_routing = False
_ipv6_routing = False
ipv4_routing = False
ipv6_routing = False
@staticmethod
def routerid(node):
@ -239,7 +239,7 @@ class QuaggaService(CoreService):
Helper to return the first IPv4 address of a node as its router ID.
"""
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
@ -280,11 +280,11 @@ class Ospfv2(QuaggaService):
not build its own configuration file but has hooks for adding to the
unified Quagga.conf file.
"""
_name = "OSPFv2"
_startup = ()
_shutdown = ("killall ospfd",)
_validate = ("pidof ospfd",)
_ipv4_routing = True
name = "OSPFv2"
startup = ()
shutdown = ("killall ospfd",)
validate = ("pidof ospfd",)
ipv4_routing = True
@staticmethod
def mtucheck(ifc):
@ -355,12 +355,12 @@ class Ospfv3(QuaggaService):
not build its own configuration file but has hooks for adding to the
unified Quagga.conf file.
"""
_name = "OSPFv3"
_startup = ()
_shutdown = ("killall ospf6d",)
_validate = ("pidof ospf6d",)
_ipv4_routing = True
_ipv6_routing = True
name = "OSPFv3"
startup = ()
shutdown = ("killall ospf6d",)
validate = ("pidof ospf6d",)
ipv4_routing = True
ipv6_routing = True
@staticmethod
def minmtu(ifc):
@ -436,8 +436,8 @@ class Ospfv3mdr(Ospfv3):
configuration file but has hooks for adding to the
unified Quagga.conf file.
"""
_name = "OSPFv3MDR"
_ipv4_routing = True
name = "OSPFv3MDR"
ipv4_routing = True
@classmethod
def generatequaggaifcconfig(cls, node, ifc):
@ -464,13 +464,13 @@ class Bgp(QuaggaService):
Peers must be manually configured, with a full mesh for those
having the same AS number.
"""
_name = "BGP"
_startup = ()
_shutdown = ("killall bgpd",)
_validate = ("pidof bgpd",)
_custom_needed = True
_ipv4_routing = True
_ipv6_routing = True
name = "BGP"
startup = ()
shutdown = ("killall bgpd",)
validate = ("pidof bgpd",)
custom_needed = True
ipv4_routing = True
ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
@ -489,11 +489,11 @@ class Rip(QuaggaService):
"""
The RIP service provides IPv4 routing for wired networks.
"""
_name = "RIP"
_startup = ()
_shutdown = ("killall ripd",)
_validate = ("pidof ripd",)
_ipv4_routing = True
name = "RIP"
startup = ()
shutdown = ("killall ripd",)
validate = ("pidof ripd",)
ipv4_routing = True
@classmethod
def generatequaggaconfig(cls, node):
@ -512,11 +512,11 @@ class Ripng(QuaggaService):
"""
The RIP NG service provides IPv6 routing for wired networks.
"""
_name = "RIPNG"
_startup = ()
_shutdown = ("killall ripngd",)
_validate = ("pidof ripngd",)
_ipv6_routing = True
name = "RIPNG"
startup = ()
shutdown = ("killall ripngd",)
validate = ("pidof ripngd",)
ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
@ -536,11 +536,11 @@ class Babel(QuaggaService):
The Babel service provides a loop-avoiding distance-vector routing
protocol for IPv6 and IPv4 with fast convergence properties.
"""
_name = "Babel"
_startup = ()
_shutdown = ("killall babeld",)
_validate = ("pidof babeld",)
_ipv6_routing = True
name = "Babel"
startup = ()
shutdown = ("killall babeld",)
validate = ("pidof babeld",)
ipv6_routing = True
@classmethod
def generatequaggaconfig(cls, node):
@ -565,11 +565,11 @@ class Xpimd(QuaggaService):
"""
PIM multicast routing based on XORP.
"""
_name = 'Xpimd'
_startup = ()
_shutdown = ('killall xpimd',)
_validate = ('pidof xpimd',)
_ipv4_routing = True
name = 'Xpimd'
startup = ()
shutdown = ('killall xpimd',)
validate = ('pidof xpimd',)
ipv4_routing = True
@classmethod
def generatequaggaconfig(cls, node):

View file

@ -11,14 +11,14 @@ class SdnService(CoreService):
"""
Parent class for SDN services.
"""
_name = None
_group = "SDN"
_depends = ()
_dirs = ()
_configs = ()
_startindex = 50
_startup = ()
_shutdown = ()
name = None
group = "SDN"
depends = ()
dirs = ()
configs = ()
startindex = 50
startup = ()
shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
@ -26,27 +26,27 @@ class SdnService(CoreService):
class OvsService(SdnService):
_name = "OvsService"
_group = "SDN"
_depends = ()
_dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
_configs = ('OvsService.sh',)
_startindex = 50
_startup = ('sh OvsService.sh',)
_shutdown = ('killall ovs-vswitchd', 'killall ovsdb-server')
name = "OvsService"
group = "SDN"
depends = ()
dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
configs = ('OvsService.sh',)
startindex = 50
startup = ('sh OvsService.sh',)
shutdown = ('killall ovs-vswitchd', 'killall ovsdb-server')
@classmethod
def generateconfig(cls, node, filename, services):
# Check whether the node is running zebra
has_zebra = 0
for s in services:
if s._name == "zebra":
if s.name == "zebra":
has_zebra = 1
# Check whether the node is running an SDN controller
has_sdn_ctrlr = 0
for s in services:
if s._name == "ryuService":
if s.name == "ryuService":
has_sdn_ctrlr = 1
cfg = "#!/bin/sh\n"
@ -100,14 +100,14 @@ class OvsService(SdnService):
class RyuService(SdnService):
_name = "ryuService"
_group = "SDN"
_depends = ()
_dirs = ()
_configs = ('ryuService.sh',)
_startindex = 50
_startup = ('sh ryuService.sh',)
_shutdown = ('killall ryu-manager',)
name = "ryuService"
group = "SDN"
depends = ()
dirs = ()
configs = ('ryuService.sh',)
startindex = 50
startup = ('sh ryuService.sh',)
shutdown = ('killall ryu-manager',)
@classmethod
def generateconfig(cls, node, filename, services):

View file

@ -9,14 +9,14 @@ from core.service import CoreService
class VPNClient(CoreService):
_name = "VPNClient"
_group = "Security"
_configs = ('vpnclient.sh',)
_startindex = 60
_startup = ('sh vpnclient.sh',)
_shutdown = ("killall openvpn",)
_validate = ("pidof openvpn",)
_custom_needed = True
name = "VPNClient"
group = "Security"
configs = ('vpnclient.sh',)
startindex = 60
startup = ('sh vpnclient.sh',)
shutdown = ("killall openvpn",)
validate = ("pidof openvpn",)
custom_needed = True
@classmethod
def generateconfig(cls, node, filename, services):
@ -36,14 +36,14 @@ class VPNClient(CoreService):
class VPNServer(CoreService):
_name = "VPNServer"
_group = "Security"
_configs = ('vpnserver.sh',)
_startindex = 50
_startup = ('sh vpnserver.sh',)
_shutdown = ("killall openvpn",)
_validate = ("pidof openvpn",)
_custom_needed = True
name = "VPNServer"
group = "Security"
configs = ('vpnserver.sh',)
startindex = 50
startup = ('sh vpnserver.sh',)
shutdown = ("killall openvpn",)
validate = ("pidof openvpn",)
custom_needed = True
@classmethod
def generateconfig(cls, node, filename, services):
@ -64,13 +64,13 @@ class VPNServer(CoreService):
class IPsec(CoreService):
_name = "IPsec"
_group = "Security"
_configs = ('ipsec.sh',)
_startindex = 60
_startup = ('sh ipsec.sh',)
_shutdown = ("killall racoon",)
_custom_needed = True
name = "IPsec"
group = "Security"
configs = ('ipsec.sh',)
startindex = 60
startup = ('sh ipsec.sh',)
shutdown = ("killall racoon",)
custom_needed = True
@classmethod
def generateconfig(cls, node, filename, services):
@ -92,12 +92,12 @@ class IPsec(CoreService):
class Firewall(CoreService):
_name = "Firewall"
_group = "Security"
_configs = ('firewall.sh',)
_startindex = 20
_startup = ('sh firewall.sh',)
_custom_needed = True
name = "Firewall"
group = "Security"
configs = ('firewall.sh',)
startindex = 20
startup = ('sh firewall.sh',)
custom_needed = True
@classmethod
def generateconfig(cls, node, filename, services):

View file

@ -8,15 +8,15 @@ class Startup(CoreService):
"""
A CORE service to start other services in order, serially
"""
_name = 'startup'
_group = 'Utility'
_depends = ()
_dirs = ()
_configs = ('startup.sh',)
_startindex = maxint
_startup = ('sh startup.sh',)
_shutdown = ()
_validate = ()
name = 'startup'
group = 'Utility'
depends = ()
dirs = ()
configs = ('startup.sh',)
startindex = maxint
startup = ('sh startup.sh',)
shutdown = ()
validate = ()
@staticmethod
def is_startup_service(s):
@ -24,13 +24,13 @@ class Startup(CoreService):
@classmethod
def generateconfig(cls, node, filename, services):
if filename != cls._configs[0]:
if filename != cls.configs[0]:
return ''
script = '#!/bin/sh\n' \
'# auto-generated by Startup (startup.py)\n\n' \
'exec > startup.log 2>&1\n\n'
for s in sorted(services, key=lambda x: x._startindex):
if cls.is_startup_service(s) or len(str(s._starttime)) > 0:
for s in sorted(services, key=lambda x: x.startindex):
if cls.is_startup_service(s) or len(str(s.starttime)) > 0:
continue
start = '\n'.join(s.getstartup(node, services))
if start:

View file

@ -8,29 +8,29 @@ UCARP_ETC = "/usr/local/etc/ucarp"
class Ucarp(CoreService):
_name = "ucarp"
_group = "Utility"
_depends = ( )
_dirs = (UCARP_ETC,)
_configs = (
name = "ucarp"
group = "Utility"
depends = ( )
dirs = (UCARP_ETC,)
configs = (
UCARP_ETC + "/default.sh", UCARP_ETC + "/default-up.sh", UCARP_ETC + "/default-down.sh", "ucarpboot.sh",)
_startindex = 65
_startup = ("sh ucarpboot.sh",)
_shutdown = ("killall ucarp",)
_validate = ("pidof ucarp",)
startindex = 65
startup = ("sh ucarpboot.sh",)
shutdown = ("killall ucarp",)
validate = ("pidof ucarp",)
@classmethod
def generateconfig(cls, node, filename, services):
"""
Return the default file contents
"""
if filename == cls._configs[0]:
if filename == cls.configs[0]:
return cls.generateUcarpConf(node, services)
elif filename == cls._configs[1]:
elif filename == cls.configs[1]:
return cls.generateVipUp(node, services)
elif filename == cls._configs[2]:
elif filename == cls.configs[2]:
return cls.generateVipDown(node, services)
elif filename == cls._configs[3]:
elif filename == cls.configs[3]:
return cls.generateUcarpBoot(node, services)
else:
raise ValueError

View file

@ -16,14 +16,14 @@ class UtilService(CoreService):
"""
Parent class for utility services.
"""
_name = None
_group = "Utility"
_depends = ()
_dirs = ()
_configs = ()
_startindex = 80
_startup = ()
_shutdown = ()
name = None
group = "Utility"
depends = ()
dirs = ()
configs = ()
startindex = 80
startup = ()
shutdown = ()
@classmethod
def generateconfig(cls, node, filename, services):
@ -31,10 +31,10 @@ class UtilService(CoreService):
class IPForwardService(UtilService):
_name = "IPForward"
_configs = ("ipforward.sh",)
_startindex = 5
_startup = ("sh ipforward.sh",)
name = "IPForward"
configs = ("ipforward.sh",)
startindex = 5
startup = ("sh ipforward.sh",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -67,9 +67,9 @@ class IPForwardService(UtilService):
class DefaultRouteService(UtilService):
_name = "DefaultRoute"
_configs = ("defaultroute.sh",)
_startup = ("sh defaultroute.sh",)
name = "DefaultRoute"
configs = ("defaultroute.sh",)
startup = ("sh defaultroute.sh",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -101,9 +101,9 @@ class DefaultRouteService(UtilService):
class DefaultMulticastRouteService(UtilService):
_name = "DefaultMulticastRoute"
_configs = ("defaultmroute.sh",)
_startup = ("sh defaultmroute.sh",)
name = "DefaultMulticastRoute"
configs = ("defaultmroute.sh",)
startup = ("sh defaultmroute.sh",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -113,7 +113,7 @@ class DefaultMulticastRouteService(UtilService):
cfg += "as needed\n"
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
if os.uname()[0] == "Linux":
rtcmd = "ip route add 224.0.0.0/4 dev"
@ -126,10 +126,10 @@ class DefaultMulticastRouteService(UtilService):
class StaticRouteService(UtilService):
_name = "StaticRoute"
_configs = ("staticroute.sh",)
_startup = ("sh staticroute.sh",)
_custom_needed = True
name = "StaticRoute"
configs = ("staticroute.sh",)
startup = ("sh staticroute.sh",)
custom_needed = True
@classmethod
def generateconfig(cls, node, filename, services):
@ -165,12 +165,12 @@ class StaticRouteService(UtilService):
class SshService(UtilService):
_name = "SSH"
_configs = ("startsshd.sh", "/etc/ssh/sshd_config",)
_dirs = ("/etc/ssh", "/var/run/sshd",)
_startup = ("sh startsshd.sh",)
_shutdown = ("killall sshd",)
_validate = ()
name = "SSH"
configs = ("startsshd.sh", "/etc/ssh/sshd_config",)
dirs = ("/etc/ssh", "/var/run/sshd",)
startup = ("sh startsshd.sh",)
shutdown = ("killall sshd",)
validate = ()
@classmethod
def generateconfig(cls, node, filename, services):
@ -178,8 +178,8 @@ class SshService(UtilService):
Use a startup script for launching sshd in order to wait for host
key generation.
"""
sshcfgdir = cls._dirs[0]
sshstatedir = cls._dirs[1]
sshcfgdir = cls.dirs[0]
sshstatedir = cls.dirs[1]
sshlibdir = "/usr/lib/openssh"
if filename == "startsshd.sh":
return """\
@ -233,12 +233,12 @@ UseDNS no
class DhcpService(UtilService):
_name = "DHCP"
_configs = ("/etc/dhcp/dhcpd.conf",)
_dirs = ("/etc/dhcp",)
_startup = ("dhcpd",)
_shutdown = ("killall dhcpd",)
_validate = ("pidof dhcpd",)
name = "DHCP"
configs = ("/etc/dhcp/dhcpd.conf",)
dirs = ("/etc/dhcp",)
startup = ("dhcpd",)
shutdown = ("killall dhcpd",)
validate = ("pidof dhcpd",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -296,11 +296,11 @@ class DhcpClientService(UtilService):
"""
Use a DHCP client for all interfaces for addressing.
"""
_name = "DHCPClient"
_configs = ("startdhcpclient.sh",)
_startup = ("sh startdhcpclient.sh",)
_shutdown = ("killall dhclient",)
_validate = ("pidof dhclient",)
name = "DHCPClient"
configs = ("startdhcpclient.sh",)
startup = ("sh startdhcpclient.sh",)
shutdown = ("killall dhclient",)
validate = ("pidof dhclient",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -327,12 +327,12 @@ class FtpService(UtilService):
"""
Start a vsftpd server.
"""
_name = "FTP"
_configs = ("vsftpd.conf",)
_dirs = ("/var/run/vsftpd/empty", "/var/ftp",)
_startup = ("vsftpd ./vsftpd.conf",)
_shutdown = ("killall vsftpd",)
_validate = ("pidof vsftpd",)
name = "FTP"
configs = ("vsftpd.conf",)
dirs = ("/var/run/vsftpd/empty", "/var/ftp",)
startup = ("vsftpd ./vsftpd.conf",)
shutdown = ("killall vsftpd",)
validate = ("pidof vsftpd",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -359,14 +359,14 @@ class HttpService(UtilService):
"""
Start an apache server.
"""
_name = "HTTP"
_configs = ("/etc/apache2/apache2.conf", "/etc/apache2/envvars",
"/var/www/index.html",)
_dirs = ("/etc/apache2", "/var/run/apache2", "/var/log/apache2",
"/run/lock", "/var/lock/apache2", "/var/www",)
_startup = ("chown www-data /var/lock/apache2", "apache2ctl start",)
_shutdown = ("apache2ctl stop",)
_validate = ("pidof apache2",)
name = "HTTP"
configs = ("/etc/apache2/apache2.conf", "/etc/apache2/envvars",
"/var/www/index.html",)
dirs = ("/etc/apache2", "/var/run/apache2", "/var/log/apache2",
"/run/lock", "/var/lock/apache2", "/var/www",)
startup = ("chown www-data /var/lock/apache2", "apache2ctl start",)
shutdown = ("apache2ctl stop",)
validate = ("pidof apache2",)
APACHEVER22, APACHEVER24 = (22, 24)
@ -375,11 +375,11 @@ class HttpService(UtilService):
"""
Generate an apache2.conf configuration file.
"""
if filename == cls._configs[0]:
if filename == cls.configs[0]:
return cls.generateapache2conf(node, filename, services)
elif filename == cls._configs[1]:
elif filename == cls.configs[1]:
return cls.generateenvvars(node, filename, services)
elif filename == cls._configs[2]:
elif filename == cls.configs[2]:
return cls.generatehtml(node, filename, services)
else:
return ""
@ -561,7 +561,7 @@ export LANG
<p>The web server software is running but no content has been added, yet.</p>
""" % node.name
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
body += "<li>%s - %s</li>\n" % (ifc.name, ifc.addrlist)
return "<html><body>%s</body></html>" % body
@ -571,14 +571,14 @@ class PcapService(UtilService):
"""
Pcap service for logging packets.
"""
_name = "pcap"
_configs = ("pcap.sh",)
_dirs = ()
_startindex = 1
_startup = ("sh pcap.sh start",)
_shutdown = ("sh pcap.sh stop",)
_validate = ("pidof tcpdump",)
_meta = "logs network traffic to pcap packet capture files"
name = "pcap"
configs = ("pcap.sh",)
dirs = ()
startindex = 1
startup = ("sh pcap.sh start",)
shutdown = ("sh pcap.sh stop",)
validate = ("pidof tcpdump",)
meta = "logs network traffic to pcap packet capture files"
@classmethod
def generateconfig(cls, node, filename, services):
@ -595,7 +595,7 @@ if [ "x$1" = "xstart" ]; then
"""
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
cfg += '# '
redir = "< /dev/null"
cfg += "tcpdump ${DUMPOPTS} -w %s.%s.pcap -i %s %s &\n" % \
@ -611,12 +611,12 @@ fi;
class RadvdService(UtilService):
_name = "radvd"
_configs = ("/etc/radvd/radvd.conf",)
_dirs = ("/etc/radvd",)
_startup = ("radvd -C /etc/radvd/radvd.conf -m logfile -l /var/log/radvd.log",)
_shutdown = ("pkill radvd",)
_validate = ("pidof radvd",)
name = "radvd"
configs = ("/etc/radvd/radvd.conf",)
dirs = ("/etc/radvd",)
startup = ("radvd -C /etc/radvd/radvd.conf -m logfile -l /var/log/radvd.log",)
shutdown = ("pkill radvd",)
validate = ("pidof radvd",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -626,7 +626,7 @@ class RadvdService(UtilService):
"""
cfg = "# auto-generated by RADVD service (utility.py)\n"
for ifc in node.netifs():
if hasattr(ifc, 'control') and ifc.control == True:
if hasattr(ifc, 'control') and ifc.control is True:
continue
prefixes = map(cls.subnetentry, ifc.addrlist)
if len(prefixes) < 1:
@ -671,11 +671,11 @@ class AtdService(UtilService):
"""
Atd service for scheduling at jobs
"""
_name = "atd"
_configs = ("startatd.sh",)
_dirs = ("/var/spool/cron/atjobs", "/var/spool/cron/atspool")
_startup = ("sh startatd.sh",)
_shutdown = ("pkill atd",)
name = "atd"
configs = ("startatd.sh",)
dirs = ("/var/spool/cron/atjobs", "/var/spool/cron/atspool")
startup = ("sh startatd.sh",)
shutdown = ("pkill atd",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -692,6 +692,6 @@ class UserDefinedService(UtilService):
"""
Dummy service allowing customization of anything.
"""
_name = "UserDefined"
_startindex = 50
_meta = "Customize this service to do anything upon startup."
name = "UserDefined"
startindex = 50
meta = "Customize this service to do anything upon startup."

View file

@ -11,15 +11,15 @@ class XorpRtrmgr(CoreService):
XORP router manager service builds a config.boot file based on other
enabled XORP services, and launches necessary daemons upon startup.
"""
_name = "xorp_rtrmgr"
_group = "XORP"
_depends = ()
_dirs = ("/etc/xorp",)
_configs = ("/etc/xorp/config.boot",)
_startindex = 35
_startup = ("xorp_rtrmgr -d -b %s -l /var/log/%s.log -P /var/run/%s.pid" % (_configs[0], _name, _name),)
_shutdown = ("killall xorp_rtrmgr",)
_validate = ("pidof xorp_rtrmgr",)
name = "xorp_rtrmgr"
group = "XORP"
depends = ()
dirs = ("/etc/xorp",)
configs = ("/etc/xorp/config.boot",)
startindex = 35
startup = ("xorp_rtrmgr -d -b %s -l /var/log/%s.log -P /var/run/%s.pid" % (configs[0], name, name),)
shutdown = ("killall xorp_rtrmgr",)
validate = ("pidof xorp_rtrmgr",)
@classmethod
def generateconfig(cls, node, filename, services):
@ -40,10 +40,10 @@ class XorpRtrmgr(CoreService):
for s in services:
try:
s._depends.index(cls._name)
s.depends.index(cls.name)
cfg += s.generatexorpconfig(node)
except ValueError:
logger.exception("error getting value from service: %s", cls._name)
logger.exception("error getting value from service: %s", cls.name)
return cfg
@ -74,15 +74,15 @@ class XorpService(CoreService):
Parent class for XORP services. Defines properties and methods
common to XORP's routing daemons.
"""
_name = None
_group = "XORP"
_depends = ("xorp_rtrmgr",)
_dirs = ()
_configs = ()
_startindex = 40
_startup = ()
_shutdown = ()
_meta = "The config file for this service can be found in the xorp_rtrmgr service."
name = None
group = "XORP"
depends = ("xorp_rtrmgr",)
dirs = ()
configs = ()
startindex = 40
startup = ()
shutdown = ()
meta = "The config file for this service can be found in the xorp_rtrmgr service."
@staticmethod
def fea(forwarding):
@ -165,7 +165,7 @@ class XorpOspfv2(XorpService):
not build its own configuration file but has hooks for adding to the
unified XORP configuration file.
"""
_name = "XORP_OSPFv2"
name = "XORP_OSPFv2"
@classmethod
def generatexorpconfig(cls, node):
@ -200,7 +200,7 @@ class XorpOspfv3(XorpService):
not build its own configuration file but has hooks for adding to the
unified XORP configuration file.
"""
_name = "XORP_OSPFv3"
name = "XORP_OSPFv3"
@classmethod
def generatexorpconfig(cls, node):
@ -227,8 +227,8 @@ class XorpBgp(XorpService):
"""
IPv4 inter-domain routing. AS numbers and peers must be customized.
"""
_name = "XORP_BGP"
_custom_needed = True
name = "XORP_BGP"
custom_needed = True
@classmethod
def generatexorpconfig(cls, node):
@ -257,7 +257,7 @@ class XorpRip(XorpService):
RIP IPv4 unicast routing.
"""
_name = "XORP_RIP"
name = "XORP_RIP"
@classmethod
def generatexorpconfig(cls, node):
@ -289,7 +289,7 @@ class XorpRipng(XorpService):
"""
RIP NG IPv6 unicast routing.
"""
_name = "XORP_RIPNG"
name = "XORP_RIPNG"
@classmethod
def generatexorpconfig(cls, node):
@ -324,7 +324,7 @@ class XorpPimSm4(XorpService):
"""
PIM Sparse Mode IPv4 multicast routing.
"""
_name = "XORP_PIMSM4"
name = "XORP_PIMSM4"
@classmethod
def generatexorpconfig(cls, node):
@ -383,7 +383,7 @@ class XorpPimSm6(XorpService):
"""
PIM Sparse Mode IPv6 multicast routing.
"""
_name = "XORP_PIMSM6"
name = "XORP_PIMSM6"
@classmethod
def generatexorpconfig(cls, node):
@ -442,7 +442,7 @@ class XorpOlsr(XorpService):
"""
OLSR IPv4 unicast MANET routing.
"""
_name = "XORP_OLSR"
name = "XORP_OLSR"
@classmethod
def generatexorpconfig(cls, node):