1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
7
# Copyright 2012 Nebula, Inc.
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
13
# http://www.apache.org/licenses/LICENSE-2.0
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
23
from django.core.urlresolvers import reverse_lazy
24
from django.utils.translation import ugettext_lazy as _
26
from horizon import exceptions
27
from horizon import forms
28
from horizon import tables
30
from openstack_dashboard import api
31
from .forms import CreateFlavor, EditFlavor
32
from .tables import FlavorsTable
35
LOG = logging.getLogger(__name__)
38
class IndexView(tables.DataTableView):
39
table_class = FlavorsTable
40
template_name = 'admin/flavors/index.html'
43
request = self.request
46
flavors = api.flavor_list(request)
48
exceptions.handle(request,
49
_('Unable to retrieve flavor list.'))
50
# Sort flavors by size
51
flavors.sort(key=lambda f: (f.vcpus, f.ram, f.disk))
55
class CreateView(forms.ModalFormView):
56
form_class = CreateFlavor
57
template_name = 'admin/flavors/create.html'
58
success_url = reverse_lazy('horizon:admin:flavors:index')
61
class EditView(forms.ModalFormView):
62
form_class = EditFlavor
63
template_name = 'admin/flavors/edit.html'
64
success_url = reverse_lazy('horizon:admin:flavors:index')
66
def get_context_data(self, **kwargs):
67
context = super(EditView, self).get_context_data(**kwargs)
68
context['flavor_id'] = self.kwargs['id']
71
def get_initial(self):
73
flavor = api.nova.flavor_get(self.request, self.kwargs['id'])
75
exceptions.handle(self.request,
76
_("Unable to retrieve flavor data."))
77
return {'flavor_id': flavor.id,
79
'vcpus': flavor.vcpus,
80
'memory_mb': flavor.ram,
81
'disk_gb': flavor.disk,
82
'eph_gb': getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral', None)}