Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / management / commands / floating-ip-state.py @ 0fc4b580

History | View | Annotate | Download (2.6 kB)

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