Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / management / commands / flavor-modify.py @ eec66d97

History | View | Annotate | Download (2.6 kB)

1 76f5441f Giorgos Verigakis
# Copyright 2012 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 76f5441f Giorgos Verigakis
from optparse import make_option
35 76f5441f Giorgos Verigakis
36 76f5441f Giorgos Verigakis
from django.core.management.base import BaseCommand, CommandError
37 b84ed662 Christos Stavrakakis
from synnefo.management.common import get_flavor
38 eec66d97 Christos Stavrakakis
from synnefo.webproject.management.utils import parse_bool
39 76f5441f Giorgos Verigakis
40 76f5441f Giorgos Verigakis
41 92f20714 Christos Stavrakakis
from logging import getLogger
42 92f20714 Christos Stavrakakis
log = getLogger(__name__)
43 92f20714 Christos Stavrakakis
44 92f20714 Christos Stavrakakis
45 76f5441f Giorgos Verigakis
class Command(BaseCommand):
46 76f5441f Giorgos Verigakis
    args = "<flavor id>"
47 76f5441f Giorgos Verigakis
    help = "Modify a flavor"
48 b84ed662 Christos Stavrakakis
49 76f5441f Giorgos Verigakis
    option_list = BaseCommand.option_list + (
50 9621c777 Christos Stavrakakis
        make_option(
51 92f20714 Christos Stavrakakis
            "--deleted",
52 92f20714 Christos Stavrakakis
            dest="deleted",
53 92f20714 Christos Stavrakakis
            metavar="True|False",
54 92f20714 Christos Stavrakakis
            choices=["True", "False"],
55 92f20714 Christos Stavrakakis
            default=None,
56 92f20714 Christos Stavrakakis
            help="Mark/unmark a flavor as deleted"),
57 9621c777 Christos Stavrakakis
    )
58 b84ed662 Christos Stavrakakis
59 76f5441f Giorgos Verigakis
    def handle(self, *args, **options):
60 76f5441f Giorgos Verigakis
        if len(args) != 1:
61 76f5441f Giorgos Verigakis
            raise CommandError("Please provide a flavor ID")
62 b84ed662 Christos Stavrakakis
63 b84ed662 Christos Stavrakakis
        flavor = get_flavor(args[0])
64 b84ed662 Christos Stavrakakis
65 92f20714 Christos Stavrakakis
        deleted = options['deleted']
66 92f20714 Christos Stavrakakis
        if deleted:
67 eec66d97 Christos Stavrakakis
            deleted = parse_bool(deleted)
68 92f20714 Christos Stavrakakis
            log.info("Marking flavor %s as deleted=%s", flavor, deleted)
69 92f20714 Christos Stavrakakis
            flavor.deleted = deleted
70 92f20714 Christos Stavrakakis
            flavor.save()
71 92f20714 Christos Stavrakakis
        else:
72 92f20714 Christos Stavrakakis
            log.info("Nothing changed!")