1 # Copyright (c) 2013 OpenStack Foundation
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 from oslo_log import log
18 from neutron._i18n import _
19 from neutron.plugins.ml2 import driver_api as api
21 LOG = log.getLogger(__name__)
24 class LoggerMechanismDriver(api.MechanismDriver):
25 """Mechanism driver that logs all calls and parameters made.
27 Generally used for testing and debugging.
33 def _log_network_call(self, method_name, context):
34 LOG.info(_("%(method)s called with network settings %(current)s "
35 "(original settings %(original)s) and "
36 "network segments %(segments)s"),
37 {'method': method_name,
38 'current': context.current,
39 'original': context.original,
40 'segments': context.network_segments})
42 def create_network_precommit(self, context):
43 self._log_network_call("create_network_precommit", context)
45 def create_network_postcommit(self, context):
46 self._log_network_call("create_network_postcommit", context)
48 def update_network_precommit(self, context):
49 self._log_network_call("update_network_precommit", context)
51 def update_network_postcommit(self, context):
52 self._log_network_call("update_network_postcommit", context)
54 def delete_network_precommit(self, context):
55 self._log_network_call("delete_network_precommit", context)
57 def delete_network_postcommit(self, context):
58 self._log_network_call("delete_network_postcommit", context)
60 def _log_subnet_call(self, method_name, context):
61 LOG.info(_("%(method)s called with subnet settings %(current)s "
62 "(original settings %(original)s)"),
63 {'method': method_name,
64 'current': context.current,
65 'original': context.original})
67 def create_subnet_precommit(self, context):
68 self._log_subnet_call("create_subnet_precommit", context)
70 def create_subnet_postcommit(self, context):
71 self._log_subnet_call("create_subnet_postcommit", context)
73 def update_subnet_precommit(self, context):
74 self._log_subnet_call("update_subnet_precommit", context)
76 def update_subnet_postcommit(self, context):
77 self._log_subnet_call("update_subnet_postcommit", context)
79 def delete_subnet_precommit(self, context):
80 self._log_subnet_call("delete_subnet_precommit", context)
82 def delete_subnet_postcommit(self, context):
83 self._log_subnet_call("delete_subnet_postcommit", context)
85 def _log_port_call(self, method_name, context):
86 network_context = context.network
87 LOG.info(_("%(method)s called with port settings %(current)s "
88 "(original settings %(original)s) "
90 "(original host %(original_host)s) "
91 "vif type %(vif_type)s "
92 "(original vif type %(original_vif_type)s) "
93 "vif details %(vif_details)s "
94 "(original vif details %(original_vif_details)s) "
95 "binding levels %(levels)s "
96 "(original binding levels %(original_levels)s) "
97 "on network %(network)s "
98 "with segments to bind %(segments_to_bind)s"),
99 {'method': method_name,
100 'current': context.current,
101 'original': context.original,
102 'host': context.host,
103 'original_host': context.original_host,
104 'vif_type': context.vif_type,
105 'original_vif_type': context.original_vif_type,
106 'vif_details': context.vif_details,
107 'original_vif_details': context.original_vif_details,
108 'levels': context.binding_levels,
109 'original_levels': context.original_binding_levels,
110 'network': network_context.current,
111 'segments_to_bind': context.segments_to_bind})
113 def create_port_precommit(self, context):
114 self._log_port_call("create_port_precommit", context)
116 def create_port_postcommit(self, context):
117 self._log_port_call("create_port_postcommit", context)
119 def update_port_precommit(self, context):
120 self._log_port_call("update_port_precommit", context)
122 def update_port_postcommit(self, context):
123 self._log_port_call("update_port_postcommit", context)
125 def delete_port_precommit(self, context):
126 self._log_port_call("delete_port_precommit", context)
128 def delete_port_postcommit(self, context):
129 self._log_port_call("delete_port_postcommit", context)
131 def bind_port(self, context):
132 self._log_port_call("bind_port", context)