Commit 9a43e008 authored by Christos Stavrakakis's avatar Christos Stavrakakis
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 f33d68bd
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from itertools import product from itertools import product
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -40,6 +41,10 @@ from synnefo.db.models import Flavor ...@@ -40,6 +41,10 @@ from synnefo.db.models import Flavor
class Command(BaseCommand): class Command(BaseCommand):
output_transaction = True output_transaction = True
option_list = BaseCommand.option_list + (
make_option("-n", "--dry-run", dest="dry_run", action="store_true"),
)
args = "<cpu>[,<cpu>,...] " \ args = "<cpu>[,<cpu>,...] " \
"<ram>[,<ram>,...] " \ "<ram>[,<ram>,...] " \
"<disk>[,<disk>,...] " \ "<disk>[,<disk>,...] " \
...@@ -66,6 +71,16 @@ class Command(BaseCommand): ...@@ -66,6 +71,16 @@ class Command(BaseCommand):
raise CommandError("Invalid values") raise CommandError("Invalid values")
for cpu, ram, disk, template in flavors: for cpu, ram, disk, template in flavors:
flavor = Flavor.objects.create(cpu=cpu, ram=ram, disk=disk, if options["dry_run"]:
disk_template=template) flavor = Flavor(cpu=cpu, ram=ram, disk=disk,
self.stdout.write("Created flavor %s\n" % (flavor.name,)) 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