Fix 'self' references by adding a PlannerBase class
This commit is contained in:
@@ -19,7 +19,6 @@ metadata, and plan configuration changes towards a given YAML target configurati
|
|||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from vppcfg.config import loopback
|
|
||||||
from vppcfg.config import interface
|
from vppcfg.config import interface
|
||||||
from vppcfg.config import lcp
|
from vppcfg.config import lcp
|
||||||
from .vppapi import VPPApi
|
from .vppapi import VPPApi
|
||||||
@@ -43,6 +42,7 @@ class Planner(PlannerPruneOperations, PlannerCreateOperations, PlannerSyncOperat
|
|||||||
vpp_api_socket="/run/vpp/api.sock",
|
vpp_api_socket="/run/vpp/api.sock",
|
||||||
vpp_json_dir=None,
|
vpp_json_dir=None,
|
||||||
):
|
):
|
||||||
|
super().__init__()
|
||||||
self.logger = logging.getLogger("vppcfg.planner")
|
self.logger = logging.getLogger("vppcfg.planner")
|
||||||
self.logger.addHandler(logging.NullHandler())
|
self.logger.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
@@ -84,7 +84,6 @@ class Planner(PlannerPruneOperations, PlannerCreateOperations, PlannerSyncOperat
|
|||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def write(self, outfile, emit_ok=False):
|
def write(self, outfile, emit_ok=False):
|
||||||
"""Emit the CLI contents to stdout (if outfile=='-') or a named file otherwise.
|
"""Emit the CLI contents to stdout (if outfile=='-') or a named file otherwise.
|
||||||
If the 'emit_ok' flag is False, emit a warning at the top and bottom of the file.
|
If the 'emit_ok' flag is False, emit a warning at the top and bottom of the file.
|
||||||
|
|||||||
32
vppcfg/vpp/planner_base.py
Normal file
32
vppcfg/vpp/planner_base.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 Pim van Pelt
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at:
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Base class defining the interface expected by planner mixins.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from abc import ABC
|
||||||
|
from typing import Dict, Any, List
|
||||||
|
|
||||||
|
|
||||||
|
class PlannerBase(ABC): # pylint: disable=too-few-public-methods
|
||||||
|
"""Abstract base class defining the interface expected by planner mixins."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
# These attributes will be set by the concrete Planner class
|
||||||
|
self.cfg: Dict[str, Any]
|
||||||
|
self.vpp: Any # VPPApi instance
|
||||||
|
self.logger: Any # Logger instance
|
||||||
|
self.cli: Dict[str, List[str]] # CLI commands grouped by operation type
|
||||||
@@ -23,9 +23,10 @@ from vppcfg.config import bondethernet
|
|||||||
from vppcfg.config import bridgedomain
|
from vppcfg.config import bridgedomain
|
||||||
from vppcfg.config import vxlan_tunnel
|
from vppcfg.config import vxlan_tunnel
|
||||||
from vppcfg.config import tap
|
from vppcfg.config import tap
|
||||||
|
from .planner_base import PlannerBase
|
||||||
|
|
||||||
|
|
||||||
class PlannerCreateOperations:
|
class PlannerCreateOperations(PlannerBase): # pylint: disable=too-few-public-methods
|
||||||
"""Mixin class providing create operations for the Planner."""
|
"""Mixin class providing create operations for the Planner."""
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ from vppcfg.config import interface
|
|||||||
from vppcfg.config import bondethernet
|
from vppcfg.config import bondethernet
|
||||||
from vppcfg.config import bridgedomain
|
from vppcfg.config import bridgedomain
|
||||||
from vppcfg.config import vxlan_tunnel
|
from vppcfg.config import vxlan_tunnel
|
||||||
from vppcfg.config import lcp
|
|
||||||
from vppcfg.config import tap
|
from vppcfg.config import tap
|
||||||
|
from .planner_base import PlannerBase
|
||||||
|
|
||||||
|
|
||||||
class PlannerPruneOperations:
|
class PlannerPruneOperations(PlannerBase): # pylint: disable=too-few-public-methods
|
||||||
"""Mixin class providing prune operations for the Planner."""
|
"""Mixin class providing prune operations for the Planner."""
|
||||||
|
|
||||||
def prune(self):
|
def prune(self):
|
||||||
@@ -264,7 +264,7 @@ class PlannerPruneOperations:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _tap_has_diff(self, ifname):
|
def _tap_has_diff(self, ifname): # pylint: disable=too-many-return-statements
|
||||||
"""Returns True if the given ifname (tap0) has different attributes between VPP
|
"""Returns True if the given ifname (tap0) has different attributes between VPP
|
||||||
and the given configuration, or if either does not exist.
|
and the given configuration, or if either does not exist.
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ from vppcfg.config import loopback
|
|||||||
from vppcfg.config import interface
|
from vppcfg.config import interface
|
||||||
from vppcfg.config import bondethernet
|
from vppcfg.config import bondethernet
|
||||||
from vppcfg.config import bridgedomain
|
from vppcfg.config import bridgedomain
|
||||||
|
from .planner_base import PlannerBase
|
||||||
|
|
||||||
|
|
||||||
class PlannerSyncOperations:
|
class PlannerSyncOperations(PlannerBase): # pylint: disable=too-few-public-methods
|
||||||
"""Mixin class providing sync operations for the Planner."""
|
"""Mixin class providing sync operations for the Planner."""
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user