ebaab5d2229909d6ed1e94c6f933ca000f66b166
[openstack-build/neutron-build.git] / neutron / extensions / external_net.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 neutron._i18n import _
17 from neutron.api import extensions
18 from neutron.api.v2 import attributes as attr
19 from neutron.common import exceptions as nexception
20
21
22 class ExternalNetworkInUse(nexception.InUse):
23     message = _("External network %(net_id)s cannot be updated to be made "
24                 "non-external, since it has existing gateway ports")
25
26
27 # For backward compatibility the 'router' prefix is kept.
28 EXTERNAL = 'router:external'
29 EXTENDED_ATTRIBUTES_2_0 = {
30     'networks': {EXTERNAL: {'allow_post': True,
31                             'allow_put': True,
32                             'default': False,
33                             'is_visible': True,
34                             'convert_to': attr.convert_to_boolean,
35                             'enforce_policy': True,
36                             'required_by_policy': True}}}
37
38
39 class External_net(extensions.ExtensionDescriptor):
40
41     @classmethod
42     def get_name(cls):
43         return "Neutron external network"
44
45     @classmethod
46     def get_alias(cls):
47         return "external-net"
48
49     @classmethod
50     def get_description(cls):
51         return _("Adds external network attribute to network resource.")
52
53     @classmethod
54     def get_updated(cls):
55         return "2013-01-14T10:00:00-00:00"
56
57     def get_extended_resources(self, version):
58         if version == "2.0":
59             return EXTENDED_ATTRIBUTES_2_0
60         else:
61             return {}