def regenerate_motd(sender, fqdn, *args, **kwargs): """ Creates `RegenerateMOTD()` task here. This should be the one and only place for creating this task. """ task = tasks.RegenerateMOTD(fqdn) TaskManager.add(task)
def regenerate_serialconsole(sender, cscreen_server_fqdn, *args, **kwargs): """ Creates `RegenerateSerialConsole()` task here. This should be the one and only place for creating this task. """ if cscreen_server_fqdn is not None: task = tasks.RegenerateSerialConsole(cscreen_server_fqdn) TaskManager.add(task)
def regenerate_cobbler(sender, domain_id, *args, **kwargs): """ Creates `RegenerateCobbler()` task here. This should be the one and only place for creating this task. """ if domain_id is None: task = tasks.RegenerateCobbler() else: task = tasks.RegenerateCobbler(domain_id) TaskManager.add(task)
def scan(self, action='all', user=None): """ Start scanning/checking the machine by creating a task. """ from taskmanager.models import TaskManager from taskmanager import tasks if action.lower() not in tasks.MachineCheck.Scan.Action.as_list: raise Exception("Unknown scan option '{}'!".format(action)) task = tasks.MachineCheck(self.fqdn, tasks.MachineCheck.Scan.to_int(action)) TaskManager.add(task)
def setup(self, setup_label, user=None): """ Setup machine (re-install distribution). """ from taskmanager.models import TaskManager from taskmanager import tasks if self.has_setup_capability(): task = tasks.SetupMachine(self.fqdn, setup_label) TaskManager.add(task) return True return False
def execute(self): """ Executes the task. """ from taskmanager import tasks for machine in Machine.objects.all(): if machine.administrative or machine.system.administrative: continue if machine.reserved_by and not machine.is_reserved_infinite(): task = tasks.CheckReservationExpiration(machine.fqdn) TaskManager.add(task)
def users_password_restore(request): if request.method == 'GET': user_id = request.GET.get('user_id', None) username = None if user_id is not None: try: user = User.objects.get(pk=user_id) username = user.username except Exception: pass form = PasswordRestoreForm(username=username) else: form = PasswordRestoreForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'].lower() username = form.cleaned_data['login'] try: user = User.objects.get(email=email, username=username) except User.DoesNotExist: messages.error(request, "E-Mail/login does not exist.") return redirect('frontend:password_restore') password = User.objects.make_random_password() user.set_password(password) user.save() task = tasks.SendRestoredPassword(user.id, password) TaskManager.add(task) # check for multiple accounts from deprecated Orthos task = tasks.CheckMultipleAccounts(user.id) TaskManager.add(task) messages.success(request, "Password restored - check your mails.") return redirect('frontend:login') return render(request, 'registration/password_reset.html', { 'form': form, 'title': 'Reset Password' })
def reserve(self, reason, until, user=None, reserve_for_user=None): """ Reserve machine. """ from taskmanager.models import TaskManager from taskmanager import tasks from .reservationhistory import ReservationHistory if not reserve_for_user: reserve_for_user = user extension = True if not reason: raise ReserveException("Please provide a reservation reason.") if until == datetime.date.max and not user.is_superuser: raise ReserveException("Infinite reservation is not allowed.") # add to history if a superuser takes over the reservation if self.reserved_by and (self.reserved_by not in [user, reserve_for_user]): reservationhistory = ReservationHistory( machine=self, reserved_by=self.reserved_by, reserved_at=self.reserved_at, reserved_until=timezone.now(), reserved_reason='{} (taken away by {})'.format( self.reserved_reason, user)) reservationhistory.save() self.reserved_at = None self.reserved_by = reserve_for_user self.reserved_reason = reason if not self.reserved_at: self.reserved_at = timezone.now() extension = False # Infinte reservation: # -------------------- # Use `datetime.date.max` for the date and `datetime.time.min` for the time. # The minimum time (0, 0) must be set so that the correct time zone calculation does not # exceed the maximum DateTime limit (CET (UTC+1) of 9999-12-31, 23:59 (UTC) would result # in `OverflowError: date value out of range`). # Normal reservation (not infinite): # ---------------------------------- # Combine the `datetime.date` object with `datetime.time.max` (23, 59) and make the # new `datetime.datetime` object time zone aware using the default time zone (see # `TIME_ZONE` in the django settings). if until == datetime.date.max: until = timezone.datetime.combine(datetime.date.max, timezone.datetime.min.time()) until = timezone.make_aware(until, timezone.utc) else: until = timezone.datetime.combine(until, timezone.datetime.max.time()) until = timezone.make_aware(until, timezone.get_default_timezone()) self.reserved_until = until self.save() self.update_motd() if not extension: task = tasks.SendReservationInformation(reserve_for_user.id, self.fqdn) TaskManager.add(task)