Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / management / commands / floating-ip-remove.py @ 55480205

History | View | Annotate | Download (2.2 kB)

1 0292883e Christos Stavrakakis
# Copyright 2013 GRNET S.A. All rights reserved.
2 9d1e6480 Marios Kogias
#
3 9d1e6480 Marios Kogias
# Redistribution and use in source and binary forms, with or
4 9d1e6480 Marios Kogias
# without modification, are permitted provided that the following
5 9d1e6480 Marios Kogias
# conditions are met:
6 9d1e6480 Marios Kogias
#
7 9d1e6480 Marios Kogias
#   1. Redistributions of source code must retain the above
8 9d1e6480 Marios Kogias
#      copyright notice, this list of conditions and the following
9 9d1e6480 Marios Kogias
#      disclaimer.
10 9d1e6480 Marios Kogias
#
11 9d1e6480 Marios Kogias
#   2. Redistributions in binary form must reproduce the above
12 9d1e6480 Marios Kogias
#      copyright notice, this list of conditions and the following
13 9d1e6480 Marios Kogias
#      disclaimer in the documentation and/or other materials
14 9d1e6480 Marios Kogias
#      provided with the distribution.
15 9d1e6480 Marios Kogias
#
16 9d1e6480 Marios Kogias
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 9d1e6480 Marios Kogias
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 9d1e6480 Marios Kogias
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 9d1e6480 Marios Kogias
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 9d1e6480 Marios Kogias
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 9d1e6480 Marios Kogias
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 9d1e6480 Marios Kogias
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 9d1e6480 Marios Kogias
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 9d1e6480 Marios Kogias
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 9d1e6480 Marios Kogias
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 9d1e6480 Marios Kogias
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 9d1e6480 Marios Kogias
# POSSIBILITY OF SUCH DAMAGE.
28 9d1e6480 Marios Kogias
#
29 9d1e6480 Marios Kogias
# The views and conclusions contained in the software and
30 9d1e6480 Marios Kogias
# documentation are those of the authors and should not be
31 9d1e6480 Marios Kogias
# interpreted as representing official policies, either expressed
32 9d1e6480 Marios Kogias
# or implied, of GRNET S.A.
33 9d1e6480 Marios Kogias
34 0292883e Christos Stavrakakis
#from optparse import make_option
35 9d1e6480 Marios Kogias
36 9d1e6480 Marios Kogias
from django.db import transaction
37 9d1e6480 Marios Kogias
from django.core.management.base import BaseCommand, CommandError
38 0292883e Christos Stavrakakis
from synnefo.management import common
39 0292883e Christos Stavrakakis
from synnefo.logic import ips
40 9d1e6480 Marios Kogias
41 9d1e6480 Marios Kogias
42 9d1e6480 Marios Kogias
class Command(BaseCommand):
43 9d1e6480 Marios Kogias
    help = "Release a floating IP"
44 9d1e6480 Marios Kogias
45 e5841f52 Marios Kogias
    @common.convert_api_faults
46 9d1e6480 Marios Kogias
    @transaction.commit_on_success
47 9d1e6480 Marios Kogias
    def handle(self, *args, **options):
48 9d1e6480 Marios Kogias
        if not args:
49 9d1e6480 Marios Kogias
            raise CommandError("Please provide a floating-ip address")
50 9d1e6480 Marios Kogias
51 0292883e Christos Stavrakakis
        floating_ip_id = args[0]
52 9d1e6480 Marios Kogias
53 0292883e Christos Stavrakakis
        floating_ip = common.get_floating_ip_by_id(floating_ip_id,
54 0292883e Christos Stavrakakis
                                                   for_update=True)
55 0292883e Christos Stavrakakis
        ips.delete_floating_ip(floating_ip)
56 0292883e Christos Stavrakakis
        self.stdout.write("Deleted floating IP '%s'.\n" % floating_ip_id)