Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / logic / management / commands / reconcile-networks.py @ 89b2b908

History | View | Annotate | Download (3.7 kB)

1
# Copyright 2011-2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
5
# are met:
6
#
7
#   1. Redistributions of source code must retain the above copyright
8
#      notice, this list of conditions and the following disclaimer.
9
#
10
#  2. Redistributions in binary form must reproduce the above copyright
11
#     notice, this list of conditions and the following disclaimer in the
12
#     documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
#
26
# The views and conclusions contained in the software and documentation are
27
# those of the authors and should not be interpreted as representing official
28
# policies, either expressed or implied, of GRNET S.A.
29
#
30
"""Reconciliation management command
31

32
Management command to reconcile the contents of the Synnefo DB with
33
the state of the Ganeti backend. See docstring on top of
34
logic/reconciliation.py for a description of reconciliation rules.
35

36
"""
37
import logging
38
from optparse import make_option
39
from django.core.management.base import BaseCommand
40
from synnefo.logic import reconciliation
41

    
42

    
43
class Command(BaseCommand):
44
    help = """Reconcile contents of Synnefo DB with state of Ganeti backend
45

46
Network reconciliation can detect and fix the following cases:
47
    - Missing database entries for a network in a Ganeti backend
48
    - Stale database networks, which do no exist in the Ganeti backend
49
    - Missing Ganeti networks
50
    - Ganeti networks that are not connected to all Ganeti nodegroups
51
    - Networks that have unsynced state
52
    - Networks that have unsynced IP pools
53
    - Orphan networks in the Ganeti backend
54
"""
55

    
56
    can_import_settings = True
57
    option_list = BaseCommand.option_list + (
58
        make_option('--fix-all', action='store_true',
59
                    dest='fix', default=False,
60
                    help='Fix all issues.'),
61
        make_option('--conflicting-ips', action='store_true',
62
                    dest='conflicting_ips', default=False,
63
                    help='Detect conflicting ips')
64
    )
65

    
66
    def handle(self, **options):
67
        conflicting_ips = options['conflicting_ips']
68
        verbosity = int(options["verbosity"])
69
        fix = options["fix"]
70

    
71
        logger = logging.getLogger("reconcile-networks")
72
        logger.propagate = 0
73

    
74
        formatter = logging.Formatter("%(message)s")
75
        log_handler = logging.StreamHandler()
76
        log_handler.setFormatter(formatter)
77
        if verbosity == 2:
78
            formatter = logging.Formatter("%(asctime)s: %(message)s")
79
            log_handler.setFormatter(formatter)
80
            logger.setLevel(logging.DEBUG)
81
        elif verbosity == 1:
82
            logger.setLevel(logging.INFO)
83
        else:
84
            logger.setLevel(logging.WARNING)
85

    
86
        logger.addHandler(log_handler)
87
        reconciler = reconciliation.NetworkReconciler(
88
            logger=logger,
89
            fix=fix,
90
            conflicting_ips=conflicting_ips)
91
        reconciler.reconcile_networks()