Activate library policy

This commit adds support to activate a library policy.

Partially-Implements blueprint add-policy-library-gui
Depends-On: I0c4a70002bd172c0b5842cc7de1c9bb5ad0bcf5a
            I9d038dd4c33ed509261f6b404ab278bd33318d3b

Change-Id: Ibe3223b08ae402037c6efe5ef50d05ba6e4d0379
This commit is contained in:
Anusha Ramineni 2017-11-08 09:42:15 +05:30
parent b2d848640b
commit a3fb879779
5 changed files with 40 additions and 4 deletions

View File

@ -55,6 +55,7 @@ And enable it in Horizon
$ ln -s <congress-dashboard>/congress_dashboard/enabled/_60_policies.py <horizon>/openstack_dashboard/local/enabled
$ ln -s <congress-dashboard>/congress_dashboard/enabled/_70_datasources.py <horizon>/openstack_dashboard/local/enabled
$ ln -s <congress-dashboard>/congress_dashboard/enabled/_75_monitoring.py <horizon>/openstack_dashboard/local/enabled
$ ln -s <congress-dashboard>/congress_dashboard/enabled/_80_library.py <horizon>/openstack_dashboard/local/enabled
Restart Apache server

View File

@ -134,10 +134,10 @@ def policies_list(request):
return policies
def policy_create(request, args):
def policy_create(request, args, library_policy_id=None):
"""Create a policy with the given properties."""
client = congressclient(request)
policy = client.create_policy(args)
policy = client.create_policy(args, library_policy_id)
return policy

View File

@ -15,6 +15,7 @@
from django.core.urlresolvers import reverse
from django.template.defaultfilters import linebreaksbr
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from congress_dashboard.api import congress
@ -24,6 +25,31 @@ def get_policy_link(datum):
return reverse('horizon:admin:library:detail', args=(datum['id'],))
class ActivatePolicy(tables.BatchAction):
name = 'activate_policy'
verbose_name = _('Activate')
icon = 'plus'
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Activate Policy",
u"Activate Policy",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Activated Policy",
u"Activated Policy",
count
)
def action(self, request, obj_id):
congress.policy_create(request, {}, obj_id)
class LibraryTable(tables.DataTable):
id = tables.Column("id", verbose_name=_("Policy ID"), hidden=True,
sortable=False)
@ -35,6 +61,7 @@ class LibraryTable(tables.DataTable):
class Meta(object):
name = "policy_library"
verbose_name = _("Policy Library")
row_actions = (ActivatePolicy, )
hidden_title = True

View File

@ -70,5 +70,9 @@ class DetailView(tables.DataTableView):
policy, _ = congress.show_library_policy(self.request, policy_id)
context['policy'] = policy
return context
except Exception:
raise
except Exception as e:
margs = {'id': policy_id, 'error': str(e)}
msg = _('Unable to get library policy %(id)s: %(error)s') % margs
LOG.exception(msg)
messages.error(self.request, msg)
return []

View File

@ -0,0 +1,4 @@
---
features:
- New panel 'Library' is added to list/show/activate library policies from
dashboard.