~ubuntu-branches/ubuntu/trusty/quantum/trusty

« back to all changes in this revision

Viewing changes to quantum/plugins/cisco/l2network_model_base.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:43:14 UTC
  • mfrom: (2.1.16)
  • Revision ID: package-import@ubuntu.com-20121123094314-e1tqsulrwe21b9aq
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/patches/*: Refreshed for opening of Grizzly.

[ Chuck Short ]
* New upstream release.
* debian/rules: FTFBS if there is missing binaries.
* debian/quantum-server.install: Add quantum-debug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
#
3
 
# Copyright 2011 Cisco Systems, Inc.  All rights reserved.
4
 
#
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
8
 
#
9
 
#         http://www.apache.org/licenses/LICENSE-2.0
10
 
#
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
15
 
#    under the License.
16
 
#
17
 
# @author: Sumit Naiksatam, Cisco Systems, Inc.
18
 
 
19
 
from abc import ABCMeta, abstractmethod
20
 
import inspect
21
 
 
22
 
 
23
 
class L2NetworkModelBase(object):
24
 
    """
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
29
 
    to that plugin.
30
 
    """
31
 
 
32
 
    __metaclass__ = ABCMeta
33
 
 
34
 
    @abstractmethod
35
 
    def get_all_networks(self, args):
36
 
        """
37
 
        :returns:
38
 
        :raises:
39
 
        """
40
 
        pass
41
 
 
42
 
    @abstractmethod
43
 
    def create_network(self, args):
44
 
        """
45
 
        :returns:
46
 
        :raises:
47
 
        """
48
 
        pass
49
 
 
50
 
    @abstractmethod
51
 
    def delete_network(self, args):
52
 
        """
53
 
        :returns:
54
 
        :raises:
55
 
        """
56
 
        pass
57
 
 
58
 
    @abstractmethod
59
 
    def get_network_details(self, args):
60
 
        """
61
 
        :returns:
62
 
        :raises:
63
 
        """
64
 
        pass
65
 
 
66
 
    @abstractmethod
67
 
    def update_network(self, args):
68
 
        """
69
 
        :returns:
70
 
        :raises:
71
 
        """
72
 
        pass
73
 
 
74
 
    @abstractmethod
75
 
    def get_all_ports(self, args):
76
 
        """
77
 
        :returns:
78
 
        :raises:
79
 
        """
80
 
        pass
81
 
 
82
 
    @abstractmethod
83
 
    def create_port(self, args):
84
 
        """
85
 
        :returns:
86
 
        :raises:
87
 
        """
88
 
        pass
89
 
 
90
 
    @abstractmethod
91
 
    def delete_port(self, args):
92
 
        """
93
 
        :returns:
94
 
        :raises:
95
 
        """
96
 
        pass
97
 
 
98
 
    @abstractmethod
99
 
    def update_port(self, args):
100
 
        """
101
 
        :returns:
102
 
        :raises:
103
 
        """
104
 
        pass
105
 
 
106
 
    @abstractmethod
107
 
    def get_port_details(self, args):
108
 
        """
109
 
        :returns:
110
 
        :raises:
111
 
        """
112
 
        pass
113
 
 
114
 
    @abstractmethod
115
 
    def plug_interface(self, args):
116
 
        """
117
 
        :returns:
118
 
        :raises:
119
 
        """
120
 
        pass
121
 
 
122
 
    @abstractmethod
123
 
    def unplug_interface(self, args):
124
 
        """
125
 
        :returns:
126
 
        :raises:
127
 
        """
128
 
        pass
129
 
 
130
 
    @classmethod
131
 
    def __subclasshook__(cls, klass):
132
 
        """
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.
139
 
        """
140
 
        if cls is L2NetworkModelBase:
141
 
            for method in cls.__abstractmethods__:
142
 
                method_ok = False
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
152
 
                if method_ok:
153
 
                    continue
154
 
                return NotImplemented
155
 
            return True
156
 
        return NotImplemented