Commit bc4f2915 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add and remove networks from backends

Extend 'snf-manage network-modify' command with '--add-to-backend' and
'--remove-from-backend' options, to create and remove an already created
public network from a Ganeti backend.
parent 39283f1f
......@@ -36,8 +36,10 @@ from optparse import make_option
from import BaseCommand, CommandError
from synnefo.db.models import Network, pooled_rapi_client
from import validate_network_info, get_network
from import (validate_network_info, get_network,
from import parse_bool
from synnefo.logic.backend import create_network, delete_network
HELP_MSG = """Modify a network.
......@@ -115,7 +117,15 @@ class Command(BaseCommand):
choices=["True", "False"],
help="Set as drained to exclude for IP allocation."
" Only used for public networks.")
" Only used for public networks."),
help="Create a public network to a Ganeti backend."),
help="Remove a public network from a Ganeti backend."),
def handle(self, *args, **options):
......@@ -164,3 +174,25 @@ class Command(BaseCommand):
add_to_backend = options["add_to_backend"]
if add_to_backend is not None:
backend = get_backend(add_to_backend)
create_network(network, backend, connect=True)
msg = "Sent job to create network '%s' in backend '%s'\n"
self.stdout.write(msg % (network, backend))
remove_from_backend = options["remove_from_backend"]
if remove_from_backend is not None:
backend = get_backend(remove_from_backend)
if network.nics.filter(machine__backend=backend,
msg = "Can not remove. There are still connected VMs to this"\
" network"
raise CommandError(msg)
network.action = "DESTROY"
delete_network(network, backend, disconnect=True)
msg = "Sent job to delete network '%s' from backend '%s'\n"
self.stdout.write(msg % (network, backend))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment