diff options
author | Simon Rettberg | 2021-04-20 16:40:25 +0200 |
---|---|---|
committer | Simon Rettberg | 2021-04-20 16:40:25 +0200 |
commit | 7c5748d3a6bc12ece61ccf782047f6200b79b325 (patch) | |
tree | d409550975adb7e014dd919892d4e110e55f62c4 /modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php | |
parent | [sysconfig] Enforce proper ldadp services running on reboot/install (diff) | |
download | slx-admin-7c5748d3a6bc12ece61ccf782047f6200b79b325.tar.gz slx-admin-7c5748d3a6bc12ece61ccf782047f6200b79b325.tar.xz slx-admin-7c5748d3a6bc12ece61ccf782047f6200b79b325.zip |
[serversetup-bwlp-ipxe] Add iPXE version selector
Diffstat (limited to 'modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php')
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php new file mode 100644 index 00000000..d6633f67 --- /dev/null +++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxebuilder.inc.php @@ -0,0 +1,82 @@ +<?php + +class IPxeBuilder +{ + + const PROP_IPXE_BUILDSTRING = 'ipxe.compile-time'; + const PROP_IPXE_HASH = 'ipxe.commit-hash'; + const PROP_IPXE_COMPILE_TASKID = 'ipxe-task-id'; + const VERSION_LIST_TASK = 'ipxe-version-list-id'; + const PROP_VERSION_SELECT_TASKID = 'ipxe-version-select-id'; + + /** + * Checkout given commit/ref of ipxe repo. Returns the according task-id, or null on error + * + * @param string $version version ref (commit, tag, ...) + * @param string|null $parent parent task id + * @return ?string + */ + public static function setIpxeVersion($version, $parent = null) + { + $task = Taskmanager::submit('IpxeVersion', [ + 'action' => 'CHECKOUT', + 'ref' => $version, + 'parentTask' => $parent, + ]); + if (!Taskmanager::isTask($task)) + return null; + TaskmanagerCallback::addCallback($task, 'ipxeVersionSet'); + Property::set(IPxeBuilder::PROP_VERSION_SELECT_TASKID, $task['id'], 2); + return $task['id']; + } + + /** + * @return array|false + */ + public static function getVersionTaskResult() + { + $task = Taskmanager::status(IPxeBuilder::VERSION_LIST_TASK); + if (!Taskmanager::isTask($task) || Taskmanager::isFailed($task)) { + $task = Taskmanager::submit('IpxeVersion', + ['id' => IPxeBuilder::VERSION_LIST_TASK, 'action' => 'LIST']); + } + $task = Taskmanager::waitComplete($task); + if (Taskmanager::isFinished($task) && !Taskmanager::isFailed($task)) { + return $task['data']; + } + return false; + } + + /** + * Callback when compile Taskmanager job finished + */ + public static function compileCompleteCallback($task) + { + if (!Taskmanager::isFinished($task) || Taskmanager::isFailed($task)) + return; + $version = 'Unknown'; + if (isset($task['data']['hash'])) { + $hash = $task['data']['hash']; + Property::set(IPxeBuilder::PROP_IPXE_HASH, $hash); + $version = $hash; + $list = IPxeBuilder::getVersionTaskResult(); + if (isset($list['versions'])) { + foreach ($list['versions'] as $v) { + if ($v['hash'] === $version) { + $version = date('Y-m-d H:i', $v['date']) . ' (' . substr($version, 0, 7) . ')'; + break; + } + } + } + } + $buildString = date('d.m.Y H:i') . ', Version: ' . $version; + Property::set(IPxeBuilder::PROP_IPXE_BUILDSTRING, $buildString); + } + + public static function setIPxeVersionCallback($task) + { + if (!Taskmanager::isFinished($task) || Taskmanager::isFailed($task) || empty($task['data']['ref'])) + return; + Property::set(IPxeBuilder::PROP_IPXE_HASH, $task['data']['ref']); + } +}
\ No newline at end of file |