root / snf-cyclades-app / synnefo / logic / management / commands / reconcile-networks.py @ 89b2b908
History | View | Annotate | Download (3.7 kB)
1 | 89b2b908 | Christos Stavrakakis | # Copyright 2011-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 0e9a423f | Christos Stavrakakis | #
|
3 | 0e9a423f | Christos Stavrakakis | # Redistribution and use in source and binary forms, with or without
|
4 | 0e9a423f | Christos Stavrakakis | # modification, are permitted provided that the following conditions
|
5 | 0e9a423f | Christos Stavrakakis | # are met:
|
6 | 0e9a423f | Christos Stavrakakis | #
|
7 | 0e9a423f | Christos Stavrakakis | # 1. Redistributions of source code must retain the above copyright
|
8 | 0e9a423f | Christos Stavrakakis | # notice, this list of conditions and the following disclaimer.
|
9 | 0e9a423f | Christos Stavrakakis | #
|
10 | 0e9a423f | Christos Stavrakakis | # 2. Redistributions in binary form must reproduce the above copyright
|
11 | 0e9a423f | Christos Stavrakakis | # notice, this list of conditions and the following disclaimer in the
|
12 | 0e9a423f | Christos Stavrakakis | # documentation and/or other materials provided with the distribution.
|
13 | 0e9a423f | Christos Stavrakakis | #
|
14 | 0e9a423f | Christos Stavrakakis | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
15 | 0e9a423f | Christos Stavrakakis | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16 | 0e9a423f | Christos Stavrakakis | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
17 | 0e9a423f | Christos Stavrakakis | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
18 | 0e9a423f | Christos Stavrakakis | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19 | 0e9a423f | Christos Stavrakakis | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
20 | 0e9a423f | Christos Stavrakakis | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
21 | 0e9a423f | Christos Stavrakakis | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
22 | 0e9a423f | Christos Stavrakakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
23 | 0e9a423f | Christos Stavrakakis | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
24 | 0e9a423f | Christos Stavrakakis | # SUCH DAMAGE.
|
25 | 0e9a423f | Christos Stavrakakis | #
|
26 | 0e9a423f | Christos Stavrakakis | # The views and conclusions contained in the software and documentation are
|
27 | 0e9a423f | Christos Stavrakakis | # those of the authors and should not be interpreted as representing official
|
28 | 0e9a423f | Christos Stavrakakis | # policies, either expressed or implied, of GRNET S.A.
|
29 | 0e9a423f | Christos Stavrakakis | #
|
30 | 0e9a423f | Christos Stavrakakis | """Reconciliation management command
|
31 | 0e9a423f | Christos Stavrakakis |
|
32 | 0e9a423f | Christos Stavrakakis | Management command to reconcile the contents of the Synnefo DB with
|
33 | 0e9a423f | Christos Stavrakakis | the state of the Ganeti backend. See docstring on top of
|
34 | 0e9a423f | Christos Stavrakakis | logic/reconciliation.py for a description of reconciliation rules.
|
35 | 0e9a423f | Christos Stavrakakis |
|
36 | 0e9a423f | Christos Stavrakakis | """
|
37 | b88c1549 | Christos Stavrakakis | import logging |
38 | 0e9a423f | Christos Stavrakakis | from optparse import make_option |
39 | c55b0cdc | Christos Stavrakakis | from django.core.management.base import BaseCommand |
40 | 89b2b908 | Christos Stavrakakis | from synnefo.logic import reconciliation |
41 | c346aed0 | Christos Stavrakakis | |
42 | 0e9a423f | Christos Stavrakakis | |
43 | 0e9a423f | Christos Stavrakakis | class Command(BaseCommand): |
44 | c346aed0 | Christos Stavrakakis | help = """Reconcile contents of Synnefo DB with state of Ganeti backend
|
45 | c346aed0 | Christos Stavrakakis |
|
46 | c346aed0 | Christos Stavrakakis | Network reconciliation can detect and fix the following cases:
|
47 | c346aed0 | Christos Stavrakakis | - Missing database entries for a network in a Ganeti backend
|
48 | c346aed0 | Christos Stavrakakis | - Stale database networks, which do no exist in the Ganeti backend
|
49 | c346aed0 | Christos Stavrakakis | - Missing Ganeti networks
|
50 | c346aed0 | Christos Stavrakakis | - Ganeti networks that are not connected to all Ganeti nodegroups
|
51 | c346aed0 | Christos Stavrakakis | - Networks that have unsynced state
|
52 | c346aed0 | Christos Stavrakakis | - Networks that have unsynced IP pools
|
53 | c346aed0 | Christos Stavrakakis | - Orphan networks in the Ganeti backend
|
54 | c346aed0 | Christos Stavrakakis | """
|
55 | c346aed0 | Christos Stavrakakis | |
56 | ad297723 | Christos Stavrakakis | can_import_settings = True
|
57 | 0e9a423f | Christos Stavrakakis | option_list = BaseCommand.option_list + ( |
58 | 0e9a423f | Christos Stavrakakis | make_option('--fix-all', action='store_true', |
59 | 0e9a423f | Christos Stavrakakis | dest='fix', default=False, |
60 | 0e9a423f | Christos Stavrakakis | help='Fix all issues.'),
|
61 | c55b0cdc | Christos Stavrakakis | make_option('--conflicting-ips', action='store_true', |
62 | c55b0cdc | Christos Stavrakakis | dest='conflicting_ips', default=False, |
63 | c55b0cdc | Christos Stavrakakis | help='Detect conflicting ips')
|
64 | cc92b70f | Christos Stavrakakis | ) |
65 | 0e9a423f | Christos Stavrakakis | |
66 | 0e9a423f | Christos Stavrakakis | def handle(self, **options): |
67 | c55b0cdc | Christos Stavrakakis | conflicting_ips = options['conflicting_ips']
|
68 | b88c1549 | Christos Stavrakakis | verbosity = int(options["verbosity"]) |
69 | b88c1549 | Christos Stavrakakis | fix = options["fix"]
|
70 | b88c1549 | Christos Stavrakakis | |
71 | b88c1549 | Christos Stavrakakis | logger = logging.getLogger("reconcile-networks")
|
72 | b88c1549 | Christos Stavrakakis | logger.propagate = 0
|
73 | b88c1549 | Christos Stavrakakis | |
74 | b88c1549 | Christos Stavrakakis | formatter = logging.Formatter("%(message)s")
|
75 | b88c1549 | Christos Stavrakakis | log_handler = logging.StreamHandler() |
76 | b88c1549 | Christos Stavrakakis | log_handler.setFormatter(formatter) |
77 | b88c1549 | Christos Stavrakakis | if verbosity == 2: |
78 | b88c1549 | Christos Stavrakakis | formatter = logging.Formatter("%(asctime)s: %(message)s")
|
79 | b88c1549 | Christos Stavrakakis | log_handler.setFormatter(formatter) |
80 | b88c1549 | Christos Stavrakakis | logger.setLevel(logging.DEBUG) |
81 | b88c1549 | Christos Stavrakakis | elif verbosity == 1: |
82 | b88c1549 | Christos Stavrakakis | logger.setLevel(logging.INFO) |
83 | b88c1549 | Christos Stavrakakis | else:
|
84 | b88c1549 | Christos Stavrakakis | logger.setLevel(logging.WARNING) |
85 | b88c1549 | Christos Stavrakakis | |
86 | b88c1549 | Christos Stavrakakis | logger.addHandler(log_handler) |
87 | 89b2b908 | Christos Stavrakakis | reconciler = reconciliation.NetworkReconciler( |
88 | 89b2b908 | Christos Stavrakakis | logger=logger, |
89 | 89b2b908 | Christos Stavrakakis | fix=fix, |
90 | 89b2b908 | Christos Stavrakakis | conflicting_ips=conflicting_ips) |
91 | b88c1549 | Christos Stavrakakis | reconciler.reconcile_networks() |