dashboard: View library policies
This commit is to list library policies through congress-dashboard TODO: show rules activate policy Partially-Implements blueprint add-policy-library-gui Change-Id: Iff59145001af7df9afb3c654346fada3c451e966
This commit is contained in:
parent
2acc8b3394
commit
f5e46c0b0a
@ -335,3 +335,17 @@ def delete_datasource(request, datasource_name):
|
||||
except Exception:
|
||||
LOG.exception("deleting datasource %s failed", datasource_name)
|
||||
raise
|
||||
|
||||
|
||||
def list_policies_from_library(request):
|
||||
client = congressclient(request)
|
||||
try:
|
||||
results = client.list_library_policy()['results']
|
||||
policies = []
|
||||
for p in results:
|
||||
policy = PolicyAPIDictWrapper(p)
|
||||
policies.append(policy)
|
||||
return policies
|
||||
except Exception:
|
||||
LOG.exception("List library policies failed")
|
||||
raise
|
||||
|
5
congress_dashboard/enabled/_80_library.py
Normal file
5
congress_dashboard/enabled/_80_library.py
Normal file
@ -0,0 +1,5 @@
|
||||
PANEL = 'library'
|
||||
PANEL_DASHBOARD = 'admin'
|
||||
PANEL_GROUP = 'policy'
|
||||
ADD_PANEL = 'congress_dashboard.library.panel.PolicyLibrary'
|
||||
AUTO_DISCOVER_STATIC_FILES = True
|
0
congress_dashboard/library/__init__.py
Normal file
0
congress_dashboard/library/__init__.py
Normal file
25
congress_dashboard/library/panel.py
Normal file
25
congress_dashboard/library/panel.py
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2017 NEC, Corp
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import horizon
|
||||
from openstack_dashboard.dashboards.admin import dashboard
|
||||
|
||||
|
||||
class PolicyLibrary(horizon.Panel):
|
||||
name = _("Library")
|
||||
slug = "library"
|
||||
permissions = ('openstack.roles.admin',)
|
||||
|
||||
dashboard.Admin.register(PolicyLibrary)
|
29
congress_dashboard/library/tables.py
Normal file
29
congress_dashboard/library/tables.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright 2017 NEC, Corp
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import tables
|
||||
|
||||
|
||||
class LibraryTable(tables.DataTable):
|
||||
id = tables.Column("id", verbose_name=_("Policy ID"), hidden=True,
|
||||
sortable=False)
|
||||
name = tables.Column("name", verbose_name=_("Policy Name"))
|
||||
desc = tables.WrappingColumn("description", verbose_name=_("Description"),
|
||||
sortable=False)
|
||||
|
||||
class Meta(object):
|
||||
name = "policy_library"
|
||||
verbose_name = _("Policy Library")
|
||||
hidden_title = True
|
12
congress_dashboard/library/templates/library/index.html
Normal file
12
congress_dashboard/library/templates/library/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Policies" %}{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
{% include "horizon/common/_page_header.html" with title=_("Policy Library") %}
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
<div id="library">
|
||||
{{policy_library_table.render}}
|
||||
{% endblock %}
|
22
congress_dashboard/library/urls.py
Normal file
22
congress_dashboard/library/urls.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright 2017 NEC, Corp
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from congress_dashboard.library import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
]
|
40
congress_dashboard/library/views.py
Normal file
40
congress_dashboard/library/views.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright 2017 NEC, Corp
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import messages
|
||||
from horizon import tables
|
||||
|
||||
from congress_dashboard.api import congress
|
||||
from congress_dashboard.library import tables as library_tables
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IndexView(tables.DataTableView):
|
||||
"""List policies from library."""
|
||||
table_class = library_tables.LibraryTable
|
||||
template_name = 'admin/library/index.html'
|
||||
|
||||
def get_data(self):
|
||||
try:
|
||||
policies = congress.list_policies_from_library(self.request)
|
||||
return policies
|
||||
except Exception as e:
|
||||
msg = _('Unable to list library policies: %s') % str(e)
|
||||
LOG.exception(msg)
|
||||
messages.error(self.request, msg)
|
||||
return []
|
Loading…
x
Reference in New Issue
Block a user