| 1 |
# Copyright (c) 2012 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_lib.api import converters |
| 17 |
from neutron_lib.api.definitions import l3 |
| 18 |
from neutron_lib import constants |
| 19 |
from neutron_lib.db import constants as db_const |
| 20 |
|
| 21 |
|
| 22 |
PROTOCOLS = constants.IPTABLES_PROTOCOL_MAP.keys() |
| 23 |
# The alias of the extension. |
| 24 |
ALIAS = 'floating-ip-port-forwarding' |
| 25 |
|
| 26 |
# Whether or not this extension is simply signaling behavior to the user |
| 27 |
# or it actively modifies the attribute map. |
| 28 |
IS_SHIM_EXTENSION = False |
| 29 |
|
| 30 |
# Whether the extension is marking the adoption of standardattr model for |
| 31 |
# legacy resources, or introducing new standardattr attributes. False or |
| 32 |
# None if the standardattr model is adopted since the introduction of |
| 33 |
# resource extension. |
| 34 |
# If this is True, the alias for the extension should be prefixed with |
| 35 |
# 'standard-attr-'. |
| 36 |
IS_STANDARD_ATTR_EXTENSION = False |
| 37 |
|
| 38 |
# The name of the extension. |
| 39 |
NAME = 'Floating IP Port Forwarding' |
| 40 |
|
| 41 |
# A prefix for API resources. An empty prefix means that the API is going |
| 42 |
# to be exposed at the v2/ level as any other core resource. |
| 43 |
API_PREFIX = '/' + l3.FLOATINGIPS |
| 44 |
|
| 45 |
# The description of the extension. |
| 46 |
DESCRIPTION = "Allow port forwarding from floating IP port to an internal port" |
| 47 |
|
| 48 |
# A timestamp of when the extension was introduced. |
| 49 |
UPDATED_TIMESTAMP = "2018-01-19T10:00:00-00:00" |
| 50 |
|
| 51 |
# The name of the resource. |
| 52 |
RESOURCE_NAME = 'port_forwarding' |
| 53 |
|
| 54 |
# The plural for the resource. |
| 55 |
COLLECTION_NAME = 'port_forwardings' |
| 56 |
|
| 57 |
# parent |
| 58 |
PARENT_RESOURCE_NAME = l3.FLOATINGIP |
| 59 |
PARENT_COLLECTION_NAME = l3.FLOATINGIPS |
| 60 |
|
| 61 |
ID = 'id' |
| 62 |
PROJECT_ID = 'project_id' |
| 63 |
EXTERNAL_PORT = 'external_port' |
| 64 |
INTERNAL_PORT = 'internal_port' |
| 65 |
INTERNAL_IP_ADDRESS = 'internal_ip_address' |
| 66 |
PROTOCOL = 'protocol' |
| 67 |
INTERNAL_PORT_ID = 'internal_port_id' |
| 68 |
RESOURCE_ATTRIBUTE_MAP = {} |
| 69 |
|
| 70 |
# The subresource attribute map for the extension. It adds child resources |
| 71 |
# to main extension's resource. The subresource map must have a parent and |
| 72 |
# a parameters entry. If an extension does not need such a map, None can |
| 73 |
# be specified (mandatory). |
| 74 |
SUB_RESOURCE_ATTRIBUTE_MAP = { |
| 75 |
COLLECTION_NAME: { |
| 76 |
'parent': {'collection_name': PARENT_COLLECTION_NAME, |
| 77 |
'member_name': PARENT_RESOURCE_NAME}, |
| 78 |
'parameters': { |
| 79 |
ID: {'allow_post': False, |
| 80 |
'allow_put': False, |
| 81 |
'validate': {'type:uuid': None}, |
| 82 |
'is_visible': True, |
| 83 |
'primary_key': True, |
| 84 |
'is_sort_key': True, |
| 85 |
'is_filter': True}, |
| 86 |
PROJECT_ID: {'allow_post': True, |
| 87 |
'allow_put': False, |
| 88 |
'validate': { |
| 89 |
'type:string': db_const.PROJECT_ID_FIELD_SIZE}, |
| 90 |
'required_by_policy': True, |
| 91 |
'is_visible': False}, |
| 92 |
EXTERNAL_PORT: { |
| 93 |
'allow_post': True, 'allow_put': True, |
| 94 |
'convert_to': converters.convert_to_int, |
| 95 |
'validate': {'type:range': [1, 65535]}, |
| 96 |
'is_visible': True, |
| 97 |
'is_sort_key': True, |
| 98 |
'is_filter': True}, |
| 99 |
INTERNAL_PORT: { |
| 100 |
'allow_post': True, 'allow_put': True, |
| 101 |
'convert_to': converters.convert_to_int, |
| 102 |
'validate': {'type:range': [1, 65535]}, |
| 103 |
'is_visible': True}, |
| 104 |
INTERNAL_IP_ADDRESS: {'allow_post': True, |
| 105 |
'allow_put': True, |
| 106 |
'validate': { |
| 107 |
'type:ip_address': None}, |
| 108 |
'is_visible': True}, |
| 109 |
PROTOCOL: {'allow_post': True, 'allow_put': True, |
| 110 |
'validate': {'type:values': PROTOCOLS}, |
| 111 |
'is_visible': True, |
| 112 |
'convert_to': converters.convert_to_protocol, |
| 113 |
'is_sort_key': True, |
| 114 |
'is_filter': True}, |
| 115 |
INTERNAL_PORT_ID: {'allow_post': True, |
| 116 |
'allow_put': True, |
| 117 |
'validate': {'type:uuid': None}, |
| 118 |
'is_visible': True, |
| 119 |
'is_sort_key': True, |
| 120 |
'is_filter': True}, |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
# The action map: it associates verbs with methods to be performed on |
| 126 |
# the API resource. |
| 127 |
ACTION_MAP = { |
| 128 |
} |
| 129 |
|
| 130 |
# The action status. |
| 131 |
ACTION_STATUS = { |
| 132 |
} |
| 133 |
|
| 134 |
# The list of required extensions. |
| 135 |
REQUIRED_EXTENSIONS = [l3.ALIAS] |
| 136 |
|
| 137 |
# The list of optional extensions. |
| 138 |
OPTIONAL_EXTENSIONS = [ |
| 139 |
] |