summaryrefslogtreecommitdiffstats
path: root/core/vswitch_controller.py
blob: 889f14bc3ad7990f910c5167300d699bc8cb3e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2015-2018 Intel Corporation., Tieto
#
# 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.
"""Interface for deployment specific vSwitch controllers
"""
import logging

class IVswitchController(object):
    """Interface class for a vSwitch controller object

    This interface is used to setup and control a vSwitch provider for a
    particular deployment scenario.
    """
    def __init__(self, deployment, vswitch_class, traffic):
        """Initializes up the generic prerequisites for deployment scenario.

        :deployment: the deployment scenario to configure
        :vswitch_class: the vSwitch class to be used.
        :traffic: dictionary with detailed traffic definition
        """
        self._logger = logging.getLogger(__name__)
        self._vswitch_class = vswitch_class
        self._vswitch = vswitch_class()
        self._deployment_scenario = deployment
        self._logger.debug('Creation using %s', str(self._vswitch_class))
        self._traffic = traffic.copy()
        self._bridge = None

    def setup(self):
        """Sets up the switch for the particular deployment scenario
        """
        raise NotImplementedError(
            "The VswitchController does not implement the \"setup\" function.")

    def stop(self):
        """Tears down the switch created in setup()
        """
        raise NotImplementedError(
            "The VswitchController does not implement the \"stop\" function.")

    def __enter__(self):
        """Sets up the switch for the particular deployment scenario
        """
        self.setup()

    def __exit__(self, type_, value, traceback):
        """Tears down the switch created in setup()
        """
        self.stop()

    def get_vswitch(self):
        """Get the controlled vSwitch

        :return: The controlled IVswitch
        """
        return self._vswitch

    def get_ports_info(self):
        """Returns a dictionary describing all ports on the vSwitch.

        See IVswitch for dictionary structure details
        """
        raise NotImplementedError(
            "The VswitchController does not implement the \"get_ports_info\" "
            "function.")

    def dump_vswitch_connections(self):
        """ Dumps connections from vswitch
        """
        raise NotImplementedError(
            "The VswitchController does not implement the "
            "\"dump_vswitch_connections\" function.")