daemon: added type hinting throughout all services and made small tweaks/fixes that were ran across

This commit is contained in:
Blake Harnden 2020-06-18 12:54:36 -07:00
parent 250bc6e1f5
commit cd74a44558
11 changed files with 560 additions and 636 deletions

View file

@ -3,9 +3,11 @@ sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
"""
import re
from typing import Tuple
import netaddr
from core.nodes.base import CoreNode
from core.services.coreservices import CoreService
@ -14,24 +16,28 @@ class SdnService(CoreService):
Parent class for SDN services.
"""
group = "SDN"
group: str = "SDN"
@classmethod
def generate_config(cls, node, filename):
def generate_config(cls, node: CoreNode, filename: str) -> str:
return ""
class OvsService(SdnService):
name = "OvsService"
executables = ("ovs-ofctl", "ovs-vsctl")
group = "SDN"
dirs = ("/etc/openvswitch", "/var/run/openvswitch", "/var/log/openvswitch")
configs = ("OvsService.sh",)
startup = ("sh OvsService.sh",)
shutdown = ("killall ovs-vswitchd", "killall ovsdb-server")
name: str = "OvsService"
group: str = "SDN"
executables: Tuple[str, ...] = ("ovs-ofctl", "ovs-vsctl")
dirs: Tuple[str, ...] = (
"/etc/openvswitch",
"/var/run/openvswitch",
"/var/log/openvswitch",
)
configs: Tuple[str, ...] = ("OvsService.sh",)
startup: Tuple[str, ...] = ("sh OvsService.sh",)
shutdown: Tuple[str, ...] = ("killall ovs-vswitchd", "killall ovsdb-server")
@classmethod
def generate_config(cls, node, filename):
def generate_config(cls, node: CoreNode, filename: str) -> str:
# Check whether the node is running zebra
has_zebra = 0
for s in node.services:
@ -46,8 +52,8 @@ class OvsService(SdnService):
cfg += "## this stops it from routing traffic without defined flows.\n"
cfg += "## remove the -- and everything after if you want it to act as a regular switch\n"
cfg += "ovs-vsctl add-br ovsbr0 -- set Bridge ovsbr0 fail-mode=secure\n"
cfg += "\n## Now add all our interfaces as ports to the switch\n"
portnum = 1
for iface in node.get_ifaces(control=False):
ifnumstr = re.findall(r"\d+", iface.name)
@ -111,21 +117,19 @@ class OvsService(SdnService):
% (portnum + 1, portnum)
)
portnum += 2
return cfg
class RyuService(SdnService):
name = "ryuService"
executables = ("ryu-manager",)
group = "SDN"
dirs = ()
configs = ("ryuService.sh",)
startup = ("sh ryuService.sh",)
shutdown = ("killall ryu-manager",)
name: str = "ryuService"
group: str = "SDN"
executables: Tuple[str, ...] = ("ryu-manager",)
configs: Tuple[str, ...] = ("ryuService.sh",)
startup: Tuple[str, ...] = ("sh ryuService.sh",)
shutdown: Tuple[str, ...] = ("killall ryu-manager",)
@classmethod
def generate_config(cls, node, filename):
def generate_config(cls, node: CoreNode, filename: str) -> str:
"""
Return a string that will be written to filename, or sent to the
GUI for user customization.