Commit 817dbd34 authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Kostas Papadimitriou
Browse files

Add --dry-run option to flavor-create

Add --dry-run option to flavor-create management command. Also, do not
crash if flavor already exists.

Refs #3366
parent 64febc4d
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
from itertools import product
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
......@@ -40,6 +41,10 @@ from synnefo.db.models import Flavor
class Command(BaseCommand):
output_transaction = True
option_list = BaseCommand.option_list + (
make_option("-n", "--dry-run", dest="dry_run", action="store_true"),
)
args = "<cpu>[,<cpu>,...] " \
"<ram>[,<ram>,...] " \
"<disk>[,<disk>,...] " \
......@@ -64,6 +69,16 @@ class Command(BaseCommand):
raise CommandError("Invalid values")
for cpu, ram, disk, template in flavors:
flavor = Flavor.objects.create(cpu=cpu, ram=ram, disk=disk,
disk_template=template)
self.stdout.write("Created flavor %s\n" % (flavor.name,))
if options["dry_run"]:
flavor = Flavor(cpu=cpu, ram=ram, disk=disk,
disk_template=template)
self.stdout.write("Creating flavor '%s'\n" % (flavor.name,))
else:
flavor, created = \
Flavor.objects.get_or_create(cpu=cpu, ram=ram, disk=disk,
disk_template=template)
if created:
self.stdout.write("Created flavor '%s'\n" % (flavor.name,))
else:
self.stdout.write("Flavor '%s' already exists\n"
% flavor.name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment