Revision 4161cb41 snf-cyclades-app/synnefo/logic/management/commands/reconcile.py

b/snf-cyclades-app/synnefo/logic/management/commands/reconcile.py
62 62
                    dest='detect_unsynced',
63 63
                    default=False, help='Detect unsynced operstate between ' +
64 64
                                        'DB and Ganeti'),
65
        make_option('--detect-build-errors', action='store_true',
66
                    dest='detect_build_errors', default=False,
67
                    help='Detect instances with build error'),
65 68
        make_option('--detect-all', action='store_true',
66 69
                    dest='detect_all',
67 70
                    default=False, help='Enable all --detect-* arguments'),
......
72 75
        make_option('--fix-unsynced', action='store_true', dest='fix_unsynced',
73 76
                    default=False, help='Fix server operstate in DB, set ' +
74 77
                                        'from Ganeti'),
78
        make_option('--fix-build-errors', action='store_true',
79
                    dest='fix_build_errors', default=False,
80
                    help='Fix (remove) instances with build errors'),
75 81
        make_option('--fix-all', action='store_true', dest='fix_all',
76 82
                    default=False, help='Enable all --fix-* arguments'))
77 83

  
......
136 142
            elif verbosity == 2:
137 143
                print >> sys.stderr, "The operstate of all servers is in sync."
138 144

  
145
        if options['detect_build_errors']:
146
            build_errors = reconciliation.instances_with_build_errors(D, G)
147
            if len(build_errors) > 0:
148
                print >> sys.stderr, "The os for the following server IDs was "\
149
                                     "not build successfully:"
150
                print "    " + "\n    ".join(
151
                    ["%d" % x for x in build_errors])
152
            elif verbosity == 2:
153
                print >> sys.stderr, "Found no instances with build errors."
154

  
139 155
        #
140 156
        # Then fix them
141 157
        #
......
172 188
                    opcode=opcode, status='success',
173 189
                    logmsg='Reconciliation: simulated Ganeti event')
174 190
            print >> sys.stderr, "    ...done"
191

  
192
        if options['fix_build_errors'] and len(build_errors) > 0:
193
            print >> sys.stderr, "Setting the state of %d build-errors VMs:" % \
194
                len(build_errors)
195
            for id in build_errors:
196
                vm = VirtualMachine.objects.get(pk=id)
197
                event_time = datetime.datetime.now()
198
                backend.process_op_status(vm=vm, etime=event_time ,jobid=-0,
199
                    opcode="OP_INSTANCE_CREATE", status='error',
200
                    logmsg='Reconciliation: simulated Ganeti event')
201
            print >> sys.stderr, "    ...done"
202

  

Also available in: Unified diff