diff --git a/cerberusdashboard/api/cerberus.py b/cerberusdashboard/api/cerberus.py index bf14052..4a7518a 100644 --- a/cerberusdashboard/api/cerberus.py +++ b/cerberusdashboard/api/cerberus.py @@ -19,7 +19,13 @@ import logging from cerberusclient import client as cerberus_client from horizon.utils.memoized import memoized # noqa from openstack_dashboard.api import base -from sticksclient import client as sticks_client +try: + from sticksclient import client as sticks_client + from sticksclient.common import exceptions as sticks_exc +except ImportError: + sticks_exc = None + sticks_client = None + pass from cerberusdashboard.utils import importutils @@ -130,3 +136,16 @@ def security_alarm_put_ticket_id(request, sa_id, ticket_id): def ticket_create(request, data): """Create a ticket from a security report.""" return sticksclient(request).tickets.create(data) + + +def is_sticks_available(request): + """Create a ticket from a security report.""" + if sticks_client is None: + LOG.exception("No module named sticksclient") + return False + try: + return isinstance(sticksclient(request).tickets.list( + data={'project': request.user.tenant_id}), list) + except sticks_exc.CommunicationError as e: + LOG.exception(e) + return False diff --git a/cerberusdashboard/exceptions.py b/cerberusdashboard/exceptions.py index 6d30602..ec9835c 100644 --- a/cerberusdashboard/exceptions.py +++ b/cerberusdashboard/exceptions.py @@ -15,9 +15,13 @@ # from cerberusclient.common import exceptions as cerberusclient -from sticksclient.common import exceptions as sticksclient +try: + from sticksclient.common import exceptions as sticksclient + # HTTPInternalServerError is thrown by Redmine when project does not exist + # This error may change in the future (refer to sticks client) + RECOVERABLE = (sticksclient.HTTPInternalServerError,) +except ImportError: + RECOVERABLE = () + pass NOT_FOUND = (cerberusclient.HTTPNotFound,) -# HTTPInternalServerError is thrown by Redmine when project does not exist -# This error may change in the future (refer to sticks client) -RECOVERABLE = (sticksclient.HTTPInternalServerError,) diff --git a/cerberusdashboard/security_alarms/tables.py b/cerberusdashboard/security_alarms/tables.py index 9713b5e..85c7c99 100644 --- a/cerberusdashboard/security_alarms/tables.py +++ b/cerberusdashboard/security_alarms/tables.py @@ -52,7 +52,8 @@ class CreateTicket(tables.BatchAction): def allowed(self, request, alarm=None): """Allow terminate action if instance not currently being deleted.""" - return not(is_associated(alarm)) + return not(is_associated(alarm)) \ + and api.cerberus.is_sticks_available(request) def action(self, request, alarm_id): alarm = api.cerberus.security_alarm_get(request, alarm_id) diff --git a/cerberusdashboard/security_reports/tables.py b/cerberusdashboard/security_reports/tables.py index 37eb46a..6a2997a 100644 --- a/cerberusdashboard/security_reports/tables.py +++ b/cerberusdashboard/security_reports/tables.py @@ -53,7 +53,8 @@ class CreateTicket(tables.BatchAction): def allowed(self, request, report=None): """Allow terminate action if instance not currently being deleted.""" - return not(is_associated(report)) + return not(is_associated(report)) \ + and api.cerberus.is_sticks_available(request) def action(self, request, report_id): report = api.cerberus.security_report_get(request, report_id) diff --git a/setup.cfg b/setup.cfg index 374b50c..82d6692 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,6 @@ summary = Dashboard for Openstack Cerberus description-file = README.rst author = OpenStack -version = 1.2-1 author-email = openstack-dev@lists.openstack.org home-page = http://www.openstack.org/ classifier =