Extended security groups API to include FAWS fields
Added new fields: "external_service" and "external_service_id" Change-Id: I0ec8427893f7838847883761de9c2349fa4a00ba JIRA: NCP-2078 Closes-Bug: #1624354
This commit is contained in:
parent
764224c456
commit
6770597bc3
62
quark/api/extensions/security_group_rules.py
Normal file
62
quark/api/extensions/security_group_rules.py
Normal file
@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2016 Rackspace Hosting Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# 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 import extensions
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
"security_group_rules": {
|
||||
"external_service": {"allow_post": True,
|
||||
"allow_put": True,
|
||||
"default": None,
|
||||
"is_visible": True},
|
||||
"external_service_id": {"allow_post": True,
|
||||
"allow_put": True,
|
||||
"default": None,
|
||||
"is_visible": True}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Security_group_rules(extensions.ExtensionDescriptor):
|
||||
"""Extends Security Group Rules for FAWS purposes."""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return 'Quark security-group-rules extension'
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
# NOTE(alexm): This string must be listed in
|
||||
# supported_extension_aliases in quark/plugin.py
|
||||
return 'faws-security-group-rule-ext'
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return 'Quark Security Group Rules API Extension'
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return ("http://docs.openstack.org/api/openstack-network/2.0/content/"
|
||||
"SecurityGroupRules.html")
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2016-09-15T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
62
quark/api/extensions/security_groups.py
Normal file
62
quark/api/extensions/security_groups.py
Normal file
@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2016 Rackspace Hosting Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# 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 import extensions
|
||||
|
||||
EXTENDED_ATTRIBUTES_2_0 = {
|
||||
"security_groups": {
|
||||
"external_service": {"allow_post": True,
|
||||
"allow_put": True,
|
||||
"default": None,
|
||||
"is_visible": True},
|
||||
"external_service_id": {"allow_post": True,
|
||||
"allow_put": True,
|
||||
"default": None,
|
||||
"is_visible": True}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Security_groups(extensions.ExtensionDescriptor):
|
||||
"""Extends Security Groups for FAWS purposes."""
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return 'Quark security-group extension'
|
||||
|
||||
@classmethod
|
||||
def get_alias(cls):
|
||||
# NOTE(alexm): This string must be listed in
|
||||
# supported_extension_aliases in quark/plugin.py
|
||||
return 'faws-security-group-ext'
|
||||
|
||||
@classmethod
|
||||
def get_description(cls):
|
||||
return 'Quark Security Groups API Extension'
|
||||
|
||||
@classmethod
|
||||
def get_namespace(cls):
|
||||
return ("http://docs.openstack.org/api/openstack-network/2.0/content/"
|
||||
"SecurityGroups.html")
|
||||
|
||||
@classmethod
|
||||
def get_updated(cls):
|
||||
return "2016-09-15T10:00:00-00:00"
|
||||
|
||||
def get_extended_resources(self, version):
|
||||
if version == "2.0":
|
||||
return EXTENDED_ATTRIBUTES_2_0
|
||||
else:
|
||||
return {}
|
@ -133,7 +133,9 @@ class Plugin(neutron_plugin_base_v2.NeutronPluginBaseV2,
|
||||
"networks_quark", "router",
|
||||
"ip_availabilities", "ports_quark",
|
||||
"floatingip", "segment_allocation_ranges",
|
||||
"scalingip", "jobs"]
|
||||
"scalingip", "jobs",
|
||||
"faws-security-group-ext",
|
||||
"faws-security-group-rule-ext"]
|
||||
|
||||
def __init__(self):
|
||||
LOG.info("Starting quark plugin")
|
||||
|
@ -138,7 +138,9 @@ def _make_security_group_dict(security_group, fields=None):
|
||||
res = {"id": security_group.get("id"),
|
||||
"description": security_group.get("description"),
|
||||
"name": security_group.get("name"),
|
||||
"tenant_id": security_group.get("tenant_id")}
|
||||
"tenant_id": security_group.get("tenant_id"),
|
||||
"external_service": security_group.get("external_service"),
|
||||
"external_service_id": security_group.get("external_service_id")}
|
||||
res["security_group_rules"] = [
|
||||
_make_security_group_rule_dict(r) for r in security_group["rules"]]
|
||||
return res
|
||||
@ -159,7 +161,9 @@ def _make_security_group_rule_dict(security_rule, fields=None):
|
||||
"protocol": protocol,
|
||||
"remote_ip_prefix": security_rule.get("remote_ip_prefix"),
|
||||
"security_group_id": security_rule.get("group_id"),
|
||||
"remote_group_id": security_rule.get("remote_group_id")}
|
||||
"remote_group_id": security_rule.get("remote_group_id"),
|
||||
"external_service": security_rule.get("external_service"),
|
||||
"external_service_id": security_rule.get("external_service_id")}
|
||||
return res
|
||||
|
||||
|
||||
|
58
quark/tests/functional/test_faws.py
Normal file
58
quark/tests/functional/test_faws.py
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright (c) 2016 Rackspace Hosting Inc.
|
||||
#
|
||||
# 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 quark import plugin
|
||||
|
||||
from quark.api.extensions import security_group_rules
|
||||
from quark.api.extensions import security_groups
|
||||
|
||||
from quark.tests.functional.base import BaseFunctionalTest
|
||||
|
||||
|
||||
class QuarkFAWSTest(BaseFunctionalTest):
|
||||
def setUp(self):
|
||||
super(QuarkFAWSTest, self).setUp()
|
||||
self.plugin = plugin.Plugin()
|
||||
self.version = '2.0'
|
||||
|
||||
|
||||
class QuarkPluginSecurityGroupsTest(QuarkFAWSTest):
|
||||
|
||||
def test_supported_extension_aliases(self):
|
||||
self.assertTrue('faws-security-group-ext' in
|
||||
self.plugin.supported_extension_aliases)
|
||||
self.assertTrue('faws-security-group-rule-ext' in
|
||||
self.plugin.supported_extension_aliases)
|
||||
|
||||
def test_security_group_extension(self):
|
||||
self.assertTrue('faws-security-group-ext' ==
|
||||
security_groups.Security_groups.get_alias())
|
||||
sg = security_groups.Security_groups()
|
||||
self.assertTrue('security_groups' in
|
||||
sg.get_extended_resources(self.version))
|
||||
attrs = sg.get_extended_resources(self.version)['security_groups']
|
||||
self.assertTrue('external_service' in attrs)
|
||||
self.assertTrue('external_service_id' in attrs)
|
||||
|
||||
def test_security_group_rule_extension(self):
|
||||
self.assertTrue('faws-security-group-rule-ext' ==
|
||||
security_group_rules.Security_group_rules.get_alias())
|
||||
sgr = security_group_rules.Security_group_rules()
|
||||
self.assertTrue('security_group_rules' in
|
||||
sgr.get_extended_resources(self.version))
|
||||
attrs = \
|
||||
sgr.get_extended_resources(self.version)['security_group_rules']
|
||||
self.assertTrue('external_service' in attrs)
|
||||
self.assertTrue('external_service_id' in attrs)
|
Loading…
Reference in New Issue
Block a user