1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Cisco Systems, Inc. All rights reserved.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
# @author: Sumit Naiksatam, Cisco Systems, Inc.
19
from abc import ABCMeta, abstractmethod
23
class L2NetworkModelBase(object):
25
Base class for L2 Network Model
26
It relies on a pluggable network configuration module to gather
27
knowledge of the system, but knows which device-specific plugins
28
to invoke for a corresponding core API call, and what parameters to pass
32
__metaclass__ = ABCMeta
35
def get_all_networks(self, args):
43
def create_network(self, args):
51
def delete_network(self, args):
59
def get_network_details(self, args):
67
def update_network(self, args):
75
def get_all_ports(self, args):
83
def create_port(self, args):
91
def delete_port(self, args):
99
def update_port(self, args):
107
def get_port_details(self, args):
115
def plug_interface(self, args):
123
def unplug_interface(self, args):
131
def __subclasshook__(cls, klass):
133
The __subclasshook__ method is a class method
134
that will be called everytime a class is tested
135
using issubclass(klass, Plugin).
136
In that case, it will check that every method
137
marked with the abstractmethod decorator is
138
provided by the plugin class.
140
if cls is L2NetworkModelBase:
141
for method in cls.__abstractmethods__:
143
for base in klass.__mro__:
144
if method in base.__dict__:
145
fn_obj = base.__dict__[method]
146
if inspect.isfunction(fn_obj):
147
abstract_fn_obj = cls.__dict__[method]
148
arg_count = fn_obj.func_code.co_argcount
149
expected_arg_count = \
150
abstract_fn_obj.func_code.co_argcount
151
method_ok = arg_count == expected_arg_count
154
return NotImplemented
156
return NotImplemented