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

b/snf-cyclades-app/synnefo/api/management/commands/network-create.py
127 127
            help="Use the network as a Floating IP pool. Floating IP pools"
128 128
                 " are created in all available backends."),
129 129
        make_option(
130
            '--backend-id',
131
            dest='backend_id',
130
            "--backend-ids",
131
            dest="backend_ids",
132 132
            default=None,
133
            help='ID of the backend that the network will be created. Only for'
134
                 ' public networks'),
133
            help="Comma seperated list of Ganeti backends IDs that the network"
134
                 " will be created. Only for public networks."),
135 135
    )
136 136

  
137 137
    @convert_api_faults
......
144 144
        gateway = options['gateway']
145 145
        subnet6 = options['subnet6']
146 146
        gateway6 = options['gateway6']
147
        backend_id = options['backend_id']
147
        backend_ids = options['backend_ids']
148 148
        public = options['public']
149 149
        flavor = options['flavor']
150 150
        mode = options['mode']
......
167 167
        if subnet6 is None and gateway6 is not None:
168 168
            raise CommandError("Can not use gateway6 without subnet6")
169 169

  
170
        if public and not (backend_id or floating_ip_pool):
171
            raise CommandError("backend-id is required")
170
        if public and not (backend_ids or floating_ip_pool):
171
            raise CommandError("backend-ids is required")
172 172
        if not userid and not public:
173 173
            raise CommandError("'owner' is required for private networks")
174 174

  
175
        if backend_id is not None:
176
            try:
177
                backend_id = int(backend_id)
178
            except ValueError:
179
                raise CommandError("Invalid backend-id: %s" % backend_id)
180
            backend = get_backend(backend_id)
181
        else:
182
            backend = None
175
        backends = []
176
        if backend_ids is not None:
177
            for backend_id in backend_ids.split(","):
178
                try:
179
                    backend_id = int(backend_id)
180
                except ValueError:
181
                    raise CommandError("Invalid backend-id: %s" % backend_id)
182
                backend = get_backend(backend_id)
183
                backends.append(backend)
183 184

  
184 185
        network = networks.create(user_id=userid, name=name, flavor=flavor,
185 186
                                  subnet=subnet, gateway=gateway,
......
187 188
                                  dhcp=dhcp, public=public, mode=mode,
188 189
                                  link=link, mac_prefix=mac_prefix, tags=tags,
189 190
                                  floating_ip_pool=floating_ip_pool,
190
                                  backend=backend, lazy_create=False)
191
                                  backends=backends, lazy_create=False)
191 192

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

Also available in: Unified diff