Cleanup lbaas table actions

The lbaas table actions were not written in a way
that makes extension or reuse as easy as other tables,
and has more complex code than is needed.  This change
cleans up this code.

Change-Id: I7c5f64366b0eaaea91b34fcde2c834ff541c720a
Closes-Bug: #1476252
This commit is contained in:
eric 2015-07-20 08:16:37 -06:00
parent ede7402604
commit eac7d7eab7
3 changed files with 45 additions and 60 deletions

View File

@ -104,6 +104,21 @@ class DeleteVipLink(policy.PolicyTargetMixin, tables.DeleteAction):
return False
return True
def delete(self, request, obj_id):
try:
vip_id = api.lbaas.pool_get(request, obj_id).vip_id
except Exception as e:
exceptions.handle(request,
_('Unable to locate VIP to delete. %s')
% e)
if vip_id is not None:
try:
api.lbaas.vip_delete(request, vip_id)
messages.success(request, _('Deleted VIP %s') % vip_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete VIP. %s') % e)
class DeletePoolLink(policy.PolicyTargetMixin, tables.DeleteAction):
name = "deletepool"
@ -130,6 +145,14 @@ class DeletePoolLink(policy.PolicyTargetMixin, tables.DeleteAction):
return False
return True
def delete(self, request, obj_id):
try:
api.lbaas.pool_delete(request, obj_id)
messages.success(request, _('Deleted pool %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete pool. %s') % e)
class DeleteMonitorLink(policy.PolicyTargetMixin,
tables.DeleteAction):
@ -152,6 +175,14 @@ class DeleteMonitorLink(policy.PolicyTargetMixin,
count
)
def delete(self, request, obj_id):
try:
api.lbaas.pool_health_monitor_delete(request, obj_id)
messages.success(request, _('Deleted monitor %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete monitor. %s') % e)
class DeleteMemberLink(policy.PolicyTargetMixin, tables.DeleteAction):
name = "deletemember"
@ -173,6 +204,14 @@ class DeleteMemberLink(policy.PolicyTargetMixin, tables.DeleteAction):
count
)
def delete(self, request, obj_id):
try:
api.lbaas.member_delete(request, obj_id)
messages.success(request, _('Deleted member %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete member. %s') % e)
class UpdatePoolLink(policy.PolicyTargetMixin, tables.LinkAction):
name = "updatepool"

View File

@ -890,10 +890,14 @@ class LoadBalancerTests(test.TestCase):
@test.create_stubs({api.lbaas: ('pool_list', 'pool_delete')})
def test_delete_pool(self):
pool = self.pools.first()
pool_list = self.pools.list()
pool = pool_list[0]
# the test pool needs to have no vip
# in order to be able to be deleted
pool.vip_id = None
api.lbaas.pool_list(
IsA(http.HttpRequest), tenant_id=self.tenant.id) \
.AndReturn(self.pools.list())
.AndReturn(pool_list)
api.lbaas.pool_delete(IsA(http.HttpRequest), pool.id)
self.mox.ReplayAll()

View File

@ -18,7 +18,6 @@ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from horizon import tabs
from horizon.utils import memoized
from horizon import workflows
@ -34,69 +33,12 @@ from openstack_dashboard.dashboards.project.loadbalancers import utils
from openstack_dashboard.dashboards.project.loadbalancers \
import workflows as project_workflows
import re
class IndexView(tabs.TabbedTableView):
tab_group_class = (project_tabs.LoadBalancerTabs)
template_name = 'project/loadbalancers/details_tabs.html'
page_title = _("Load Balancer")
def post(self, request, *args, **kwargs):
"""This method is messy because table actions
were not implemented correctly. ideally,
this code can be refactored to move items into
table actions
"""
obj_ids = request.POST.getlist('object_ids')
action = request.POST['action']
results = re.search('.delete([a-z]+)', action)
if not results:
return super(IndexView, self).post(request, *args, **kwargs)
m = results.group(1)
if obj_ids == []:
obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
if m == 'monitor':
for obj_id in obj_ids:
try:
api.lbaas.pool_health_monitor_delete(request, obj_id)
messages.success(request, _('Deleted monitor %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete monitor. %s') % e)
if m == 'pool':
for obj_id in obj_ids:
try:
api.lbaas.pool_delete(request, obj_id)
messages.success(request, _('Deleted pool %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete pool. %s') % e)
if m == 'member':
for obj_id in obj_ids:
try:
api.lbaas.member_delete(request, obj_id)
messages.success(request, _('Deleted member %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete member. %s') % e)
if m == 'vip':
for obj_id in obj_ids:
try:
vip_id = api.lbaas.pool_get(request, obj_id).vip_id
except Exception as e:
exceptions.handle(request,
_('Unable to locate VIP to delete. %s')
% e)
if vip_id is not None:
try:
api.lbaas.vip_delete(request, vip_id)
messages.success(request, _('Deleted VIP %s') % vip_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete VIP. %s') % e)
return self.get(request, *args, **kwargs)
class AddPoolView(workflows.WorkflowView):
workflow_class = project_workflows.AddPool