diff --git a/kingbird_dashboard/api/client.py b/kingbird_dashboard/api/client.py index d6b3f16..c8fac77 100644 --- a/kingbird_dashboard/api/client.py +++ b/kingbird_dashboard/api/client.py @@ -22,6 +22,10 @@ from kingbirdclient.api import client as kb_client SERVICE_TYPE = 'synchronization' +NOVA_API_VERSION = "2.37" + +GLANCE_API_VERSION = "2" + @memoized.memoized def kingbird_dashboardclient(request): @@ -75,3 +79,21 @@ def detail_quota(request, target_tenant_id): quota_detail(target_tenant_id) except kingbirdclient.exceptions.APIException: raise + + +def sync_list(request, action=None): + """List the sync jobs.""" + return kingbird_dashboardclient(request).sync_manager.\ + list_sync_jobs(action) + + +def sync_job_detail(request, job_id): + """Detail information of sync job.""" + return kingbird_dashboardclient(request).sync_manager.\ + sync_job_detail(job_id) + + +def sync_delete(request, job_id): + """Delete sync jobs from database.""" + return kingbird_dashboardclient(request).sync_manager.\ + delete_sync_job(job_id) diff --git a/kingbird_dashboard/resource_management/__init__.py b/kingbird_dashboard/resource_management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kingbird_dashboard/resource_management/panel.py b/kingbird_dashboard/resource_management/panel.py new file mode 100644 index 0000000..ba7fe3e --- /dev/null +++ b/kingbird_dashboard/resource_management/panel.py @@ -0,0 +1,30 @@ +# Copyright 2012 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Copyright 2012 Nebula, Inc. +# +# 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 kingbird_dashboard import dashboard + + +class ResourceManagement(horizon.Panel): + name = _("Resource Management") + slug = 'resource_management' + +dashboard.Kingbird.register(ResourceManagement) diff --git a/kingbird_dashboard/resource_management/tables.py b/kingbird_dashboard/resource_management/tables.py new file mode 100644 index 0000000..bd234f5 --- /dev/null +++ b/kingbird_dashboard/resource_management/tables.py @@ -0,0 +1,115 @@ +# 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 django.utils.translation import ungettext_lazy + +from horizon import tables + +from kingbird_dashboard.api import client as kb_client + + +class DeleteSyncJob(tables.DeleteAction): + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Sync Job", + u"Delete Sync Jobs", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Sync Job", + u"Deleted Sync Jobs", + count + ) + + def delete(self, request, job_id): + kb_client.sync_delete(request, job_id) + + +class DetailSyncJobTable(tables.DataTable): + + resource_sync_id = tables.Column( + "id", + verbose_name=_("Resource Sync Identifier"), + ) + resource_name = tables.Column( + "resource_name", + verbose_name=_("Resource Identifier") + ) + source_region = tables.Column( + "source_region", + verbose_name=_("Source Region") + ) + target_region = tables.Column( + "target_region", + verbose_name=_("Target Region") + ) + resource_type = tables.Column( + "resource_type", + verbose_name=_("Resource Type") + ) + status = tables.Column( + "status", + verbose_name=_("Status") + ) + created_at = tables.Column( + "created_at", + verbose_name=_("Created") + ) + updated_at = tables.Column( + "updated_at", + verbose_name=_("Updated") + ) + + def get_object_id(self, datum): + return datum.id + + class Meta(object): + name = "job_set" + verbose_name = _("Job Details") + + +class ResourceSyncTable(tables.DataTable): + + id = tables.Column( + "id", + verbose_name=_("ID"), + link="horizon:kingbird:resource_management:detail" + ) + sync_status = tables.Column( + "status", + verbose_name=_("Status") + ) + created_at = tables.Column( + "created_at", + verbose_name=_("Created") + ) + updated_at = tables.Column( + "updated_at", + verbose_name=_("Updated") + ) + + def get_object_display(self, datum): + return datum.id + + class Meta(object): + name = "job_set" + verbose_name = _("Resource Management") + table_actions = ( + DeleteSyncJob, + ) + row_actions = (DeleteSyncJob,) diff --git a/kingbird_dashboard/resource_management/templates/resource_management/detail.html b/kingbird_dashboard/resource_management/templates/resource_management/detail.html new file mode 100644 index 0000000..4751533 --- /dev/null +++ b/kingbird_dashboard/resource_management/templates/resource_management/detail.html @@ -0,0 +1,7 @@ +{% extends 'kingbird/default/table.html' %} +{% load i18n %} +{% block title %}{% trans "Job Details" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Job Details") %} +{% endblock page_header %} diff --git a/kingbird_dashboard/resource_management/templates/resource_management/index.html b/kingbird_dashboard/resource_management/templates/resource_management/index.html new file mode 100644 index 0000000..4892fab --- /dev/null +++ b/kingbird_dashboard/resource_management/templates/resource_management/index.html @@ -0,0 +1,7 @@ +{% extends 'kingbird/default/table.html' %} +{% load i18n %} +{% block title %}{% trans "Resource Management" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Resource Management") %} +{% endblock page_header %} diff --git a/kingbird_dashboard/resource_management/urls.py b/kingbird_dashboard/resource_management/urls.py new file mode 100644 index 0000000..e1de17f --- /dev/null +++ b/kingbird_dashboard/resource_management/urls.py @@ -0,0 +1,28 @@ +# Copyright 2012 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Copyright 2012 Nebula, Inc. +# +# 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 kingbird_dashboard.resource_management import views + +SYNCJOB = r'^(?P[^/]+)/%s$' + +urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='index'), + url(SYNCJOB % 'detail', views.DetailView.as_view(), name='detail'), +] diff --git a/kingbird_dashboard/resource_management/views.py b/kingbird_dashboard/resource_management/views.py new file mode 100644 index 0000000..9b69d1a --- /dev/null +++ b/kingbird_dashboard/resource_management/views.py @@ -0,0 +1,51 @@ +# Copyright 2017 - StackStorm, Inc. +# +# 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.core.urlresolvers import reverse + +from horizon import exceptions +from horizon import tables + + +from kingbird_dashboard.api import client as kb_client +from kingbird_dashboard.resource_management import tables as kb_tables + + +class IndexView(tables.DataTableView): + table_id = "sync_jobs" + table_class = kb_tables.ResourceSyncTable + template_name = 'kingbird/resource_management/index.html' + + def get_data(self): + try: + response = kb_client.sync_list(self.request) + return response + except Exception: + pass + + +class DetailView(tables.DataTableView): + table_id = "job_detail" + table_class = kb_tables.DetailSyncJobTable + template_name = 'kingbird/resource_management/detail.html' + + def get_data(self, **kwargs): + try: + job_id = self.kwargs['job_id'] + job = kb_client.sync_job_detail(self.request, job_id) + return job + except Exception: + msg = _('Unable to get job_details "%s".') % job_id + redirect = reverse('horizon:kingbird:resource_management:index') + exceptions.handle(self.request, msg, redirect=redirect)