Revision 64cdd31b

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.webproject.management.utils import pprint_table
38
from synnefo.webproject.management.utils import pprint_table, parse_bool
39 39

  
40 40
from synnefo import quotas
41
from synnefo.db.models import Network
41
from synnefo.db.models import Network, Backend
42 42
from synnefo.db.utils import validate_mac, InvalidMacAddress
43 43
from synnefo.logic.backend import create_network
44 44
from synnefo.api.util import values_from_flavor
......
127 127
            default=None,
128 128
            help='The tags of the Network (comma separated strings)'),
129 129
        make_option(
130
            '--floating-ip-pool',
131
            dest='floating_ip_pool',
132
            default="False",
133
            choices=["True", "False"],
134
            metavar="True|False",
135
            help="Use the network as a Floating IP pool. Floating IP pools"
136
                 " are created in all available backends."),
137
        make_option(
130 138
            '--backend-id',
131 139
            dest='backend_id',
132 140
            default=None,
......
149 157
        mac_prefix = options['mac_prefix']
150 158
        tags = options['tags']
151 159
        userid = options["owner"]
160
        floating_ip_pool = parse_bool(options["floating_ip_pool"])
152 161

  
153 162
        if not name:
154 163
            raise CommandError("Name is required")
......
156 165
            raise CommandError("Subnet is required")
157 166
        if not flavor:
158 167
            raise CommandError("Flavor is required")
159
        if public and not backend_id:
168
        if public and not (backend_id or floating_ip_pool):
160 169
            raise CommandError("backend-id is required")
161 170
        if not userid and not public:
162 171
            raise CommandError("'owner' is required for private networks")
......
198 207
           "link": link,
199 208
           "mac_prefix": mac_prefix,
200 209
           "tags": tags,
210
           "floating_ip_pool": floating_ip_pool,
201 211
           "state": "ACTIVE"}
202 212

  
203 213
        if dry_run:
......
209 219
        if userid:
210 220
            quotas.issue_and_accept_commission(network)
211 221

  
212
        if backend_id:
213
            # Create BackendNetwork only to the specified Backend
222
        # Create network in Backend if needed
223
        if floating_ip_pool:
224
            backends = Backend.objects.filter(offline=False)
225
        elif backend_id:
226
            backends = [backend]
227
        else:
228
            backends = []
229

  
230
        for backend in backends:
214 231
            network.create_backend_network(backend)
215
            create_network(network=network, backend=backend, connect=True)
232
            self.stdout.write("Trying to connect network to backend '%s'\n" %
233
                              backend)
234
            jobs = create_network(network=network, backend=backend,
235
                                   connect=True)
236
            self.stdout.write("Successfully issued jobs: %s\n" %
237
                              ",".join(jobs))

Also available in: Unified diff