Revision cf1984d8 snf-cyclades-app/synnefo/api/management/commands/flavor-create.py
b/snf-cyclades-app/synnefo/api/management/commands/flavor-create.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from itertools import product |
35 |
from optparse import make_option |
|
35 | 36 |
|
36 | 37 |
from django.core.management.base import BaseCommand, CommandError |
37 | 38 |
|
... | ... | |
40 | 41 |
|
41 | 42 |
class Command(BaseCommand): |
42 | 43 |
output_transaction = True |
44 |
|
|
45 |
option_list = BaseCommand.option_list + ( |
|
46 |
make_option("-n", "--dry-run", dest="dry_run", action="store_true"), |
|
47 |
) |
|
43 | 48 |
args = "<cpu>[,<cpu>,...] " \ |
44 | 49 |
"<ram>[,<ram>,...] " \ |
45 | 50 |
"<disk>[,<disk>,...] " \ |
... | ... | |
66 | 71 |
raise CommandError("Invalid values") |
67 | 72 |
|
68 | 73 |
for cpu, ram, disk, template in flavors: |
69 |
flavor = Flavor.objects.create(cpu=cpu, ram=ram, disk=disk, |
|
70 |
disk_template=template) |
|
71 |
self.stdout.write("Created flavor %s\n" % (flavor.name,)) |
|
74 |
if options["dry_run"]: |
|
75 |
flavor = Flavor(cpu=cpu, ram=ram, disk=disk, |
|
76 |
disk_template=template) |
|
77 |
self.stdout.write("Creating flavor '%s'\n" % (flavor.name,)) |
|
78 |
else: |
|
79 |
flavor, created = \ |
|
80 |
Flavor.objects.get_or_create(cpu=cpu, ram=ram, disk=disk, |
|
81 |
disk_template=template) |
|
82 |
if created: |
|
83 |
self.stdout.write("Created flavor '%s'\n" % (flavor.name,)) |
|
84 |
else: |
|
85 |
self.stdout.write("Flavor '%s' already exists\n" |
|
86 |
% flavor.name) |
Also available in: Unified diff