Merge "Add edit buttons for vip, member and monitor"
This commit is contained in:
commit
ff46438f71
@ -147,7 +147,6 @@ def vip_get(request, vip_id):
|
||||
return Vip(vip)
|
||||
|
||||
|
||||
# not linked to UI yet
|
||||
def vip_update(request, vip_id, **kwargs):
|
||||
vip = quantumclient(request).update_vip(vip_id, kwargs).get('vip')
|
||||
return Vip(vip)
|
||||
@ -249,6 +248,11 @@ def pool_health_monitor_get(request, monitor_id):
|
||||
return PoolMonitor(monitor)
|
||||
|
||||
|
||||
def pool_health_monitor_update(request, monitor_id, **kwargs):
|
||||
monitor = quantumclient(request).update_health_monitor(monitor_id, kwargs)
|
||||
return PoolMonitor(monitor)
|
||||
|
||||
|
||||
def pool_health_monitor_delete(request, mon_id):
|
||||
quantumclient(request).delete_health_monitor(mon_id)
|
||||
|
||||
@ -283,7 +287,6 @@ def member_get(request, member_id):
|
||||
return Member(member)
|
||||
|
||||
|
||||
# not linked to UI yet
|
||||
def member_update(request, member_id, **kwargs):
|
||||
member = quantumclient(request).update_member(member_id, kwargs)
|
||||
return Member(member)
|
||||
|
@ -68,3 +68,179 @@ class UpdatePool(forms.SelfHandlingForm):
|
||||
LOG.info(msg)
|
||||
redirect = reverse(self.failure_url)
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class UpdateVip(forms.SelfHandlingForm):
|
||||
name = forms.CharField(max_length=80, label=_("Name"))
|
||||
vip_id = forms.CharField(label=_("ID"),
|
||||
widget=forms.TextInput(
|
||||
attrs={'readonly': 'readonly'}))
|
||||
description = forms.CharField(required=False,
|
||||
max_length=80, label=_("Description"))
|
||||
pool_id = forms.ChoiceField(label=_("Pool"))
|
||||
session_persistence = forms.ChoiceField(
|
||||
required=False, initial={}, label=_("Session Persistence"))
|
||||
|
||||
cookie_name = forms.CharField(
|
||||
initial="", required=False,
|
||||
max_length=80, label=_("Cookie Name"),
|
||||
help_text=_("Required for APP_COOKIE persistence;"
|
||||
" Ignored otherwise."))
|
||||
|
||||
connection_limit = forms.IntegerField(
|
||||
min_value=-1, label=_("Connection Limit"),
|
||||
help_text=_("Maximum number of connections allowed "
|
||||
"for the VIP or '-1' if the limit is not set"))
|
||||
admin_state_up = forms.BooleanField(label=_("Admin State"), required=False)
|
||||
|
||||
failure_url = 'horizon:project:loadbalancers:index'
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(UpdateVip, self).__init__(request, *args, **kwargs)
|
||||
|
||||
pool_id_choices = []
|
||||
try:
|
||||
pools = api.lbaas.pools_get(request)
|
||||
except:
|
||||
pools = []
|
||||
exceptions.handle(request,
|
||||
_('Unable to retrieve pools list.'))
|
||||
pools = sorted(pools,
|
||||
key=lambda pool: pool.name)
|
||||
for p in pools:
|
||||
if (p.vip_id is None) or (p.id == kwargs['initial']['pool_id']):
|
||||
pool_id_choices.append((p.id, p.name))
|
||||
self.fields['pool_id'].choices = pool_id_choices
|
||||
|
||||
session_persistence_choices = []
|
||||
for mode in ('SOURCE_IP', 'HTTP_COOKIE', 'APP_COOKIE'):
|
||||
session_persistence_choices.append((mode, mode))
|
||||
self.fields[
|
||||
'session_persistence'].choices = session_persistence_choices
|
||||
|
||||
def handle(self, request, context):
|
||||
if context['session_persistence']:
|
||||
stype = context['session_persistence']
|
||||
if stype == 'APP_COOKIE':
|
||||
cookie = context['cookie_name']
|
||||
context['session_persistence'] = {'type': stype,
|
||||
'cookie_name': cookie}
|
||||
else:
|
||||
context['session_persistence'] = {'type': stype}
|
||||
else:
|
||||
context['session_persistence'] = {}
|
||||
|
||||
try:
|
||||
data = {'vip': {'name': context['name'],
|
||||
'description': context['description'],
|
||||
'pool_id': context['pool_id'],
|
||||
'session_persistence':
|
||||
context['session_persistence'],
|
||||
'connection_limit': context['connection_limit'],
|
||||
'admin_state_up': context['admin_state_up'],
|
||||
}}
|
||||
vip = api.lbaas.vip_update(request, context['vip_id'], **data)
|
||||
msg = _('VIP %s was successfully updated.') % context['name']
|
||||
LOG.debug(msg)
|
||||
messages.success(request, msg)
|
||||
return vip
|
||||
except:
|
||||
msg = _('Failed to update VIP %s') % context['name']
|
||||
LOG.info(msg)
|
||||
redirect = reverse(self.failure_url)
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class UpdateMember(forms.SelfHandlingForm):
|
||||
member_id = forms.CharField(label=_("ID"),
|
||||
widget=forms.TextInput(
|
||||
attrs={'readonly': 'readonly'}))
|
||||
pool_id = forms.ChoiceField(label=_("Pool"))
|
||||
weight = forms.IntegerField(max_value=256, min_value=0, label=_("Weight"),
|
||||
help_text=_("Relative part of requests this "
|
||||
"pool member serves compared to others"))
|
||||
admin_state_up = forms.BooleanField(label=_("Admin State"), required=False)
|
||||
|
||||
failure_url = 'horizon:project:loadbalancers:index'
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(UpdateMember, self).__init__(request, *args, **kwargs)
|
||||
|
||||
pool_id_choices = []
|
||||
try:
|
||||
pools = api.lbaas.pools_get(request)
|
||||
except:
|
||||
pools = []
|
||||
exceptions.handle(request,
|
||||
_('Unable to retrieve pools list.'))
|
||||
pools = sorted(pools,
|
||||
key=lambda pool: pool.name)
|
||||
for p in pools:
|
||||
pool_id_choices.append((p.id, p.name))
|
||||
self.fields['pool_id'].choices = pool_id_choices
|
||||
|
||||
def handle(self, request, context):
|
||||
try:
|
||||
data = {'member': {'pool_id': context['pool_id'],
|
||||
'weight': context['weight'],
|
||||
'admin_state_up': context['admin_state_up']}}
|
||||
member = api.lbaas.member_update(request,
|
||||
context['member_id'], **data)
|
||||
msg = _('Member %s was successfully updated.')\
|
||||
% context['member_id']
|
||||
LOG.debug(msg)
|
||||
messages.success(request, msg)
|
||||
return member
|
||||
except:
|
||||
msg = _('Failed to update member %s') % context['member_id']
|
||||
LOG.info(msg)
|
||||
redirect = reverse(self.failure_url)
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class UpdateMonitor(forms.SelfHandlingForm):
|
||||
monitor_id = forms.CharField(label=_("ID"),
|
||||
widget=forms.TextInput(
|
||||
attrs={'readonly': 'readonly'}))
|
||||
delay = forms.IntegerField(
|
||||
min_value=1,
|
||||
label=_("Delay"),
|
||||
help_text=_("The minimum time in seconds between regular checks "
|
||||
"of a member"))
|
||||
timeout = forms.IntegerField(
|
||||
min_value=1,
|
||||
label=_("Timeout"),
|
||||
help_text=_("The maximum time in seconds for a monitor to wait "
|
||||
"for a reply"))
|
||||
max_retries = forms.IntegerField(
|
||||
max_value=10, min_value=1,
|
||||
label=_("Max Retries (1~10)"),
|
||||
help_text=_("Number of permissible failures before changing "
|
||||
"the status of member to inactive"))
|
||||
admin_state_up = forms.BooleanField(label=_("Admin State"), required=False)
|
||||
|
||||
failure_url = 'horizon:project:loadbalancers:index'
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(UpdateMonitor, self).__init__(request, *args, **kwargs)
|
||||
|
||||
def handle(self, request, context):
|
||||
try:
|
||||
data = {'health_monitor': {
|
||||
'delay': context['delay'],
|
||||
'timeout': context['timeout'],
|
||||
'max_retries': context['max_retries'],
|
||||
'admin_state_up': context['admin_state_up']}}
|
||||
monitor = api.lbaas.pool_health_monitor_update(request,
|
||||
context['monitor_id'], **data)
|
||||
msg = _('Health monitor %s was successfully updated.')\
|
||||
% context['monitor_id']
|
||||
LOG.debug(msg)
|
||||
messages.success(request, msg)
|
||||
return monitor
|
||||
except:
|
||||
msg = _('Failed to update health monitor %s')\
|
||||
% context['monitor_id']
|
||||
LOG.info(msg)
|
||||
redirect = reverse(self.failure_url)
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
@ -112,6 +112,39 @@ class UpdatePoolLink(tables.LinkAction):
|
||||
return base_url
|
||||
|
||||
|
||||
class UpdateVipLink(tables.LinkAction):
|
||||
name = "updatevip"
|
||||
verbose_name = _("Edit VIP")
|
||||
classes = ("btn-updatevip",)
|
||||
|
||||
def get_link_url(self, pool):
|
||||
base_url = reverse("horizon:project:loadbalancers:updatevip",
|
||||
kwargs={'vip_id': pool.vip_id})
|
||||
return base_url
|
||||
|
||||
|
||||
class UpdateMemberLink(tables.LinkAction):
|
||||
name = "updatemember"
|
||||
verbose_name = _("Edit Member")
|
||||
classes = ("btn-updatemember",)
|
||||
|
||||
def get_link_url(self, member):
|
||||
base_url = reverse("horizon:project:loadbalancers:updatemember",
|
||||
kwargs={'member_id': member.id})
|
||||
return base_url
|
||||
|
||||
|
||||
class UpdateMonitorLink(tables.LinkAction):
|
||||
name = "updatemonitor"
|
||||
verbose_name = _("Edit Monitor")
|
||||
classes = ("btn-updatemonitor",)
|
||||
|
||||
def get_link_url(self, monitor):
|
||||
base_url = reverse("horizon:project:loadbalancers:updatemonitor",
|
||||
kwargs={'monitor_id': monitor.id})
|
||||
return base_url
|
||||
|
||||
|
||||
def get_vip_link(pool):
|
||||
return reverse("horizon:project:loadbalancers:vipdetails",
|
||||
args=(http.urlquote(pool.vip_id),))
|
||||
@ -131,8 +164,8 @@ class PoolsTable(tables.DataTable):
|
||||
name = "poolstable"
|
||||
verbose_name = _("Pools")
|
||||
table_actions = (AddPoolLink, DeletePoolLink)
|
||||
row_actions = (UpdatePoolLink, AddVipLink, DeleteVipLink,
|
||||
DeletePoolLink)
|
||||
row_actions = (UpdatePoolLink, AddVipLink, UpdateVipLink,
|
||||
DeleteVipLink, DeletePoolLink)
|
||||
|
||||
|
||||
def get_pool_link(member):
|
||||
@ -159,7 +192,7 @@ class MembersTable(tables.DataTable):
|
||||
name = "memberstable"
|
||||
verbose_name = _("Members")
|
||||
table_actions = (AddMemberLink, DeleteMemberLink)
|
||||
row_actions = (DeleteMemberLink,)
|
||||
row_actions = (UpdateMemberLink, DeleteMemberLink)
|
||||
|
||||
|
||||
class MonitorsTable(tables.DataTable):
|
||||
@ -172,4 +205,4 @@ class MonitorsTable(tables.DataTable):
|
||||
name = "monitorstable"
|
||||
verbose_name = _("Monitors")
|
||||
table_actions = (AddMonitorLink, DeleteMonitorLink)
|
||||
row_actions = (DeleteMonitorLink,)
|
||||
row_actions = (UpdateMonitorLink, DeleteMonitorLink)
|
||||
|
@ -0,0 +1,25 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}update_pool_form{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:project:loadbalancers:updatemember' member_id %}{% endblock %}
|
||||
|
||||
{% block modal-header %}{% trans "Edit Member" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "You may update member attributes here: edit pool, weight or admin state." %}</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Save Changes" %}" />
|
||||
<a href="{% url 'horizon:project:loadbalancers:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
@ -0,0 +1,25 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}update_monitor_form{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:project:loadbalancers:updatemonitor' monitor_id %}{% endblock %}
|
||||
|
||||
{% block modal-header %}{% trans "Edit Monitor" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "You may update health monitor attributes here: edit delay, timeout, max retries or admin state." %}</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Save Changes" %}" />
|
||||
<a href="{% url 'horizon:project:loadbalancers:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
@ -0,0 +1,25 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}update_vip_form{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:project:loadbalancers:updatevip' vip_id %}{% endblock %}
|
||||
|
||||
{% block modal-header %}{% trans "Edit VIP" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right">
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "You may update VIP attributes here: edit name, description, pool, session persistence, connection limit or admin state." %}</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Save Changes" %}" />
|
||||
<a href="{% url 'horizon:project:loadbalancers:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Edit Member" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Edit Member") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'project/loadbalancers/_updatemember.html' %}
|
||||
{% endblock %}
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Edit Monitor" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Edit Monitor") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'project/loadbalancers/_updatemonitor.html' %}
|
||||
{% endblock %}
|
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Edit VIP" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Edit VIP") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'project/loadbalancers/_updatevip.html' %}
|
||||
{% endblock %}
|
@ -38,6 +38,9 @@ class LoadBalancerTests(test.TestCase):
|
||||
MONITOR_DETAIL_PATH = 'horizon:%s:loadbalancers:monitordetails' % DASHBOARD
|
||||
|
||||
UPDATEPOOL_PATH = 'horizon:%s:loadbalancers:updatepool' % DASHBOARD
|
||||
UPDATEVIP_PATH = 'horizon:%s:loadbalancers:updatevip' % DASHBOARD
|
||||
UPDATEMEMBER_PATH = 'horizon:%s:loadbalancers:updatemember' % DASHBOARD
|
||||
UPDATEMONITOR_PATH = 'horizon:%s:loadbalancers:updatemonitor' % DASHBOARD
|
||||
|
||||
def set_up_expect(self):
|
||||
# retrieve pools
|
||||
@ -256,8 +259,8 @@ class LoadBalancerTests(test.TestCase):
|
||||
subnet_id=vip.subnet_id,
|
||||
protocol_port=vip.protocol_port,
|
||||
protocol=vip.protocol,
|
||||
session_persistence=vip.session_persistence,
|
||||
cookie_name=vip.cookie_name,
|
||||
session_persistence=vip.session_persistence['type'],
|
||||
cookie_name=vip.session_persistence['cookie_name'],
|
||||
connection_limit=vip.connection_limit,
|
||||
admin_state_up=vip.admin_state_up).AndReturn(Vip(vip))
|
||||
|
||||
@ -273,8 +276,8 @@ class LoadBalancerTests(test.TestCase):
|
||||
'subnet': vip.subnet,
|
||||
'protocol_port': vip.protocol_port,
|
||||
'protocol': vip.protocol,
|
||||
'session_persistence': vip.session_persistence,
|
||||
'cookie_name': vip.cookie_name,
|
||||
'session_persistence': vip.session_persistence['type'],
|
||||
'cookie_name': vip.session_persistence['cookie_name'],
|
||||
'connection_limit': vip.connection_limit,
|
||||
'admin_state_up': vip.admin_state_up}
|
||||
|
||||
@ -305,8 +308,8 @@ class LoadBalancerTests(test.TestCase):
|
||||
'subnet_id': vip.subnet_id,
|
||||
'protocol_port': 65536,
|
||||
'protocol': vip.protocol,
|
||||
'session_persistence': vip.session_persistence,
|
||||
'cookie_name': vip.cookie_name,
|
||||
'session_persistence': vip.session_persistence['type'],
|
||||
'cookie_name': vip.session_persistence['cookie_name'],
|
||||
'connection_limit': -2,
|
||||
'admin_state_up': vip.admin_state_up}
|
||||
|
||||
@ -572,3 +575,129 @@ class LoadBalancerTests(test.TestCase):
|
||||
res = self.client.get(reverse(self.UPDATEPOOL_PATH, args=(pool.id,)))
|
||||
|
||||
self.assertTemplateUsed(res, 'project/loadbalancers/updatepool.html')
|
||||
|
||||
@test.create_stubs({api.lbaas: ('pools_get', 'vip_get',
|
||||
'vip_update')})
|
||||
def test_update_vip_post(self):
|
||||
vip = self.vips.first()
|
||||
|
||||
api.lbaas.pools_get(IsA(http.HttpRequest)).AndReturn(self.pools.list())
|
||||
api.lbaas.vip_get(IsA(http.HttpRequest), vip.id).AndReturn(vip)
|
||||
|
||||
data = {'name': vip.name,
|
||||
'description': vip.description,
|
||||
'pool_id': vip.pool_id,
|
||||
'session_persistence': {},
|
||||
'connection_limit': vip.connection_limit,
|
||||
'admin_state_up': vip.admin_state_up}
|
||||
|
||||
api.lbaas.vip_update(IsA(http.HttpRequest), vip.id, vip=data)\
|
||||
.AndReturn(vip)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'vip_id': vip.id})
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEVIP_PATH, args=(vip.id,)), form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
|
||||
|
||||
@test.create_stubs({api.lbaas: ('vip_get', 'pools_get')})
|
||||
def test_update_vip_get(self):
|
||||
vip = self.vips.first()
|
||||
|
||||
api.lbaas.pools_get(IsA(http.HttpRequest)).AndReturn(self.pools.list())
|
||||
api.lbaas.vip_get(IsA(http.HttpRequest), vip.id).AndReturn(vip)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(reverse(self.UPDATEVIP_PATH, args=(vip.id,)))
|
||||
|
||||
self.assertTemplateUsed(res, 'project/loadbalancers/updatevip.html')
|
||||
|
||||
@test.create_stubs({api.lbaas: ('pools_get', 'member_get',
|
||||
'member_update')})
|
||||
def test_update_member_post(self):
|
||||
member = self.members.first()
|
||||
|
||||
api.lbaas.pools_get(IsA(http.HttpRequest)).AndReturn(self.pools.list())
|
||||
api.lbaas.member_get(IsA(http.HttpRequest), member.id)\
|
||||
.AndReturn(member)
|
||||
|
||||
data = {'pool_id': member.pool_id,
|
||||
'weight': member.weight,
|
||||
'admin_state_up': member.admin_state_up}
|
||||
|
||||
api.lbaas.member_update(IsA(http.HttpRequest), member.id, member=data)\
|
||||
.AndReturn(member)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'member_id': member.id})
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEMEMBER_PATH, args=(member.id,)), form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
|
||||
|
||||
@test.create_stubs({api.lbaas: ('member_get', 'pools_get')})
|
||||
def test_update_member_get(self):
|
||||
member = self.members.first()
|
||||
|
||||
api.lbaas.pools_get(IsA(http.HttpRequest)).AndReturn(self.pools.list())
|
||||
api.lbaas.member_get(IsA(http.HttpRequest), member.id)\
|
||||
.AndReturn(member)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(
|
||||
reverse(self.UPDATEMEMBER_PATH, args=(member.id,)))
|
||||
|
||||
self.assertTemplateUsed(res, 'project/loadbalancers/updatemember.html')
|
||||
|
||||
@test.create_stubs({api.lbaas: ('pool_health_monitor_get',
|
||||
'pool_health_monitor_update')})
|
||||
def test_update_monitor_post(self):
|
||||
monitor = self.monitors.first()
|
||||
|
||||
api.lbaas.pool_health_monitor_get(IsA(http.HttpRequest), monitor.id)\
|
||||
.AndReturn(monitor)
|
||||
|
||||
data = {'delay': monitor.delay,
|
||||
'timeout': monitor.timeout,
|
||||
'max_retries': monitor.max_retries,
|
||||
'admin_state_up': monitor.admin_state_up}
|
||||
|
||||
api.lbaas.pool_health_monitor_update(IsA(http.HttpRequest),
|
||||
monitor.id, health_monitor=data).AndReturn(monitor)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = data.copy()
|
||||
form_data.update({'monitor_id': monitor.id})
|
||||
|
||||
res = self.client.post(
|
||||
reverse(self.UPDATEMONITOR_PATH, args=(monitor.id,)), form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
|
||||
|
||||
@test.create_stubs({api.lbaas: ('pool_health_monitor_get',)})
|
||||
def test_update_monitor_get(self):
|
||||
monitor = self.monitors.first()
|
||||
|
||||
api.lbaas.pool_health_monitor_get(IsA(http.HttpRequest), monitor.id)\
|
||||
.AndReturn(monitor)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(
|
||||
reverse(self.UPDATEMONITOR_PATH, args=(monitor.id,)))
|
||||
|
||||
self.assertTemplateUsed(
|
||||
res, 'project/loadbalancers/updatemonitor.html')
|
||||
|
@ -18,7 +18,8 @@ from django.conf.urls.defaults import url, patterns
|
||||
|
||||
from .views import IndexView
|
||||
from .views import AddPoolView, AddMemberView, AddMonitorView, AddVipView
|
||||
from .views import UpdatePoolView
|
||||
from .views import (UpdatePoolView, UpdateMemberView,
|
||||
UpdateVipView, UpdateMonitorView)
|
||||
from .views import PoolDetailsView, VipDetailsView
|
||||
from .views import MemberDetailsView, MonitorDetailsView
|
||||
|
||||
@ -29,8 +30,14 @@ urlpatterns = patterns(
|
||||
url(r'^updatepool/(?P<pool_id>[^/]+)/$',
|
||||
UpdatePoolView.as_view(), name='updatepool'),
|
||||
url(r'^addvip/(?P<pool_id>[^/]+)/$', AddVipView.as_view(), name='addvip'),
|
||||
url(r'^updatevip/(?P<vip_id>[^/]+)/$',
|
||||
UpdateVipView.as_view(), name='updatevip'),
|
||||
url(r'^addmember$', AddMemberView.as_view(), name='addmember'),
|
||||
url(r'^updatemember/(?P<member_id>[^/]+)/$',
|
||||
UpdateMemberView.as_view(), name='updatemember'),
|
||||
url(r'^addmonitor$', AddMonitorView.as_view(), name='addmonitor'),
|
||||
url(r'^updatemonitor/(?P<monitor_id>[^/]+)/$',
|
||||
UpdateMonitorView.as_view(), name='updatemonitor'),
|
||||
url(r'^pool/(?P<pool_id>[^/]+)/$',
|
||||
PoolDetailsView.as_view(), name='pooldetails'),
|
||||
url(r'^vip/(?P<vip_id>[^/]+)/$',
|
||||
|
@ -30,7 +30,7 @@ from horizon import workflows
|
||||
from openstack_dashboard import api
|
||||
|
||||
from .workflows import AddPool, AddMember, AddMonitor, AddVip
|
||||
from .forms import UpdatePool
|
||||
from .forms import UpdatePool, UpdateVip, UpdateMember, UpdateMonitor
|
||||
from .tabs import LoadBalancerTabs, PoolDetailsTabs, VipDetailsTabs
|
||||
from .tabs import MemberDetailsTabs, MonitorDetailsTabs
|
||||
from .tables import DeleteMonitorLink
|
||||
@ -179,4 +179,106 @@ class UpdatePoolView(forms.ModalFormView):
|
||||
'pool_id': pool['id'],
|
||||
'description': pool['description'],
|
||||
'lb_method': pool['lb_method'],
|
||||
'admin_state': pool['admin_state_up']}
|
||||
'admin_state_up': pool['admin_state_up']}
|
||||
|
||||
|
||||
class UpdateVipView(forms.ModalFormView):
|
||||
form_class = UpdateVip
|
||||
template_name = "project/loadbalancers/updatevip.html"
|
||||
context_object_name = 'vip'
|
||||
success_url = reverse_lazy("horizon:project:loadbalancers:index")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UpdateVipView, self).get_context_data(**kwargs)
|
||||
context["vip_id"] = self.kwargs['vip_id']
|
||||
return context
|
||||
|
||||
def _get_object(self, *args, **kwargs):
|
||||
if not hasattr(self, "_object"):
|
||||
vip_id = self.kwargs['vip_id']
|
||||
try:
|
||||
self._object = api.lbaas.vip_get(self.request, vip_id)
|
||||
except:
|
||||
redirect = self.success_url
|
||||
msg = _('Unable to retrieve vip details.')
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
return self._object
|
||||
|
||||
def get_initial(self):
|
||||
vip = self._get_object()
|
||||
stype = vip['session_persistence']
|
||||
if stype['type'] == 'APP_COOKIE':
|
||||
cookie = stype['cookie_name']
|
||||
else:
|
||||
cookie = ''
|
||||
|
||||
return {'name': vip['name'],
|
||||
'vip_id': vip['id'],
|
||||
'description': vip['description'],
|
||||
'pool_id': vip['pool_id'],
|
||||
'session_persistence': vip['session_persistence']['type'],
|
||||
'cookie_name': cookie,
|
||||
'connection_limit': vip['connection_limit'],
|
||||
'admin_state_up': vip['admin_state_up']}
|
||||
|
||||
|
||||
class UpdateMemberView(forms.ModalFormView):
|
||||
form_class = UpdateMember
|
||||
template_name = "project/loadbalancers/updatemember.html"
|
||||
context_object_name = 'member'
|
||||
success_url = reverse_lazy("horizon:project:loadbalancers:index")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UpdateMemberView, self).get_context_data(**kwargs)
|
||||
context["member_id"] = self.kwargs['member_id']
|
||||
return context
|
||||
|
||||
def _get_object(self, *args, **kwargs):
|
||||
if not hasattr(self, "_object"):
|
||||
member_id = self.kwargs['member_id']
|
||||
try:
|
||||
self._object = api.lbaas.member_get(self.request, member_id)
|
||||
except:
|
||||
redirect = self.success_url
|
||||
msg = _('Unable to retrieve member details.')
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
return self._object
|
||||
|
||||
def get_initial(self):
|
||||
member = self._get_object()
|
||||
return {'member_id': member['id'],
|
||||
'pool_id': member['pool_id'],
|
||||
'weight': member['weight'],
|
||||
'admin_state_up': member['admin_state_up']}
|
||||
|
||||
|
||||
class UpdateMonitorView(forms.ModalFormView):
|
||||
form_class = UpdateMonitor
|
||||
template_name = "project/loadbalancers/updatemonitor.html"
|
||||
context_object_name = 'monitor'
|
||||
success_url = reverse_lazy("horizon:project:loadbalancers:index")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UpdateMonitorView, self).get_context_data(**kwargs)
|
||||
context["monitor_id"] = self.kwargs['monitor_id']
|
||||
return context
|
||||
|
||||
def _get_object(self, *args, **kwargs):
|
||||
if not hasattr(self, "_object"):
|
||||
monitor_id = self.kwargs['monitor_id']
|
||||
try:
|
||||
self._object = api.lbaas.pool_health_monitor_get(
|
||||
self.request, monitor_id)
|
||||
except:
|
||||
redirect = self.success_url
|
||||
msg = _('Unable to retrieve health monitor details.')
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
return self._object
|
||||
|
||||
def get_initial(self):
|
||||
monitor = self._get_object()
|
||||
return {'monitor_id': monitor['id'],
|
||||
'delay': monitor['delay'],
|
||||
'timeout': monitor['timeout'],
|
||||
'max_retries': monitor['max_retries'],
|
||||
'admin_state_up': monitor['admin_state_up']}
|
||||
|
@ -273,8 +273,8 @@ def data(TEST):
|
||||
'protocol_port': 80,
|
||||
'protocol': pool_dict['protocol'],
|
||||
'pool_id': pool_dict['id'],
|
||||
'session_persistence': {},
|
||||
'cookie_name': '',
|
||||
'session_persistence': {'type': 'APP_COOKIE',
|
||||
'cookie_name': 'jssessionid'},
|
||||
'connection_limit': 10,
|
||||
'admin_state_up': True}
|
||||
TEST.api_vips.add(vip_dict)
|
||||
@ -292,8 +292,8 @@ def data(TEST):
|
||||
'protocol_port': 80,
|
||||
'protocol': pool_dict['protocol'],
|
||||
'pool_id': pool_dict['id'],
|
||||
'session_persistence': 'APP_COOKIE',
|
||||
'cookie_name': 'jssessionid',
|
||||
'session_persistence': {'type': 'APP_COOKIE',
|
||||
'cookie_name': 'jssessionid'},
|
||||
'connection_limit': 10,
|
||||
'admin_state_up': True}
|
||||
TEST.api_vips.add(vip_dict)
|
||||
|
Loading…
x
Reference in New Issue
Block a user