feat: add `features` command

Signed-off-by: black-desk <me@black-desk.cn>
This commit is contained in:
black-desk 2024-01-20 13:19:22 +08:00
parent cc0ed79e08
commit f86c9dc246
No known key found for this signature in database
GPG Key ID: 761EE6143999AE8B
7 changed files with 170 additions and 69 deletions

View File

@ -112,50 +112,50 @@ pfl_add_library(
include/ocppi/configure.hpp.in
include/ocppi/runtime/configure.hpp.in
SOURCES
# find -regex '\.\/src\/.*\.\(h\|c\)pp'
./src/ocppi/InvalidArgumentError.cpp
# find -regex '\.\/src\/.*\.\(h\|c\)pp' | sort
./src/ocppi/cli/CommandFailedError.cpp
./src/ocppi/cli/CommonCLI.cpp
./src/ocppi/cli/crun/Crun.cpp
./src/ocppi/cli/runc/Runc.cpp
./src/ocppi/cli/youki/Youki.cpp
./src/ocppi/cli/CommonCLI.cpp
./src/ocppi/configure.cpp
./src/ocppi/runtime/ContainerID.cpp
./src/ocppi/runtime/CreateOption.cpp
./src/ocppi/runtime/DeleteOption.cpp
./src/ocppi/runtime/KillOption.cpp
./src/ocppi/runtime/Runtime.cpp
./src/ocppi/runtime/Signal.cpp
./src/ocppi/runtime/StartOption.cpp
./src/ocppi/InvalidArgumentError.cpp
./src/ocppi/runtime/config/ConfigLoader.cpp
./src/ocppi/runtime/config/IncompatibleVersionError.cpp
./src/ocppi/runtime/config/InvalidConfigError.cpp
./src/ocppi/runtime/config/KeyMissingError.cpp
./src/ocppi/runtime/config/WrongTypeError.cpp
./src/ocppi/runtime/configure.cpp
./src/ocppi/runtime/config/WrongTypeError.cpp
./src/ocppi/runtime/ContainerID.cpp
./src/ocppi/runtime/CreateOption.cpp
./src/ocppi/runtime/DeleteOption.cpp
./src/ocppi/runtime/FeaturesOption.cpp
./src/ocppi/runtime/GlobalOption.cpp
./src/ocppi/runtime/KillOption.cpp
./src/ocppi/runtime/RunOption.cpp
./src/ocppi/runtime/Runtime.cpp
./src/ocppi/runtime/semver_range.cpp
./src/ocppi/runtime/semver_range.hpp
./src/ocppi/runtime/GlobalOption.cpp
./src/ocppi/runtime/Signal.cpp
./src/ocppi/runtime/StartOption.cpp
./src/ocppi/runtime/StateOption.cpp
./src/ocppi/runtime/RunOption.cpp
HEADERS
# find -regex '\.\/include\/.*\.hpp'
./include/ocppi/cli/crun/Crun.hpp
./include/ocppi/cli/runc/Runc.hpp
./include/ocppi/cli/youki/Youki.hpp
# find -regex '\.\/include\/.*\.hpp' | sort
./include/ocppi/cli/CLI.hpp
./include/ocppi/cli/CommandFailedError.hpp
./include/ocppi/cli/CommonCLI.hpp
./include/ocppi/runtime/ContainerID.hpp
./include/ocppi/runtime/Signal.hpp
./include/ocppi/cli/crun/Crun.hpp
./include/ocppi/cli/runc/Runc.hpp
./include/ocppi/cli/youki/Youki.hpp
./include/ocppi/InvalidArgumentError.hpp
./include/ocppi/runtime/config/ConfigLoader.hpp
./include/ocppi/runtime/config/IncompatibleVersionError.hpp
./include/ocppi/runtime/config/InvalidConfigError.hpp
./include/ocppi/runtime/config/KeyMissingError.hpp
./include/ocppi/runtime/config/WrongTypeError.hpp
./include/ocppi/runtime/config/types/Anet.hpp
./include/ocppi/runtime/config/types/BlockIO.hpp
./include/ocppi/runtime/config/types/BlockIODeviceThrottle.hpp
./include/ocppi/runtime/config/types/BlockIODeviceWeight.hpp
./include/ocppi/runtime/config/types/BlockIO.hpp
./include/ocppi/runtime/config/types/BoottimeClass.hpp
./include/ocppi/runtime/config/types/Capabilities.hpp
./include/ocppi/runtime/config/types/CappedCPU.hpp
@ -167,6 +167,7 @@ pfl_add_library(
./include/ocppi/runtime/config/types/FluffyCPU.hpp
./include/ocppi/runtime/config/types/FluffyMemory.hpp
./include/ocppi/runtime/config/types/Generators.hpp
./include/ocppi/runtime/config/types/helper.hpp
./include/ocppi/runtime/config/types/Hook.hpp
./include/ocppi/runtime/config/types/Hooks.hpp
./include/ocppi/runtime/config/types/HugepageLimit.hpp
@ -178,15 +179,15 @@ pfl_add_library(
./include/ocppi/runtime/config/types/IntelRdt.hpp
./include/ocppi/runtime/config/types/IoPriority.hpp
./include/ocppi/runtime/config/types/Kernel.hpp
./include/ocppi/runtime/config/types/Linux.hpp
./include/ocppi/runtime/config/types/LinuxDevice.hpp
./include/ocppi/runtime/config/types/Linux.hpp
./include/ocppi/runtime/config/types/LinuxResources.hpp
./include/ocppi/runtime/config/types/Mount.hpp
./include/ocppi/runtime/config/types/NamespaceReference.hpp
./include/ocppi/runtime/config/types/NamespaceType.hpp
./include/ocppi/runtime/config/types/NetworkInterfacePriority.hpp
./include/ocppi/runtime/config/types/Personality.hpp
./include/ocppi/runtime/config/types/PersonalityDomain.hpp
./include/ocppi/runtime/config/types/Personality.hpp
./include/ocppi/runtime/config/types/Pids.hpp
./include/ocppi/runtime/config/types/Process.hpp
./include/ocppi/runtime/config/types/PurpleCPU.hpp
@ -194,65 +195,66 @@ pfl_add_library(
./include/ocppi/runtime/config/types/Rdma.hpp
./include/ocppi/runtime/config/types/ResourcesNetwork.hpp
./include/ocppi/runtime/config/types/Rlimit.hpp
./include/ocppi/runtime/config/types/RootfsPropagation.hpp
./include/ocppi/runtime/config/types/Root.hpp
./include/ocppi/runtime/config/types/RootImageFormat.hpp
./include/ocppi/runtime/config/types/RootfsPropagation.hpp
./include/ocppi/runtime/config/types/Scheduler.hpp
./include/ocppi/runtime/config/types/SchedulerFlag.hpp
./include/ocppi/runtime/config/types/Scheduler.hpp
./include/ocppi/runtime/config/types/SchedulerPolicy.hpp
./include/ocppi/runtime/config/types/Seccomp.hpp
./include/ocppi/runtime/config/types/SeccompAction.hpp
./include/ocppi/runtime/config/types/SeccompArch.hpp
./include/ocppi/runtime/config/types/SeccompFlag.hpp
./include/ocppi/runtime/config/types/Seccomp.hpp
./include/ocppi/runtime/config/types/SeccompOperators.hpp
./include/ocppi/runtime/config/types/Solaris.hpp
./include/ocppi/runtime/config/types/Storage.hpp
./include/ocppi/runtime/config/types/Syscall.hpp
./include/ocppi/runtime/config/types/SyscallArg.hpp
./include/ocppi/runtime/config/types/Syscall.hpp
./include/ocppi/runtime/config/types/TimeOffsets.hpp
./include/ocppi/runtime/config/types/User.hpp
./include/ocppi/runtime/config/types/Vm.hpp
./include/ocppi/runtime/config/types/Windows.hpp
./include/ocppi/runtime/config/types/WindowsDevice.hpp
./include/ocppi/runtime/config/types/Windows.hpp
./include/ocppi/runtime/config/types/WindowsNetwork.hpp
./include/ocppi/runtime/config/types/WindowsResources.hpp
./include/ocppi/runtime/config/types/Zos.hpp
./include/ocppi/runtime/config/types/ZosDevice.hpp
./include/ocppi/runtime/config/types/helper.hpp
./include/ocppi/runtime/config/ConfigLoader.hpp
./include/ocppi/runtime/config/types/Zos.hpp
./include/ocppi/runtime/config/WrongTypeError.hpp
./include/ocppi/runtime/ContainerID.hpp
./include/ocppi/runtime/CreateOption.hpp
./include/ocppi/runtime/DeleteOption.hpp
./include/ocppi/runtime/ExecOption.hpp
./include/ocppi/runtime/FeaturesOption.hpp
./include/ocppi/runtime/features/types/Apparmor.hpp
./include/ocppi/runtime/features/types/Cgroup.hpp
./include/ocppi/runtime/features/types/Features.hpp
./include/ocppi/runtime/features/types/Generators.hpp
./include/ocppi/runtime/features/types/helper.hpp
./include/ocppi/runtime/features/types/IntelRdt.hpp
./include/ocppi/runtime/features/types/Linux.hpp
./include/ocppi/runtime/features/types/NamespaceType.hpp
./include/ocppi/runtime/features/types/Seccomp.hpp
./include/ocppi/runtime/features/types/SeccompAction.hpp
./include/ocppi/runtime/features/types/SeccompArch.hpp
./include/ocppi/runtime/features/types/SeccompFlag.hpp
./include/ocppi/runtime/features/types/Seccomp.hpp
./include/ocppi/runtime/features/types/SeccompOperators.hpp
./include/ocppi/runtime/features/types/Selinux.hpp
./include/ocppi/runtime/features/types/helper.hpp
./include/ocppi/runtime/state/types/Generators.hpp
./include/ocppi/runtime/state/types/State.hpp
./include/ocppi/runtime/state/types/Status.hpp
./include/ocppi/runtime/state/types/helper.hpp
./include/ocppi/runtime/CreateOption.hpp
./include/ocppi/runtime/DeleteOption.hpp
./include/ocppi/runtime/ExecOption.hpp
./include/ocppi/runtime/GlobalOption.hpp
./include/ocppi/runtime/KillOption.hpp
./include/ocppi/runtime/ListOption.hpp
./include/ocppi/runtime/RunOption.hpp
./include/ocppi/runtime/Runtime.hpp
./include/ocppi/runtime/Signal.hpp
./include/ocppi/runtime/SpecRuntime.hpp
./include/ocppi/runtime/StartOption.hpp
./include/ocppi/runtime/StateOption.hpp
./include/ocppi/runtime/RunOption.hpp
./include/ocppi/runtime/state/types/Generators.hpp
./include/ocppi/runtime/state/types/helper.hpp
./include/ocppi/runtime/state/types/State.hpp
./include/ocppi/runtime/state/types/Status.hpp
./include/ocppi/types/ContainerListItem.hpp
./include/ocppi/types/Generators.hpp
./include/ocppi/types/helper.hpp
./include/ocppi/InvalidArgumentError.hpp
EXAMPLES
parse-config
using-crun

View File

@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
#include "ocppi/runtime/FeaturesOption.hpp"
#include "ocppi/runtime/Runtime.hpp"
namespace ocppi::cli
@ -10,6 +11,47 @@ class CLI : public virtual runtime::Runtime {
public:
[[nodiscard]]
virtual auto bin() const noexcept -> const std::filesystem::path & = 0;
protected:
[[nodiscard]]
virtual auto generateGlobalOptions(const runtime::GlobalOption &option)
const noexcept -> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::FeaturesOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::CreateOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::DeleteOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::ExecOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::KillOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::ListOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::StartOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::StateOption &option) const noexcept
-> std::vector<std::string> = 0;
[[nodiscard]]
virtual auto generateSubcommandOptions(const runtime::RunOption &option)
const noexcept -> std::vector<std::string> = 0;
};
}

View File

@ -8,6 +8,8 @@
#include "ocppi/cli/CLI.hpp"
#include "ocppi/runtime/ContainerID.hpp"
#include "ocppi/runtime/FeaturesOption.hpp"
#include "ocppi/runtime/features/types/Features.hpp"
#include "tl/expected.hpp"
namespace ocppi
@ -57,40 +59,36 @@ class CommonCLI : public virtual CLI {
auto logger() const -> const std::unique_ptr<spdlog::logger> &;
[[nodiscard]]
virtual auto generateGlobalOptions(const runtime::GlobalOption &option)
const noexcept -> std::vector<std::string>;
auto generateGlobalOptions(const runtime::GlobalOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::CreateOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::FeaturesOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::DeleteOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::CreateOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::ExecOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::DeleteOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::KillOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::ExecOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::ListOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::KillOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::StartOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::ListOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(
const runtime::StateOption &option) const noexcept
-> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::StartOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
virtual auto generateSubcommandOptions(const runtime::RunOption &option)
const noexcept -> std::vector<std::string>;
auto generateSubcommandOptions(const runtime::StateOption &option)
const noexcept -> std::vector<std::string> override;
[[nodiscard]]
auto generateSubcommandOptions(const runtime::RunOption &option)
const noexcept -> std::vector<std::string> override;
public:
CommonCLI(const CommonCLI &) = delete;
@ -102,6 +100,15 @@ class CommonCLI : public virtual CLI {
[[nodiscard]]
auto bin() const noexcept -> const std::filesystem::path & override;
[[nodiscard]]
auto features() const noexcept
-> tl::expected<runtime::features::types::Features,
std::exception_ptr> override;
[[nodiscard]]
auto features(const runtime::FeaturesOption &option) const noexcept
-> tl::expected<runtime::features::types::Features,
std::exception_ptr> override;
[[nodiscard]]
auto state(const runtime::ContainerID &id) const noexcept
-> tl::expected<runtime::state::types::State,

View File

@ -0,0 +1,15 @@
#pragma once
#include <string> // for basic_string, string
#include <vector> // for vector
#include "ocppi/runtime/GlobalOption.hpp" // for GlobalOption
namespace ocppi::runtime
{
struct FeaturesOption : public GlobalOption {
std::vector<std::string> extra;
};
}

View File

@ -8,9 +8,11 @@
#include "ocppi/runtime/ContainerID.hpp"
#include "ocppi/runtime/CreateOption.hpp"
#include "ocppi/runtime/DeleteOption.hpp"
#include "ocppi/runtime/FeaturesOption.hpp"
#include "ocppi/runtime/KillOption.hpp"
#include "ocppi/runtime/StartOption.hpp"
#include "ocppi/runtime/StateOption.hpp"
#include "ocppi/runtime/features/types/Features.hpp"
#include "ocppi/runtime/state/types/State.hpp"
#include "tl/expected.hpp"
@ -33,6 +35,15 @@ class SpecRuntime {
auto operator=(SpecRuntime &&) -> SpecRuntime & = delete;
virtual ~SpecRuntime() = default;
[[nodiscard]]
virtual auto features() const noexcept
-> tl::expected<features::types::Features,
std::exception_ptr> = 0;
[[nodiscard]]
virtual auto features(const FeaturesOption &option) const noexcept
-> tl::expected<features::types::Features,
std::exception_ptr> = 0;
[[nodiscard]]
virtual auto state(const ContainerID &id) const noexcept
-> tl::expected<state::types::State, std::exception_ptr> = 0;

View File

@ -29,7 +29,8 @@
#include "ocppi/runtime/Signal.hpp"
#include "ocppi/runtime/StartOption.hpp"
#include "ocppi/runtime/StateOption.hpp"
#include "ocppi/runtime/state/types/Generators.hpp" // IWYU pragma: keep
#include "ocppi/runtime/features/types/Generators.hpp" // IWYU pragma: keep
#include "ocppi/runtime/state/types/Generators.hpp" // IWYU pragma: keep
#include "ocppi/runtime/state/types/State.hpp"
#include "ocppi/types/ContainerListItem.hpp"
#include "ocppi/types/Generators.hpp" // IWYU pragma: keep
@ -265,7 +266,6 @@ auto CommonCLI::run(const runtime::ContainerID &id,
return this->run(id, pathToBundle, {});
}
[[nodiscard]]
auto CommonCLI::run(const runtime::ContainerID &id,
const std::filesystem::path &pathToBundle,
const runtime::RunOption &option) noexcept
@ -283,6 +283,23 @@ try {
return tl::unexpected(std::current_exception());
}
auto CommonCLI::features() const noexcept
-> tl::expected<runtime::features::types::Features, std::exception_ptr>
{
return this->features({});
}
auto CommonCLI::features(const runtime::FeaturesOption &option) const noexcept
-> tl::expected<runtime::features::types::Features, std::exception_ptr>
try {
return doCommand<runtime::features::types::Features>(
this->bin(), this->logger(),
this->generateGlobalOptions(option), "features",
this->generateSubcommandOptions(option), {});
} catch (...) {
return tl::unexpected(std::current_exception());
}
auto CommonCLI::generateGlobalOptions(const runtime::GlobalOption &option)
const noexcept -> std::vector<std::string>
{
@ -367,4 +384,10 @@ auto CommonCLI::generateSubcommandOptions(const runtime::RunOption &option)
return option.extra;
}
auto CommonCLI::generateSubcommandOptions(const runtime::FeaturesOption &option)
const noexcept -> std::vector<std::string>
{
return option.extra;
}
}

View File

@ -0,0 +1 @@
#include "ocppi/runtime/FeaturesOption.hpp" // IWYU pragma: keep