Hide unnecessary fields based on Loadbalancer Monitor type
Change-Id: I83a56c8067af8f6ec87d89192156658232ad87cf Fixes: bug 1152138
This commit is contained in:
parent
a53d6491a9
commit
b4923b5dee
@ -217,15 +217,17 @@ def pool_health_monitor_create(request, **kwargs):
|
|||||||
:param expected_codes: http return code
|
:param expected_codes: http return code
|
||||||
:param admin_state_up: admin state
|
:param admin_state_up: admin state
|
||||||
"""
|
"""
|
||||||
body = {'health_monitor': {'type': kwargs['type'],
|
monitor_type = kwargs['type'].upper()
|
||||||
|
body = {'health_monitor': {'type': monitor_type,
|
||||||
'delay': kwargs['delay'],
|
'delay': kwargs['delay'],
|
||||||
'timeout': kwargs['timeout'],
|
'timeout': kwargs['timeout'],
|
||||||
'max_retries': kwargs['max_retries'],
|
'max_retries': kwargs['max_retries'],
|
||||||
'http_method': kwargs['http_method'],
|
|
||||||
'url_path': kwargs['url_path'],
|
|
||||||
'expected_codes': kwargs['expected_codes'],
|
|
||||||
'admin_state_up': kwargs['admin_state_up']
|
'admin_state_up': kwargs['admin_state_up']
|
||||||
}}
|
}}
|
||||||
|
if monitor_type in ['HTTP', 'HTTPS']:
|
||||||
|
body['health_monitor']['http_method'] = kwargs['http_method']
|
||||||
|
body['health_monitor']['url_path'] = kwargs['url_path']
|
||||||
|
body['health_monitor']['expected_codes'] = kwargs['expected_codes']
|
||||||
mon = quantumclient(request).create_health_monitor(body).get(
|
mon = quantumclient(request).create_health_monitor(body).get(
|
||||||
'health_monitor')
|
'health_monitor')
|
||||||
body = {'health_monitor': {'id': mon['id']}}
|
body = {'health_monitor': {'id': mon['id']}}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
<dt>{% trans "Max Retries: " %}</dt>
|
<dt>{% trans "Max Retries: " %}</dt>
|
||||||
<dd>{{ monitor.max_retries }}</dd>
|
<dd>{{ monitor.max_retries }}</dd>
|
||||||
|
|
||||||
|
{% if monitor.type == 'HTTP' or monitor.type == 'HTTPS' %}
|
||||||
<dt>{% trans "HTTP Method: " %}</dt>
|
<dt>{% trans "HTTP Method: " %}</dt>
|
||||||
<dd>{{ monitor.http_method }}</dd>
|
<dd>{{ monitor.http_method }}</dd>
|
||||||
|
|
||||||
@ -29,6 +30,7 @@
|
|||||||
|
|
||||||
<dt>{% trans "Expected Codes: " %}</dt>
|
<dt>{% trans "Expected Codes: " %}</dt>
|
||||||
<dd>{{ monitor.expected_codes }}</dd>
|
<dd>{{ monitor.expected_codes }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<dt>{% trans "Admin State Up: " %}</dt>
|
<dt>{% trans "Admin State Up: " %}</dt>
|
||||||
<dd>{{ monitor.admin_state_up }}</dd>
|
<dd>{{ monitor.admin_state_up }}</dd>
|
||||||
|
@ -63,7 +63,7 @@ class AddPoolAction(workflows.Action):
|
|||||||
protocol_choices.append(('HTTPS', 'HTTPS'))
|
protocol_choices.append(('HTTPS', 'HTTPS'))
|
||||||
self.fields['protocol'].choices = protocol_choices
|
self.fields['protocol'].choices = protocol_choices
|
||||||
|
|
||||||
lb_method_choices = [('', _("Select a Protocol"))]
|
lb_method_choices = [('', _("Select a Method"))]
|
||||||
lb_method_choices.append(('ROUND_ROBIN', 'ROUND_ROBIN'))
|
lb_method_choices.append(('ROUND_ROBIN', 'ROUND_ROBIN'))
|
||||||
lb_method_choices.append(('LEAST_CONNECTIONS', 'LEAST_CONNECTIONS'))
|
lb_method_choices.append(('LEAST_CONNECTIONS', 'LEAST_CONNECTIONS'))
|
||||||
lb_method_choices.append(('SOURCE_IP', 'SOURCE_IP'))
|
lb_method_choices.append(('SOURCE_IP', 'SOURCE_IP'))
|
||||||
@ -357,18 +357,69 @@ class AddMember(workflows.Workflow):
|
|||||||
|
|
||||||
class AddMonitorAction(workflows.Action):
|
class AddMonitorAction(workflows.Action):
|
||||||
pool_id = forms.ChoiceField(label=_("Pool"))
|
pool_id = forms.ChoiceField(label=_("Pool"))
|
||||||
type = forms.ChoiceField(label=_("Type"))
|
type = forms.ChoiceField(
|
||||||
delay = forms.CharField(max_length=80, label=_("Delay"))
|
label=_("Type"),
|
||||||
timeout = forms.CharField(max_length=80, label=_("Timeout"))
|
choices=[('ping', _('PING')),
|
||||||
max_retries = forms.CharField(max_length=80,
|
('tcp', _('TCP')),
|
||||||
label=_("Max Retries (1~10)"))
|
('http', _('HTTP')),
|
||||||
|
('https', _('HTTPS'))],
|
||||||
|
widget=forms.Select(attrs={
|
||||||
|
'class': 'switchable',
|
||||||
|
'data-slug': 'type'
|
||||||
|
}))
|
||||||
|
delay = forms.CharField(
|
||||||
|
max_length=80,
|
||||||
|
label=_("Delay"),
|
||||||
|
help_text=_("The minimum time in seconds between regular checks "
|
||||||
|
"of a member"))
|
||||||
|
timeout = forms.CharField(
|
||||||
|
max_length=80,
|
||||||
|
label=_("Timeout"),
|
||||||
|
help_text=_("The maximum time in seconds for a monitor to wait "
|
||||||
|
"for a reply"))
|
||||||
|
max_retries = forms.CharField(
|
||||||
|
max_length=80,
|
||||||
|
label=_("Max Retries (1~10)"),
|
||||||
|
help_text=_("Number of permissible failures before changing "
|
||||||
|
"the status of member to inactive"))
|
||||||
http_method = forms.ChoiceField(
|
http_method = forms.ChoiceField(
|
||||||
initial="GET", required=False, label=_("HTTP Method"))
|
initial="GET",
|
||||||
|
required=False,
|
||||||
|
choices=[('GET', _('GET'))],
|
||||||
|
label=_("HTTP Method"),
|
||||||
|
help_text=_("HTTP method used to check health status of a member"),
|
||||||
|
widget=forms.Select(attrs={
|
||||||
|
'class': 'switched',
|
||||||
|
'data-switch-on': 'type',
|
||||||
|
'data-type-http': _('HTTP Method'),
|
||||||
|
'data-type-https': _('HTTP Method')
|
||||||
|
}))
|
||||||
url_path = forms.CharField(
|
url_path = forms.CharField(
|
||||||
initial="/", required=False, max_length=80, label=_("URL"))
|
initial="/",
|
||||||
expected_codes = forms.CharField(
|
required=False,
|
||||||
initial="200", required=False, max_length=80,
|
max_length=80,
|
||||||
label=_("Expected HTTP Status Codes"))
|
label=_("URL"),
|
||||||
|
widget=forms.TextInput(attrs={
|
||||||
|
'class': 'switched',
|
||||||
|
'data-switch-on': 'type',
|
||||||
|
'data-type-http': _('URL'),
|
||||||
|
'data-type-https': _('URL')
|
||||||
|
}))
|
||||||
|
expected_codes = forms.RegexField(
|
||||||
|
initial="200",
|
||||||
|
required=False,
|
||||||
|
max_length=80,
|
||||||
|
regex=r'^(\d{3}(\s*,\s*\d{3})*)$|^(\d{3}-\d{3})$',
|
||||||
|
label=_("Expected HTTP Status Codes"),
|
||||||
|
help_text=_("Expected code may be a single value (e.g. 200), "
|
||||||
|
"a list of values (e.g. 200, 202), "
|
||||||
|
"or range of values (e.g. 200-204)"),
|
||||||
|
widget=forms.TextInput(attrs={
|
||||||
|
'class': 'switched',
|
||||||
|
'data-switch-on': 'type',
|
||||||
|
'data-type-http': _('Expected HTTP Status Codes'),
|
||||||
|
'data-type-https': _('Expected HTTP Status Codes')
|
||||||
|
}))
|
||||||
admin_state_up = forms.BooleanField(label=_("Admin State"),
|
admin_state_up = forms.BooleanField(label=_("Admin State"),
|
||||||
initial=True, required=False)
|
initial=True, required=False)
|
||||||
|
|
||||||
@ -385,16 +436,27 @@ class AddMonitorAction(workflows.Action):
|
|||||||
_('Unable to retrieve pools list.'))
|
_('Unable to retrieve pools list.'))
|
||||||
self.fields['pool_id'].choices = pool_id_choices
|
self.fields['pool_id'].choices = pool_id_choices
|
||||||
|
|
||||||
type_choices = [('', _("Select Type"))]
|
def clean(self):
|
||||||
type_choices.append(('PING', 'PING'))
|
cleaned_data = super(AddMonitorAction, self).clean()
|
||||||
type_choices.append(('TCP', 'TCP'))
|
type_opt = cleaned_data.get('type')
|
||||||
type_choices.append(('HTTP', 'HTTP'))
|
|
||||||
type_choices.append(('HTTPS', 'HTTPS'))
|
|
||||||
self.fields['type'].choices = type_choices
|
|
||||||
|
|
||||||
http_method_choices = [('', _("Select HTTP Method"))]
|
if type_opt in ['http', 'https']:
|
||||||
http_method_choices.append(('GET', 'GET'))
|
http_method_opt = cleaned_data.get('http_method')
|
||||||
self.fields['http_method'].choices = http_method_choices
|
url_path = cleaned_data.get('url_path')
|
||||||
|
expected_codes = cleaned_data.get('expected_codes')
|
||||||
|
|
||||||
|
if not http_method_opt:
|
||||||
|
msg = _('Please choose a HTTP method')
|
||||||
|
self._errors['http_method'] = self.error_class([msg])
|
||||||
|
if not url_path:
|
||||||
|
msg = _('Please specify an URL')
|
||||||
|
self._errors['url_path'] = self.error_class([msg])
|
||||||
|
if not expected_codes:
|
||||||
|
msg = _('Please enter a single value (e.g. 200), '
|
||||||
|
'a list of values (e.g. 200, 202), '
|
||||||
|
'or range of values (e.g. 200-204)')
|
||||||
|
self._errors['expected_codes'] = self.error_class([msg])
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
name = _("MonitorDetails")
|
name = _("MonitorDetails")
|
||||||
|
@ -206,9 +206,6 @@ class LbaasApiTests(test.APITestCase):
|
|||||||
'delay': '10',
|
'delay': '10',
|
||||||
'timeout': '10',
|
'timeout': '10',
|
||||||
'max_retries': '10',
|
'max_retries': '10',
|
||||||
'http_method': 'GET',
|
|
||||||
'url_path': '/monitor',
|
|
||||||
'expected_codes': '200',
|
|
||||||
'admin_state_up': True
|
'admin_state_up': True
|
||||||
}
|
}
|
||||||
form_data_with_pool_id = {
|
form_data_with_pool_id = {
|
||||||
@ -217,9 +214,6 @@ class LbaasApiTests(test.APITestCase):
|
|||||||
'delay': '10',
|
'delay': '10',
|
||||||
'timeout': '10',
|
'timeout': '10',
|
||||||
'max_retries': '10',
|
'max_retries': '10',
|
||||||
'http_method': 'GET',
|
|
||||||
'url_path': '/monitor',
|
|
||||||
'expected_codes': '200',
|
|
||||||
'admin_state_up': True}
|
'admin_state_up': True}
|
||||||
monitor = {'health_monitor': {
|
monitor = {'health_monitor': {
|
||||||
'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
|
'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
|
||||||
@ -227,9 +221,6 @@ class LbaasApiTests(test.APITestCase):
|
|||||||
'delay': '10',
|
'delay': '10',
|
||||||
'timeout': '10',
|
'timeout': '10',
|
||||||
'max_retries': '10',
|
'max_retries': '10',
|
||||||
'http_method': 'GET',
|
|
||||||
'url_path': '/monitor',
|
|
||||||
'expected_codes': '200',
|
|
||||||
'admin_state_up': True}}
|
'admin_state_up': True}}
|
||||||
monitor_id = {'health_monitor': {
|
monitor_id = {'health_monitor': {
|
||||||
'id': 'abcdef-c3eb-4fee-9763-12de3338041e'}}
|
'id': 'abcdef-c3eb-4fee-9763-12de3338041e'}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user