Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / logic / management / commands / ip-list.py @ 5d805533

History | View | Annotate | Download (3.1 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
35 3bb5e4b7 Marios Kogias
from snf_django.management.commands import ListCommand
36 3bb5e4b7 Marios Kogias
from synnefo.db.models import IPAddressLog
37 3bb5e4b7 Marios Kogias
from optparse import make_option
38 0fc4b580 Marios Kogias
39 3bb5e4b7 Marios Kogias
from logging import getLogger
40 3bb5e4b7 Marios Kogias
log = getLogger(__name__)
41 0fc4b580 Marios Kogias
42 3bb5e4b7 Marios Kogias
43 3bb5e4b7 Marios Kogias
class Command(ListCommand):
44 0fc4b580 Marios Kogias
    help = "Information about a floating IP"
45 0fc4b580 Marios Kogias
46 3bb5e4b7 Marios Kogias
    option_list = ListCommand.option_list + (
47 3bb5e4b7 Marios Kogias
        make_option(
48 3bb5e4b7 Marios Kogias
            '--address',
49 3bb5e4b7 Marios Kogias
            dest='address',
50 a5a15eba Christos Stavrakakis
            help="Display IP history only for this address"),
51 3bb5e4b7 Marios Kogias
        make_option(
52 3bb5e4b7 Marios Kogias
            '--server',
53 3bb5e4b7 Marios Kogias
            dest='server',
54 a5a15eba Christos Stavrakakis
            help="Display IP history only for this server"),
55 a5a15eba Christos Stavrakakis
        make_option(
56 a5a15eba Christos Stavrakakis
            '--active',
57 a5a15eba Christos Stavrakakis
            dest="active",
58 a5a15eba Christos Stavrakakis
            action="store_true",
59 a5a15eba Christos Stavrakakis
            default=False,
60 a5a15eba Christos Stavrakakis
            help="Display only IPs that are currently in use")
61 3bb5e4b7 Marios Kogias
    )
62 3bb5e4b7 Marios Kogias
63 3bb5e4b7 Marios Kogias
    object_class = IPAddressLog
64 3bb5e4b7 Marios Kogias
    order_by = "allocated_at"
65 0fc4b580 Marios Kogias
66 3bb5e4b7 Marios Kogias
    FIELDS = {
67 3bb5e4b7 Marios Kogias
        "address": ("address", "The IP address"),
68 3bb5e4b7 Marios Kogias
        "server": ("server_id", "The the server connected to"),
69 3bb5e4b7 Marios Kogias
        "network": ("network_id", "The id of the network"),
70 3bb5e4b7 Marios Kogias
        "allocated_at": ("allocated_at", "Datetime IP allocated to server"),
71 3bb5e4b7 Marios Kogias
        "released_at": ("released_at", "Datetime IP released from server"),
72 3bb5e4b7 Marios Kogias
        "active": ("active", "Whether IP still allocated to server"),
73 3bb5e4b7 Marios Kogias
    }
74 0fc4b580 Marios Kogias
75 3bb5e4b7 Marios Kogias
    fields = ["address", "server", "network", "allocated_at", "released_at"]
76 0fc4b580 Marios Kogias
77 3bb5e4b7 Marios Kogias
    def handle_args(self, *args, **options):
78 3bb5e4b7 Marios Kogias
        if options["address"]:
79 3bb5e4b7 Marios Kogias
            self.filters["address"] = options["address"]
80 3bb5e4b7 Marios Kogias
        if options["server"]:
81 3bb5e4b7 Marios Kogias
            self.filters["server_id"] = options["server"]
82 a5a15eba Christos Stavrakakis
        if options["active"]:
83 a5a15eba Christos Stavrakakis
            self.filters["active"] = True