diff --git a/octaviaclient/osc/v2/constants.py b/octaviaclient/osc/v2/constants.py index 09cb551..2d9d580 100644 --- a/octaviaclient/osc/v2/constants.py +++ b/octaviaclient/osc/v2/constants.py @@ -147,6 +147,7 @@ L7POLICY_ROWS = ( 'updated_at', 'redirect_pool_id', 'redirect_url', + 'redirect_prefix', 'action', 'position', 'id', diff --git a/octaviaclient/osc/v2/l7policy.py b/octaviaclient/osc/v2/l7policy.py index ab9ba35..702f279 100644 --- a/octaviaclient/osc/v2/l7policy.py +++ b/octaviaclient/osc/v2/l7policy.py @@ -22,7 +22,8 @@ from octaviaclient.osc.v2 import constants as const from octaviaclient.osc.v2 import utils as v2_utils from octaviaclient.osc.v2 import validate -ACTION_CHOICES = ['REDIRECT_TO_URL', 'REDIRECT_TO_POOL', 'REJECT'] +ACTION_CHOICES = ['REDIRECT_TO_URL', 'REDIRECT_TO_POOL', + 'REDIRECT_PREFIX', 'REJECT'] class CreateL7Policy(command.ShowOne): @@ -67,6 +68,11 @@ class CreateL7Policy(command.ShowOne): metavar='', help="Set the URL to redirect requests to." ) + redirect_group.add_argument( + '--redirect-prefix', + metavar='', + help="Set the URL Prefix to redirect requests to." + ) parser.add_argument( '--position', @@ -220,7 +226,11 @@ class SetL7Policy(command.Command): metavar='', help="Set the URL to redirect requests to." ) - + redirect_group.add_argument( + '--redirect-prefix', + metavar='', + help="Set the URL Prefix to redirect requests to." + ) parser.add_argument( '--position', metavar='', diff --git a/octaviaclient/osc/v2/utils.py b/octaviaclient/osc/v2/utils.py index 0cca41b..c9c4f40 100644 --- a/octaviaclient/osc/v2/utils.py +++ b/octaviaclient/osc/v2/utils.py @@ -297,6 +297,7 @@ def get_l7policy_attrs(client_manager, parsed_args): 'name': ('name', str), 'description': ('description', str), 'redirect_url': ('redirect_url', str), + 'redirect_prefix': ('redirect_prefix', str), 'l7policy': ( 'l7policy_id', 'l7policies', diff --git a/octaviaclient/osc/v2/validate.py b/octaviaclient/osc/v2/validate.py index 10ac08a..edc390e 100644 --- a/octaviaclient/osc/v2/validate.py +++ b/octaviaclient/osc/v2/validate.py @@ -24,6 +24,9 @@ def check_l7policy_attrs(attrs): elif attrs['action'] == 'REDIRECT_TO_URL': if 'redirect_url' not in attrs: msg = 'Missing argument: --redirect-url' + elif attrs['action'] == 'REDIRECT_PREFIX': + if 'redirect_prefix' not in attrs: + msg = 'Missing argument: --redirect-prefix' if msg is not None: raise exceptions.CommandError(msg) diff --git a/octaviaclient/tests/unit/osc/v2/test_validations.py b/octaviaclient/tests/unit/osc/v2/test_validations.py index 09e3e77..60d149d 100644 --- a/octaviaclient/tests/unit/osc/v2/test_validations.py +++ b/octaviaclient/tests/unit/osc/v2/test_validations.py @@ -48,6 +48,19 @@ class TestValidations(utils.TestCommand): exceptions.CommandError, validate.check_l7policy_attrs, attrs_dict) + attrs_dict = { + "action": "redirect_prefix".upper(), + "redirect_prefix": "prefix", + } + try: + validate.check_l7policy_attrs(attrs_dict) + except exceptions.CommandError as e: + self.fail("%s raised unexpectedly" % e) + attrs_dict.pop("redirect_prefix") + self.assertRaises( + exceptions.CommandError, + validate.check_l7policy_attrs, attrs_dict) + def test_check_l7rule_attrs(self): for i in ("cookie", "header"): attrs_dict = { diff --git a/releasenotes/notes/add-redirect-prefix-2f66455b3eacf5b6.yaml b/releasenotes/notes/add-redirect-prefix-2f66455b3eacf5b6.yaml new file mode 100644 index 0000000..9f295f9 --- /dev/null +++ b/releasenotes/notes/add-redirect-prefix-2f66455b3eacf5b6.yaml @@ -0,0 +1,4 @@ +--- +features: + - Add REDIRECT_PREFIX action for L7 Policy in l7policy create, + and set command