Revision bad9404c snf-cyclades-app/synnefo/api/management/commands/network-list.py

b/snf-cyclades-app/synnefo/api/management/commands/network-list.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 format_bool
38

  
37
from synnefo.management.common import format_bool, filter_results
39 38
from synnefo.db.models import Network
40 39

  
40
FIELDS = Network._meta.get_all_field_names()
41

  
41 42

  
42 43
class Command(BaseCommand):
43 44
    help = "List networks"
......
63 64
            dest='ipv6',
64 65
            default=False,
65 66
            help="Show IPv6 information of the network"),
67
        make_option('--filter-by',
68
            dest='filter_by',
69
            help="Filter results. Comma seperated list of key 'cond' val pairs"
70
                 " that displayed entries must satisfy. e.g."
71
                 " --filter-by \"name=Network-1,link!=prv0\"."
72
                 " Available keys are: %s" % ", ".join(FIELDS))
73

  
66 74
        )
67 75

  
68 76
    def handle(self, *args, **options):
......
77 85
        if options['public']:
78 86
            networks = networks.filter(public=True)
79 87

  
88
        filter_by = options['filter_by']
89
        if filter_by:
90
            networks = filter_results(networks, filter_by)
91

  
80 92
        labels = ['id', 'name', 'type', 'owner',
81 93
                  'mac_prefix', 'dhcp', 'state', 'link', 'vms', 'public']
82 94
        columns = [3, 16, 22, 30, 10, 6, 8, 12, 4, 6]

Also available in: Unified diff