610878e76c0eb0d86d524fab8c2beffb2897bec9
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / drivers / type_local.py
1 # Copyright (c) 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
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
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
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
14 #    under the License.
15
16 from oslo_log import log
17 import six
18
19 from neutron._i18n import _, _LI
20 from neutron.common import exceptions as exc
21 from neutron.plugins.common import constants as p_const
22 from neutron.plugins.ml2 import driver_api as api
23
24 LOG = log.getLogger(__name__)
25
26
27 class LocalTypeDriver(api.TypeDriver):
28     """Manage state for local networks with ML2.
29
30     The LocalTypeDriver implements the 'local' network_type. Local
31     network segments provide connectivity between VMs and other
32     devices running on the same node, provided that a common local
33     network bridging technology is available to those devices. Local
34     network segments do not provide any connectivity between nodes.
35     """
36
37     def __init__(self):
38         LOG.info(_LI("ML2 LocalTypeDriver initialization complete"))
39
40     def get_type(self):
41         return p_const.TYPE_LOCAL
42
43     def initialize(self):
44         pass
45
46     def is_partial_segment(self, segment):
47         return False
48
49     def validate_provider_segment(self, segment):
50         for key, value in six.iteritems(segment):
51             if value and key != api.NETWORK_TYPE:
52                 msg = _("%s prohibited for local provider network") % key
53                 raise exc.InvalidInput(error_message=msg)
54
55     def reserve_provider_segment(self, session, segment):
56         # No resources to reserve
57         return segment
58
59     def allocate_tenant_segment(self, session):
60         # No resources to allocate
61         return {api.NETWORK_TYPE: p_const.TYPE_LOCAL}
62
63     def release_segment(self, session, segment):
64         # No resources to release
65         pass
66
67     def get_mtu(self, physical_network=None):
68         pass