Revision 5ec446aa snf-cyclades-app/synnefo/api/management/commands/network-modify.py
b/snf-cyclades-app/synnefo/api/management/commands/network-modify.py | ||
---|---|---|
36 | 36 |
from django.core.management.base import BaseCommand, CommandError |
37 | 37 |
|
38 | 38 |
from synnefo.db.models import Network, pooled_rapi_client |
39 |
from synnefo.management.common import validate_network_info, get_network |
|
39 |
from synnefo.management.common import (validate_network_info, get_network, |
|
40 |
get_backend) |
|
40 | 41 |
from synnefo.webproject.management.utils import parse_bool |
42 |
from synnefo.logic.backend import create_network, delete_network |
|
41 | 43 |
|
42 | 44 |
HELP_MSG = """Modify a network. |
43 | 45 |
|
... | ... | |
115 | 117 |
metavar="True|False", |
116 | 118 |
choices=["True", "False"], |
117 | 119 |
help="Set as drained to exclude for IP allocation." |
118 |
" Only used for public networks.") |
|
120 |
" Only used for public networks."), |
|
121 |
make_option( |
|
122 |
"--add-to-backend", |
|
123 |
dest="add_to_backend", |
|
124 |
help="Create a public network to a Ganeti backend."), |
|
125 |
make_option( |
|
126 |
"--remove-from-backend", |
|
127 |
dest="remove_from_backend", |
|
128 |
help="Remove a public network from a Ganeti backend."), |
|
119 | 129 |
) |
120 | 130 |
|
121 | 131 |
def handle(self, *args, **options): |
... | ... | |
164 | 174 |
remove_reserved_ips=remove_reserved_ips) |
165 | 175 |
|
166 | 176 |
network.save() |
177 |
|
|
178 |
add_to_backend = options["add_to_backend"] |
|
179 |
if add_to_backend is not None: |
|
180 |
backend = get_backend(add_to_backend) |
|
181 |
network.create_backend_network(backend=backend) |
|
182 |
create_network(network, backend, connect=True) |
|
183 |
msg = "Sent job to create network '%s' in backend '%s'\n" |
|
184 |
self.stdout.write(msg % (network, backend)) |
|
185 |
|
|
186 |
remove_from_backend = options["remove_from_backend"] |
|
187 |
if remove_from_backend is not None: |
|
188 |
backend = get_backend(remove_from_backend) |
|
189 |
if network.nics.filter(machine__backend=backend, |
|
190 |
machine__deleted=False).exists(): |
|
191 |
msg = "Can not remove. There are still connected VMs to this"\ |
|
192 |
" network" |
|
193 |
raise CommandError(msg) |
|
194 |
network.action = "DESTROY" |
|
195 |
network.save() |
|
196 |
delete_network(network, backend, disconnect=True) |
|
197 |
msg = "Sent job to delete network '%s' from backend '%s'\n" |
|
198 |
self.stdout.write(msg % (network, backend)) |
Also available in: Unified diff