Revision fae6e5f0 snf-cyclades-app/synnefo/api/management/commands/floating-ip-dettach.py

b/snf-cyclades-app/synnefo/api/management/commands/floating-ip-dettach.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from optparse import make_option
34
#from optparse import make_option
35 35

  
36 36
from django.core.management.base import BaseCommand, CommandError
37
from synnefo.management.common import get_floating_ip_by_address
37
from synnefo.management import common
38 38
from synnefo.logic import servers
39 39

  
40
class Command(BaseCommand):
41
    can_import_settings = True
42
    output_transaction = True
43 40

  
41
class Command(BaseCommand):
44 42
    help = "Dettach a floating IP from a VM or router"
45 43

  
44
    @common.convert_api_faults
46 45
    def handle(self, *args, **options):
47
        if not args or len(args)>1:
46
        if not args or len(args) > 1:
48 47
            raise CommandError("Command accepts exactly one argument")
49 48

  
50
        address = args[0]
49
        floating_ip_id = args[0]
51 50

  
52 51
        #get the floating-ip
53
        floating_ip = get_floating_ip_by_address(address, for_update=True)
52
        floating_ip = common.get_floating_ip_by_id(floating_ip_id,
53
                                                   for_update=True)
54 54

  
55 55
        if not floating_ip.nic:
56 56
            raise CommandError('This floating IP is not attached to a device')
57 57

  
58 58
        nic = floating_ip.nic
59 59
        vm = nic.machine
60

  
61
        servers.disconnect(vm, nic)
60
        servers.delete_port(nic)
62 61
        self.stdout.write("Dettached floating IP %s from  %s.\n"
63
                           % (floating_ip_id, vm))
62
                          % (floating_ip_id, vm))

Also available in: Unified diff