Commit c9d3bdc2 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos Committed by Christos Stavrakakis
Browse files

cyclades: Update some snf-manage *-remove commands

* Add support for removal of multiple targets in snf-manage
port-remove, server-remove, network-remove and floating-ip-remove
commands
parent ba6cb8ee
......@@ -52,9 +52,13 @@ class Command(RemoveCommand):
force = options['force']
self.confirm_deletion(force, "floating ip(s)", args)
floating_ip_id = args[0]
floating_ip = common.get_floating_ip_by_id(floating_ip_id,
for_update=True)
ips.delete_floating_ip(floating_ip)
self.stdout.write("Deleted floating IP '%s'.\n" % floating_ip_id)
for floating_ip_id in args:
self.stdout.write("\n")
try:
floating_ip = common.get_floating_ip_by_id(floating_ip_id,
for_update=True)
ips.delete_floating_ip(floating_ip)
self.stdout.write("Deleted floating IP '%s'.\n" %
floating_ip_id)
except CommandError as e:
self.stdout.write("Error -- %s\n" % e.message)
......@@ -30,6 +30,7 @@
from django.core.management.base import CommandError
from snf_django.management.commands import RemoveCommand
from snf_django.lib.api import faults
from synnefo.logic import networks
from synnefo.management.common import get_network, convert_api_faults
......@@ -40,17 +41,22 @@ class Command(RemoveCommand):
@convert_api_faults
def handle(self, *args, **options):
if len(args) < 1:
if not args:
raise CommandError("Please provide a network ID")
force = options['force']
self.confirm_deletion(force, "network(s)", args)
network = get_network(args[0], for_update=True)
for network_id in args:
self.stdout.write("\n")
try:
network = get_network(network_id, for_update=True)
self.stdout.write('Removing network: %s\n' %
network.backend_id)
self.stdout.write('Removing network: %s\n' % network.backend_id)
networks.delete(network)
networks.delete(network)
self.stdout.write("Successfully submitted Ganeti jobs to"
" remove network %s\n" % network.backend_id)
self.stdout.write("Successfully submitted Ganeti jobs to"
" remove network %s\n" % network.backend_id)
except (CommandError, faults.BadRequest) as e:
self.stdout.write("Error -- %s\n" % e.message)
......@@ -51,18 +51,24 @@ class Command(RemoveCommand):
@common.convert_api_faults
def handle(self, *args, **options):
if len(args) < 1:
if not args:
raise CommandError("Please provide a port ID")
force = options['force']
self.confirm_deletion(force, "port(s)", args)
port = common.get_port(args[0], for_update=True)
for port_id in args:
self.stdout.write("\n")
try:
port = common.get_port(port_id, for_update=True)
servers.delete_port(port)
servers.delete_port(port)
wait = parse_bool(options["wait"])
if port.machine is not None:
common.wait_server_task(port.machine, wait, stdout=self.stdout)
else:
self.stdout.write("Successfully removed port %s\n" % port)
wait = parse_bool(options["wait"])
if port.machine is not None:
common.wait_server_task(port.machine, wait,
stdout=self.stdout)
else:
self.stdout.write("Successfully removed port %s\n" % port)
except CommandError as e:
self.stdout.write("Error -- %s\n" % e.message)
......@@ -39,6 +39,7 @@ from synnefo.management.common import (get_vm, convert_api_faults,
from synnefo.logic import servers
from snf_django.management.commands import RemoveCommand
from snf_django.management.utils import parse_bool
from snf_django.lib.api import faults
class Command(RemoveCommand):
......@@ -57,21 +58,28 @@ class Command(RemoveCommand):
@convert_api_faults
def handle(self, *args, **options):
if len(args) != 1:
if not args:
raise CommandError("Please provide a server ID")
force = options['force']
self.confirm_deletion(force, "server(s)", args)
server = get_vm(args[0])
for server_id in args:
self.stdout.write("\n")
try:
server = get_vm(server_id)
self.stdout.write("Trying to remove server '%s' from backend '%s'\n" %
(server.backend_vm_id, server.backend))
self.stdout.write("Trying to remove server '%s' from backend "
"'%s' \n" % (server.backend_vm_id,
server.backend))
server = servers.destroy(server)
jobID = server.task_job_id
server = servers.destroy(server)
jobID = server.task_job_id
self.stdout.write("Issued OP_INSTANCE_REMOVE with id: %s\n" % jobID)
self.stdout.write("Issued OP_INSTANCE_REMOVE with id: %s\n" %
jobID)
wait = parse_bool(options["wait"])
wait_server_task(server, wait, self.stdout)
wait = parse_bool(options["wait"])
wait_server_task(server, wait, self.stdout)
except (CommandError, faults.BadRequest) as e:
self.stdout.write("Error -- %s\n" % e.message)
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