Check if the key meets the cinder API validation

In create qos spec form under the volume type panel,
if the key does not match the regex,
it would failed to create qos spec

This patch implements the regex validation for the spec in qos_specs as
implemented in cinder[1].
[1] https://github.com/openstack/cinder/blob/master/cinder/api/validation/parameter_types.py#L150

Change-Id: I295541ab3adb16b28ffe69cae1cfb48a3daf7d31
Closes-Bug: #1822734
This commit is contained in:
pengyuesheng 2019-04-02 15:30:57 +08:00
parent e4bc70b290
commit a6fae3b109
1 changed files with 11 additions and 1 deletions

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import re
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
@ -20,9 +22,17 @@ from horizon import messages
from openstack_dashboard import api
KEY_NAME_REGEX = re.compile(r"^[a-zA-Z0-9-_:. /]+$", re.UNICODE)
KEY_ERROR_MESSAGES = {
'invalid': _("The key must match the following the regex: "
"'^[a-zA-Z0-9-_:. /]'")}
class CreateKeyValuePair(forms.SelfHandlingForm):
# this if for creating a spec key-value pair for an existing QOS Spec
key = forms.CharField(max_length=255, label=_("Key"))
key = forms.RegexField(max_length=255, label=_("Key"),
regex=KEY_NAME_REGEX,
error_messages=KEY_ERROR_MESSAGES)
value = forms.CharField(max_length=255, label=_("Value"))
def handle(self, request, data):