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.contrib import messages
24
from django.utils.translation import ugettext as _
25
from novaclient import exceptions as api_exceptions
27
from horizon import api
28
from horizon import forms
29
from horizon import tables
30
from .forms import CreateFlavor
31
from .tables import FlavorsTable
34
LOG = logging.getLogger(__name__)
37
class IndexView(tables.DataTableView):
38
table_class = FlavorsTable
39
template_name = 'syspanel/flavors/index.html'
42
request = self.request
45
flavors = api.flavor_list(request)
46
except api_exceptions.Unauthorized, e:
47
LOG.exception('Unauthorized attempt to access flavor list.')
48
messages.error(request, _('Unauthorized.'))
50
LOG.exception('Exception while fetching usage info')
51
if not hasattr(e, 'message'):
53
messages.error(request, _('Unable to get flavor list: %s') %
55
flavors.sort(key=lambda x: x.id, reverse=True)
59
class CreateView(forms.ModalFormView):
60
form_class = CreateFlavor
61
template_name = 'syspanel/flavors/create.html'
63
def get_initial(self):
64
# TODO(tres): Get rid of this hacky bit of nonsense after flavors get
65
# converted to nova client.
66
flavors = api.flavor_list(self.request)
67
flavors.sort(key=lambda f: f.id, reverse=True)
68
return {'flavor_id': int(flavors[0].id) + 1}