Skip to content

Commit

Permalink
Merge "Add quota support to octavia's l7policy and l7rule"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jul 27, 2020
2 parents ae6f344 + 5d91913 commit c78a1b2
Show file tree
Hide file tree
Showing 33 changed files with 1,481 additions and 47 deletions.
28 changes: 28 additions & 0 deletions api-ref/source/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,34 @@ quota-health_monitor-optional:
in: body
required: false
type: integer
quota-l7policy:
description: |
The configured l7policy quota limit. A setting of ``null`` means it is
using the deployment default quota. A setting of ``-1`` means unlimited.
in: body
required: true
type: integer
quota-l7policy-optional:
description: |
The configured l7policy quota limit. A setting of ``null`` means it is
using the deployment default quota. A setting of ``-1`` means unlimited.
in: body
required: false
type: integer
quota-l7rule:
description: |
The configured l7rule quota limit. A setting of ``null`` means it is
using the deployment default quota. A setting of ``-1`` means unlimited.
in: body
required: true
type: integer
quota-l7rule-optional:
description: |
The configured l7rule quota limit. A setting of ``null`` means it is
using the deployment default quota. A setting of ``-1`` means unlimited.
in: body
required: false
type: integer
quota-listener:
description: |
The configured listener quota limit. A setting of ``null`` means it is
Expand Down
2 changes: 1 addition & 1 deletion api-ref/source/v2/examples/quota-update-curl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
curl -X PUT -H "Content-Type: application/json" -H "X-Auth-Token: <token>" -d '{"quota":{"loadbalancer":10,"listener":-1,"member":50,"pool":-1,"healthmonitor":-1}}' http://198.51.100.10:9876/v2/lbaas/quotas/e3cd678b11784734bc366148aa37580e
curl -X PUT -H "Content-Type: application/json" -H "X-Auth-Token: <token>" -d '{"quota":{"loadbalancer":10,"listener":-1,"member":50,"pool":-1,"healthmonitor":-1,"l7policy":15,"l7rule":25}}' http://198.51.100.10:9876/v2/lbaas/quotas/e3cd678b11784734bc366148aa37580e
4 changes: 3 additions & 1 deletion api-ref/source/v2/examples/quota-update-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"listener": -1,
"member": 50,
"pool": -1,
"healthmonitor": -1
"healthmonitor": -1,
"l7policy": 15,
"l7rule": 25
}
}
4 changes: 3 additions & 1 deletion api-ref/source/v2/examples/quota-update-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"listener": -1,
"member": 50,
"pool": -1,
"healthmonitor": -1
"healthmonitor": -1,
"l7policy": 15,
"l7rule": 25
}
}
4 changes: 3 additions & 1 deletion api-ref/source/v2/examples/quotas-defaults-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"listener": -1,
"member": -1,
"pool": -1,
"healthmonitor": -1
"healthmonitor": -1,
"l7policy": -1,
"l7rule": -1
}
}
4 changes: 3 additions & 1 deletion api-ref/source/v2/examples/quotas-list-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"healthmonitor": -1,
"listener": null,
"project_id": "e3cd678b11784734bc366148aa37580e",
"pool": null
"pool": null,
"l7policy": 3,
"l7rule": null
}
]
}
4 changes: 3 additions & 1 deletion api-ref/source/v2/examples/quotas-show-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"listener": -1,
"member": 50,
"pool": -1,
"healthmonitor": -1
"healthmonitor": -1,
"l7policy": 20,
"l7rule": -1
}
}
10 changes: 10 additions & 0 deletions api-ref/source/v2/quota.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Response Parameters
.. rest_parameters:: ../parameters.yaml

- healthmonitor: quota-health_monitor
- l7policy: quota-l7policy
- l7rule: quota-l7rule
- listener: quota-listener
- loadbalancer: quota-load_balancer
- member: quota-member
Expand Down Expand Up @@ -99,6 +101,8 @@ Response Parameters
.. rest_parameters:: ../parameters.yaml

- healthmonitor: quota-health_monitor
- l7policy: quota-l7policy
- l7rule: quota-l7rule
- listener: quota-listener
- loadbalancer: quota-load_balancer
- member: quota-member
Expand Down Expand Up @@ -156,6 +160,8 @@ Response Parameters
.. rest_parameters:: ../parameters.yaml

- healthmonitor: quota-health_monitor
- l7policy: quota-l7policy
- l7rule: quota-l7rule
- listener: quota-listener
- loadbalancer: quota-load_balancer
- member: quota-member
Expand Down Expand Up @@ -206,6 +212,8 @@ Request
.. rest_parameters:: ../parameters.yaml

- healthmonitor: quota-health_monitor-optional
- l7policy: quota-l7policy-optional
- l7rule: quota-l7rule-optional
- listener: quota-listener-optional
- loadbalancer: quota-load_balancer-optional
- member: quota-member-optional
Expand All @@ -230,6 +238,8 @@ Response Parameters
.. rest_parameters:: ../parameters.yaml

- healthmonitor: quota-health_monitor
- l7policy: quota-l7policy
- l7rule: quota-l7rule
- listener: quota-listener
- loadbalancer: quota-load_balancer
- member: quota-member
Expand Down
2 changes: 2 additions & 0 deletions etc/octavia.conf
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@
# default_member_quota = -1
# default_pool_quota = -1
# default_health_monitor_quota = -1
# default_l7policy_quota = -1
# default_l7rule_quota = -1

[audit]
# Enable auditing of API requests.
Expand Down
5 changes: 4 additions & 1 deletion octavia/api/root_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def index(self):
self._add_a_version(versions, 'v2.17', 'v2', 'SUPPORTED',
'2020-04-29T00:00:00Z', host_url)
# Pool TLS versions
self._add_a_version(versions, 'v2.18', 'v2', 'CURRENT',
self._add_a_version(versions, 'v2.18', 'v2', 'SUPPORTED',
'2020-04-29T01:00:00Z', host_url)
# Add quota support to octavia's l7policy and l7rule
self._add_a_version(versions, 'v2.19', 'v2', 'CURRENT',
'2020-05-12T00:00:00Z', host_url)
return {'versions': versions}
8 changes: 7 additions & 1 deletion octavia/api/v2/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def _get_default_quotas(self, project_id):
listener=CONF.quotas.default_listener_quota,
pool=CONF.quotas.default_pool_quota,
health_monitor=CONF.quotas.default_health_monitor_quota,
member=CONF.quotas.default_member_quota)
member=CONF.quotas.default_member_quota,
l7policy=CONF.quotas.default_l7policy_quota,
l7rule=CONF.quotas.default_l7rule_quota)
return quotas

def _get_db_quotas(self, session, project_id):
Expand Down Expand Up @@ -213,6 +215,10 @@ def _get_db_quotas(self, session, project_id):
default_health_monitor_quota)
if db_quotas.member is None:
db_quotas.member = CONF.quotas.default_member_quota
if db_quotas.l7policy is None:
db_quotas.l7policy = CONF.quotas.default_l7policy_quota
if db_quotas.l7rule is None:
db_quotas.l7rule = CONF.quotas.default_l7rule_quota
return db_quotas

def _auth_get_all(self, context, project_id):
Expand Down
8 changes: 8 additions & 0 deletions octavia/api/v2/controllers/l7rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def post(self, rule_):

lock_session = db_api.get_session(autocommit=False)
try:
if self.repositories.check_quota_met(
context.session,
lock_session,
data_models.L7Rule,
l7rule.project_id):
raise exceptions.QuotaException(
resource=data_models.L7Rule._name())

l7rule_dict = db_prepare.create_l7rule(
l7rule.to_dict(render_unsets=True), self.l7policy_id)

Expand Down
6 changes: 6 additions & 0 deletions octavia/api/v2/types/quotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class QuotaBase(base.BaseType):
# Misspelled version, deprecated in Rocky
health_monitor = wtypes.wsattr(wtypes.IntegerType(
minimum=consts.MIN_QUOTA, maximum=consts.MAX_QUOTA))
l7policy = wtypes.wsattr(wtypes.IntegerType(
minimum=consts.MIN_QUOTA, maximum=consts.MAX_QUOTA))
l7rule = wtypes.wsattr(wtypes.IntegerType(
minimum=consts.MIN_QUOTA, maximum=consts.MAX_QUOTA))

def to_dict(self, render_unsets=False):
quota_dict = super(QuotaBase, self).to_dict(render_unsets)
Expand Down Expand Up @@ -70,6 +74,8 @@ class QuotaAllBase(base.BaseType):
healthmonitor = wtypes.wsattr(wtypes.IntegerType())
# Misspelled version, deprecated in Rocky, remove in T
health_monitor = wtypes.wsattr(wtypes.IntegerType())
l7policy = wtypes.wsattr(wtypes.IntegerType())
l7rule = wtypes.wsattr(wtypes.IntegerType())

_type_to_model_map = {'loadbalancer': 'load_balancer',
'healthmonitor': 'health_monitor'}
Expand Down
6 changes: 6 additions & 0 deletions octavia/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,12 @@
cfg.IntOpt('default_health_monitor_quota',
default=constants.QUOTA_UNLIMITED,
help=_('Default per project health monitor quota.')),
cfg.IntOpt('default_l7policy_quota',
default=constants.QUOTA_UNLIMITED,
help=_('Default per project l7policy quota.')),
cfg.IntOpt('default_l7rule_quota',
default=constants.QUOTA_UNLIMITED,
help=_('Default per project l7rule quota.')),
]

audit_opts = [
Expand Down
10 changes: 9 additions & 1 deletion octavia/common/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,22 +756,30 @@ def __init__(self,
pool=None,
health_monitor=None,
member=None,
l7policy=None,
l7rule=None,
in_use_health_monitor=None,
in_use_listener=None,
in_use_load_balancer=None,
in_use_member=None,
in_use_pool=None):
in_use_pool=None,
in_use_l7policy=None,
in_use_l7rule=None):
self.project_id = project_id
self.health_monitor = health_monitor
self.listener = listener
self.load_balancer = load_balancer
self.pool = pool
self.member = member
self.l7policy = l7policy
self.l7rule = l7rule
self.in_use_health_monitor = in_use_health_monitor
self.in_use_listener = in_use_listener
self.in_use_load_balancer = in_use_load_balancer
self.in_use_member = in_use_member
self.in_use_pool = in_use_pool
self.in_use_l7policy = in_use_l7policy
self.in_use_l7rule = in_use_l7rule


class Flavor(BaseDataModel):
Expand Down
2 changes: 2 additions & 0 deletions octavia/controller/worker/v1/flows/l7policy_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def get_delete_l7policy_flow(self):
requires=constants.LOADBALANCER))
delete_l7policy_flow.add(database_tasks.DeleteL7PolicyInDB(
requires=constants.L7POLICY))
delete_l7policy_flow.add(database_tasks.DecrementL7policyQuota(
requires=constants.L7POLICY))
delete_l7policy_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
requires=[constants.LOADBALANCER, constants.LISTENERS]))

Expand Down
2 changes: 2 additions & 0 deletions octavia/controller/worker/v1/flows/l7rule_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def get_delete_l7rule_flow(self):
requires=constants.LOADBALANCER))
delete_l7rule_flow.add(database_tasks.DeleteL7RuleInDB(
requires=constants.L7RULE))
delete_l7rule_flow.add(database_tasks.DecrementL7ruleQuota(
requires=constants.L7RULE))
delete_l7rule_flow.add(database_tasks.MarkL7PolicyActiveInDB(
requires=constants.L7POLICY))
delete_l7rule_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
Expand Down

0 comments on commit c78a1b2

Please sign in to comment.