Revision c59f7e0f
b/snf-cyclades-app/synnefo/logic/management/commands/reconcile-servers.py | ||
---|---|---|
84 | 84 |
dest='fix_build_errors', default=False, |
85 | 85 |
help='Fix (remove) instances with build errors'), |
86 | 86 |
make_option('--fix-unsynced-nics', action='store_true', |
87 |
dest='fix_unsynced_nics', default=False,
|
|
88 |
help='Fix unsynced nics between DB and Ganeti'),
|
|
87 |
dest='fix_unsynced_nics', default=False, |
|
88 |
help='Fix unsynced nics between DB and Ganeti'), |
|
89 | 89 |
make_option('--fix-all', action='store_true', dest='fix_all', |
90 | 90 |
default=False, help='Enable all --fix-* arguments'), |
91 | 91 |
make_option('--backend-id', default=None, dest='backend-id', |
... | ... | |
160 | 160 |
if options['detect_build_errors']: |
161 | 161 |
build_errors = reconciliation.instances_with_build_errors(D, G) |
162 | 162 |
if len(build_errors) > 0: |
163 |
print >> sys.stderr, "The os for the following server IDs was "\ |
|
164 |
"not build successfully:" |
|
163 |
msg = "The os for the following server IDs was not build"\ |
|
164 |
" successfully:" |
|
165 |
print >> sys.stderr, msg |
|
165 | 166 |
print " " + "\n ".join( |
166 | 167 |
["%d" % x for x in build_errors]) |
167 | 168 |
elif verbosity == 2: |
... | ... | |
172 | 173 |
if not nics: |
173 | 174 |
print ''.ljust(18) + 'None' |
174 | 175 |
for index, info in nics.items(): |
175 |
print ''.ljust(18) + 'nic/' + str(index) + ': MAC: %s, IP: %s, Network: %s' % \ |
|
176 |
(info['mac'], info['ipv4'], info['network']) |
|
176 |
print ''.ljust(18) + 'nic/' + str(index) +\ |
|
177 |
': MAC: %s, IP: %s, Network: %s' % \ |
|
178 |
(info['mac'], info['ipv4'], info['network']) |
|
177 | 179 |
|
178 | 180 |
unsynced_nics = reconciliation.unsynced_nics(DBNics, GNics) |
179 | 181 |
if len(unsynced_nics) > 0: |
180 |
print >> sys.stderr, "The NICs of servers with the following IDs "\ |
|
181 |
"are unsynced:" |
|
182 |
msg = "The NICs of the servers with the following IDs are"\ |
|
183 |
" unsynced:" |
|
184 |
print >> sys.stderr, msg |
|
182 | 185 |
for id, nics in unsynced_nics.items(): |
183 | 186 |
print ''.ljust(2) + '%6d:' % id |
184 | 187 |
print ''.ljust(8) + '%8s:' % 'DB' |
... | ... | |
233 | 236 |
print >> sys.stderr, " ...done" |
234 | 237 |
|
235 | 238 |
if options['fix_build_errors'] and len(build_errors) > 0: |
236 |
print >> sys.stderr, "Setting the state of %d build-errors VMs:" % \
|
|
237 |
len(build_errors) |
|
239 |
print >> sys.stderr, "Setting the state of %d build-errors VMs:" %\ |
|
240 |
len(build_errors)
|
|
238 | 241 |
for id in build_errors: |
239 | 242 |
vm = VirtualMachine.objects.get(pk=id) |
240 | 243 |
event_time = datetime.datetime.now() |
241 |
backend_mod.process_op_status(vm=vm, etime=event_time, jobid=-0, |
|
244 |
backend_mod.process_op_status( |
|
245 |
vm=vm, etime=event_time, jobid=-0, |
|
242 | 246 |
opcode="OP_INSTANCE_CREATE", status='error', |
243 | 247 |
logmsg='Reconciliation: simulated Ganeti event') |
244 | 248 |
print >> sys.stderr, " ...done" |
245 | 249 |
|
246 | 250 |
if options['fix_unsynced_nics'] and len(unsynced_nics) > 0: |
247 | 251 |
print >> sys.stderr, "Setting the nics of %d out-of-sync VMs:" % \ |
248 |
len(unsynced_nics)
|
|
252 |
len(unsynced_nics) |
|
249 | 253 |
for id, nics in unsynced_nics.items(): |
250 | 254 |
vm = VirtualMachine.objects.get(pk=id) |
251 | 255 |
nics = nics[1] # Ganeti nics |
b/snf-cyclades-gtools/synnefo/ganeti/hook.py | ||
---|---|---|
78 | 78 |
if env.startswith("GANETI_INSTANCE_NIC"): |
79 | 79 |
s = env.replace("GANETI_INSTANCE_NIC", "").split('_', 1) |
80 | 80 |
if len(s) == 2 and s[0].isdigit() and\ |
81 |
s[1] in ('MAC', 'IP', 'BRIDGE', 'NETWORK'): |
|
81 |
s[1] in ('MAC', 'IP', 'BRIDGE', 'NETWORK'):
|
|
82 | 82 |
index = int(s[0]) |
83 | 83 |
key = key_to_attr[s[1]] |
84 | 84 |
|
... | ... | |
119 | 119 |
ganeti_nic_count = int(environ['GANETI_INSTANCE_NIC_COUNT']) |
120 | 120 |
if len(indexes) != ganeti_nic_count: |
121 | 121 |
logger.error("I have %d NICs, Ganeti says number of NICs is %d", |
122 |
len(indexes), ganeti_nic_count) |
|
122 |
len(indexes), ganeti_nic_count)
|
|
123 | 123 |
raise Exception("Inconsistent number of NICs in Ganeti environment") |
124 | 124 |
|
125 | 125 |
if indexes != range(0, len(indexes)): |
126 |
logger.error("Ganeti NIC indexes are not consecutive starting at zero."); |
|
127 |
logger.error("NIC indexes are: %s. Environment is: %s", indexes, environ) |
|
126 |
msg = "Ganeti NIC indexes are not consecutive starting at zero." |
|
127 |
logger.error(msg) |
|
128 |
msg = "NIC indexes are: %s. Environment is: %s" % (indexes, environ) |
|
129 |
logger.error(msg) |
|
128 | 130 |
raise Exception("Unexpected inconsistency in the Ganeti environment") |
129 | 131 |
|
130 | 132 |
# Construct the notification |
... | ... | |
193 | 195 |
def run(self): |
194 | 196 |
if self.on_master(): |
195 | 197 |
notifs = [] |
196 |
notifs.append(("net", ganeti_net_status(self.logger, self.environ))) |
|
198 |
notifs.append(("net", |
|
199 |
ganeti_net_status(self.logger, self.environ)) |
|
200 |
) |
|
197 | 201 |
|
198 | 202 |
self.publish_msgs(notifs) |
199 | 203 |
|
... | ... | |
214 | 218 |
op = os.environ['GANETI_HOOKS_PATH'] |
215 | 219 |
phase = os.environ['GANETI_HOOKS_PHASE'] |
216 | 220 |
except KeyError: |
217 |
raise Exception("Environment missing one of: " \ |
|
218 |
"GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH, GANETI_HOOKS_PHASE") |
|
221 |
raise Exception("Environment missing one of: " |
|
222 |
"GANETI_INSTANCE_NAME, GANETI_HOOKS_PATH," |
|
223 |
" GANETI_HOOKS_PHASE") |
|
219 | 224 |
|
220 | 225 |
prefix = instance.split('-')[0] |
221 | 226 |
|
222 | 227 |
# FIXME: The hooks should only run for Synnefo instances. |
223 | 228 |
# Uncomment the following lines for a shared Ganeti deployment. |
224 | 229 |
# Currently, the following code is commented out because multiple |
225 |
# backend prefixes are used in the same Ganeti installation during development. |
|
230 |
# backend prefixes are used in the same Ganeti installation during |
|
231 |
# development. |
|
226 | 232 |
#if not instance.startswith(settings.BACKEND_PREFIX_ID): |
227 | 233 |
# logger.warning("Ignoring non-Synnefo instance %s", instance) |
228 | 234 |
# return 0 |
... | ... | |
238 | 244 |
try: |
239 | 245 |
hook = hooks[(op, phase)](logger, os.environ, instance, prefix) |
240 | 246 |
except KeyError: |
241 |
raise Exception("No hook found for operation = '%s', phase = '%s'" % (op, phase)) |
|
247 |
raise Exception("No hook found for operation = '%s', phase = '%s'" % |
|
248 |
(op, phase)) |
|
242 | 249 |
return hook.run() |
243 | 250 |
|
244 | 251 |
if __name__ == "__main__": |
Also available in: Unified diff