summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-11 11:32:29 +0200
committerSimon Rettberg2022-05-11 11:32:29 +0200
commit7493d9496e96278726bd94b1d12770124c3f63a1 (patch)
treed181469adf0a9dcbfd7f16ddae7192bb8eb4df26 /inc
parent[baseconfig_bwlp] Add SLX_DHCP_OTHER_NICS (diff)
downloadslx-admin-7493d9496e96278726bd94b1d12770124c3f63a1.tar.gz
slx-admin-7493d9496e96278726bd94b1d12770124c3f63a1.tar.xz
slx-admin-7493d9496e96278726bd94b1d12770124c3f63a1.zip
[vmstore] Add types where possible and do false -> null
Diffstat (limited to 'inc')
-rw-r--r--inc/event.inc.php8
-rw-r--r--inc/trigger.inc.php36
2 files changed, 23 insertions, 21 deletions
diff --git a/inc/event.inc.php b/inc/event.inc.php
index 2d916b48..57b4871e 100644
--- a/inc/event.inc.php
+++ b/inc/event.inc.php
@@ -45,7 +45,7 @@ class Event
// Check status of all tasks
// Mount vm store
- if ($mountId === false) {
+ if ($mountId === null) {
EventLog::info('No VM store type defined.');
$everythingFine = false;
} else {
@@ -58,7 +58,7 @@ class Event
$everythingFine = false;
}
// iPXE generation
- if ($ipxeId === false) {
+ if ($ipxeId === null) {
EventLog::failure('Cannot generate PXE menu: Taskmanager unreachable!');
$everythingFine = false;
} else {
@@ -78,10 +78,10 @@ class Event
$mountId = Trigger::mount();
$mountStatus = Taskmanager::waitComplete($mountId, 10000);
}
- if ($mountId !== false && Taskmanager::isFailed($mountStatus)) {
+ if ($mountId !== null && Taskmanager::isFailed($mountStatus)) {
EventLog::failure('Mounting VM store failed', $mountStatus['data']['messages'] ?? '');
$everythingFine = false;
- } elseif ($mountId !== false && !Taskmanager::isFinished($mountStatus)) {
+ } elseif ($mountId !== null && !Taskmanager::isFinished($mountStatus)) {
// TODO: Still running - create callback
}
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index 6acd6f87..df06229b 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -15,12 +15,12 @@ class Trigger
* Compile iPXE pxelinux menu. Needs to be done whenever the server's IP
* address changes.
*
- * @return string|false false if launching task failed, task-id otherwise
+ * @return ?string false if launching task failed, task-id otherwise
*/
- public static function ipxe($taskId = null)
+ public static function ipxe(string $taskId = null)
{
- static $lastResult = false;
- if ($lastResult !== false)
+ static $lastResult = null;
+ if ($lastResult !== null)
return $lastResult;
$hooks = Hook::load('ipxe-update');
foreach ($hooks as $hook) {
@@ -37,7 +37,8 @@ class Trigger
$taskId = $ret['id'];
}
}
- return $lastResult = ($taskId ?? false);
+ $lastResult = $taskId;
+ return $taskId;
}
/**
@@ -48,7 +49,7 @@ class Trigger
* @return boolean true if current configured IP address is still valid, or if a new address could
* successfully be determined, false otherwise
*/
- public static function autoUpdateServerIp()
+ public static function autoUpdateServerIp(): bool
{
for ($i = 0; $i < 5; ++$i) {
$task = Taskmanager::submit('LocalAddressesList');
@@ -59,7 +60,7 @@ class Trigger
if ($task === false)
return false;
$task = Taskmanager::waitComplete($task, 10000);
- if (!isset($task['data']['addresses']) || empty($task['data']['addresses']))
+ if (empty($task['data']['addresses']))
return false;
$serverIp = Property::getServerIp();
@@ -96,17 +97,17 @@ class Trigger
/**
* Mount the VM store into the server.
*
- * @param array $vmstore VM Store configuration to use. If false, read from properties
+ * @param array|false $vmstore VM Store configuration to use. If false, read from properties
* @param bool $ifLocalOnly Only execute task if the storage type is local (used for DNBD3)
- * @return string|false task id of mount procedure, or false on error
+ * @return ?string task id of mount procedure, or false on error
*/
- public static function mount($vmstore = false, $ifLocalOnly = false)
+ public static function mount($vmstore = false, bool $ifLocalOnly = false)
{
if ($vmstore === false) {
$vmstore = Property::getVmStoreConfig();
}
if (!is_array($vmstore))
- return false;
+ return null;
if (isset($vmstore['storetype'])) {
$storetype = $vmstore['storetype'];
} else {
@@ -124,7 +125,7 @@ class Trigger
}
// Bail out if storage is not local, and we only want to run it in that case
if ($ifLocalOnly && $addr !== 'null')
- return false;
+ return null;
if (isset($vmstore[$opts])) {
$opts = $vmstore[$opts];
}else {
@@ -143,7 +144,7 @@ class Trigger
// for the taskmanager to give us the existing id
$status = Taskmanager::waitComplete($status, 100);
}
- return $status['data']['existingTask'] ?? $status['id'] ?? false;
+ return $status['data']['existingTask'] ?? $status['id'] ?? null;
}
/**
@@ -151,7 +152,7 @@ class Trigger
*
* @return boolean Whether there are still callbacks pending
*/
- public static function checkCallbacks()
+ public static function checkCallbacks(): bool
{
$tasksLeft = false;
$callbackList = TaskmanagerCallback::getPendingCallbacks();
@@ -162,15 +163,16 @@ class Trigger
foreach ($callbacks as $callback) {
TaskmanagerCallback::handleCallback($callback, $status);
}
- if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status))
+ if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status)) {
Taskmanager::release($status);
- else
+ } else {
$tasksLeft = true;
+ }
}
return $tasksLeft;
}
- private static function triggerDaemons($action, $parent, &$taskids)
+ private static function triggerDaemons(string $action, $parent, &$taskids)
{
$task = Taskmanager::submit('Systemctl', array(
'operation' => $action,