Create Resource-management folder.

This Commit is to create Resource-management folder and this is a
base commit for resource-management panel and dashboard related to
resource-management.This commit supports "sync list","sync show"
and "sync delete" features in kingbird-dashboard.

Change-Id: I86f2d73bc416798e5c249ddb9b996c4df71534d1
This commit is contained in:
Goutham Pratapa 2018-03-26 07:58:29 +05:30 committed by GouthamPratapa
parent d5e3a8399a
commit 2932de7186
8 changed files with 260 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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,)

View File

@ -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 %}

View File

@ -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 %}

View File

@ -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<job_id>[^/]+)/%s$'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(SYNCJOB % 'detail', views.DetailView.as_view(), name='detail'),
]

View File

@ -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)