Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.4 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

    
40
from synnefo.logic import reconciliation
41
from snf_django.management.commands import SynnefoCommand
42

    
43

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

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

    
56
    can_import_settings = True
57
    option_list = SynnefoCommand.option_list + (
58
        make_option('--fix-all', action='store_true',
59
                    dest='fix', default=False,
60
                    help='Fix all issues.'),
61
    )
62

    
63
    def handle(self, **options):
64
        verbosity = int(options["verbosity"])
65
        fix = options["fix"]
66

    
67
        logger = logging.getLogger("reconcile-networks")
68
        logger.propagate = 0
69

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

    
82
        logger.addHandler(log_handler)
83
        reconciler = reconciliation.NetworkReconciler(logger=logger, fix=fix)
84
        reconciler.reconcile_networks()