def _vm_replica_cb_detail(repname, action, jsons, key_json_idx=None): """Create tasklog detail""" res = {'repname': repname} if not jsons: return res for out in jsons: if 'msg' in out: res['msg'] = out['msg'] res['rc'] = out['rc'] if key_json_idx is None: if action == 'POST': key_json_idx = 0 elif action == 'DELETE': key_json_idx = -1 if key_json_idx is not None: try: res['time_elapsed'] = jsons[key_json_idx]['time_elapsed'] except (IndexError, KeyError): pass return ', '.join(['%s=%s' % (k, to_string(v)) for k, v in res.items()])
def get(self): request = self.request ser = AlertSerializer(request, data=self.data) if not ser.is_valid(): return FailureTaskResponse(request, ser.errors) dc_bound = ser.data['dc_bound'] if dc_bound: tg = TG_DC_BOUND else: tg = TG_DC_UNBOUND if not request.dc.is_default(): request.dc = DefaultDc() # Warning: Changing request.dc logger.info( '"%s %s" user="******" _changed_ dc="%s" permissions=%s', request.method, request.path, request.user.username, request.dc.name, request.dc_user_permissions) if not request.dc.settings.MON_ZABBIX_ENABLED: # dc1_settings raise Http404 _apiview_ = {'view': 'mon_alert_list', 'method': request.method} _tidlock = [ 'mon_alert_list', 'dc_id=%s' % request.dc.id, 'vm_uuids=%s' % ','.join(ser.vms or ()), 'node_uuids=%s' % ','.join(ser.nodes or ()), ] task_kwargs = { 'vm_uuids': ser.vms, 'node_uuids': ser.nodes, } for key, val in ser.data.items(): _apiview_[key] = val if not (key.startswith('vm_') or key.startswith('node_')): task_kwargs[key] = val _tidlock.append('%s=%s' % (key, to_string(val))) tidlock = ':'.join(_tidlock) ter = mon_alert_list.call(request, None, (request.dc.id, ), kwargs=task_kwargs, meta={'apiview': _apiview_}, tg=tg, tidlock=tidlock, cache_result=tidlock, cache_timeout=self.cache_timeout) return mgmt_task_response(request, *ter, obj=request.dc, api_view=_apiview_, dc_bound=dc_bound, data=self.data, detail_dict=ser.detail_dict(force_full=True))
def __disk_nics_add_rem(items, id_name, id_value): add_rem = [ '%s=%s' % (key, to_string(val)) for key, val in iteritems(items) if key != id_name ] return '%s=%s: ' % (id_name, id_value) + ', '.join(add_rem)
def __get_changes(items): return [ '%s=%s->%s' % (key, to_string(val[0]), to_string(val[1])) for key, val in iteritems(items) ]
def _vm_backup_cb_detail(data): """Create tasklog detail - used by vm_backup_cb and vm_backup_list_cb""" return ', '.join([ '%s=%s' % (k, to_string(v)) for k, v in iteritems(data) if k in BACKUP_LOG_DETAIL ])
def vm_snapshot_cb(result, task_id, vm_uuid=None, snap_id=None): """ A callback function for api.vm.snapshot.views.vm_snapshot. """ snap = Snapshot.objects.select_related('vm').get(id=snap_id) vm = snap.vm action = result['meta']['apiview']['method'] msg = result.get('message', '') if result['returncode'] == 0: if msg: result['detail'] = 'msg=' + to_string(msg) else: result['detail'] = '' if action == 'POST': snap.status = snap.OK result['message'] = 'Snapshot successfully created' if snap.fsfreeze: if 'freeze failed' in msg: snap.fsfreeze = False result['message'] += ' (filesystem freeze failed)' MonitoringBackend.vm_send_alert( vm, 'Snapshot %s of server %s@disk-%s was created, but filesystem ' 'freeze failed.' % (snap.name, vm.hostname, snap.array_disk_id), priority=MonitoringBackend.WARNING) snap.save(update_fields=('status', 'fsfreeze')) if snap.define and snap.define.retention: # Retention - delete oldest snapshot assert vm == snap.define.vm assert snap.disk_id == snap.define.disk_id from api.vm.snapshot.views import vm_snapshot_list _delete_oldest(Snapshot, snap.define, vm_snapshot_list, 'snapnames', task_id, LOG_SNAPS_DELETE) elif action == 'PUT': snap.status = snap.OK snap.save_status() if result['meta']['apiview']['force']: # TODO: check indexes Snapshot.objects.filter(vm=vm, disk_id=snap.disk_id, id__gt=snap.id).delete() vm.revert_notready() result['message'] = 'Snapshot successfully restored' elif action == 'DELETE': snap.delete() result['message'] = 'Snapshot successfully deleted' else: _vm_snapshot_cb_failed( result, task_id, snap, action) # Delete snapshot or update snapshot status logger.error( 'Found nonzero returncode in result from %s vm_snapshot(%s, %s). Error: %s', action, vm_uuid, snap, msg) raise TaskException(result, 'Got bad return code (%s). Error: %s' % (result['returncode'], msg), snap=snap) task_log_cb_success(result, task_id, vm=vm, **result['meta']) return result
def _vm_snapshot_cb_detail(data): """Create tasklog detail - used by vm_snapshot_cb in case of a restore from other VM""" return ', '.join([ '%s=%s' % (k, to_string(v)) for k, v in iteritems(data) if k in SNAPSHOT_LOG_DETAIL ])