Revision d09a166e

b/snf-cyclades-app/synnefo/api/management/commands/network-create.py
35 35

  
36 36
from django.core.management.base import BaseCommand, CommandError
37 37
from synnefo.management.common import validate_network_info, get_backend
38
from synnefo.management.common import pprint_table
38 39

  
39 40
from synnefo.db.models import Network
40 41
from synnefo.logic.backend import create_network
......
51 52

  
52 53
    option_list = BaseCommand.option_list + (
53 54
        make_option(
55
            "-n",
56
            "--dry-run",
57
            dest="dry_run",
58
            default=False,
59
            action="store_true"),
60
        make_option(
54 61
            '--name',
55 62
            dest='name',
56 63
            help="Name of network"),
......
129 136
        if args:
130 137
            raise CommandError("Command doesn't accept any arguments")
131 138

  
139
        dry_run = options["dry_run"]
132 140
        name = options['name']
133 141
        subnet = options['subnet']
134 142
        backend_id = options['backend_id']
......
170 178
        if not link or not mode:
171 179
            raise CommandError("Can not create network."
172 180
                               " No connectivity link or mode")
173

  
174
        network = Network.objects.create(name=name,
175
                                         userid=options['owner'],
176
                                         subnet=subnet,
177
                                         gateway=gateway,
178
                                         gateway6=gateway6,
179
                                         subnet6=subnet6,
180
                                         dhcp=options['dhcp'],
181
                                         flavor=flavor,
182
                                         public=public,
183
                                         mode=mode,
184
                                         link=link,
185
                                         mac_prefix=mac_prefix,
186
                                         tags=tags,
187
                                         state='PENDING')
181
        netinfo = {
182
           "name": name,
183
           "userid": options["owner"],
184
           "subnet": subnet,
185
           "gateway": gateway,
186
           "gateway6": gateway6,
187
           "subnet6": subnet6,
188
           "dhcp": options["dhcp"],
189
           "flavor": flavor,
190
           "public": public,
191
           "mode": mode,
192
           "link": link,
193
           "mac_prefix": mac_prefix,
194
           "tags": tags,
195
           "state": "PENDING"}
196

  
197
        if dry_run:
198
            self.stdout.write("Creating network:\n")
199
            pprint_table(self.stdout, tuple(netinfo.items()))
200
            return
201

  
202
        network = Network.objects.create(**netinfo)
188 203

  
189 204
        if public:
190 205
            # Create BackendNetwork only to the specified Backend

Also available in: Unified diff