diff options
author | Tzu-Mainn Chen <tzumainn@redhat.com> | 2014-04-03 18:51:41 +0200 |
---|---|---|
committer | Tzu-Mainn Chen <tzumainn@redhat.com> | 2014-04-04 13:42:40 +0200 |
commit | d010384fd3101ecea4794889e8ee79defb1df80d (patch) | |
tree | e8c08ba571d543c664431e8c2b2ec09738559f4f /tuskar_ui/infrastructure/flavors/views.py | |
parent | 1126213b1a0b8b9eb3de6e1d8f74246e7cd78227 (diff) | |
download | tuskar-ui-d010384fd3101ecea4794889e8ee79defb1df80d.tar.gz |
Rename node profile to flavor
Implements: blueprint rename-node-profiles-to-flavors
Change-Id: Ic530041615d04878ff9586038abaf9e8dc7f707a
Diffstat (limited to 'tuskar_ui/infrastructure/flavors/views.py')
-rw-r--r-- | tuskar_ui/infrastructure/flavors/views.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/tuskar_ui/infrastructure/flavors/views.py b/tuskar_ui/infrastructure/flavors/views.py new file mode 100644 index 00000000..ed8dc3d5 --- /dev/null +++ b/tuskar_ui/infrastructure/flavors/views.py @@ -0,0 +1,87 @@ +# -*- coding: utf8 -*- +# +# 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_lazy +from django.utils.translation import ugettext_lazy as _ + +import horizon.exceptions +import horizon.tables +import horizon.tabs +import horizon.workflows + +import tuskar_ui.api +from tuskar_ui.infrastructure.flavors import tables +from tuskar_ui.infrastructure.flavors import tabs +from tuskar_ui.infrastructure.flavors import workflows + + +def image_get(request, image_id, error_message): + # TODO(dtantsur): there should be generic way to handle exceptions + try: + return tuskar_ui.api.image_get(request, image_id) + except Exception: + horizon.exceptions.handle(request, error_message) + + +class IndexView(horizon.tabs.TabbedTableView): + tab_group_class = tabs.FlavorTabs + template_name = 'infrastructure/flavors/index.html' + + +class CreateView(horizon.workflows.WorkflowView): + workflow_class = workflows.CreateFlavor + template_name = 'infrastructure/flavors/create.html' + + def get_initial(self): + suggestion_id = self.kwargs.get('suggestion_id') + if not suggestion_id: + return super(CreateView, self).get_initial() + node = tuskar_ui.api.Node.get(self.request, suggestion_id) + suggestion = tabs.FlavorSuggestion.from_node(node) + return { + 'name': suggestion.name, + 'vcpus': suggestion.vcpus, + 'memory_mb': suggestion.ram, + 'disk_gb': suggestion.disk, + 'arch': suggestion.cpu_arch, + } + + +class DetailView(horizon.tables.DataTableView): + table_class = tables.FlavorRolesTable + template_name = 'infrastructure/flavors/details.html' + error_redirect = reverse_lazy('horizon:infrastructure:flavors:index') + + def get_context_data(self, **kwargs): + context = super(DetailView, self).get_context_data(**kwargs) + context['flavor'] = tuskar_ui.api.Flavor.get( + self.request, + kwargs.get('flavor_id'), + _error_redirect=self.error_redirect + ) + context['kernel_image'] = image_get( + self.request, + context['flavor'].kernel_image_id, + error_message=_("Cannot get kernel image details") + ) + context['ramdisk_image'] = image_get( + self.request, + context['flavor'].ramdisk_image_id, + error_message=_("Cannot get ramdisk image details") + ) + return context + + def get_data(self): + return [role for role in tuskar_ui.api.OvercloudRole.list(self.request) + if role.flavor_id == str(self.kwargs.get('flavor_id'))] |