<reponame>libunamari/faucet-tests
"""Implement configuration API."""

# Copyright (C) 2015 <NAME>, <NAME> and <NAME>.
# Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd.
# Copyright (C) 2015--2017 The Contributors
#
# 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.


class FaucetAPI(object):
    """An API for communicating with Faucet.

    Contains methods for interacting with a running faucet controller from
    within a RyuApp. This app should be run together with faucet in the same
    ryu-manager process.

    It can be accessed by use of the _CONTEXTS dictionary within a RyuApp.
    eg.

    class ExampleApp(app_manager.RyuApp):

        _CONTEXTS = {
            'faucet_api': FaucetAPI
            }

        def __init__(self, *args, **kwargs):
            self.is_api_registered = False
            self.faucet_api = kwargs['faucet_api']

        @set_ev_cls(EventFaucetAPIRegistered, MAIN_DISPATCHER)
        def _api_registered(self):
            self.is_api_registered = True

        def print_faucet_config(self):
            if self.is_api_registered:
                print(self.faucet_api.get_config())
    """

    def __init__(self, *args, **kwargs):
        self.faucet = None

    def is_registered(self):
        """Return True if registered and ready to serve API requests."""
        return self.faucet is not None

    def _register(self, faucet):
        """Register with FAUCET RyuApp."""
        if self.faucet is None:
            self.faucet = faucet

    def reload_config(self):
        """Reload config from config file in FAUCET_CONFIG env variable."""
        if self.faucet is not None:
            self.faucet.reload_config(None)

    def get_config(self):
        """Get the current running config of Faucet as a python dictionary."""
        if self.faucet is not None:
            return self.faucet.get_config()
        return None

    def get_tables(self, dp_id):
        """Get current FAUCET tables as a dict of table name: table no."""
        if self.faucet is not None:
            return self.faucet.get_tables(dp_id)
        return None

    def push_config(self, config):
        """Push supplied config to FAUCET."""
        raise NotImplementedError

    def add_port_acl(self, port, acl):
        """Add an ACL to a port."""
        raise NotImplementedError

    def add_vlan_acl(self, vlan, acl):
        """Add an ACL to a VLAN."""
        raise NotImplementedError

    def delete_port_acl(self, port, acl):
        """Delete an ACL from a port."""
        raise NotImplementedError

    def delete_vlan_acl(self, vlan, acl):
        """Delete an ACL from a VLAN."""
        raise NotImplementedError

"""Implement configuration API."""

# Copyright (C) 2015 <NAME>, <NAME> and <NAME>.
# Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd.
# Copyright (C) 2015--2017 The Contributors
#
# 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.


class FaucetAPI(object):
    """An API for communicating with Faucet.

    Contains methods for interacting with a running faucet controller from
    within a RyuApp. This app should be run together with faucet in the same
    ryu-manager process.

    It can be accessed by use of the _CONTEXTS dictionary within a RyuApp.
    eg.

    class ExampleApp(app_manager.RyuApp):

        _CONTEXTS = {
            'faucet_api': FaucetAPI
            }

        def __init__(self, *args, **kwargs):
            self.is_api_registered = False
            self.faucet_api = kwargs['faucet_api']

        @set_ev_cls(EventFaucetAPIRegistered, MAIN_DISPATCHER)
        def _api_registered(self):
            self.is_api_registered = True

        def print_faucet_config(self):
            if self.is_api_registered:
                print(self.faucet_api.get_config())
    """

    def __init__(self, *args, **kwargs):
        self.faucet = None

    def is_registered(self):
        """Return True if registered and ready to serve API requests."""
        return self.faucet is not None

    def _register(self, faucet):
        """Register with FAUCET RyuApp."""
        if self.faucet is None:
            self.faucet = faucet

    def reload_config(self):
        """Reload config from config file in FAUCET_CONFIG env variable."""
        if self.faucet is not None:
            self.faucet.reload_config(None)

    def get_config(self):
        """Get the current running config of Faucet as a python dictionary."""
        if self.faucet is not None:
            return self.faucet.get_config()
        return None

    def get_tables(self, dp_id):
        """Get current FAUCET tables as a dict of table name: table no."""
        if self.faucet is not None:
            return self.faucet.get_tables(dp_id)
        return None

    def push_config(self, config):
        """Push supplied config to FAUCET."""
        raise NotImplementedError

    def add_port_acl(self, port, acl):
        """Add an ACL to a port."""
        raise NotImplementedError

    def add_vlan_acl(self, vlan, acl):
        """Add an ACL to a VLAN."""
        raise NotImplementedError

    def delete_port_acl(self, port, acl):
        """Delete an ACL from a port."""
        raise NotImplementedError

    def delete_vlan_acl(self, vlan, acl):
        """Delete an ACL from a VLAN."""
        raise NotImplementedError
Implement configuration API. # Copyright (C) 2015 <NAME>, <NAME> and <NAME>. # Copyright (C) 2015 Research and Education Advanced Network New Zealand Ltd. # Copyright (C) 2015--2017 The Contributors # # 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. An API for communicating with Faucet.      Contains methods for interacting with a running faucet controller from     within a RyuApp. This app should be run together with faucet in the same     ryu-manager process.      It can be accessed by use of the _CONTEXTS dictionary within a RyuApp.     eg.      class ExampleApp(app_manager.RyuApp):          _CONTEXTS = {             'faucet_api': FaucetAPI             }          def __init__(self, *args, **kwargs):             self.is_api_registered = False             self.faucet_api = kwargs['faucet_api']          @set_ev_cls(EventFaucetAPIRegistered, MAIN_DISPATCHER)         def _api_registered(self):             self.is_api_registered = True          def print_faucet_config(self):             if self.is_api_registered:                 print(self.faucet_api.get_config()) Return True if registered and ready to serve API requests. Register with FAUCET RyuApp. Reload config from config file in FAUCET_CONFIG env variable. Get the current running config of Faucet as a python dictionary. Get current FAUCET tables as a dict of table name: table no. Push supplied config to FAUCET. Add an ACL to a port. Add an ACL to a VLAN. Delete an ACL from a port. Delete an ACL from a VLAN.