Group Policy Mapping API-1: EP, EPG, L2 Policy, L3 Policy
(Patch series identifier: GPM-API-1) This patch extends the initial set of Group Policy API resources with attributes mapping those resources to traditional Neutron resources. Subsequent patches will add the DB, plugin, and driver support for these mapping attributes. Author: Bob Kukura <kukura@noironetworks.com> Co-Authored-By: Sumit Naiksatam <sumitnaiksatam@gmail.com> Co-Authored-By: Stephen Wong <s3wong@midokura.com> Co-Authored-By: Mohammad Banikazemi <mb@us.ibm.com> Co-Authored-By: Mandeep Dhami <dhami@noironetworks.com> Change-Id: I617efd632f6ca423b58f2e9ba504cf6c4bc2ac53
This commit is contained in:
parent
1f1e1b26d9
commit
ed23bdc855
|
@ -0,0 +1,71 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.api.v2 import attributes as attr
|
||||
|
||||
from gbp.neutron.extensions import group_policy as gp
|
||||
|
||||
|
||||
# Extended attributes for Group Policy resource to map to Neutron constructs
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
gp.ENDPOINTS: {
|
||||
'port_id': {'allow_post': True, 'allow_put': False,
|
||||
'validate': {'type:uuid_or_none': None},
|
||||
'is_visible': True, 'default': None},
|
||||
},
|
||||
gp.ENDPOINT_GROUPS: {
|
||||
'subnets': {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:uuid_list': None},
|
||||
'convert_to': attr.convert_none_to_empty_list,
|
||||
'is_visible': True, 'default': None},
|
||||
},
|
||||
gp.L2_POLICIES: {
|
||||
'network_id': {'allow_post': True, 'allow_put': False,
|
||||
'validate': {'type:uuid_or_none': None},
|
||||
'is_visible': True, 'default': None},
|
||||
},
|
||||
gp.L3_POLICIES: {
|
||||
'routers': {'allow_post': True, 'allow_put': True,
|
||||
'validate': {'type:uuid_list': None},
|
||||
'convert_to': attr.convert_none_to_empty_list,
|
||||
'is_visible': True, 'default': None},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Group_policy_mapping(object):
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return "Group Policy Abstraction Mapping to Neutron Resources"
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
return "group-policy-mapping"
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return "Extension for Group Policy Abstraction Mapping"
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return "http://wiki.openstack.org/neutron/gp/v2.0/"
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2014-03-03T12:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
|
@ -0,0 +1,107 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.plugins.common import constants
|
||||
|
||||
from gbp.neutron.extensions import group_policy as gp
|
||||
from gbp.neutron.extensions import group_policy_mapping as gpm
|
||||
from gbp.neutron.tests.unit import test_extension_group_policy as tgp
|
||||
|
||||
|
||||
class GroupPolicyMappingExtTestCase(tgp.GroupPolicyExtensionTestCase):
|
||||
def setUp(self):
|
||||
self._saved_gp_attr_map = {}
|
||||
for k, v in gp.RESOURCE_ATTRIBUTE_MAP.iteritems():
|
||||
self._saved_gp_attr_map[k] = v.copy()
|
||||
self.addCleanup(self._restore_gp_attr_map)
|
||||
|
||||
super(tgp.GroupPolicyExtensionTestCase, self).setUp()
|
||||
|
||||
attr_map = gp.RESOURCE_ATTRIBUTE_MAP
|
||||
attr_map[gp.ENDPOINTS].update(
|
||||
gpm.EXTENDED_ATTRIBUTES_2_0[gp.ENDPOINTS])
|
||||
attr_map[gp.ENDPOINT_GROUPS].update(
|
||||
gpm.EXTENDED_ATTRIBUTES_2_0[gp.ENDPOINT_GROUPS])
|
||||
attr_map[gp.L2_POLICIES].update(
|
||||
gpm.EXTENDED_ATTRIBUTES_2_0[gp.L2_POLICIES])
|
||||
attr_map[gp.L3_POLICIES].update(
|
||||
gpm.EXTENDED_ATTRIBUTES_2_0[gp.L3_POLICIES])
|
||||
plural_mappings = {'l2_policy': 'l2_policies',
|
||||
'l3_policy': 'l3_policies'}
|
||||
self._setUpExtension(
|
||||
tgp.GP_PLUGIN_BASE_NAME, constants.GROUP_POLICY, attr_map,
|
||||
gp.Group_policy, tgp.GROUPPOLICY_URI,
|
||||
plural_mappings=plural_mappings)
|
||||
self.instance = self.plugin.return_value
|
||||
|
||||
def _restore_gp_attr_map(self):
|
||||
gp.RESOURCE_ATTRIBUTE_MAP = self._saved_gp_attr_map
|
||||
|
||||
def _get_create_endpoint_default_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_endpoint_default_attrs())
|
||||
attrs.update({'port_id': None})
|
||||
return attrs
|
||||
|
||||
def _get_create_endpoint_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_endpoint_attrs())
|
||||
attrs.update({'port_id': tgp._uuid()})
|
||||
return attrs
|
||||
|
||||
def _get_create_endpoint_group_default_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_endpoint_group_default_attrs())
|
||||
attrs.update({'subnets': []})
|
||||
return attrs
|
||||
|
||||
def _get_create_endpoint_group_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_endpoint_group_attrs())
|
||||
attrs.update({'subnets': [tgp._uuid()]})
|
||||
return attrs
|
||||
|
||||
def _get_update_endpoint_group_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_update_endpoint_group_attrs())
|
||||
attrs.update({'subnets': [tgp._uuid()]})
|
||||
return attrs
|
||||
|
||||
def _get_create_l2_policy_default_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_l2_policy_default_attrs())
|
||||
attrs.update({'network_id': None})
|
||||
return attrs
|
||||
|
||||
def _get_create_l2_policy_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_l2_policy_attrs())
|
||||
attrs.update({'network_id': tgp._uuid()})
|
||||
return attrs
|
||||
|
||||
def _get_create_l3_policy_default_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_l3_policy_default_attrs())
|
||||
attrs.update({'routers': []})
|
||||
return attrs
|
||||
|
||||
def _get_create_l3_policy_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_create_l3_policy_attrs())
|
||||
attrs.update({'routers': [tgp._uuid(), tgp._uuid()]})
|
||||
return attrs
|
||||
|
||||
def _get_update_l3_policy_attrs(self):
|
||||
attrs = (super(GroupPolicyMappingExtTestCase, self).
|
||||
_get_update_l3_policy_attrs())
|
||||
attrs.update({'routers': [tgp._uuid(), tgp._uuid()]})
|
||||
return attrs
|
Loading…
Reference in New Issue