From b638036428d694b891a9a67f5af586574331ed2c Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Thu, 30 Oct 2025 02:30:11 +0000 Subject: [PATCH 001/118] add virtrust/,keep. Signed-off-by: Jamie-Cui --- virtrust/,keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 virtrust/,keep diff --git a/virtrust/,keep b/virtrust/,keep new file mode 100644 index 0000000..e69de29 -- Gitee From ce4657ce0ea9adbb99cd93d57e74dc1e336663b5 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Thu, 30 Oct 2025 02:30:24 +0000 Subject: [PATCH 002/118] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?virtrust/,keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- virtrust/,keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 virtrust/,keep diff --git a/virtrust/,keep b/virtrust/,keep deleted file mode 100644 index e69de29..0000000 -- Gitee From bbb50a6ddc90d69745adbadaa9f9375035b64069 Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Thu, 30 Oct 2025 02:30:43 +0000 Subject: [PATCH 003/118] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20virtrust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- virtrust/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 virtrust/.keep diff --git a/virtrust/.keep b/virtrust/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From 5c595d7028e9eef631c9749ebeb92329b90375ce Mon Sep 17 00:00:00 2001 From: Jamie Cui Date: Thu, 30 Oct 2025 19:59:01 +0800 Subject: [PATCH 004/118] feat(virtrust-sh): implement virtrust shell with libvirt integration Initial implementation of the virtrust-sh shell interface that provides command-line access to libvirt operations. Includes core infrastructure for command parsing, execution framework, and initial set of domain management commands (create, destroy, start, migrate, list, undefine). Integrates with existing virtrust logging and libvirt error handling systems. --- virtrust/src/virtrust-sh/CMakeLists.txt | 18 ++ virtrust/src/virtrust-sh/defines.h | 13 ++ virtrust/src/virtrust-sh/main.cpp | 165 ++++++++++++++++++ .../src/virtrust-sh/operator/CMakeLists.txt | 22 +++ .../src/virtrust-sh/operator/op_create.cpp | 91 ++++++++++ virtrust/src/virtrust-sh/operator/op_create.h | 29 +++ .../src/virtrust-sh/operator/op_destroy.cpp | 92 ++++++++++ .../src/virtrust-sh/operator/op_destroy.h | 31 ++++ virtrust/src/virtrust-sh/operator/op_itf.cpp | 58 ++++++ virtrust/src/virtrust-sh/operator/op_itf.h | 73 ++++++++ virtrust/src/virtrust-sh/operator/op_list.h | 29 +++ .../src/virtrust-sh/operator/op_migrate.h | 30 ++++ virtrust/src/virtrust-sh/operator/op_start.h | 31 ++++ .../src/virtrust-sh/operator/op_undefine.h | 31 ++++ virtrust/src/virtrust-sh/operator/op_utils.h | 31 ++++ 15 files changed, 744 insertions(+) create mode 100644 virtrust/src/virtrust-sh/CMakeLists.txt create mode 100644 virtrust/src/virtrust-sh/defines.h create mode 100644 virtrust/src/virtrust-sh/main.cpp create mode 100644 virtrust/src/virtrust-sh/operator/CMakeLists.txt create mode 100644 virtrust/src/virtrust-sh/operator/op_create.cpp create mode 100644 virtrust/src/virtrust-sh/operator/op_create.h create mode 100644 virtrust/src/virtrust-sh/operator/op_destroy.cpp create mode 100644 virtrust/src/virtrust-sh/operator/op_destroy.h create mode 100644 virtrust/src/virtrust-sh/operator/op_itf.cpp create mode 100644 virtrust/src/virtrust-sh/operator/op_itf.h create mode 100644 virtrust/src/virtrust-sh/operator/op_list.h create mode 100644 virtrust/src/virtrust-sh/operator/op_migrate.h create mode 100644 virtrust/src/virtrust-sh/operator/op_start.h create mode 100644 virtrust/src/virtrust-sh/operator/op_undefine.h create mode 100644 virtrust/src/virtrust-sh/operator/op_utils.h diff --git a/virtrust/src/virtrust-sh/CMakeLists.txt b/virtrust/src/virtrust-sh/CMakeLists.txt new file mode 100644 index 0000000..16a577c --- /dev/null +++ b/virtrust/src/virtrust-sh/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (C) 2025 by Huawei Technologies Co., Ltd. All rights reserved. + +add_library(virtrust-sh-obj OBJECT) + +set(VIRTRUST_SH_SOURCE_FILES "") + +add_subdirectory(operator) + +target_source(virtrust-sh-obj PRIVATE ${VIRTRUST_SH_SOURCE_FILES}) + +target_include_directories( + virtrust-sh-obj PRIVATE $ + ${CMAKE_DEPENDENCY_INCLUDEDIR}) + +target_link_libraries(virtrust-sh PRIVATE virtrust-sh-obj virtrust-shared) + +install(TARGETS virtrust-sh RUNTIME DESTINATION bin PERMISSIONS OWNER_READ + OWNER_EXECUTE) diff --git a/virtrust/src/virtrust-sh/defines.h b/virtrust/src/virtrust-sh/defines.h new file mode 100644 index 0000000..b1a8abc --- /dev/null +++ b/virtrust/src/virtrust-sh/defines.h @@ -0,0 +1,13 @@ +// Copyright (C) 2025 by Huawei Technologies Co., Ltd. All rights reserved. + +#pragma once + +#include + +namespace virtrust { +constexpr std::string_view VIRTRUST_SH_VERSION = "1.0.0"; +constexpr std::string_view VIRTRUST_SH_VIRT_INSTALL_PATH = + "/usr/bin/virt-install"; +constexpr std::string_view VIRTRUST_SH_LOGFILE_NAME = "virtrust.log"; +constexpr int VIRTRUST_SH__CMD_STR_MAX_LEN = 1024; +} // namespace virtrust diff --git a/virtrust/src/virtrust-sh/main.cpp b/virtrust/src/virtrust-sh/main.cpp new file mode 100644 index 0000000..447071b --- /dev/null +++ b/virtrust/src/virtrust-sh/main.cpp @@ -0,0 +1,165 @@ +// Copyright (C) 2025 by Huawei Technologies Co., Ltd. All rights reserved. + +#include +#include + +#include +#include +#include +#include +#include + +#include "spdlog/fmt/fmt.h" + +#include "virtrust-sh/defines.h" +#include "virtrust-sh/operator/op_itf.h" +#include "virtrust/base/custom_logger.h" +#include "virtrust/base/logger.h" + +namespace { + +std::string GetLogPath() { + return std::filesystem::current_path() / virtrust::VIRTRUST_SH_LOGFILE_NAME; +} + +void PrintVersion(std::string_view progname) { + fmt::print("{} version: {}\n", progname, virtrust::VIRTRUST_SH_VERSION); +} + +void PrintUsage(std::string_view progname) { + fmt::print( + "\n" + " USAGE:\n" + " {} [options]... []\n" + " {} [options]... [args...]\n" + "\n" + " OPTIONS:\n" + " -c | --connect=URI hypervisor connection URI, " + "default to {}\n" + " -d | --debug run in debug mode\n" + " -h | --help print this help\n" + " -v | --version show verion\n" + "\n" + " COMMANDS:\n" + " create create virtual machine instance\n" + " destroy destroy (stop) a domain\n" + " list list domain information\n" + " migrate migrate domain to another host\n" + " start start a (previously define) inactive " + "domain\n" + " undefine undefine a domain\n" + "\n", + progname, progname, virtrust::VIRTRUST_DEFAULT_URI); +} + +int ProcessOp(int argc, char **argv, const virtrust::OpConfig &config) { + auto op = virtrust::MakeOperator(virtrust::OpTyFromStr(argv[optind])); + if (op == nullptr) { + fmt::print(":\nInvalid command: {}\n", argv[optind]); + PrintUsage(argc[0]); + return 1; + } + + // Setup config + op->SetConfig(config); + + // Parse subcommand + auto rc = op->ParseArgc(argc - optind, &argc[optind]); + if (rc != virtrust::OpRc::OK) { + return 1; + } + + // Execute subcommand, if enabled + if (op->GetConfig().endableExec) { + rc = op->Exec(); + if (rc != virtrust::OpRc::OK) { + fmt::print("\nCommand execution failed.\nSee log at: {}\n", GetLogPath); + return 1; + } + } + fmt::print("\nCommand execution succeed.\nSee log at: {}\n", GetLogPath); + return 0; +} + +int ProcessArgs(int argc, char **argv) { + int arg = -1; + int longindex = -1; + std::vector