Revision b47f167a snf-cyclades-app/synnefo/api/management/commands/network-create.py

b/snf-cyclades-app/synnefo/api/management/commands/network-create.py
37 37
from synnefo.management.common import get_backend, convert_api_faults
38 38
from synnefo.webproject.management.utils import parse_bool
39 39

  
40
from synnefo.db.models import Network, Backend
40
from synnefo.db.models import Network
41 41
from synnefo.logic import networks
42
from synnefo.logic.backend import create_network
43 42

  
44 43
NETWORK_FLAVORS = Network.FLAVORS.keys()
45 44

  
......
177 176
            try:
178 177
                backend_id = int(backend_id)
179 178
            except ValueError:
180
                raise CommandError("Invalid backend-id: %s", backend_id)
179
                raise CommandError("Invalid backend-id: %s" % backend_id)
181 180
            backend = get_backend(backend_id)
181
        else:
182
            backend = None
182 183

  
183 184
        network = networks.create(user_id=userid, name=name, flavor=flavor,
184 185
                                  subnet=subnet, gateway=gateway,
185 186
                                  subnet6=subnet6, gateway6=gateway6,
186 187
                                  dhcp=dhcp, public=public, mode=mode,
187 188
                                  link=link, mac_prefix=mac_prefix, tags=tags,
188
                                  floating_ip_pool=floating_ip_pool)
189

  
190
        self.stdout.write("Successfully created network '%s' in DB.\n",
191
                          network)
192
        # Create network in Backend if needed
193
        if floating_ip_pool:
194
            backends = Backend.objects.filter(offline=False)
195
        elif backend_id:
196
            backends = [backend]
197
        else:
198
            backends = []
199

  
200
        for backend in backends:
201
            self.stdout.write("Creating network in backend '%s'\n", backend)
202
            network.create_backend_network(backend)
203
            jobs = create_network(network=network, backend=backend,
204
                                  connect=True)
205
            self.stdout.write("Successfully issued jobs: %s\n" %
206
                              ",".join(map(str, jobs)))
189
                                  floating_ip_pool=floating_ip_pool,
190
                                  backend=backend, lazy_create=False)
191

  
192
        self.stdout.write("Created network '%s' in DB.\n" % network)

Also available in: Unified diff