Merge "Add bandwidth_limit rules as sub-collection of qos policy" into feature/qos
This commit is contained in:
commit
7a8e0711d1
|
@ -14,12 +14,15 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
import itertools
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from neutron.api import extensions
|
from neutron.api import extensions
|
||||||
from neutron.api.v2 import attributes as attr
|
from neutron.api.v2 import attributes as attr
|
||||||
|
from neutron.api.v2 import base
|
||||||
from neutron.api.v2 import resource_helper
|
from neutron.api.v2 import resource_helper
|
||||||
|
from neutron import manager
|
||||||
from neutron.plugins.common import constants
|
from neutron.plugins.common import constants
|
||||||
from neutron.services import service_base
|
from neutron.services import service_base
|
||||||
|
|
||||||
|
@ -31,17 +34,13 @@ QOS_RULE_COMMON_FIELDS = {
|
||||||
'validate': {'type:uuid': None},
|
'validate': {'type:uuid': None},
|
||||||
'is_visible': True,
|
'is_visible': True,
|
||||||
'primary_key': True},
|
'primary_key': True},
|
||||||
'qos_policy_id': {'allow_post': True, 'allow_put': False,
|
|
||||||
'is_visible': True, 'required_by_policy': True},
|
|
||||||
'type': {'allow_post': True, 'allow_put': True, 'is_visible': True,
|
'type': {'allow_post': True, 'allow_put': True, 'is_visible': True,
|
||||||
'default': '',
|
'default': '',
|
||||||
'validate': {'type:values': VALID_RULE_TYPES}},
|
'validate': {'type:values': VALID_RULE_TYPES}},
|
||||||
'tenant_id': {'allow_post': True, 'allow_put': False,
|
}
|
||||||
'required_by_policy': True,
|
|
||||||
'is_visible': True}}
|
|
||||||
|
|
||||||
RESOURCE_ATTRIBUTE_MAP = {
|
RESOURCE_ATTRIBUTE_MAP = {
|
||||||
'qos_policies': {
|
'policies': {
|
||||||
'id': {'allow_post': False, 'allow_put': False,
|
'id': {'allow_post': False, 'allow_put': False,
|
||||||
'validate': {'type:uuid': None},
|
'validate': {'type:uuid': None},
|
||||||
'is_visible': True, 'primary_key': True},
|
'is_visible': True, 'primary_key': True},
|
||||||
|
@ -56,18 +55,25 @@ RESOURCE_ATTRIBUTE_MAP = {
|
||||||
'convert_to': attr.convert_to_boolean},
|
'convert_to': attr.convert_to_boolean},
|
||||||
'tenant_id': {'allow_post': True, 'allow_put': False,
|
'tenant_id': {'allow_post': True, 'allow_put': False,
|
||||||
'required_by_policy': True,
|
'required_by_policy': True,
|
||||||
'is_visible': True}},
|
'is_visible': True}
|
||||||
#TODO(QoS): Here instead of using the resource helper we may
|
}
|
||||||
# need to set a subcontroller for qos-rules, so we
|
}
|
||||||
# can meet the spec definition.
|
|
||||||
'qos_bandwidthlimit_rules':
|
SUB_RESOURCE_ATTRIBUTE_MAP = {
|
||||||
dict(QOS_RULE_COMMON_FIELDS,
|
'bandwidth_limit_rules': {
|
||||||
**{'max_kbps': {'allow_post': True, 'allow_put': True,
|
'parent': {'collection_name': 'policies',
|
||||||
'is_visible': True, 'default': None,
|
'member_name': 'policy'},
|
||||||
'validate': {'type:non_negative', None}},
|
'parameters': dict(QOS_RULE_COMMON_FIELDS,
|
||||||
'max_burst_kbps': {'allow_post': True, 'allow_put': True,
|
**{'max_kbps': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:non_negative': None}},
|
||||||
|
'max_burst_kbps': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
'is_visible': True, 'default': 0,
|
'is_visible': True, 'default': 0,
|
||||||
'validate': {'type:non_negative', None}}})}
|
'validate': {'type:non_negative': None}}})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QOS_POLICY_ID = "qos_policy_id"
|
QOS_POLICY_ID = "qos_policy_id"
|
||||||
|
|
||||||
|
@ -116,16 +122,46 @@ class Qos(extensions.ExtensionDescriptor):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_resources(cls):
|
def get_resources(cls):
|
||||||
"""Returns Ext Resources."""
|
"""Returns Ext Resources."""
|
||||||
|
special_mappings = {'policies': 'policy'}
|
||||||
plural_mappings = resource_helper.build_plural_mappings(
|
plural_mappings = resource_helper.build_plural_mappings(
|
||||||
{'policies': 'policy'}, RESOURCE_ATTRIBUTE_MAP)
|
special_mappings, itertools.chain(RESOURCE_ATTRIBUTE_MAP,
|
||||||
|
SUB_RESOURCE_ATTRIBUTE_MAP))
|
||||||
attr.PLURALS.update(plural_mappings)
|
attr.PLURALS.update(plural_mappings)
|
||||||
#TODO(QoS): manually register some resources to make sure
|
|
||||||
# we match what's defined in the spec.
|
resources = resource_helper.build_resource_info(
|
||||||
return resource_helper.build_resource_info(plural_mappings,
|
plural_mappings,
|
||||||
RESOURCE_ATTRIBUTE_MAP,
|
RESOURCE_ATTRIBUTE_MAP,
|
||||||
constants.QOS,
|
constants.QOS,
|
||||||
translate_name=True,
|
translate_name=True,
|
||||||
allow_bulk=True)
|
allow_bulk=True)
|
||||||
|
|
||||||
|
plugin = manager.NeutronManager.get_service_plugins()[constants.QOS]
|
||||||
|
for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP:
|
||||||
|
resource_name = collection_name[:-1]
|
||||||
|
parent = SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get('parent')
|
||||||
|
params = SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||||
|
'parameters')
|
||||||
|
|
||||||
|
controller = base.create_resource(collection_name, resource_name,
|
||||||
|
plugin, params,
|
||||||
|
allow_bulk=True,
|
||||||
|
parent=parent,
|
||||||
|
allow_pagination=True,
|
||||||
|
allow_sorting=True)
|
||||||
|
|
||||||
|
resource = extensions.ResourceExtension(
|
||||||
|
collection_name,
|
||||||
|
controller, parent,
|
||||||
|
path_prefix=constants.COMMON_PREFIXES[
|
||||||
|
constants.QOS],
|
||||||
|
attr_map=params)
|
||||||
|
resources.append(resource)
|
||||||
|
|
||||||
|
return resources
|
||||||
|
|
||||||
|
def update_attributes_map(self, attributes, extension_attrs_map=None):
|
||||||
|
super(Qos, self).update_attributes_map(
|
||||||
|
attributes, extension_attrs_map=RESOURCE_ATTRIBUTE_MAP)
|
||||||
|
|
||||||
def get_extended_resources(self, version):
|
def get_extended_resources(self, version):
|
||||||
if version == "2.0":
|
if version == "2.0":
|
||||||
|
@ -146,45 +182,48 @@ class QoSPluginBase(service_base.ServicePluginBase):
|
||||||
return constants.QOS
|
return constants.QOS
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_qos_policy(self, context, qos_policy_id, fields=None):
|
def get_policy(self, context, policy_id, fields=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_qos_policies(self, context, filters=None, fields=None,
|
def get_policies(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
page_reverse=False):
|
page_reverse=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def create_qos_policy(self, context, qos_policy):
|
def create_policy(self, context, qos_policy):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def update_qos_policy(self, context, qos_policy_id, qos_policy):
|
def update_policy(self, context, policy_id, qos_policy):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def delete_qos_policy(self, context, qos_policy_id):
|
def delete_policy(self, context, policy_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_qos_bandwidth_limit_rule(self, context, rule_id, fields=None):
|
def get_policy_bandwidth_limit_rule(self, context, rule_id,
|
||||||
|
policy_id, fields=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_qos_bandwith_limit_rules(self, context, filters=None, fields=None,
|
def get_policy_bandwidth_limit_rules(self, context, policy_id,
|
||||||
sorts=None, limit=None, marker=None,
|
filters=None, fields=None,
|
||||||
page_reverse=False):
|
sorts=None, limit=None,
|
||||||
|
marker=None, page_reverse=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def create_qos_bandwidth_limit_rule(self, context, rule):
|
def create_policy_bandwidth_limit_rule(self, context, policy_id, rule):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def update_qos_bandwidth_limit_rule(self, context, rule_id, rule):
|
def update_policy_bandwidth_limit_rule(self, context, rule_id,
|
||||||
|
policy_id, rule):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def delete_qos_bandwith_limit_rule(self, context, rule_id):
|
def delete_policy_bandwidth_limit_rule(self, context, rule_id, policy_id):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -49,37 +49,39 @@ class QoSPlugin(qos.QoSPluginBase):
|
||||||
# extension of resources
|
# extension of resources
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_qos_policy(self, context, qos_policy):
|
def create_policy(self, context, qos_policy):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_qos_policy(self, context, qos_policy_id, qos_policy):
|
def update_policy(self, context, policy_id, qos_policy):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def delete_qos_policy(self, context, qos_policy_id):
|
def delete_policy(self, context, policy_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_qos_policy(self, context, qos_policy_id, fields=None):
|
def get_policy(self, context, policy_id, fields=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_qos_policies(self, context, filters=None, fields=None,
|
def get_policies(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
page_reverse=False):
|
page_reverse=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def create_qos_bandwidth_limit_rule(self, context,
|
def create_policy_bandwidth_limit_rule(self, context, policy_id, rule):
|
||||||
qos_bandwidthlimit_rule):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def update_qos_bandwidth_limit_rule(self, context, rule_id, rule):
|
def update_policy_bandwidth_limit_rule(self, context, rule_id,
|
||||||
|
policy_id, rule):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_qos_bandwidth_limit_rule(self, context, rule_id, fields=None):
|
def get_policy_bandwidth_limit_rule(self, context, rule_id,
|
||||||
|
policy_id, fields=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def delete_qos_bandwith_limit_rule(self, context, rule_id):
|
def delete_policy_bandwidth_limit_rule(self, context, rule_id, policy_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_qos_bandwith_limit_rules(self, context, filters=None, fields=None,
|
def get_policy_bandwidth_limit_rules(self, context, policy_id,
|
||||||
sorts=None, limit=None, marker=None,
|
filters=None, fields=None,
|
||||||
page_reverse=False):
|
sorts=None, limit=None,
|
||||||
|
marker=None, page_reverse=False):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue