Revision 6c77ed37 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 |
|
40 |
from synnefo.db.models import Network, Backend
|
|
41 | 41 |
from synnefo.logic import networks |
42 | 42 |
|
43 | 43 |
NETWORK_FLAVORS = Network.FLAVORS.keys() |
... | ... | |
131 | 131 |
dest="backend_ids", |
132 | 132 |
default=None, |
133 | 133 |
help="Comma seperated list of Ganeti backends IDs that the network" |
134 |
" will be created. Only for public networks."), |
|
134 |
" will be created. Only for public networks. Use 'all' to" |
|
135 |
" create network in all available backends."), |
|
135 | 136 |
) |
136 | 137 |
|
137 | 138 |
@convert_api_faults |
... | ... | |
174 | 175 |
|
175 | 176 |
backends = [] |
176 | 177 |
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) |
|
178 |
if backend_ids == "all": |
|
179 |
backends = Backend.objects.filter(offline=False) |
|
180 |
else: |
|
181 |
for backend_id in backend_ids.split(","): |
|
182 |
try: |
|
183 |
backend_id = int(backend_id) |
|
184 |
except ValueError: |
|
185 |
raise CommandError("Invalid backend-id: %s" |
|
186 |
% backend_id) |
|
187 |
backend = get_backend(backend_id) |
|
188 |
backends.append(backend) |
|
184 | 189 |
|
185 | 190 |
network = networks.create(user_id=userid, name=name, flavor=flavor, |
186 | 191 |
subnet=subnet, gateway=gateway, |
Also available in: Unified diff