~ubuntu-branches/ubuntu/raring/horizon/raring

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/admin/flavors/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 08:49:14 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20121123084914-95m0mzmiicdw64ti
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/patches/add_juju_settings_pannel.patch: Disable during
  Grizzly dev. cycle. 

[ Chuck Short ]
* New upstream relase.
* Refreshed patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 United States Government as represented by the
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
# Copyright 2012 Nebula, Inc.
 
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
import logging
 
22
 
 
23
from django.core.urlresolvers import reverse_lazy
 
24
from django.utils.translation import ugettext_lazy as _
 
25
 
 
26
from horizon import exceptions
 
27
from horizon import forms
 
28
from horizon import tables
 
29
 
 
30
from openstack_dashboard import api
 
31
from .forms import CreateFlavor, EditFlavor
 
32
from .tables import FlavorsTable
 
33
 
 
34
 
 
35
LOG = logging.getLogger(__name__)
 
36
 
 
37
 
 
38
class IndexView(tables.DataTableView):
 
39
    table_class = FlavorsTable
 
40
    template_name = 'admin/flavors/index.html'
 
41
 
 
42
    def get_data(self):
 
43
        request = self.request
 
44
        flavors = []
 
45
        try:
 
46
            flavors = api.flavor_list(request)
 
47
        except:
 
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))
 
52
        return flavors
 
53
 
 
54
 
 
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')
 
59
 
 
60
 
 
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')
 
65
 
 
66
    def get_context_data(self, **kwargs):
 
67
        context = super(EditView, self).get_context_data(**kwargs)
 
68
        context['flavor_id'] = self.kwargs['id']
 
69
        return context
 
70
 
 
71
    def get_initial(self):
 
72
        try:
 
73
            flavor = api.nova.flavor_get(self.request, self.kwargs['id'])
 
74
        except:
 
75
            exceptions.handle(self.request,
 
76
                              _("Unable to retrieve flavor data."))
 
77
        return {'flavor_id': flavor.id,
 
78
                'name': flavor.name,
 
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)}