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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. try:
  49. checkpoint = karborclient.checkpoint_get(
  50. self.request,
  51. restore.provider_id,
  52. restore.checkpoint_id)
  53. plan_name = checkpoint.protection_plan["name"]
  54. except Exception:
  55. plan_name = "Not Found"
  56. provider = karborclient.provider_get(self.request,
  57. restore.provider_id)
  58. setattr(restore, "name", plan_name)
  59. setattr(restore, "provider_name", provider.name)
  60. except Exception:
  61. self._prev = False
  62. self._more = False
  63. exceptions.handle(self.request,
  64. _('Unable to retrieve restore list.'))
  65. return restores