def __init__(self, task_id=None, **kwargs): if not task_id: dc_id = cq.conf.ERIGONES_DEFAULT_DC # DefaultDc().id system_user_id = cq.conf.ERIGONES_TASK_USER # 7 task_id = task_id_from_string(system_user_id, dummy=True, dc_id=dc_id, tt=TT_DUMMY, tg=TG_DC_UNBOUND) kwargs['broadcast'] = True super(BroadcastEvent, self).__init__(task_id, **kwargs)
def __init__(self, user_id, dc_id=None, **kwargs): if dc_id: tg = TG_DC_BOUND else: tg = TG_DC_UNBOUND dc_id = cq.conf.ERIGONES_DEFAULT_DC # DefaultDc().id task_id = task_id_from_string(user_id, dummy=True, dc_id=dc_id, tt=TT_DUMMY, tg=tg) kwargs['direct'] = True super(DirectEvent, self).__init__(task_id, **kwargs)
def node_status_changed_event(task_id, node, **kwargs): """node_status_changed signal callback -> connected in api.signals""" siosid = getattr(task_id, 'siosid', None) task_id = task_id_from_string(TASK_USER, owner_id=node.owner_id, tt=TT_DUMMY, tg=TG_DC_UNBOUND) # Emit NodeStatusChanged into socket.io NodeStatusChanged( task_id, node_hostname=node.hostname, status=node.status, status_display=node.get_status_display(), siosid=siosid, ).send() for vm in node.vm_set.all(): tid = task_id_from_string(TASK_USER, owner_id=vm.owner_id, dc_id=vm.dc_id, tt=TT_DUMMY, tg=TG_DC_BOUND) # Emit VmStatusChanged into socket.io VmStatusChanged(tid, vm).send()
def _vm_status_dispatcher(self): """THREAD: Reads VM status changes from queue and creates a vm_status_event_cb task for every status change""" from que.utils import task_id_from_string, send_task_forever # Circular imports vm_status_task = self._conf.ERIGONES_VM_STATUS_TASK task_user = self._conf.ERIGONES_TASK_USER queue = self.vm_status_queue logger.info('Emitting VM status changes on node %s via %s', self.node_uuid, vm_status_task) while True: event = queue.get() task_id = task_id_from_string(task_user) logger.info('Creating task %s for event: "%s"', task_id, event) # Create VM status task send_task_forever(self.label, vm_status_task, args=(event, task_id), queue=Q_MGMT, expires=None, task_id=task_id)
def vm_replica_sync_cb(result, task_id): """ Internal task called as callback by esrep after each sync. After successful update of slave_vm.last_sync it will create an event and send it into socket.io. """ slave_vm = result['slave'] master_vm_hostname = result['master_hostname'] last_sync = _parse_last_sync(result) slave_vm_filter = Q(vm=slave_vm) & (Q(last_sync__lt=last_sync) | Q(last_sync__isnull=True)) if SlaveVm.objects.filter(slave_vm_filter).update(last_sync=last_sync): logger.debug('Slave VM %s (%s) last_sync=%s saved', slave_vm, master_vm_hostname, last_sync) event_task_id = task_id_from_string(None, task_prefix=result['task_prefix']) VmReplicaSynced(event_task_id, vm_hostname=master_vm_hostname, last_sync=last_sync.isoformat()).send() else: logger.warn('Slave VM %s (%s) received invalid last_sync=%s', slave_vm, master_vm_hostname, last_sync) return result
def _esrep_callback(self): vm = self.vm task_id = task_id_from_string(settings.SYSTEM_USER, owner_id=vm.owner.id, dc_id=vm.dc.id) task_prefix = ''.join(task_prefix_from_task_id(task_id)) return 'que.replication:esrep_sync_cb:%s' % task_prefix
def __init__(self, node, **kwargs): # Create such a task_id that info is send to SuperAdmins and node owner task_id = task_id_from_string(node.owner.id, dummy=True, dc_id=DEFAULT_DC, tt=TT_DUMMY, tg=TG_DC_UNBOUND) kwargs['node_hostname'] = node.hostname super(NodeSystemRestarted, self).__init__(task_id, **kwargs)
def reserve(self, entry): new_entry = super(ESDCDatabaseScheduler, self).reserve(entry) new_entry.options['task_id'] = task_id_from_string(self.app.conf.ERIGONES_TASK_USER) return new_entry
def apply_async(self, entry, *args, **kwargs): entry.options['task_id'] = task_id_from_string(self.app.conf.ERIGONES_TASK_USER) return super(ESDCScheduler, self).apply_async(entry, *args, **kwargs)