Horizon plugin for karbor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (c) 2016 Huawei, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. from django.utils.translation import ugettext_lazy as _
  15. from horizon import exceptions
  16. from horizon import tables as horizon_tables
  17. from karbor_dashboard.api import karbor as karborclient
  18. from karbor_dashboard.restores import tables
  19. class IndexView(horizon_tables.DataTableView):
  20. table_class = tables.RestoresTable
  21. template_name = 'restores/index.html'
  22. page_title = _("Restores")
  23. def has_prev_data(self, table):
  24. return self._prev
  25. def has_more_data(self, table):
  26. return self._more
  27. def get_data(self):
  28. request = self.request
  29. prev_marker = request.GET.get(
  30. tables.RestoresTable._meta.prev_pagination_param, None)
  31. if prev_marker is not None:
  32. marker = prev_marker
  33. else:
  34. marker = request.GET.get(
  35. tables.RestoresTable._meta.pagination_param, None)
  36. reversed_order = prev_marker is not None
  37. restores = []
  38. try:
  39. restores, self._more, self._prev = \
  40. karborclient.restore_list_paged(
  41. self.request,
  42. marker=marker,
  43. paginate=True,
  44. sort_dir='asc',
  45. sort_key='id',
  46. reversed_order=reversed_order)
  47. for restore in restores:
  48. checkpoint = karborclient.checkpoint_get(
  49. self.request,
  50. restore.provider_id,
  51. restore.checkpoint_id)
  52. provider = karborclient.provider_get(self.request,
  53. restore.provider_id)
  54. setattr(restore, "name", checkpoint.protection_plan["name"])
  55. setattr(restore, "provider_name", provider.name)
  56. except Exception:
  57. self._prev = False
  58. self._more = False
  59. exceptions.handle(self.request,
  60. _('Unable to retrieve restore list.'))
  61. return restores