Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / management / commands / flavor-list.py @ 291c782f

History | View | Annotate | Download (2.3 kB)

1 b0e7f310 Christos Stavrakakis
# Copyright 2012-2013 GRNET S.A. All rights reserved.
2 76f5441f Giorgos Verigakis
#
3 76f5441f Giorgos Verigakis
# Redistribution and use in source and binary forms, with or
4 76f5441f Giorgos Verigakis
# without modification, are permitted provided that the following
5 76f5441f Giorgos Verigakis
# conditions are met:
6 76f5441f Giorgos Verigakis
#
7 76f5441f Giorgos Verigakis
#   1. Redistributions of source code must retain the above
8 76f5441f Giorgos Verigakis
#      copyright notice, this list of conditions and the following
9 76f5441f Giorgos Verigakis
#      disclaimer.
10 76f5441f Giorgos Verigakis
#
11 76f5441f Giorgos Verigakis
#   2. Redistributions in binary form must reproduce the above
12 76f5441f Giorgos Verigakis
#      copyright notice, this list of conditions and the following
13 76f5441f Giorgos Verigakis
#      disclaimer in the documentation and/or other materials
14 76f5441f Giorgos Verigakis
#      provided with the distribution.
15 76f5441f Giorgos Verigakis
#
16 76f5441f Giorgos Verigakis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 76f5441f Giorgos Verigakis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 76f5441f Giorgos Verigakis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 76f5441f Giorgos Verigakis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 76f5441f Giorgos Verigakis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 76f5441f Giorgos Verigakis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 76f5441f Giorgos Verigakis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 76f5441f Giorgos Verigakis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 76f5441f Giorgos Verigakis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 76f5441f Giorgos Verigakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 76f5441f Giorgos Verigakis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 76f5441f Giorgos Verigakis
# POSSIBILITY OF SUCH DAMAGE.
28 76f5441f Giorgos Verigakis
#
29 76f5441f Giorgos Verigakis
# The views and conclusions contained in the software and
30 76f5441f Giorgos Verigakis
# documentation are those of the authors and should not be
31 76f5441f Giorgos Verigakis
# interpreted as representing official policies, either expressed
32 76f5441f Giorgos Verigakis
# or implied, of GRNET S.A.
33 76f5441f Giorgos Verigakis
34 b0e7f310 Christos Stavrakakis
from synnefo.webproject.management.commands import ListCommand
35 b0e7f310 Christos Stavrakakis
from synnefo.db.models import Flavor, VirtualMachine
36 76f5441f Giorgos Verigakis
37 76f5441f Giorgos Verigakis
38 b0e7f310 Christos Stavrakakis
class Command(ListCommand):
39 b0e7f310 Christos Stavrakakis
    help = "List available server flavors"
40 76f5441f Giorgos Verigakis
41 b0e7f310 Christos Stavrakakis
    object_class = Flavor
42 b0e7f310 Christos Stavrakakis
    deleted_field = "deleted"
43 bad9404c Christos Stavrakakis
44 b0e7f310 Christos Stavrakakis
    def get_vms(flavor):
45 b0e7f310 Christos Stavrakakis
        return VirtualMachine.objects.filter(flavor=flavor, deleted=False)\
46 b0e7f310 Christos Stavrakakis
                                     .count()
47 76f5441f Giorgos Verigakis
48 b0e7f310 Christos Stavrakakis
    FIELDS = {
49 b0e7f310 Christos Stavrakakis
        "id": ("id", "Flavor's unique ID"),
50 b0e7f310 Christos Stavrakakis
        "name": ("name", "Flavor's unique name"),
51 b0e7f310 Christos Stavrakakis
        "cpu": ("cpu", "Number of CPUs"),
52 b0e7f310 Christos Stavrakakis
        "ram": ("ram", "Size(MB) of RAM"),
53 b0e7f310 Christos Stavrakakis
        "disk": ("disk", "Size(GB) of disk"),
54 b0e7f310 Christos Stavrakakis
        "template": ("disk_template", "Disk template"),
55 b0e7f310 Christos Stavrakakis
        "vms": (get_vms, "Number of active servers using this flavor")
56 b0e7f310 Christos Stavrakakis
    }
57 af88de58 Christos Stavrakakis
58 b0e7f310 Christos Stavrakakis
    fields = ["id", "name", "cpu", "ram", "disk", "template", "vms"]