Revision 39a6388d snf-cyclades-app/synnefo/api/management/commands/flavor-create.py

b/snf-cyclades-app/synnefo/api/management/commands/flavor-create.py
37 37

  
38 38
from synnefo.db.models import Flavor
39 39

  
40
from ._common import format_bool, format_date
41

  
42 40

  
43 41
class Command(BaseCommand):
42
    output_transaction = True
44 43
    args = "<cpu>[,<cpu>,...] " \
45 44
           "<ram>[,<ram>,...] " \
46 45
           "<disk>[,<disk>,...] " \
47 46
           "<disk template>[,<disk template>,...]"
48
    help = "Create one or more flavors"
49
    
47
    help = "Create one or more flavors.\n\nThe flavors that will be created are"\
48
           " those belonging to the cartesian product of the arguments"\
49

  
50 50
    def handle(self, *args, **options):
51 51
        if len(args) != 4:
52 52
            raise CommandError("Invalid number of arguments")
53
        
53

  
54 54
        cpus = args[0].split(',')
55 55
        rams = args[1].split(',')
56 56
        disks = args[2].split(',')
57 57
        templates = args[3].split(',')
58
        
58

  
59 59
        flavors = []
60 60
        for cpu, ram, disk, template in product(cpus, rams, disks, templates):
61 61
            try:
62 62
                flavors.append((int(cpu), int(ram), int(disk), template))
63 63
            except ValueError:
64 64
                raise CommandError("Invalid values")
65
        
65

  
66 66
        for cpu, ram, disk, template in flavors:
67 67
            flavor = Flavor.objects.create(cpu=cpu, ram=ram, disk=disk,
68 68
                                           disk_template=template)

Also available in: Unified diff