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

b/snf-cyclades-app/synnefo/api/management/commands/floating-ip-attach.py
34 34
from optparse import make_option
35 35

  
36 36
from django.core.management.base import BaseCommand, CommandError
37
from synnefo.management.common import convert_api_faults
38

  
39
from synnefo.api import util
40
from synnefo.management.common import get_network, get_vm
37
from synnefo.management import common
41 38
from synnefo.logic import servers
42 39

  
43 40

  
44 41
class Command(BaseCommand):
45
    can_import_settings = True
46
    output_transaction = True
47

  
48 42
    help = "Attach a floating IP to a VM or router"
49 43

  
50 44
    option_list = BaseCommand.option_list + (
......
55 49
            help='The server id the floating-ip will be attached to'),
56 50
    )
57 51

  
58
    @convert_api_faults
52
    @common.convert_api_faults
59 53
    def handle(self, *args, **options):
60 54
        if not args or len(args) > 1:
61 55
            raise CommandError("Command accepts exactly one argument")
62 56

  
63
        floating_ip = args[0]  # this is the floating-ip address
57
        floating_ip_id = args[0]  # this is the floating-ip address
64 58
        device = options['machine']
65 59

  
66 60
        if not device:
67 61
            raise CommandError('Please give either a server or a router id')
68 62

  
69 63
        #get the vm
70
        vm = get_vm(device)
71

  
72
        servers.add_floating_ip(vm, floating_ip)
64
        vm = common.get_vm(device)
65
        floating_ip = common.get_floating_ip_by_id(floating_ip_id,
66
                                                   for_update=True)
67
        servers.create_port(vm.userid, floating_ip.network,
68
                            use_ipaddress=floating_ip, machine=vm)
73 69

  
74 70
        self.stdout.write("Attached %s to %s.\n" % (floating_ip, vm))

Also available in: Unified diff