instance($run); if ($instance === null) { return StepResult::fail('no_instance'); } $node = (string) $run->context('node'); $vmid = (int) $run->context('vmid'); $status = $this->pve->forHost($instance->host)->vmStatus($node, $vmid); if (($status['status'] ?? '') !== 'running') { if ($run->started_at !== null && $run->started_at->copy()->addSeconds(self::RUNNING_DEADLINE)->isPast()) { return StepResult::fail('restart_did_not_come_back'); } return StepResult::poll(5, 'waiting for the machine to come back'); } if (($short = $this->shortfall($status, $instance->cores, $instance->ram_mb)) !== null) { return StepResult::fail('restart_applied_nothing: '.$short); } // Only here. The machine is running, its guest agent has answered (the // step before this one), and it is running on what was sold. if ($instance->restartIsPending()) { $instance->update(['restart_required_since' => null]); } $run->events()->create([ 'step' => $this->key(), 'attempt' => $run->attempt, 'outcome' => 'info', 'message' => "Die Maschine läuft wieder mit {$instance->cores} vCPU und {$instance->ram_mb} MB RAM. " .'Der offene Neustart ist damit erledigt.', ]); return StepResult::advance(); } /** * What the running guest is short of, or null when it is not short of * anything we can see. * * Compared with `>=` rather than `===`: Proxmox rounds memory and a host may * legitimately give a guest more than was asked for, and refusing a machine * for being too big would be a strange way to protect a customer. * * @param array $status */ private function shortfall(array $status, ?int $cores, ?int $ramMb): ?string { if (isset($status['cpus']) && $cores > 0 && (int) $status['cpus'] < $cores) { return "{$status['cpus']} statt {$cores} vCPU"; } if (isset($status['maxmem']) && $ramMb > 0) { $actualMb = (int) ((int) $status['maxmem'] / 1048576); if ($actualMb < $ramMb) { return "{$actualMb} statt {$ramMb} MB RAM"; } } return null; } }