Revision b84ed662 snf-cyclades-app/synnefo/api/management/commands/flavor-modify.py
b/snf-cyclades-app/synnefo/api/management/commands/flavor-modify.py | ||
---|---|---|
34 | 34 |
from optparse import make_option |
35 | 35 |
|
36 | 36 |
from django.core.management.base import BaseCommand, CommandError |
37 |
from synnefo.management.common import get_flavor |
|
37 | 38 |
|
38 |
from synnefo.db.models import Flavor |
|
39 | 39 |
|
40 | 40 |
|
41 | 41 |
class Command(BaseCommand): |
42 | 42 |
args = "<flavor id>" |
43 | 43 |
help = "Modify a flavor" |
44 |
|
|
44 |
|
|
45 | 45 |
option_list = BaseCommand.option_list + ( |
46 | 46 |
make_option('--set-deleted', |
47 | 47 |
action='store_true', |
... | ... | |
52 | 52 |
dest='undeleted', |
53 | 53 |
help="Mark a server as not deleted"), |
54 | 54 |
) |
55 |
|
|
55 |
|
|
56 | 56 |
def handle(self, *args, **options): |
57 | 57 |
if len(args) != 1: |
58 | 58 |
raise CommandError("Please provide a flavor ID") |
59 |
|
|
60 |
try: |
|
61 |
flavor_id = int(args[0]) |
|
62 |
flavor = Flavor.objects.get(id=flavor_id) |
|
63 |
except (ValueError, Flavor.DoesNotExist): |
|
64 |
raise CommandError("Invalid flavor ID") |
|
65 |
|
|
59 |
|
|
60 |
|
|
61 |
flavor = get_flavor(args[0]) |
|
62 |
|
|
66 | 63 |
if options.get('deleted'): |
67 | 64 |
flavor.deleted = True |
68 | 65 |
elif options.get('undeleted'): |
69 | 66 |
flavor.deleted = False |
70 |
|
|
67 |
|
|
71 | 68 |
flavor.save() |
Also available in: Unified diff