OpenStack Dashboard (Horizon)
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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # vim: tabstop=4 shiftwidth=4 softtabstop=4
  2. # Copyright 2012 United States Government as represented by the
  3. # Administrator of the National Aeronautics and Space Administration.
  4. # All Rights Reserved.
  5. #
  6. # Copyright 2012 Nebula, Inc.
  7. # Copyright 2012 OpenStack LLC
  8. #
  9. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  10. # not use this file except in compliance with the License. You may obtain
  11. # a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing, software
  16. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  18. # License for the specific language governing permissions and limitations
  19. # under the License.
  20. """
  21. Views for Instances and Volumes.
  22. """
  23. import logging
  24. from django.contrib import messages
  25. from django.utils.translation import ugettext as _
  26. from django.utils.datastructures import SortedDict
  27. from novaclient import exceptions as novaclient_exceptions
  28. from horizon import api
  29. from horizon import exceptions
  30. from horizon import tables
  31. from .instances.tables import InstancesTable
  32. from .volumes.tables import VolumesTable
  33. LOG = logging.getLogger(__name__)
  34. class IndexView(tables.MultiTableView):
  35. table_classes = (InstancesTable, VolumesTable)
  36. template_name = 'nova/instances_and_volumes/index.html'
  37. def get_instances_data(self):
  38. # Gather our instances
  39. try:
  40. instances = api.server_list(self.request)
  41. except:
  42. instances = []
  43. exceptions.handle(self.request, _('Unable to retrieve instances.'))
  44. # Gather our flavors and correlate our instances to them
  45. if instances:
  46. try:
  47. flavors = api.flavor_list(self.request)
  48. full_flavors = SortedDict([(str(flavor.id), flavor) for \
  49. flavor in flavors])
  50. for instance in instances:
  51. instance.full_flavor = full_flavors[instance.flavor["id"]]
  52. except:
  53. msg = _('Unable to retrieve instance size information.')
  54. exceptions.handle(self.request, msg)
  55. return instances
  56. def get_volumes_data(self):
  57. # Gather our volumes
  58. try:
  59. volumes = api.volume_list(self.request)
  60. except novaclient_exceptions.ClientException, e:
  61. volumes = []
  62. LOG.exception("ClientException in volume index")
  63. messages.error(self.request, _('Unable to fetch volumes: %s') % e)
  64. return volumes