change format of source code

Signed-off-by: haozi007 <liuhao27@huawei.com>
This commit is contained in:
haozi007 2020-05-26 19:35:10 +08:00
parent f045485f4c
commit f2157a4b60
716 changed files with 7 additions and 142359 deletions

View File

@ -1,113 +0,0 @@
cmake_minimum_required (VERSION 2.8)
project (isulad)
include(cmake/helper.cmake)
include(cmake/options.cmake)
include(cmake/set_build_flags.cmake)
#set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler")
set(GIT_COMMIT_HASH "d03048c03e5f83d8de4e6f164f354a9cb8316362")
message("-- commit id: " ${GIT_COMMIT_HASH})
add_definitions(-DISULAD_GIT_COMMIT="${GIT_COMMIT_HASH}")
execute_process(
COMMAND sh -c "date --rfc-3339 ns | sed -e 's/ /T/'"
OUTPUT_VARIABLE BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("-- build time: " ${BUILD_DATE})
add_definitions(-DISULAD_BUILD_TIME="${BUILD_DATE}")
if (NOT ISULAD_ROOT_PATH)
add_definitions(-DISULAD_ROOT_PATH="/var/lib/isulad")
endif()
if (NOT ISULAD_STATE_PATH)
add_definitions(-DISULAD_STATE_PATH="/var/run/isulad")
endif()
if (LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR_DEFAULT ${LIB_INSTALL_DIR})
else()
set(LIB_INSTALL_DIR_DEFAULT "lib")
endif()
# check depends library and headers
include(cmake/checker.cmake)
if (CHECKER_RESULT)
message(FATAL_ERROR "ERROR: Check library and headers failed")
endif()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
"${CMAKE_BINARY_DIR}/conf/config.h"
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/isulad.pc.in"
"${CMAKE_BINARY_DIR}/conf/isulad.pc"
)
# parse .proto files
include(cmake/protoc.cmake)
# llt and coverage
SET(CMAKE_VERBOSE_MAKEFILE OFF)
IF(ENABLE_COVERAGE)
MESSAGE(STATUS "Enable coverage compile option")
SET(COVERAGE_C_OPTION "${COVERAGE_OPTION} -fprofile-arcs -ftest-coverage -fkeep-inline-functions -fkeep-static-functions")
SET(COVERAGE_CXX_OPTION "${COVERAGE_OPTION} -fprofile-arcs -ftest-coverage")
ENDIF(ENABLE_COVERAGE)
IF(ENABLE_ASAN)
MESSAGE(STATUS "Enable asan compile option")
SET(ASAN_OPTIONS "${ASAN_OPTION} -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer")
ENDIF(ENABLE_ASAN)
IF(CMAKE_BUILD_TYPE STREQUAL Debug)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_C_OPTION} ${ASAN_OPTIONS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_CXX_OPTION} ${ASAN_OPTIONS}")
ENDIF()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
OPTION(ENABLE_LLT "llt switch" OFF)
IF(ENABLE_LLT)
enable_testing()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
ENDIF(ENABLE_LLT)
# install all files
install(FILES ${CMAKE_BINARY_DIR}/conf/isulad.pc
DESTINATION ${LIB_INSTALL_DIR_DEFAULT}/pkgconfig PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/libisula.h
DESTINATION include/isulad)
install(FILES src/connect/client/isula_connect.h
DESTINATION include/isulad)
install(FILES src/container_def.h
DESTINATION include/isulad)
install(FILES src/types_def.h
DESTINATION include/isulad)
install(FILES src/error.h
DESTINATION include/isulad)
install(FILES src/engines/engine.h
DESTINATION include/isulad)
# install config files
set(conf_prefix "/etc")
if (CMAKE_INSTALL_SYSCONFDIR)
set(conf_prefix ${CMAKE_INSTALL_SYSCONFDIR})
endif()
install(FILES src/contrib/config/daemon.json
DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/config/config.json src/contrib/config/systemcontainer_config.json
DESTINATION ${conf_prefix}/default/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/config/seccomp_default.json
DESTINATION ${conf_prefix}/isulad PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/config/hooks/default.json
DESTINATION ${conf_prefix}/default/isulad/hooks PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE)
install(FILES src/contrib/sysmonitor/isulad-check.sh
DESTINATION ${conf_prefix}/default/isulad PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
install(FILES src/contrib/sysmonitor/isulad-monit
DESTINATION ${conf_prefix}/sysmonitor/process PERMISSIONS OWNER_READ OWNER_WRITE)

View File

@ -1,265 +0,0 @@
#######################################################################
##- @Copyright (C) Huawei Technologies., Ltd. 2019. All rights reserved.
# - lcr licensed under the Mulan PSL v2.
# - You can use this software according to the terms and conditions of the Mulan PSL v2.
# - You may obtain a copy of Mulan PSL v2 at:
# - http://license.coscl.org.cn/MulanPSL2
# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# - PURPOSE.
# - See the Mulan PSL v2 for more details.
##- @Description: prepare compile container envrionment
##- @Author: lifeng
##- @Create: 2020-01-10
#######################################################################
# This file describes the isulad compile container image.
#
# Usage:
#
# docker build --build-arg http_proxy=YOUR_HTTP_PROXY_IF_NEEDED \
# --build-arg https_proxy=YOUR_HTTPS_PROXY_IF_NEEDED \
# -t YOUR_IMAGE_NAME -f ./Dockerfile .
FROM centos:7.6.1810
MAINTAINER LiFeng <lifeng68@huawei.com>
# Install dependency package
RUN yum clean all && yum swap -y fakesystemd systemd && \
yum install -y epel-release \
yum update -y && \
yum install -y automake \
autoconf \
libtool \
make \
cmake \
which \
gdb \
strace \
rpm-build \
graphviz \
libcap \
libcap-devel \
libxslt \
docbook2X \
libselinux \
libselinux-devel \
libseccomp \
libseccomp-devel \
yajl-devel \
git \
bridge-utils \
dnsmasq \
libcgroup \
rsync \
iptables \
iproute \
net-tools \
unzip \
tar \
wget \
gtest \
gtest-devel \
gmock \
gmock-devel \
cppcheck \
python3 \
python3-pip \
python \
python-pip \
device-mapper-devel \
libcurl-devel \
zlib-devel \
glibc-headers \
openssl-devel \
gcc \
gcc-c++ \
hostname \
sqlite-devel \
gpgme \
gpgme-devel \
expect \
systemd-devel \
systemd-libs \
go \
CUnit \
CUnit-devel \
valgrind \
e2fsprogs
RUN pip install xlrd
RUN yum clean all && \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; \
do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
RUN echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" >> /etc/bashrc && \
echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH" >> /etc/bashrc && \
echo "/usr/lib" >> /etc/ld.so.conf && \
echo "/usr/local/lib" >> /etc/ld.so.conf
# disalbe sslverify
RUN git config --global http.sslverify false
# Centos has no protobuf, protobuf-devel, grpc, grpc-devel, grpc-plugin
# and we should install them manually.
# install protobuf
RUN set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/protobuf.git && \
cd protobuf && \
tar -xzvf protobuf-all-3.9.0.tar.gz && \
cd protobuf-3.9.0 && \
./autogen.sh && \
./configure && \
make -j $(nproc) && \
make install && \
ldconfig
# install c-ares
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/c-ares.git && \
cd c-ares && \
tar -xzvf c-ares-1.15.0.tar.gz && \
cd c-ares-1.15.0 && \
autoreconf -if && \
./configure --enable-shared --disable-dependency-tracking && \
make -j $(nproc) && \
make install && \
ldconfig
# install grpc
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/grpc.git && \
cd grpc && \
tar -xzvf grpc-1.22.0.tar.gz && \
cd grpc-1.22.0 && \
make -j $(nproc) && \
make install && \
ldconfig
# install libevent
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/libevent.git && \
cd libevent && \
tar -xzvf libevent-2.1.11-stable.tar.gz && \
cd libevent-2.1.11-stable && \
./autogen.sh && \
./configure && \
make -j $(nproc) && \
make install && \
ldconfig
# install libevhtp
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/libevhtp.git && \
cd libevhtp && \
tar -xzvf libevhtp-1.2.16.tar.gz && \
cd libevhtp-1.2.16 && \
patch -p1 -F1 -s < ../0001-support-dynamic-threads.patch && \
patch -p1 -F1 -s < ../0002-close-openssl.patch && \
rm -rf build && \
mkdir build && \
cd build && \
cmake -D EVHTP_BUILD_SHARED=on -D EVHTP_DISABLE_SSL=on ../ && \
make -j $(nproc) && \
make install && \
ldconfig
# install http-parser
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/http-parser.git && \
cd http-parser && \
tar -xzvf http-parser-2.9.2.tar.gz && \
cd http-parser-2.9.2 && \
make -j CFLAGS="-Wno-error" && \
make CFLAGS="-Wno-error" install && \
ldconfig
# install libwebsockets
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/libwebsockets.git && \
cd libwebsockets && \
tar -xzvf libwebsockets-2.4.2.tar.gz && \
cd libwebsockets-2.4.2 && \
patch -p1 -F1 -s < ../libwebsockets-fix-coredump.patch && \
mkdir build && \
cd build && \
cmake -DLWS_WITH_SSL=0 -DLWS_MAX_SMP=32 -DCMAKE_BUILD_TYPE=Debug ../ && \
make -j $(nproc) && \
make install && \
ldconfig
# install lxc
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/src-openeuler/lxc.git && \
cd lxc && \
./apply-patches && \
cd lxc-3.0.3 && \
./autogen.sh && \
./configure && \
make -j $(nproc) && \
make install && \
ldconfig
# install lcr
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/openeuler/lcr.git && \
cd lcr && \
mkdir build && \
cd build && \
cmake ../ && \
make -j $(nproc) && \
make install && \
ldconfig
# install clibcni
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/openeuler/clibcni.git && \
cd clibcni && \
mkdir build && \
cd build && \
cmake ../ && \
make -j $(nproc) && \
make install && \
ldconfig
# install iSulad-img
RUN export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH && \
set -x && \
cd ~ && \
git clone https://gitee.com/openeuler/iSulad-img.git && \
cd iSulad-img && \
./apply-patch && \
make -j $(nproc) && \
make install && \
ldconfig
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

View File

@ -1,127 +0,0 @@
木兰宽松许可证, 第2版
木兰宽松许可证, 第2版
2020年1月 http://license.coscl.org.cn/MulanPSL2
您对“软件”的复制、使用、修改及分发受木兰宽松许可证第2版“本许可证”的如下条款的约束
0. 定义
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
“法人实体”是指提交贡献的机构及其“关联实体”。
“关联实体”是指对“本许可证”下的行为方而言控制、受控制或与其共同受控制的机构此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
1. 授予版权许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
2. 授予专利许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
3. 无商标许可
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可但您为满足第4条规定的声明义务而必须使用除外。
4. 分发限制
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
5. 免责声明与责任限制
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
6. 语言
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
条款结束
如何将木兰宽松许可证第2版应用到您的软件
如果您希望将木兰宽松许可证第2版应用到您的新软件为了方便接收者查阅建议您完成如下三步
1 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
2 请您在软件包的一级目录下创建以“LICENSE”为名的文件将整个许可证文本放入该文件中
3 请将如下声明文本放入每个源文件的头部注释中。
Copyright (c) [Year] [name of copyright holder]
[Software Name] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
Mulan Permissive Software LicenseVersion 2
Mulan Permissive Software LicenseVersion 2 (Mulan PSL v2)
January 2020 http://license.coscl.org.cn/MulanPSL2
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
0. Definition
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
Contribution means the copyrightable work licensed by a particular Contributor under this License.
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
Legal Entity means the entity making a Contribution and all its Affiliates.
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, control means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
1. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
2. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
3. No Trademark License
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
4. Distribution Restriction
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
5. Disclaimer of Warranty and Limitation of Liability
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW ITS CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
6. Language
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
END OF THE TERMS AND CONDITIONS
How to Apply the Mulan Permissive Software LicenseVersion 2 (Mulan PSL v2) to Your Software
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
Copyright (c) [Year] [name of copyright holder]
[Software Name] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.

View File

@ -1,74 +0,0 @@
<img src="logo/isula-logo.png" alt="iSulad" style="zoom:80%;" />
## iSulad
`iSulad` is a light weight container runtime daemon which is designed for IOT and Cloud infrastructure.`iSulad` has the characteristics of light, fast and not limited by hardware specifications and architecture, and can be applied more widely.
## Getting Started
### Installing
To install iSulad, you can use `rpm` or `yum` package manager command with `openEuler` repository.
Install iSulad with yum
```sh
yum install -y iSulad
```
### Run
We provide `systemd` service to start `iSulad`
```sh
systemctl start isulad # run the server with systemd command
```
You can use direct command to start `iSulad` server
```sh
$ sudo isulad # run the server with default socket name and default log level and images manage function
```
### Operations on containers:
`iSulad` provides command line `isulad` to talk with server.
Here are some sample commands to manager containers.
List all containers in your own environment:
```sh
# list containers
$ sudo isula ps -a
```
Create a container with busybox named `test`
```sh
# create a container 'test' with image busybox
$ sudo isula create -t -n test busybox
```
Start this container `test`
```sh
# start the container 'test'
$ sudo isula start test
```
Kill the container `test`
```sh
# kill the container 'test'
$ sudo isula kill test
```
Remove the container `test`
```sh
# remove the container 'test'
$ sudo isula rm test
```
### Build from source
Build requirements for developers are listed in [build_guide](./docs/build_guide.md)
### Integration
Integrate with `kubenetes` are listed in [integration.md](./docs/integration.md)
## How to Contribute
We always welcome new contributors. And we are happy to provide guidance for the new contributors.
iSulad follows the kernel coding conventions. You can find a detailed introduction at:
- https://www.kernel.org/doc/html/v4.10/process/coding-style.html
## Licensing
iSulad is licensed under the Mulan PSL v2.

View File

@ -1,152 +0,0 @@
include(CheckIncludeFile)
# check depends library and headers
find_package(PkgConfig REQUIRED)
# check python3
find_program(CMD_PYTHON python3)
_CHECK(CMD_PYTHON "CMD_PYTHON-NOTFOUND" "python3")
# check tools
find_program(CMD_TAR tar)
_CHECK(CMD_TAR "CMD_TAR-NOTFOUND" "tar")
find_program(CMD_SHA256 sha256sum)
_CHECK(CMD_SHA256 "CMD_SHA256-NOTFOUND" "sha256sum")
find_program(CMD_GZIP gzip)
_CHECK(CMD_GZIP "CMD_GZIP-NOTFOUND" "gzip")
# check std headers ctype.h sys/param.h sys/capability.h
find_path(STD_HEADER_CTYPE ctype.h)
_CHECK(STD_HEADER_CTYPE "STD_HEADER_CTYPE-NOTFOUND" "ctype.h")
find_path(STD_HEADER_SYS_PARAM sys/param.h)
_CHECK(STD_HEADER_SYS_PARAM "STD_HEADER_SYS_PARAM-NOTFOUND" "sys/param.h")
CHECK_INCLUDE_FILE(sys/capability.h HAVE_LIBCAP)
if (HAVE_LIBCAP)
message("-- found linux capability.h --- works")
add_definitions(-DHAVE_LIBCAP_H=1)
else()
message("-- found linux capability.h --- no")
endif()
if (SYSTEMD_NOTIFY)
# check systemd
find_path(SYSTEMD_INCLUDE_DIR systemd/sd-daemon.h)
_CHECK(SYSTEMD_INCLUDE_DIR "SYSTEMD_INCLUDE_DIR-NOTFOUND" "systemd/sd-daemon.h")
find_library(SYSTEMD_LIBRARY systemd)
_CHECK(SYSTEMD_LIBRARY "SYSTEMD_LIBRARY-NOTFOUND" "libsystemd.so")
endif()
# check zlib
pkg_check_modules(PC_ZLIB "zlib>=1.2.8")
find_path(ZLIB_INCLUDE_DIR zlib.h
HINTS ${PC_ZLIB_INCLUDEDIR} ${PC_ZLIB_INCLUDE_DIRS})
_CHECK(ZLIB_INCLUDE_DIR "ZLIB_INCLUDE_DIR-NOTFOUND" "zlib.h")
find_library(ZLIB_LIBRARY z
HINTS ${PC_ZLIB_LIBDIR} ${PC_ZLIB_LIBRARY_DIRS})
_CHECK(ZLIB_LIBRARY "ZLIB_LIBRARY-NOTFOUND" "libz.so")
# check libyajl
pkg_check_modules(PC_LIBYAJL REQUIRED "yajl>=2")
find_path(LIBYAJL_INCLUDE_DIR yajl/yajl_tree.h
HINTS ${PC_LIBYAJL_INCLUDEDIR} ${PC_LIBYAJL_INCLUDE_DIRS})
_CHECK(LIBYAJL_INCLUDE_DIR "LIBYAJL_INCLUDE_DIR-NOTFOUND" "yajl/yajl_tree.h")
find_library(LIBYAJL_LIBRARY yajl
HINTS ${PC_LIBYAJL_LIBDIR} ${PC_LIBYAJL_LIBRARY_DIRS})
_CHECK(LIBYAJL_LIBRARY "LIBYAJL_LIBRARY-NOTFOUND" "libyajl.so")
find_path(HTTP_PARSER_INCLUDE_DIR http_parser.h)
_CHECK(HTTP_PARSER_INCLUDE_DIR "HTTP_PARSER_INCLUDE_DIR-NOTFOUND" "http_parser.h")
find_library(HTTP_PARSER_LIBRARY http_parser)
_CHECK(HTTP_PARSER_LIBRARY "HTTP_PARSER_LIBRARY-NOTFOUND" "libhttp_parser.so")
pkg_check_modules(PC_CURL "libcurl>=7.4.0")
find_path(CURL_INCLUDE_DIR "curl/curl.h"
HINTS ${PC_CURL_INCLUDEDIR} ${PC_CURL_INCLUDE_DIRS})
_CHECK(CURL_INCLUDE_DIR "CURL_INCLUDE_DIR-NOTFOUND" "curl/curl.h")
find_library(CURL_LIBRARY curl
HINTS ${PC_CURL_LIBDIR} ${PC_CURL_LIBRARY_DIRS})
_CHECK(CURL_LIBRARY "CURL_LIBRARY-NOTFOUND" "libcurl.so")
pkg_check_modules(PC_SELINUX "libselinux>=2.0")
find_path(SELINUX_INCLUDE_DIR "selinux/selinux.h"
HINTS ${PC_SELINUX_INCLUDEDIR} ${PC_SELINUX_INCLUDE_DIRS})
_CHECK(SELINUX_INCLUDE_DIR "SELINUX_INCLUDE_DIR-NOTFOUND" "selinux/selinux.h")
find_library(SELINUX_LIBRARY selinux
HINTS ${PC_SELINUX_LIBDIR} ${PC_SELINUX_LIBRARY_DIRS})
_CHECK(SELINUX_LIBRARY "SELINUX_LIBRARY-NOTFOUND" "libselinux.so")
if (OPENSSL_VERIFY)
find_path(OPENSSL_INCLUDE_DIR openssl/x509.h)
_CHECK(OPENSSL_INCLUDE_DIR "OPENSSL_INCLUDE_DIR-NOTFOUND" "openssl/x509.h")
endif()
if (GRPC_CONNECTOR OR ENABLE_OCI_IMAGE)
# check protobuf
pkg_check_modules(PC_PROTOBUF "protobuf>=3.1.0")
find_library(PROTOBUF_LIBRARY protobuf
HINTS ${PC_PROTOBUF_LIBDIR} ${PC_PROTOBUF_LIBRARY_DIRS})
_CHECK(PROTOBUF_LIBRARY "PROTOBUF_LIBRARY-NOTFOUND" "libprotobuf.so")
find_program(CMD_PROTOC protoc)
_CHECK(CMD_PROTOC "CMD_PROTOC-NOTFOUND" "protoc")
find_program(CMD_GRPC_CPP_PLUGIN grpc_cpp_plugin)
_CHECK(CMD_GRPC_CPP_PLUGIN "CMD_GRPC_CPP_PLUGIN-NOTFOUND" "grpc_cpp_plugin")
# check grpc
find_path(GRPC_INCLUDE_DIR grpc/grpc.h)
_CHECK(GRPC_INCLUDE_DIR "GRPC_INCLUDE_DIR-NOTFOUND" "grpc/grpc.h")
find_library(GRPC_PP_REFLECTION_LIBRARY grpc++_reflection)
_CHECK(GRPC_PP_REFLECTION_LIBRARY "GRPC_PP_REFLECTION_LIBRARY-NOTFOUND" "libgrpc++_reflection.so")
find_library(GRPC_PP_LIBRARY grpc++)
_CHECK(GRPC_PP_LIBRARY "GRPC_PP_LIBRARY-NOTFOUND" "libgrpc++.so")
find_library(GRPC_LIBRARY grpc)
_CHECK(GRPC_LIBRARY "GRPC_LIBRARY-NOTFOUND" "libgrpc.so")
find_library(GPR_LIBRARY gpr)
_CHECK(GPR_LIBRARY "GPR_LIBRARY-NOTFOUND" "libgpr.so")
endif()
if (GRPC_CONNECTOR)
# check websocket
find_path(WEBSOCKET_INCLUDE_DIR libwebsockets.h)
_CHECK(WEBSOCKET_INCLUDE_DIR "WEBSOCKET_INCLUDE_DIR-NOTFOUND" libwebsockets.h)
find_library(WEBSOCKET_LIBRARY websockets)
_CHECK(WEBSOCKET_LIBRARY "WEBSOCKET_LIBRARY-NOTFOUND" "libwebsockets.so")
# check clibcni
pkg_check_modules(PC_CLIBCNI REQUIRED "clibcni")
find_path(CLIBCNI_INCLUDE_DIR clibcni/api.h
HINTS ${PC_CLIBCNI_INCLUDEDIR} ${PC_CLIBCNI_INCLUDE_DIRS})
_CHECK(CLIBCNI_INCLUDE_DIR "CLIBCNI_INCLUDE_DIR-NOTFOUND" "clibcni/api.h")
find_library(CLIBCNI_LIBRARY clibcni
HINTS ${PC_CLIBCNI_LIBDIR} ${PC_CLIBCNI_LIBRARY_DIRS})
_CHECK(CLIBCNI_LIBRARY "CLIBCNI_LIBRARY-NOTFOUND" "libclibcni.so")
else()
pkg_check_modules(PC_EVENT "event>=2.1.8")
find_path(EVENT_INCLUDE_DIR event.h
HINTS ${PC_EVENT_INCLUDEDIR} ${PC_EVENT_INCLUDE_DIRS})
_CHECK(EVENT_INCLUDE_DIR "EVENT_INCLUDE_DIR-NOTFOUND" "event.h")
find_library(EVENT_LIBRARY event
HINTS ${PC_EVENT_LIBDIR} ${PC_EVENT_LIBRARY_DIRS})
_CHECK(EVENT_LIBRARY "EVENT_LIBRARY-NOTFOUND" "libevent.so")
pkg_check_modules(PC_EVHTP "evhtp>=1.2.16")
find_path(EVHTP_INCLUDE_DIR evhtp/evhtp.h
HINTS ${PC_EVHTP_INCLUDEDIR} ${PC_EVHTP_INCLUDE_DIRS})
_CHECK(EVHTP_INCLUDE_DIR "EVHTP_INCLUDE_DIR-NOTFOUND" "evhtp/evhtp.h")
find_library(EVHTP_LIBRARY evhtp
HINTS ${PC_EVHTP_LIBDIR} ${PC_EVHTP_LIBRARY_DIRS})
_CHECK(EVHTP_LIBRARY "EVHTP_LIBRARY-NOTFOUND" "libevhtp.so")
endif()
if (ENABLE_EMBEDDED_IMAGE)
pkg_check_modules(PC_SQLITE3 "sqlite3>=3.7.17")
find_path(SQLIT3_INCLUDE_DIR sqlite3.h
HINTS ${PC_SQLITE3_INCLUDEDIR} ${PC_SQLITE3_INCLUDE_DIRS})
_CHECK(SQLIT3_INCLUDE_DIR "SQLIT3_INCLUDE_DIR-NOTFOUND" "sqlite3.h")
find_library(SQLITE3_LIBRARY sqlite3
HINTS ${PC_SQLITE3_LIBDIR} ${PC_SQLITE3_LIBRARY_DIRS})
_CHECK(SQLITE3_LIBRARY "SQLITE3_LIBRARY-NOTFOUND" "libsqlite3.so")
endif()

View File

@ -1,9 +0,0 @@
# use to check result
macro(_CHECK)
if (${ARGV0} STREQUAL "${ARGV1}")
message("ERROR: can not find " ${ARGV2} " program")
set(CHECKER_RESULT 1)
else()
message("-- found " ${ARGV2} " --- works")
endif()
endmacro()

View File

@ -1,62 +0,0 @@
# build which type of lcr library
option(USESHARED "set type of libs, default is shared" ON)
if (USESHARED STREQUAL "ON")
set(LIBTYPE "SHARED")
message("-- Build shared library")
else ()
set(LIBTYPE "STATIC")
message("-- Build static library")
endif()
option(ENABLE_GRPC "use grpc as connector" ON)
if (ENABLE_GRPC STREQUAL "ON")
add_definitions(-DGRPC_CONNECTOR)
set(GRPC_CONNECTOR 1)
endif()
option(ENABLE_SYSTEMD_NOTIFY "enable systemd notify" ON)
if (ENABLE_SYSTEMD_NOTIFY STREQUAL "ON")
add_definitions(-DSYSTEMD_NOTIFY)
set(SYSTEMD_NOTIFY 1)
endif()
option(ENABLE_OPENSSL_VERIFY "use ssl with connector" ON)
if (ENABLE_OPENSSL_VERIFY STREQUAL "ON")
add_definitions(-DOPENSSL_VERIFY)
set(OPENSSL_VERIFY 1)
endif()
option(PACKAGE "set isulad package" ON)
if (PACKAGE STREQUAL "ON")
set(ISULAD_PACKAGE "iSulad")
endif()
option(VERSION "set isulad version" ON)
if (VERSION STREQUAL "ON")
set(ISULAD_VERSION "2.0.0")
endif()
option(DEBUG "set isulad gcc option" ON)
if (DEBUG STREQUAL "ON")
add_definitions("-g -O2")
endif()
option(GCOV "set isulad gcov option" OFF)
if (GCOV STREQUAL "ON")
set(ISULAD_GCOV "ON")
endif()
# set OCI image server type
option(DISABLE_OCI "disable oci image" OFF)
if (DISABLE_OCI STREQUAL "ON")
message("Disable OCI image")
else()
add_definitions(-DENABLE_OCI_IMAGE=1)
set(ENABLE_OCI_IMAGE 2)
endif()
option(ENABLE_EMBEDDED "enable embedded image" OFF)
if (ENABLE_EMBEDDED STREQUAL "ON")
add_definitions(-DENABLE_EMBEDDED_IMAGE=1)
set(ENABLE_EMBEDDED_IMAGE 1)
endif()

View File

@ -1,87 +0,0 @@
set(PROTOS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/api/services)
set(TYPES_PROTOS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/api/types)
set(GRPC_OUT_PRE_PATH ${CMAKE_BINARY_DIR}/grpc)
set(TYPES_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/types)
set(CONTAINER_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/services/containers)
set(IMAGE_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/services/images)
set(CRI_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/services/cri)
set(IMAGE_SERVICE_PROTOS_OUT_PATH ${GRPC_OUT_PRE_PATH}/src/api/image_client)
execute_process(COMMAND mkdir -p ${TYPES_PROTOS_OUT_PATH})
execute_process(COMMAND ${CMD_PROTOC} -I ${TYPES_PROTOS_PATH} --cpp_out=${TYPES_PROTOS_OUT_PATH}
${TYPES_PROTOS_PATH}/descriptor.proto ERROR_VARIABLE types_err)
if (types_err)
message("Parse types.proto failed: ")
message(FATAL_ERROR ${types_err})
endif()
if (GRPC_CONNECTOR)
message("---------------Generate GRPC proto-----------------------")
execute_process(COMMAND mkdir -p ${CONTAINER_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${IMAGE_PROTOS_OUT_PATH})
execute_process(COMMAND mkdir -p ${CRI_PROTOS_OUT_PATH})
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --cpp_out=${CONTAINER_PROTOS_OUT_PATH}
${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
if (containers_err)
message("Parse containers.proto failed: ")
message(FATAL_ERROR ${containers_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/containers --grpc_out=${CONTAINER_PROTOS_OUT_PATH}
--plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/containers/container.proto ERROR_VARIABLE containers_err)
if (containers_err)
message("Parse containers.proto plugin failed: ")
message(FATAL_ERROR ${containers_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images -I ${TYPES_PROTOS_PATH}
--cpp_out=${IMAGE_PROTOS_OUT_PATH} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
if (images_err)
message("Parse images.proto failed: ")
message(FATAL_ERROR ${images_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/images -I ${TYPES_PROTOS_PATH} --grpc_out=${IMAGE_PROTOS_OUT_PATH}
--plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/images/images.proto ERROR_VARIABLE images_err)
if (images_err)
message("Parse images.proto plugin failed: ")
message(FATAL_ERROR ${images_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --cpp_out=${CRI_PROTOS_OUT_PATH} ${PROTOS_PATH}/cri/api.proto
ERROR_VARIABLE cri_err)
if (cri_err)
message("Parse cri.proto failed: ")
message(FATAL_ERROR ${cri_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${PROTOS_PATH}/cri --grpc_out=${CRI_PROTOS_OUT_PATH}
--plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${PROTOS_PATH}/cri/api.proto ERROR_VARIABLE cri_err)
if (cri_err)
message("Parse cri.proto plugin failed: ")
message(FATAL_ERROR ${cri_err})
endif()
endif()
if (ENABLE_OCI_IMAGE)
message("---------------Generate OCI image proto-----------------------")
execute_process(COMMAND mkdir -p ${IMAGE_SERVICE_PROTOS_OUT_PATH})
execute_process(COMMAND ${CMD_PROTOC} -I ${CMAKE_CURRENT_SOURCE_DIR}/src/api/image_client --cpp_out=${IMAGE_SERVICE_PROTOS_OUT_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/src/api/image_client/isula_image.proto ERROR_VARIABLE image_client_err)
if (image_client_err)
message("Parse image client api.proto failed: ")
message(FATAL_ERROR ${image_client_err})
endif()
execute_process(COMMAND ${CMD_PROTOC} -I ${CMAKE_CURRENT_SOURCE_DIR}/src/api/image_client --grpc_out=${IMAGE_SERVICE_PROTOS_OUT_PATH}
--plugin=protoc-gen-grpc=${CMD_GRPC_CPP_PLUGIN} ${CMAKE_CURRENT_SOURCE_DIR}/src/api/image_client/isula_image.proto
ERROR_VARIABLE image_client_err)
endif()
if (image_client_err)
message("Parse image client api.proto plugin failed: ")
message(FATAL_ERROR ${image_client_err})
endif()

View File

@ -1,19 +0,0 @@
# set common FLAGS
set(CMAKE_C_FLAGS "-fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -rdynamic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
if (GRPC_CONNECTOR OR ENABLE_OCI_IMAGE)
set(CMAKE_CXX_FLAGS "-fPIC -std=c++11 -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIE -pie -shared -pthread")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIE -pie")
if (ISULAD_GCOV)
set(CMAKE_C_FLAGS_DEBUG "-Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -fprofile-arcs -ftest-coverage")
message("-----CXXFLAGS: " ${CMAKE_CXX_FLAGS_DEBUG})
message("------compile with gcov-------------")
message("-----CFLAGS: " ${CMAKE_C_FLAGS_DEBUG})
message("------------------------------------")
endif()

View File

@ -1 +0,0 @@
#cmakedefine VERSION "@ISULAD_VERSION@"

View File

@ -1,43 +0,0 @@
# iSulad Architecture
## Overview
![architecture](design/arch.jpg)
iSulad is an OCI-compliant container runtime engine that emphasizes simplicity, robustness, performance and lightweight.
As a daemon process, it manages the entire container life cycle of the host system, including image transmission and storage, container execution and monitoring management, container resource management, and network management. iSulad provides Docker-like CLI for users.
You can use Docker-like commands to manage container images and iSulad provides gRPC APIs which comply with the CRI standard for Kubernetes.
iSulad is divided into different modules, and the modules are organized into subsystems. Understanding these modules, subsystems, and their relationships is important to modify and extend iSulad.
This document describes the high-level system architecture design. For more information about each module, please refer to the relevant design documents.
## Subsystem
You can interact with the iSulad by invoking gRPC APIs exported by the subsystem.
- **image service** : Image management service, provides image-related operations, such as image download, query, and deletion.
- **execution service**: Container life cycle management service, provides container-related operations, such as container creation, startup, and deletion.
- **network**The network subsystem is responsible for network management capabilities of the pod of the CRI. When a pod is started, the pod is added to the network plane specified in the configuration file through the CNI interface. When a pod is stopped, the CNI API is used to remove the pod from the network plane where the pod is located and clear related network resources.
## Module
- **image content** : Managing Image Metadata and Container File Systems
- **resource manage**: Container resource management module, for example, setting available CPU and memory resource limits
- **Executor**Runtime for executing actual container operations. The LCR acts as the default runtime and can be extended through the plug-in mechanism.
- **Events**Container event collection module
- **Plugins**Provides the plugin mechanism to extend container capabilities through different plugins.
- **HA**This module provides fault locating and garbage collection service.
### Network architecture design
The figure shows the architecture:
![CNI_architecture](./design/CNI_architecture.png)

View File

@ -1,41 +0,0 @@
# iSulad Architecture
## Overview
![architecture](design/arch.jpg)
iSulad是一个基于OCI标准的容器运行引擎强调简单性、健壮性和轻量化。
作为守护进程iSulad提供容器生命周期管理相关服务包括镜像的传输和存储、容器执行和监控管理、容器资源管理以及网络等。iSulad对外提供与docker类似的CLI命令行接口可使用该命令行进行容器管理并且提供符合CRI接口标准的gRPC API可供kubernetes 按照CRI接口协议调用。
为了方便理解我们将iSulad分成不同的模块并根据模块的类别组织成子系统。了解这些模块、子系统及其关系是修改和扩展iSulad的关键
本文档将仅描述各个模块的high-level功能设计。有关每个模块的详细信息请参阅相关设计文档。
## 子系统
用户可通过调用子系统提供的GRPC API与iSulad进行交互。
- **image service** : 镜像管理服务,提供镜像相关操作,如镜像下载、查询、删除等
- **execution service**: 容器生命周期管理服务,提供容器的相关操作,如容器创建、启动、删除等
- **network**网络子模块负责CRI的Pod的网络管理能力。当Pod启动时通过CNI的接口把该Pod加入到配置文件制定的网络平面中当Pod停止时通过CNI的接口把该Pod从所在的网络平面中退出并且清理相关的网络资源。
## 模块
- **image content** : 管理镜像元数据以及容器文件系统。
- **resource manage**: 容器资源管理如设置可用cpu、memory等资源限制
- **Executor**执行实际容器操作的runtime提供lcr作为默认runtime可通过plugin机制扩展
- **Events**:容器事件收集
- **Plugins**:提供插件机制,通过不同插件,实现扩展容器功能。
- **HA**提供日志机制用于定位问题提供garbage collect 机制回收容器D/Z 等异常容器资源。
### 网络架构设计
架构图,如下:
![CNI_architecture](./design/CNI_architecture.png)

View File

@ -1,76 +0,0 @@
# Build iSulad from source
If you intend to contribute on iSulad. Thanks for your effort. Every contribution is very appreciated for us.
## Build iSulad based on openEuler distribution
If you use the openEuler distribution, you can easily install various dependent packages via yum.
### Install Dependencies
```sh
$ sudo yum install -y cmake gcc-c++ systemd-devel yajl-devel libcurl libcurl-devel clibcni clibcni-devel protobuf-devel grpc-devel grpc-plugins http-parser-devel libwebsockets-devel libevhtp-devel libevent-devel lcr lxc-devel
```
### Build steps:
Run the cmds under the iSulad source directory
```sh
$ sudo mkdir build
$ sudo cd build
$ sudo cmake ..
$ sudo make
$ sudo make install
```
## Trial iSulad Via Docker container
You can try to use iSulad via Docker container. The following steps guide you how to create a Docker container which can run iSulad inside.
#### Build image
You can build `iSulad` via a Linux-based Docker container. You can build an image from the`Dockerfile` in the source directory. From the iSulad source root directory you can run the following command to make your image.
```sh
$ sudo docker build --build-arg http_proxy=YOUR_HTTP_PROXY_IF_NEED
--build-arg https_proxy=YOUR_HTTPS_PROXY_IF_NEED \
-t YOUR_IMAGE_NAME -f ./Dockerfile .
```
#### Prepare root directory for the iSulad
Let's prepare a root directory on host, and we will mount this directory into the container. This directory be used by `iSulad` in container.
```sh
$ sudo mkdir -p /var/lib/isulad
```
#### Build iSulad in container
Let's suppose that you built an image called `isulad:dev`.
Then from the iSulad source root directory you can run the following command:
```sh
$ sudo docker run -tid --name YOUR_CONTAINER_NAME -v /var/lib/isulad:/var/lib/isulad -v `pwd`:/src/isulad --privileged isulad:dev
```
Let's suppose that you run an container named `iSulad_build`. Then you can use the following commands to build iSulad in your container `iSulad_build`:
```bash
// enter the container
$ sudo docker exec -it iSulad_build bash
// Now you enter the container, so build iSulad in the container by following commands
# cd /src/isulad
# mkdir build
# cd build
# cmake ..
# make
# make install
```
Now You can use direct command to start `iSulad` server in the container
```sh
$ sudo isulad # run the server with default socket name and default log level and images manage function
```

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

View File

@ -1,131 +0,0 @@
# Integrate kubenetes
## Configuration
1. Configure `isulad`
Configure the `pod-sandbox-image` in `/etc/isulad/daemon.json`:
```json
"pod-sandbox-image": "my-pause:1.0.0"
```
Configure the `endpoint`of `isulad`:
```json
"hosts" : [
"unix:///var/run/isulad.sock"
]
```
if `hosts` is not configured, the default endpoint is `unix:///var/run/isulad.sock`.
2. Restart `isulad`:
```bash
$ sudo systemctl restart isulad
```
3. Start `kubelet` based on the configuration or default value:
```bash
$ /usr/bin/bubelet
--container-runtime-endpoint=unix:///var/run/isulad.sock
--image-service-endpoint=unix:///var/run/isulad.sock
--pod-infra-container-image=my-pause:1.0.0
...
```
## Use RuntimeClass
RuntimeClass is used for selecting the container runtime configuration to use to run a pods containers, see [runtime-class](https://kubernetes.io/docs/concepts/containers/runtime-class/). Currently, only `kata-containers` and `runc` this two `oci runtime` are supported.
1. Configure `isulad` in `/etc/isulad/daemon.json`:
```json
"runtimes": {
"runc":{
"path": "/usr/bin/runc",
"runtime-args": []
},
"kata-runtime": {
"path": "/usr/bin/kata-runtime",
"runtime-args": [
"--kata-config",
"/usr/share/defaults/kata-containers/configuration.toml"
]
}
}
```
2. Extra configuration
`iSulad` supports the `overlay2` and `devicemapper` as storage drivers. The default value is `overlay2`.
In some scenarios, using block device type as storage drivers is a better choice, such as run a `kata-containers`. The procedure for configuring the `devicemapper` is as follows:
Create ThinPool:
```bash
$ sudo pvcreate /dev/sdb1 # /dev/sdb1 for example
$ sudo vgcreate isulad /dev/sdb
$ sudo echo y | lvcreate --wipesignatures y -n thinpool isulad -L 200G
$ sudo echo y | lvcreate --wipesignatures y -n thinpoolmeta isulad -L 20G
$ sudo lvconvert -y --zero n -c 512K --thinpool isulad/thinpool --poolmetadata isulad/thinpoolmeta
$ sudo lvchange --metadataprofile isulad-thinpool isulad/thinpool
```
Add configuration for `devicemapper` in `/etc/isulad/daemon.json`:
```json
"storage-driver": "devicemapper"
"storage-opts": [
"dm.thinpooldev=/dev/mapper/isulad-thinpool",
"dm.fs=ext4",
"dm.min_free_space=10%"
]
```
3. Restart `isulad`:
```bash
$ sudo systemctl restart isulad
```
4. Define `RuntimeClass CRD` for example:
```yaml
apiVersion: node.k8s.io/v1beta1
kind: RuntimeClass
metadata:
name: kata-runtime
handler: kata-runtime
```
5. Define pod spec `kata-pod.yaml` for example:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: kata-pod-example
spec:
runtimeClassName: kata-runtime
containers:
- name: kata-pod
image: busybox:latest
command: ["/bin/sh"]
args: ["-c", "sleep 1000"]
hostNetwork: true
```
6. Run pod:
```bash
$ kubectl create -f kata-pod.yaml
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
kata-pod-example 1/1 Running 4 2s
```

BIN
iSulad-2.0.2.tar.gz Normal file

Binary file not shown.

View File

@ -1,5 +1,5 @@
%global _version 2.0.0
%global _release 20200406.224614.gitd03048c0
%global _version 2.0.2
%global _release 20200526.193459.gitf045485f
%global is_systemd 1
%global debug_package %{nil}
@ -9,7 +9,7 @@ Release: %{_release}
Summary: Lightweight Container Runtime Daemon
License: Mulan PSL v2
URL: isulad
Source: iSulad-2.0.tar.gz
Source: iSulad-2.0.2.tar.gz
BuildRoot: {_tmppath}/iSulad-%{version}
ExclusiveArch: x86_64 aarch64
@ -29,15 +29,15 @@ Requires(preun): chkconfig
Requires(preun): initscripts
%endif
BuildRequires: cmake gcc-c++ lxc lxc-devel lcr yajl yajl-devel clibcni-devel
BuildRequires: cmake gcc-c++ lxc lxc-devel lcr-devel yajl-devel clibcni-devel
BuildRequires: grpc grpc-plugins grpc-devel protobuf-devel
BuildRequires: libcurl libcurl-devel sqlite-devel
BuildRequires: http-parser-devel
BuildRequires: libseccomp-devel libcap-devel libselinux-devel libwebsockets libwebsockets-devel
BuildRequires: systemd-devel git python3
BuildRequires: systemd-devel git
Requires: iSulad-img lcr lxc clibcni
Requires: grpc protobuf yajl
Requires: grpc protobuf
Requires: libcurl
Requires: sqlite http-parser libseccomp
Requires: libcap libselinux libwebsockets
@ -48,7 +48,7 @@ This is a umbrella project for gRPC-services based Lightweight Container
Runtime Daemon, written by C.
%prep
%autosetup -c -n iSulad-%{version}
%autosetup -n %{name} -Sgit -p1
%build
mkdir -p build

View File

@ -1,12 +0,0 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_PREFIX@/lib
localstatedir=@CMAKE_INSTALL_PREFIX@/var
includedir=@CMAKE_INSTALL_PREFIX@/include
Name: libisula
Description: light-weighted container runtime daemon library
Version: @ISULAD_VERSION@
URL: iSulad
Libs: -L@CMAKE_INSTALL_PREFIX@/lib -lisula
Cflags: -I@CMAKE_INSTALL_PREFIX@/include

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,255 +0,0 @@
# generate .c and .h to analyse json file
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/json)
# get json generate source files
aux_source_directory(${CMAKE_BINARY_DIR}/json generatesrcs)
message("-- Get generate srcs: " ${generatesrcs})
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/json/schema/src commonjsonsrcs)
message("-- Get common json srcs: " ${commonjsonsrcs})
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/json topjsonsrcs)
message("-- Get top json srcs: " ${topjsonsrcs})
list(APPEND JSON_FILES ${generatesrcs} ${commonjsonsrcs} ${topjsonsrcs})
list(REMOVE_DUPLICATES JSON_FILES)
set(CHECKED_INCLUDE_DIRS
${STD_HEADER_CTYPE}
${STD_HEADER_SYS_PARAM}
${LIBYAJL_INCLUDE_DIR}
${HTTP_PARSER_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${CURL_INCLUDE_DIR}
${SYSTEMD_INCLUDE_DIR}
)
if (GRPC_CONNECTOR)
list(APPEND CHECKED_INCLUDE_DIRS
${GRPC_INCLUDE_DIR}
${CLIBCNI_INCLUDE_DIR}
${WEBSOCKET_INCLUDE_DIR}
)
else()
list(APPEND CHECKED_INCLUDE_DIRS
${SQLIT3_INCLUDE_DIR}
${EVENT_INCLUDE_DIR}
${EVHTP_INCLUDE_DIR}
)
endif()
list(REMOVE_DUPLICATES CHECKED_INCLUDE_DIRS)
set(SHARED_INCS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cutils
${CMAKE_CURRENT_SOURCE_DIR}/sha256
${CMAKE_CURRENT_SOURCE_DIR}/tar
${CMAKE_CURRENT_SOURCE_DIR}/console
${CMAKE_CURRENT_SOURCE_DIR}/json
${CMAKE_CURRENT_SOURCE_DIR}/json/schema/src
${CMAKE_BINARY_DIR}/json
${CMAKE_BINARY_DIR}/conf
${CHECKED_INCLUDE_DIRS}
)
add_subdirectory(tar)
add_subdirectory(sha256)
add_subdirectory(cutils)
add_subdirectory(console)
set(SHARED_SRCS
${JSON_FILES}
${TAR_SRCS}
${SHA256_SRCS}
${CUTILS_SRCS}
${CONSOLE_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/container_def.c
${CMAKE_CURRENT_SOURCE_DIR}/types_def.c
${CMAKE_CURRENT_SOURCE_DIR}/error.c
${CMAKE_CURRENT_SOURCE_DIR}/path.c
${CMAKE_CURRENT_SOURCE_DIR}/log.c
${CMAKE_CURRENT_SOURCE_DIR}/mainloop.c
)
# get all c and header files
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/connect)
if (GRPC_CONNECTOR)
# GRPC
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/types CONNECT_API_TYPES)
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/containers CONNECT_API_CONTAINERS)
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/images CONNECT_API_IMAGES)
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/cri CONNECT_API_CRI)
set(CONNECT_API ${CONNECT_API_TYPES} ${CONNECT_API_CONTAINERS} ${CONNECT_API_IMAGES} ${CONNECT_API_CRI})
list(APPEND SHARED_INCS
${CMAKE_BINARY_DIR}/grpc/src/api/types
${CMAKE_BINARY_DIR}/grpc/src/api/services/containers
${CMAKE_BINARY_DIR}/grpc/src/api/services/images
${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
${CMAKE_CURRENT_SOURCE_DIR}/cpputils
)
add_subdirectory(cpputils)
add_subdirectory(websocket)
list(APPEND SHARED_SRCS ${CPPUTILS_SRCS})
else()
list(APPEND SHARED_INCS
${CMAKE_CURRENT_SOURCE_DIR}/api/services/containers/rest
${CMAKE_CURRENT_SOURCE_DIR}/api/services/images/rest
)
endif()
list(APPEND SHARED_SRCS ${CONNECT_API} ${CPPUTILS_SRCS})
list(REMOVE_DUPLICATES SHARED_INCS)
list(REMOVE_DUPLICATES SHARED_SRCS)
add_subdirectory(http)
# ------ build libisula ------
if (OPENSSL_VERIFY)
list(APPEND CONNECTOR ${CMAKE_CURRENT_SOURCE_DIR}/http/certificate.c)
endif()
add_library(libisula ${LIBTYPE}
${CMAKE_CURRENT_SOURCE_DIR}/libisula.c
${CMAKE_CURRENT_SOURCE_DIR}/pack_config.c
${CONNECTOR}
${SHARED_SRCS}
)
target_include_directories(libisula PUBLIC
${SHARED_INCS}
${CONNECTOR_INCS}
${CMAKE_CURRENT_SOURCE_DIR}/http
)
# set libisula FLAGS
set_target_properties(libisula PROPERTIES PREFIX "")
target_link_libraries(libisula ${LIBYAJL_LIBRARY} ${SELINUX_LIBRARY})
if (GRPC_CONNECTOR)
target_link_libraries(libisula -Wl,--as-needed -lstdc++ -lcrypto)
target_link_libraries(libisula -Wl,--as-needed ${PROTOBUF_LIBRARY})
target_link_libraries(libisula -Wl,--no-as-needed ${GRPC_PP_REFLECTION_LIBRARY} ${GRPC_PP_LIBRARY} ${GRPC_LIBRARY} ${GPR_LIBRARY})
else()
target_link_libraries(libisula ${EVHTP_LIBRARY} ${EVENT_LIBRARY} ${ZLIB_LIBRARY} -ldl libhttpclient)
endif()
# ------ build libisula finish -----
add_subdirectory(cmd)
# ------ build isula -------
add_executable(isula
${ISULA_SRCS}
)
target_include_directories(isula PUBLIC ${ISULA_INCS} ${SHARED_INCS})
target_link_libraries(isula libisula -lpthread)
# ------ build isula finish -------
# ------ build isulad-shim -------
add_executable(isulad-shim
${ISULAD_SHIM_SRCS}
${CMAKE_BINARY_DIR}/json/shim_client_process_state.c
${CMAKE_BINARY_DIR}/json/json_common.c
${CMAKE_BINARY_DIR}/json/logger_json_file.c
${commonjsonsrcs}
)
target_include_directories(isulad-shim PUBLIC ${ISULAD_SHIM_INCS} ${SHARED_INCS})
target_link_libraries(isulad-shim ${LIBYAJL_LIBRARY} -lpthread)
# ------ build isula-shim finish -------
# ------ build isulad -------
add_subdirectory(services)
add_subdirectory(image)
add_subdirectory(runtime)
if (ENABLE_OCI_IMAGE)
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/types CONNECT_API_TYPES)
aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/image_client/ IMAGE_CLIENT_SRCS)
list(APPEND IMAGE_SRCS
${ISULA_IMAGE_CLIENT_SRCS}
${CONNECT_API_TYPES} ${IMAGE_CLIENT_SRCS}
)
list(APPEND IMAGE_INCS
${CMAKE_BINARY_DIR}/grpc/src/api/types
${CMAKE_BINARY_DIR}/grpc/src/api/image_client
${GRPC_INCLUDE_DIR}
${ISULA_IMAGE_CLIENT_INCS}
)
endif()
add_subdirectory(engines)
add_subdirectory(plugin)
add_subdirectory(map)
add_subdirectory(config)
add_executable(isulad
${CONNECT_SOCKET} ${SHARED_SRCS}
${ISULAD_SRCS} ${SERVICES_SRCS}
${HTTP_SRCS}
${ENGINES_SRCS}
${IMAGE_SRCS}
${RUNTIME_SRCS}
${PLUGIN_SRCS}
${MAP_SRCS} ${CONFIG_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/filters.c
${CMAKE_CURRENT_SOURCE_DIR}/namespace.c
${CMAKE_CURRENT_SOURCE_DIR}/libisulad.c
${CMAKE_CURRENT_SOURCE_DIR}/sysctl_tools.c
${WEBSOCKET_SERVICE_SRCS}
)
target_include_directories(isulad PUBLIC
${SHARED_INCS}
${CONNECT_SOCKET_INCS}
${SERVICES_INCS}
${IMAGE_INCS}
${RUNTIME_INCS}
${ENGINES_INCS}
${ISULAD_INCS}
${CMAKE_CURRENT_SOURCE_DIR}/plugin
${CMAKE_CURRENT_SOURCE_DIR}/map
${CMAKE_CURRENT_SOURCE_DIR}/config
${CMAKE_CURRENT_SOURCE_DIR}/http
${WEBSOCKET_SERVICE_INCS}
)
target_link_libraries(isulad ${LIBYAJL_LIBRARY} ${SYSTEMD_LIBRARY} ${SELINUX_LIBRARY})
target_link_libraries(isulad -ldl ${ZLIB_LIBRARY} -lpthread libhttpclient)
if (ENABLE_EMBEDDED_IMAGE)
target_link_libraries(isulad ${SQLITE3_LIBRARY})
endif()
if (GRPC_CONNECTOR)
message("GRPC iSulad")
target_link_libraries(isulad -Wl,--as-needed -lstdc++ -lcrypto)
target_link_libraries(isulad -Wl,--as-needed ${PROTOBUF_LIBRARY})
target_link_libraries(isulad -Wl,--no-as-needed ${GRPC_PP_REFLECTION_LIBRARY} ${GRPC_PP_LIBRARY} ${GRPC_LIBRARY} ${GPR_LIBRARY})
target_link_libraries(isulad ${CLIBCNI_LIBRARY} ${WEBSOCKET_LIBRARY})
else()
message("Restful iSulad")
target_link_libraries(isulad ${EVHTP_LIBRARY} ${EVENT_LIBRARY})
endif()
if (ENABLE_OCI_IMAGE)
target_link_libraries(isulad -Wl,--as-needed -lstdc++)
target_link_libraries(isulad -Wl,--as-needed ${PROTOBUF_LIBRARY})
target_link_libraries(isulad -Wl,--no-as-needed ${GRPC_PP_REFLECTION_LIBRARY} ${GRPC_PP_LIBRARY} ${GRPC_LIBRARY} ${GPR_LIBRARY})
endif()
if (ISULAD_GCOV)
target_link_libraries(isula -lgcov)
target_link_libraries(libisula -lgcov)
target_link_libraries(isulad -lgcov)
endif()
# ------ build isulad finish -------
# ------ install binary --------
install(TARGETS libisula
LIBRARY DESTINATION ${LIB_INSTALL_DIR_DEFAULT} PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
install(TARGETS isula
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
install(TARGETS isulad-shim
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)
install(TARGETS isulad
RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)

View File

@ -1,598 +0,0 @@
// #######################################################################
// ##- @Copyright (C) Huawei Technologies., Ltd. 2019-2020. All rights reserved.
// # - iSulad licensed under the Mulan PSL v2.
// # - You can use this software according to the terms and conditions of the Mulan PSL v2.
// # - You may obtain a copy of Mulan PSL v2 at:
// # - http://license.coscl.org.cn/MulanPSL2
// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// # - PURPOSE.
// # - See the Mulan PSL v2 for more details.
// ##- @Description: generate grpc
// ##- @Author: wujing
// ##- @Create: 2020-01-26
// #######################################################################
/*
Since some of this code is derived from Kubernetes, their copyright
is retained here....
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// To regenerate api.pb.go run hack/update-generated-runtime.sh
syntax = 'proto3';
package isula;
// ImageService defines the public APIs for managing images.
service ImageService {
// ListImages lists existing images.
rpc ListImages(ListImagesRequest) returns (ListImagesResponse) {}
// ImageStatus returns the status of the image. If the image is not
// present, returns a response with ImageStatusResponse.Image set to
// nil.
rpc ImageStatus(ImageStatusRequest) returns (ImageStatusResponse) {}
// Get image information
rpc ImageInfo(ImageInfoRequest) returns (ImageInfoResponse) {}
// PullImage pulls an image with authentication config.
rpc PullImage(PullImageRequest) returns (PullImageResponse) {}
// RemoveImage removes the image.
// This call is idempotent, and must not return an error if the image has
// already been removed.
rpc RemoveImage(RemoveImageRequest) returns (RemoveImageResponse) {}
// ImageFSInfo returns information of the filesystem that is used to store images.
rpc ImageFsInfo(ImageFsInfoRequest) returns (ImageFsInfoResponse) {}
// Load image from file
rpc LoadImage(LoadImageRequest) returns (LoadImageResponose) {}
// isulad image services
// get all Container rootfs
rpc ListContainers(ListContainersRequest) returns (ListContainersResponse) {}
// create rootfs for container
rpc ContainerPrepare(ContainerPrepareRequest) returns (ContainerPrepareResponse) {}
// remove rootfs of container
rpc ContainerRemove(ContainerRemoveRequest) returns (ContainerRemoveResponse) {}
// mount rwlayer for container
rpc ContainerMount(ContainerMountRequest) returns (ContainerMountResponse) {}
// umount rwlayer of container
rpc ContainerUmount(ContainerUmountRequest) returns (ContainerUmountResponse) {}
// export container rootfs
rpc ContainerExport(ContainerExportRequest) returns (ContainerExportResponse) {}
// get filesystem usage of container
rpc ContainerFsUsage(ContainerFsUsageRequest) returns (ContainerFsUsageResponse) {}
// get status of graphdriver
rpc GraphdriverStatus(GraphdriverStatusRequest) returns (GraphdriverStatusResponse) {}
// get metadata of graphdriver
rpc GraphdriverMetadata(GraphdriverMetadataRequest) returns (GraphdriverMetadataResponse) {}
// login registry
rpc Login(LoginRequest) returns (LoginResponse) {}
// logout registry
rpc Logout(LogoutRequest) returns (LogoutResponse) {}
// health check service
rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse) {}
// Add a tag to the image
rpc TagImage(TagImageRequest) returns (TagImageResponse) {}
}
message HealthCheckRequest {}
message HealthCheckResponse {
string errmsg = 1;
uint32 cc = 2;
}
message LoginRequest {
string server = 1;
string username = 2;
string password = 3;
}
message LoginResponse {
string errmsg = 1;
uint32 cc = 2;
}
message LogoutRequest {
string server = 1;
}
message LogoutResponse {
string errmsg = 1;
uint32 cc = 2;
}
message ContainerExportRequest {
string name_id = 1;
string output = 2;
uint32 uid = 3;
uint32 gid = 4;
uint32 offset = 5;
}
message ContainerExportResponse {
string errmsg = 1;
uint32 cc = 2;
}
message LoadImageRequest {
string file = 1;
string tag = 2;
}
message LoadImageResponose {
string outmsg = 1;
string errmsg = 2;
uint32 cc = 3;
}
message GraphdriverStatusRequest {}
message GraphdriverStatusResponse {
string status = 1;
string errmsg = 2;
uint32 cc = 3;
}
message GraphdriverMetadataRequest {
string name_id = 1;
}
message GraphdriverMetadataResponse {
map<string,string> metadata = 1;
string name = 2;
string errmsg = 3;
uint32 cc = 4;
}
message ContainerFsUsageRequest {
string name_id = 1;
}
message ContainerFsUsageResponse {
string usage = 1;
string errmsg = 2;
uint32 cc = 3;
}
message ContainerUmountRequest {
string name_id = 1;
bool force = 2;
}
message ContainerUmountResponse {
string errmsg = 1;
uint32 cc = 2;
}
message ContainerMountRequest {
string name_id = 1;
}
message ContainerMountResponse {
string errmsg = 1;
uint32 cc = 2;
}
message ContainerRemoveRequest {
string name_id = 1;
}
message ContainerRemoveResponse {
string errmsg = 1;
uint32 cc = 2;
}
message ContainerPrepareRequest {
string image = 1;
string id = 2;
string name = 3;
repeated string storage_opts = 4;
}
message ContainerPrepareResponse {
string mount_point = 1;
string image_conf = 2;
string errmsg = 3;
uint32 cc = 4;
}
message ListContainersRequest {}
message ListContainersResponse {
map<string, bool> containers = 1;
string errmsg = 2;
uint32 cc = 3;
}
// DNSConfig specifies the DNS servers and search domains of a sandbox.
message DNSConfig {
// List of DNS servers of the cluster.
repeated string servers = 1;
// List of DNS search domains of the cluster.
repeated string searches = 2;
// List of DNS options. See https://linux.die.net/man/5/resolv.conf
// for all available options.
repeated string options = 3;
}
enum Protocol {
TCP = 0;
UDP = 1;
}
// PortMapping specifies the port mapping configurations of a sandbox.
message PortMapping {
// Protocol of the port mapping.
Protocol protocol = 1;
// Port number within the container. Default: 0 (not specified).
int32 container_port = 2;
// Port number on the host. Default: 0 (not specified).
int32 host_port = 3;
// Host IP.
string host_ip = 4;
}
enum MountPropagation {
// No mount propagation ("private" in Linux terminology).
PROPAGATION_PRIVATE = 0;
// Mounts get propagated from the host to the container ("rslave" in Linux).
PROPAGATION_HOST_TO_CONTAINER = 1;
// Mounts get propagated from the host to the container and from the
// container to the host ("rshared" in Linux).
PROPAGATION_BIDIRECTIONAL = 2;
}
// Mount specifies a host volume to mount into a container.
message Mount {
// Path of the mount within the container.
string container_path = 1;
// Path of the mount on the host.
string host_path = 2;
// If set, the mount is read-only.
bool readonly = 3;
// If set, the mount needs SELinux relabeling.
bool selinux_relabel = 4;
// Requested propagation mode.
MountPropagation propagation = 5;
}
// NamespaceOption provides options for Linux namespaces.
message NamespaceOption {
// If set, use the host's network namespace.
bool host_network = 1;
// If set, use the host's PID namespace.
bool host_pid = 2;
// If set, use the host's IPC namespace.
bool host_ipc = 3;
}
// Int64Value is the wrapper of int64.
message Int64Value {
// The value.
int64 value = 1;
}
// SELinuxOption are the labels to be applied to the container.
message SELinuxOption {
string user = 1;
string role = 2;
string type = 3;
string level = 4;
}
// LinuxSandboxSecurityContext holds linux security configuration that will be
// applied to a sandbox. Note that:
// 1) It does not apply to containers in the pods.
// 2) It may not be applicable to a PodSandbox which does not contain any running
// process.
message LinuxSandboxSecurityContext {
// Configurations for the sandbox's namespaces.
// This will be used only if the PodSandbox uses namespace for isolation.
NamespaceOption namespace_options = 1;
// Optional SELinux context to be applied.
SELinuxOption selinux_options = 2;
// UID to run sandbox processes as, when applicable.
Int64Value run_as_user = 3;
// If set, the root filesystem of the sandbox is read-only.
bool readonly_rootfs = 4;
// List of groups applied to the first process run in the sandbox, in
// addition to the sandbox's primary GID.
repeated int64 supplemental_groups = 5;
// Indicates whether the sandbox will be asked to run a privileged
// container. If a privileged container is to be executed within it, this
// MUST be true.
// This allows a sandbox to take additional security precautions if no
// privileged containers are expected to be run.
bool privileged = 6;
// Seccomp profile for the sandbox, candidate values are:
// * docker/default: the default profile for the docker container runtime
// * unconfined: unconfined profile, ie, no seccomp sandboxing
// * localhost/<full-path-to-profile>: the profile installed on the node.
// <full-path-to-profile> is the full path of the profile.
// Default: "", which is identical with unconfined.
string seccomp_profile_path = 7;
}
// LinuxPodSandboxConfig holds platform-specific configurations for Linux
// host platforms and Linux-based containers.
message LinuxPodSandboxConfig {
// Parent cgroup of the PodSandbox.
// The cgroupfs style syntax will be used, but the container runtime can
// convert it to systemd semantics if needed.
string cgroup_parent = 1;
// LinuxSandboxSecurityContext holds sandbox security attributes.
LinuxSandboxSecurityContext security_context = 2;
// Sysctls holds linux sysctls config for the sandbox.
map<string, string> sysctls = 3;
}
// PodSandboxMetadata holds all necessary information for building the sandbox name.
// The container runtime is encouraged to expose the metadata associated with the
// PodSandbox in its user interface for better user experience. For example,
// the runtime can construct a unique PodSandboxName based on the metadata.
message PodSandboxMetadata {
// Pod name of the sandbox. Same as the pod name in the PodSpec.
string name = 1;
// Pod UID of the sandbox. Same as the pod UID in the PodSpec.
string uid = 2;
// Pod namespace of the sandbox. Same as the pod namespace in the PodSpec.
string namespace = 3;
// Attempt number of creating the sandbox. Default: 0.
uint32 attempt = 4;
}
// PodSandboxConfig holds all the required and optional fields for creating a
// sandbox.
message PodSandboxConfig {
// Metadata of the sandbox. This information will uniquely identify the
// sandbox, and the runtime should leverage this to ensure correct
// operation. The runtime may also use this information to improve UX, such
// as by constructing a readable name.
PodSandboxMetadata metadata = 1;
// Hostname of the sandbox.
string hostname = 2;
// Path to the directory on the host in which container log files are
// stored.
// By default the log of a container going into the LogDirectory will be
// hooked up to STDOUT and STDERR. However, the LogDirectory may contain
// binary log files with structured logging data from the individual
// containers. For example, the files might be newline separated JSON
// structured logs, systemd-journald journal files, gRPC trace files, etc.
// E.g.,
// PodSandboxConfig.LogDirectory = `/var/log/pods/<podUID>/`
// ContainerConfig.LogPath = `containerName_Instance#.log`
//
// WARNING: Log management and how kubelet should interface with the
// container logs are under active discussion in
// https://issues.k8s.io/24677. There *may* be future change of direction
// for logging as the discussion carries on.
string log_directory = 3;
// DNS config for the sandbox.
DNSConfig dns_config = 4;
// Port mappings for the sandbox.
repeated PortMapping port_mappings = 5;
// Key-value pairs that may be used to scope and select individual resources.
map<string, string> labels = 6;
// Unstructured key-value map that may be set by the kubelet to store and
// retrieve arbitrary metadata. This will include any annotations set on a
// pod through the Kubernetes API.
//
// Annotations MUST NOT be altered by the runtime; the annotations stored
// here MUST be returned in the PodSandboxStatus associated with the pod
// this PodSandboxConfig creates.
//
// In general, in order to preserve a well-defined interface between the
// kubelet and the container runtime, annotations SHOULD NOT influence
// runtime behaviour.
//
// Annotations can also be useful for runtime authors to experiment with
// new features that are opaque to the Kubernetes APIs (both user-facing
// and the CRI). Whenever possible, however, runtime authors SHOULD
// consider proposing new typed fields for any new features instead.
map<string, string> annotations = 7;
// Optional configurations specific to Linux hosts.
LinuxPodSandboxConfig linux = 8;
}
// ImageSpec is an internal representation of an image. Currently, it wraps the
// value of a Container's Image field (e.g. imageID or imageDigest), but in the
// future it will include more detailed information about the different image types.
message ImageSpec {
string image = 1;
}
message ImageFilter {
// Spec of the image.
ImageSpec image = 1;
}
message ListImagesRequest {
// Filter to list images.
ImageFilter filter = 1;
bool check = 2;
}
message HealthCheck {
repeated string test = 1;
int64 interval = 2;
int64 timeout = 3;
int64 start_period = 4;
int32 retries = 5;
bool exit_on_unhealthy = 6;
}
// Basic information about a container image.
message Image {
// ID of the image.
string id = 1;
// Other names by which this image is known.
repeated string repo_tags = 2;
// Digests by which this image is known.
repeated string repo_digests = 3;
// Size of the image in bytes. Must be > 0.
uint64 size = 4;
// UID that will run the command(s). This is used as a default if no user is
// specified when creating the container. UID and the following user name
// are mutually exclusive.
Int64Value uid = 5;
// User name that will run the command(s). This is used if UID is not set
// and no user is specified when creating container.
string username = 6;
// Create time of image
string created = 7;
// Load time of image
string loaded = 8;
// oci image spec
ImageSpec spec = 9;
// Health check
HealthCheck healthcheck = 10;
}
message ListImagesResponse {
// List of images.
repeated Image images = 1;
string errmsg = 2;
uint32 cc = 3;
}
message ImageStatusRequest {
// Spec of the image.
ImageSpec image = 1;
// Verbose indicates whether to return extra information about the image.
bool verbose = 2;
}
message ImageStatusResponse {
// Status of the image.
Image image = 1;
// Info is extra information of the Image. The key could be abitrary string, and
// value should be in json format. The information could include anything useful
// for debug, e.g. image config for oci image based container runtime.
// It should only be returned non-empty when Verbose is true.
map<string, string> info = 2;
string errmsg = 3;
uint32 cc = 4;
}
message ImageInfoRequest {
ImageSpec image = 1;
}
message ImageInfoResponse {
string spec = 1;
string errmsg = 2;
uint32 cc = 3;
}
// AuthConfig contains authorization information for connecting to a registry.
message AuthConfig {
string username = 1;
string password = 2;
string auth = 3;
string server_address = 4;
// IdentityToken is used to authenticate the user and get
// an access token for the registry.
string identity_token = 5;
// RegistryToken is a bearer token to be sent to a registry
string registry_token = 6;
}
message PullImageRequest {
// Spec of the image.
ImageSpec image = 1;
// Authentication configuration for pulling the image.
AuthConfig auth = 2;
// Config of the PodSandbox, which is used to pull image in PodSandbox context.
PodSandboxConfig sandbox_config = 3;
}
message PullImageResponse {
// Reference to the image in use. For most runtimes, this should be an
// image ID or digest.
string image_ref = 1;
string errmsg = 2;
uint32 cc = 3;
}
message RemoveImageRequest {
// Spec of the image to remove.
ImageSpec image = 1;
bool force = 2;
}
message RemoveImageResponse {
string errmsg = 1;
uint32 cc = 2;
}
message ImageFsInfoRequest {}
// UInt64Value is the wrapper of uint64.
message UInt64Value {
// The value.
uint64 value = 1;
}
// StorageIdentifier uniquely identify the storage..
message StorageIdentifier{
// UUID of the device.
string uuid = 1;
}
// FilesystemUsage provides the filesystem usage information.
message FilesystemUsage {
// Timestamp in nanoseconds at which the information were collected. Must be > 0.
int64 timestamp = 1;
// The underlying storage of the filesystem.
StorageIdentifier storage_id = 2;
// UsedBytes represents the bytes used for images on the filesystem.
// This may differ from the total bytes used on the filesystem and may not
// equal CapacityBytes - AvailableBytes.
UInt64Value used_bytes = 3;
// InodesUsed represents the inodes used by the images.
// This may not equal InodesCapacity - InodesAvailable because the underlying
// filesystem may also be used for purposes other than storing images.
UInt64Value inodes_used = 4;
}
message ImageFsInfoResponse {
// Information of image filesystem(s).
repeated FilesystemUsage image_filesystems = 1;
string errmsg = 2;
uint32 cc = 3;
}
message TagImageRequest {
ImageSpec srcName = 1;
ImageSpec destName = 2;
}
message TagImageResponse {
string errmsg = 1;
uint32 cc = 2;
}

View File

@ -1,463 +0,0 @@
// #######################################################################
// ##- @Copyright (C) Huawei Technologies., Ltd. 2019. All rights reserved.
// # - iSulad licensed under the Mulan PSL v2.
// # - You can use this software according to the terms and conditions of the Mulan PSL v2.
// # - You may obtain a copy of Mulan PSL v2 at:
// # - http://license.coscl.org.cn/MulanPSL2
// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// # - PURPOSE.
// # - See the Mulan PSL v2 for more details.
// ##- @Description: generate grpc
// ##- @Author: wujing
// ##- @Create: 2019-04-25
// #######################################################################
syntax = "proto3";
option optimize_for = CODE_SIZE;
import "google/protobuf/timestamp.proto";
package containers;
enum ContainerStatus {
UNKNOWN = 0;
CREATED = 1;
STARTING = 2;
RUNNING = 3;
STOPPED = 4;
PAUSED = 5;
RESTARTING = 6;
}
enum EventType {
EXIT = 0;
STOPPED1 = 1;
STARTING1 = 2;
RUNNING1 = 3;
STOPPING = 4;
ABORTING = 5;
FREEZING = 6;
FROZEN = 7;
THAWED = 8;
OOM = 9;
CREATE = 10;
START = 11;
EXEC_ADDED = 12;
PAUSED1 = 13;
}
message Container {
string id = 1;
int32 pid = 2;
ContainerStatus status = 3;
string interface = 4;
string ipv4 = 5;
string ipv6 = 6;
string image = 7;
string command = 8;
double ram = 9;
double swap = 10;
uint32 exit_code = 11;
uint64 restartcount = 12;
string startat = 13;
string finishat = 14;
string runtime = 15;
string name = 16;
string health_state = 17;
int64 created = 18;
}
message Container_info {
string id = 1;
uint64 pids_current = 2;
uint64 cpu_use_nanos = 3;
uint64 cpu_use_user = 4;
uint64 cpu_use_kernel = 5;
uint64 cpu_system_use = 6;
uint32 online_cpus = 7;
uint64 blkio_read = 8;
uint64 blkio_write = 9;
uint64 mem_used = 10;
uint64 mem_limit = 11;
uint64 kmem_used = 12;
uint64 kmem_limit = 13;
}
message Event {
google.protobuf.Timestamp timestamp = 1;
string opt = 2;
string id = 3;
map<string, string> annotations= 4;
}
service ContainerService {
rpc Create(CreateRequest) returns (CreateResponse);
rpc Start(StartRequest) returns (StartResponse);
rpc RemoteStart(stream RemoteStartRequest) returns (stream RemoteStartResponse);
rpc Top(TopRequest) returns (TopResponse);
rpc Stop(StopRequest) returns (StopResponse);
rpc Kill(KillRequest) returns (KillResponse);
rpc Delete(DeleteRequest) returns (DeleteResponse);
rpc Pause(PauseRequest) returns (PauseResponse);
rpc Resume(ResumeRequest) returns (ResumeResponse);
rpc Inspect(InspectContainerRequest) returns (InspectContainerResponse);
rpc List(ListRequest) returns (ListResponse);
rpc Stats(StatsRequest) returns (StatsResponse);
rpc Wait(WaitRequest) returns (WaitResponse);
rpc Events(EventsRequest) returns (stream Event);
rpc Exec(ExecRequest) returns (ExecResponse);
rpc RemoteExec(stream RemoteExecRequest) returns (stream RemoteExecResponse);
rpc Version(VersionRequest) returns (VersionResponse);
rpc Info(InfoRequest) returns (InfoResponse);
rpc Update(UpdateRequest) returns (UpdateResponse);
rpc Attach(stream AttachRequest) returns (stream AttachResponse);
rpc Restart(RestartRequest) returns (RestartResponse);
rpc Export(ExportRequest) returns (ExportResponse);
rpc CopyFromContainer(CopyFromContainerRequest) returns (stream CopyFromContainerResponse);
rpc CopyToContainer(stream CopyToContainerRequest) returns (stream CopyToContainerResponse);
rpc Rename(RenameRequest) returns (RenameResponse);
rpc Logs(LogsRequest) returns (stream LogsResponse);
rpc Resize(ResizeRequest) returns (ResizeResponse);
}
message CreateRequest {
string id = 1;
string rootfs = 2;
// Image contains the reference of the image used to build the
// specification and snapshots for running this container.
//
string image = 3;
string runtime = 4;
string hostconfig = 5;
string customconfig = 6;
}
message CreateResponse {
string id = 1;
int32 pid = 2;
uint32 cc = 3;
string errmsg = 4;
}
message StartRequest {
string id = 1;
string stdin = 2;
bool attach_stdin = 3;
string stdout = 4;
bool attach_stdout = 5;
string stderr = 6;
bool attach_stderr = 7;
}
message StartResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message RemoteStartRequest {
bytes stdin = 1;
bool finish = 2;
}
message RemoteStartResponse {
bytes stdout = 1;
bytes stderr = 2;
bool finish = 3;
}
message TopRequest {
string id = 1;
repeated string args = 2;
}
message TopResponse {
bytes titles = 1;
repeated bytes processes = 2;
uint32 cc = 3;
string errmsg = 4;
}
message StopRequest {
string id = 1;
bool force = 2;
int32 timeout = 3;
}
message StopResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message RestartRequest {
string id = 1;
int32 timeout = 2;
}
message RestartResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message KillRequest {
string id = 1;
uint32 signal = 2;
}
message KillResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message DeleteRequest {
string id = 1;
bool force = 2;
}
message DeleteResponse {
string id = 1;
uint32 exit_status = 2;
uint32 cc = 3;
string errmsg = 4;
}
message PauseRequest {
string id = 1;
}
message PauseResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message ResumeRequest {
string id = 1;
}
message ResumeResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message InspectContainerRequest {
string id = 1;
bool bformat = 2;
int32 timeout = 3;
}
message InspectContainerResponse {
string ContainerJSON = 1;
uint32 cc = 2;
string errmsg = 3;
}
message ListRequest {
map<string, string> filters = 1;
bool all = 2;
}
message ListResponse {
repeated Container containers = 1;
uint32 cc = 2;
string errmsg = 3;
}
message StatsRequest {
repeated string containers = 2;
bool all = 3;
}
message StatsResponse {
repeated Container_info containers = 1;
uint32 cc = 2;
string errmsg = 3;
}
message WaitRequest {
string id = 1;
uint32 condition = 2;
}
message WaitResponse {
uint32 cc = 1;
uint32 exit_code = 2;
string errmsg = 3;
}
message EventsRequest {
google.protobuf.Timestamp since = 1;
google.protobuf.Timestamp until = 2;
bool storeOnly = 3;
string id = 4;
}
message ExecRequest {
// ContainerID specifies the container in which to exec the process.
string container_id = 1;
bool tty = 2;
bool open_stdin = 3;
bool attach_stdin = 4;
bool attach_stdout = 5;
bool attach_stderr = 6;
string stdin = 7;
string stdout = 8;
string stderr = 9;
repeated string argv = 10;
repeated string env = 11;
string user = 12;
string suffix = 13;
}
message ExecResponse {
int32 pid = 1;
uint32 exit_code = 2;
uint32 cc = 3;
string errmsg = 4;
}
message RemoteExecRequest {
repeated bytes cmd = 1;
bool finish = 2;
}
message RemoteExecResponse {
bytes stdout = 1;
bytes stderr = 2;
bool finish = 3;
}
message AttachRequest {
bytes stdin = 1;
bool finish = 2;
}
message AttachResponse {
bytes stdout = 1;
bytes stderr = 2;
bool finish = 3;
}
message VersionRequest {
}
message VersionResponse {
string version = 1;
string git_commit = 2;
string build_time = 3;
string root_path = 4;
uint32 cc = 5;
string errmsg = 6;
}
message InfoRequest {
}
message InfoResponse {
uint32 cc = 1;
string errmsg = 2;
string version = 3;
uint32 containers_num = 4;
uint32 c_running = 5;
uint32 c_paused = 6;
uint32 c_stopped = 7;
uint32 images_num = 8;
string kversion = 9;
string os_type = 10;
string architecture = 11;
string nodename = 12;
uint32 cpus = 13;
string operating_system = 14;
string cgroup_driver = 15;
string logging_driver = 16;
string huge_page_size = 17;
string isulad_root_dir = 18;
uint32 total_mem = 19;
string http_proxy = 20;
string https_proxy = 21;
string no_proxy = 22;
string driver_name = 23;
string driver_status = 24;
}
message UpdateRequest {
string id = 1;
string hostconfig = 2;
}
message UpdateResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message ExportRequest {
string id = 1;
string file = 2;
}
message ExportResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message CopyFromContainerRequest {
string id = 1;
string runtime = 2;
string srcpath = 3;
}
message CopyFromContainerResponse {
bytes data = 1;
}
message CopyToContainerRequest {
bytes data = 1;
}
message CopyToContainerResponse {
bool finish = 1;
}
message RenameRequest {
string oldname = 1;
string newname = 2;
}
message RenameResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}
message LogsRequest {
string id = 1;
string runtime = 2;
string since = 3;
string until = 4;
bool timestamps = 5;
bool follow = 6;
int64 tail = 7;
bool details = 8;
}
message LogsResponse {
bytes data = 1;
string stream = 2;
string time = 3;
bytes attrs = 4;
}
message ResizeRequest {
string id = 1;
string suffix = 2;
uint32 height = 3;
uint32 width = 4;
}
message ResizeResponse {
string id = 1;
uint32 cc = 2;
string errmsg = 3;
}

View File

@ -1,82 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-22
* Description: provide container rest definition
**********************************************************************************/
#ifndef CONTAINER_REST_H_
#define CONTAINER_REST_H_
#include "container_create_request.h"
#include "container_create_response.h"
#include "container_start_request.h"
#include "container_start_response.h"
#include "container_stop_request.h"
#include "container_stop_response.h"
#include "container_restart_request.h"
#include "container_restart_response.h"
#include "container_pause_request.h"
#include "container_pause_response.h"
#include "container_kill_request.h"
#include "container_kill_response.h"
#include "container_update_request.h"
#include "container_update_response.h"
#include "container_version_request.h"
#include "container_version_response.h"
#include "container_exec_request.h"
#include "container_exec_response.h"
#include "container_delete_request.h"
#include "container_delete_response.h"
#include "container_inspect_request.h"
#include "container_inspect_response.h"
#include "container_list_request.h"
#include "container_list_response.h"
#include "container_attach_request.h"
#include "container_attach_response.h"
#include "container_resume_request.h"
#include "container_resume_response.h"
#include "container_wait_request.h"
#include "container_wait_response.h"
#ifndef RestHttpHead
#define RestHttpHead "http://localhost"
#endif
#define ContainerServiceCreate "/ContainerService/Create"
#define ContainerServiceStart "/ContainerService/Start"
#define ContainerServiceRestart "/ContainerService/Restart"
#define ContainerServiceStop "/ContainerService/Stop"
#define ContainerServiceVersion "/ContainerService/Version"
#define ContainerServiceUpdate "/ContainerService/Update"
#define ContainerServicePause "/ContainerService/Pause"
#define ContainerServiceKill "/ContainerService/Kill"
#define ContainerServiceExec "/ContainerService/Exec"
#define ContainerServiceRemove "/ContainerService/Remove"
#define ContainerServiceInspect "/ContainerService/Inspect"
#define ContainerServiceList "/ContainerService/List"
#define ContainerServiceAttach "/ContainerService/Attach"
#define ContainerServiceResume "/ContainerService/Resume"
#define ContainerServiceWait "/ContainerService/Wait"
/* "/ContainerService/Kill",
"/ContainerService/Delete",
"/ContainerService/Pause",
"/ContainerService/Info",
"/ContainerService/Inspect",
"/ContainerService/Stats",
"/ContainerService/Events",
"/ContainerService/Exec",
"/ContainerService/Version",
"/ContainerService/Update",
"/ContainerService/Attach",
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,54 +0,0 @@
// #######################################################################
// ##- @Copyright (C) Huawei Technologies., Ltd. 2019-2020. All rights reserved.
// # - iSulad licensed under the Mulan PSL v2.
// # - You can use this software according to the terms and conditions of the Mulan PSL v2.
// # - You may obtain a copy of Mulan PSL v2 at:
// # - http://license.coscl.org.cn/MulanPSL2
// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// # - PURPOSE.
// # - See the Mulan PSL v2 for more details.
// ##- @Description: generate grpc
// ##- @Author: tanyifeng
// ##- @Create: 2020-01-16
// #######################################################################
//
// Since some of this code is derived from grpc, their copyright
// is retained here....
//
// Copyright 2015 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// The canonical version of this proto can be found at
// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto
syntax = "proto3";
option optimize_for = CODE_SIZE;
message HealthCheckRequest {
string service = 1;
}
message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
}
ServingStatus status = 1;
}
service HealthService{
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
}

View File

@ -1,185 +0,0 @@
// #######################################################################
// ##- @Copyright (C) Huawei Technologies., Ltd. 2019-2020. All rights reserved.
// # - iSulad licensed under the Mulan PSL v2.
// # - You can use this software according to the terms and conditions of the Mulan PSL v2.
// # - You may obtain a copy of Mulan PSL v2 at:
// # - http://license.coscl.org.cn/MulanPSL2
// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// # - PURPOSE.
// # - See the Mulan PSL v2 for more details.
// ##- @Description: generate grpc
// ##- @Author: wujing
// ##- @Create: 2020-01-16
// #######################################################################
/*
Since some of this code is derived from containerd, their copyright
is retained here....
Copyright 2013-2016 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
syntax = "proto3";
option optimize_for = CODE_SIZE;
import "google/protobuf/timestamp.proto";
import "descriptor.proto";
package images;
// Images is a service that allows one to register images with containerd.
//
// In containerd, an image is merely the mapping of a name to a content root,
// described by a descriptor. The behavior and state of image is purely
// dictated by the type of the descriptor.
//
// From the perspective of this service, these references are mostly shallow,
// in that the existence of the required content won't be validated until
// required by consuming services.
//
// As such, this can really be considered a "metadata service".
service ImagesService {
// List returns a list of all images known to containerd.
rpc List(ListImagesRequest) returns (ListImagesResponse);
// Delete deletes the image by name.
rpc Delete(DeleteImageRequest) returns (DeleteImageResponse);
// load image from archive.
rpc Load(LoadImageRequest) returns (LoadImageResponse);
//inspect image
rpc Inspect(InspectImageRequest) returns (InspectImageResponse);
// Login to a Docker registry
rpc Login(LoginRequest) returns (LoginResponse);
// Logout from a Docker registry
rpc Logout(LogoutRequest) returns (LogoutResponse);
// Add a tag to the image
rpc Tag(TagImageRequest) returns (TagImageResponse);
}
message Image {
// Name provides a unique name for the image.
//
// Containerd treats this as the primary identifier.
string name = 1;
// Labels provides free form labels for the image. These are runtime only
// and do not get inherited into the package image in any way.
//
// Labels may be updated using the field mask.
// The combined size of a key/value pair cannot exceed 4096 bytes.
map<string, string> labels = 2;
// Target describes the content entry point of the image.
containerd.types.Descriptor target = 3;
// CreatedAt is the time the image was first created.
google.protobuf.Timestamp created_at = 7;
// UpdatedAt is the last time the image was mutated.
google.protobuf.Timestamp updated_at = 8;
}
message ListImagesRequest {
// Filters contains one or more filters using the syntax defined in the
// containerd filter package.
//
// The returned result will be those that match any of the provided
// filters. Expanded, images that match the following will be
// returned:
//
// filters[0] or filters[1] or ... or filters[n-1] or filters[n]
//
// If filters is zero-length or nil, all items will be returned.
map<string, string> filters = 1;
}
message ListImagesResponse {
repeated Image images = 1;
uint32 cc = 2;
string errmsg = 3;
}
message DeleteImageRequest {
string name = 1;
bool force = 2;
}
message DeleteImageResponse {
string name = 1;
uint32 cc = 2;
string errmsg = 3;
}
message TagImageRequest {
string src_name = 1;
string dest_name = 2;
}
message TagImageResponse {
uint32 cc = 1;
string errmsg = 2;
}
message LoadImageRequest {
string file = 1;
string type = 2;
string tag = 3;
}
message LoadImageResponse {
uint32 cc = 1;
string errmsg = 2;
}
message InspectImageRequest {
string id = 1;
bool bformat = 2;
int32 timeout = 3;
}
message InspectImageResponse {
string ImageJSON = 1;
uint32 cc = 2;
string errmsg = 3;
}
message LoginRequest {
string username = 1;
string password = 2;
string server = 3;
string type = 4;
}
message LoginResponse {
uint32 cc = 1;
string errmsg = 2;
}
message LogoutRequest {
string server = 1;
string type = 2;
}
message LogoutResponse {
uint32 cc = 1;
string errmsg = 2;
}

View File

@ -1,37 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2017-11-22
* Description: provide container image rest definition
********************************************************************************/
#ifndef IMAGE_REST_H_
#define IMAGE_REST_H_
#include "image_load_image_request.h"
#include "image_load_image_response.h"
#include "image_list_images_request.h"
#include "image_list_images_response.h"
#include "image_delete_image_request.h"
#include "image_delete_image_response.h"
#include "image_inspect_request.h"
#include "image_inspect_response.h"
#ifndef RestHttpHead
#define RestHttpHead "http://localhost"
#endif
#define ImagesServiceLoad "/ImagesService/Load"
#define ImagesServiceList "/ImagesService/List"
#define ImagesServiceDelete "/ImagesService/Delete"
#define ImagesServiceInspect "/ImagesService/Inspect"
#endif

View File

@ -1,49 +0,0 @@
// #######################################################################
// ##- @Copyright (C) Huawei Technologies., Ltd. 2019-2020. All rights reserved.
// # - iSulad licensed under the Mulan PSL v2.
// # - You can use this software according to the terms and conditions of the Mulan PSL v2.
// # - You may obtain a copy of Mulan PSL v2 at:
// # - http://license.coscl.org.cn/MulanPSL2
// # - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// # - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// # - PURPOSE.
// # - See the Mulan PSL v2 for more details.
// ##- @Description: generate grpc
// ##- @Author: wujing
// ##- @Create: 2019-01-16
// #######################################################################
/*
Since some of this code is derived from containerd, their copyright
is retained here....
Copyright 2013-2016 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
syntax = "proto3";
option optimize_for = CODE_SIZE;
package containerd.types;
// Descriptor describes a blob in a content store.
//
// This descriptor can be used to reference content from an
// oci descriptor found in a manifest.
// See https://godoc.org/github.com/opencontainers/image-spec/specs-go/v1#Descriptor
message Descriptor {
string media_type = 1;
string digest = 2;
int64 size = 3;
}

View File

@ -1,14 +0,0 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} comm_srcs)
add_subdirectory(isula)
set(ISULA_SRCS ${comm_srcs} ${CMD_ISULA_SRCS} PARENT_SCOPE)
set(ISULA_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULA_INCS} PARENT_SCOPE)
add_subdirectory(isulad)
set(ISULAD_SRCS ${comm_srcs} ${CMD_ISULAD_SRCS} PARENT_SCOPE)
set(ISULAD_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULAD_INCS} PARENT_SCOPE)
add_subdirectory(isulad-shim)
set(ISULAD_SHIM_SRCS ${CMD_ISULAD_SHIM_SRCS} PARENT_SCOPE)
set(ISULAD_SHIM_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMD_ISULAD_SHIM_INCS} PARENT_SCOPE)

View File

@ -1,824 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2017-11-22
* Description: provide command functions
******************************************************************************/
#define _GNU_SOURCE
#include "commander.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <regex.h>
#include <limits.h>
#include "libisulad.h"
#include "utils.h"
#include "log.h"
void command_help_isulad_head()
{
fprintf(stdout, "isulad\n\nlightweight container runtime daemon\n");
}
int compare_options(const void *s1, const void *s2)
{
return strcmp((*(const command_option_t *)s1).large, (*(const command_option_t *)s2).large);
}
void print_options(int options_len, const command_option_t *options)
{
int i = 0;
int max_opt_len = 0;
for (i = 0; i < options_len; i++) {
command_option_t option = options[i];
// -s
int len = 2;
// -s, --large, 6 is the length of "-s, --".
if (option.large != NULL) {
len = (int)(strlen(option.large) + 6);
}
if (len > max_opt_len) {
max_opt_len = len;
}
}
// format: " -s, --large description"
// 6 is the total length of black before "-s" and "description"
max_opt_len += 6;
for (i = 0; i < options_len; i++) {
command_option_t option = options[i];
int curindex = 0;
int space_left = 0;
curindex = fprintf(stdout, " ");
if (option.small) {
curindex += fprintf(stdout, "-%c", (char)option.small);
}
if (option.large != NULL) {
if (option.small) {
curindex += fprintf(stdout, ", --%s", option.large);
} else {
curindex += fprintf(stdout, " --%s", option.large);
}
}
if (curindex <= max_opt_len) {
space_left = max_opt_len - curindex;
}
fprintf(stdout, "%*s%s\n", space_left, "", option.description);
}
fputc('\n', stdout);
}
void command_help(command_t *self)
{
const char *progname = strrchr(self->name, '/');
if (progname == NULL) {
progname = self->name;
} else {
progname++;
}
if (self->type != NULL && strcmp(self->type, "isulad") == 0) {
command_help_isulad_head();
}
fprintf(stdout, "\nUsage: %s %s\n\n", progname, self->usage);
fprintf(stdout, "%s\n\n", self->description);
qsort(self->options, (size_t)self->option_count, sizeof(self->options[0]), compare_options);
print_options(self->option_count, self->options);
}
int command_valid_socket(command_option_t *option, const char *arg)
{
if (!util_validate_socket(arg)) {
COMMAND_ERROR("Invalid socket name : %s", arg);
return -1;
}
return 0;
}
void command_init(command_t *self, command_option_t *opts, int opts_len, int argc, const char **argv,
const char *description, const char *usage)
{
(void)memset(self, 0, sizeof(command_t));
self->name = argv[0];
self->argc = argc - 2;
self->argv = argv + 2;
self->usage = usage;
self->description = description;
self->options = opts;
self->option_count = opts_len;
}
void command_option(command_t *self, command_option_type_t type, void *data, int small, const char *large,
const char *desc, command_callback_t cb)
{
if (self->option_count == COMMANDER_MAX_OPTIONS) {
COMMAND_ERROR("Maximum option definitions exceeded");
exit(EINVALIDARGS);
}
int n = self->option_count++;
command_option_t *opt = &self->options[n];
opt->type = type;
opt->data = data;
opt->cb = cb;
opt->small = small;
opt->description = desc;
opt->large = large;
}
static int read_option_arg(command_t *self, command_option_t *opt, const char **opt_arg, const char **readed)
{
if (self == NULL || opt == NULL || opt_arg == NULL) {
return -1;
}
if (opt->hasdata) {
*readed = *opt_arg;
*opt_arg = NULL;
}
if (!opt->hasdata && self->argc > 1) {
opt->hasdata = true;
*readed = *++self->argv;
self->argc--;
}
if (!opt->hasdata) {
COMMAND_ERROR("Flag needs an argument: --%s", opt->large);
return -1;
}
return 0;
}
static int command_get_bool_option_data(command_option_t *option, const char **opt_arg)
{
bool converted_bool = (option->type == CMD_OPT_TYPE_BOOL) ? true : false;
if (option->hasdata) {
int ret = util_str_to_bool(*opt_arg, &converted_bool);
if (ret != 0) {
COMMAND_ERROR("Invalid boolean value \"%s\" for flag --%s", *opt_arg, option->large);
return -1;
}
*opt_arg = NULL;
}
*(bool *)option->data = converted_bool;
return 0;
}
static int command_get_string_option_data(command_t *self, command_option_t *option, const char **opt_arg)
{
if (read_option_arg(self, option, opt_arg, (const char **)option->data)) {
return -1;
}
if (option->cb != NULL) {
return option->cb(option, *(char **)option->data);
}
return 0;
}
static int command_get_string_dup_option_data(command_t *self, command_option_t *option, const char **opt_arg)
{
const char *readed_item = NULL;
if (read_option_arg(self, option, opt_arg, &readed_item) != 0) {
return -1;
}
if (*(char **)option->data != NULL) {
free(*(char **)option->data);
}
*(char **)option->data = util_strdup_s(readed_item);
if (option->cb != NULL) {
return option->cb(option, readed_item);
}
return 0;
}
static int command_get_callback_option_data(command_t *self, command_option_t *option, const char **opt_arg)
{
const char *readed_item = NULL;
if (read_option_arg(self, option, opt_arg, &readed_item)) {
return -1;
}
if (option->cb == NULL) {
COMMAND_ERROR("Must specify callback for type array");
return -1;
}
return option->cb(option, readed_item);
}
static int command_get_option_data(command_t *self, command_option_t *option, const char **opt_arg)
{
if (option == NULL) {
return -1;
}
switch (option->type) {
case CMD_OPT_TYPE_BOOL:
case CMD_OPT_TYPE_BOOL_FALSE:
return command_get_bool_option_data(option, opt_arg);
case CMD_OPT_TYPE_STRING:
return command_get_string_option_data(self, option, opt_arg);
case CMD_OPT_TYPE_STRING_DUP:
return command_get_string_dup_option_data(self, option, opt_arg);
case CMD_OPT_TYPE_CALLBACK:
return command_get_callback_option_data(self, option, opt_arg);
default:
COMMAND_ERROR("Unkown command option type:%d", (int)(option->type));
return -1;
}
}
int have_short_options(command_t *self, char arg)
{
int i;
for (i = 0; i < self->option_count; i++) {
if (self->options[i].small == arg) {
return 0;
}
}
return -1;
}
static int command_parse_options(command_t *self, const char **opt_arg, bool *found)
{
int j = 0;
for (j = 0; j < self->option_count; ++j) {
command_option_t *opt = &self->options[j];
opt->hasdata = false;
if (opt->small != (*opt_arg)[0]) {
continue;
}
// match flag
*found = true;
if ((*opt_arg)[1]) {
if ((*opt_arg)[1] == '=') {
*opt_arg = *opt_arg + 2;
opt->hasdata = true;
} else {
*opt_arg = *opt_arg + 1;
}
} else {
*opt_arg = NULL;
}
if (command_get_option_data(self, opt, opt_arg)) {
return -1;
}
break;
}
return 0;
}
static int command_parse_short_arg(command_t *self, const char *arg)
{
bool found = false;
const char *opt_arg = arg;
do {
found = false;
if (command_parse_options(self, &opt_arg, &found)) {
return -1;
}
} while (found && opt_arg != NULL);
if (opt_arg != NULL) {
COMMAND_ERROR("Unkown flag found:'%c'", opt_arg[0]);
exit(EINVALIDARGS);
}
return 0;
}
static int command_parse_long_arg(command_t *self, const char *arg)
{
int j = 0;
if (strcmp(arg, "help") == 0) {
command_help(self);
exit(0);
}
for (j = 0; j < self->option_count; ++j) {
command_option_t *opt = &self->options[j];
const char *opt_arg = NULL;
opt->hasdata = false;
if (opt->large == NULL) {
continue;
}
opt_arg = str_skip_str(arg, opt->large);
if (opt_arg == NULL) {
continue;
}
if (opt_arg[0]) {
if (opt_arg[0] != '=') {
continue;
}
opt_arg = opt_arg + 1;
opt->hasdata = true;
} else {
opt_arg = NULL;
}
if (command_get_option_data(self, opt, &opt_arg)) {
return -1;
}
return 0;
}
COMMAND_ERROR("Unkown flag found:'--%s'\n", arg);
exit(EINVALIDARGS);
}
int command_parse_args(command_t *self, int *argc, char * const **argv)
{
int ret = 0;
for (; self->argc; self->argc--, self->argv++) {
const char *arg_opt = self->argv[0];
if (arg_opt[0] != '-' || !arg_opt[1]) {
break;
}
// short option
if (arg_opt[1] != '-') {
arg_opt = arg_opt + 1;
ret = command_parse_short_arg(self, arg_opt);
if (!ret) {
continue;
}
break;
}
// --
if (!arg_opt[2]) {
self->argc--;
self->argv++;
break;
}
// long option
arg_opt = arg_opt + 2;
ret = command_parse_long_arg(self, arg_opt);
if (ret == 0) {
continue;
}
break;
}
if (self->argc > 0) {
*argc = self->argc;
*argv = (char * const *)self->argv;
}
return ret;
}
int command_valid_socket_append_array(command_option_t *option, const char *arg)
{
int len;
char **pos = NULL;
if (option == NULL) {
return -1;
}
if (!util_validate_socket(arg)) {
COMMAND_ERROR("Invalid socket name : %s", arg);
return -1;
}
for (pos = *(char ***)(option->data), len = 0; pos != NULL && *pos != NULL; pos++, len++) {
if (strcmp(*pos, arg) == 0) {
break;
}
}
if (pos != NULL && *pos != NULL) {
return 0;
}
if (util_array_append(option->data, arg) != 0) {
ERROR("merge hosts config failed");
return -1;
}
len++;
if (len > MAX_HOSTS) {
COMMAND_ERROR("Too many hosts, the max number is %d", MAX_HOSTS);
return -1;
}
return 0;
}
static int check_default_ulimit_input(const char *val)
{
int ret = 0;
if (val == NULL || strcmp(val, "") == 0) {
COMMAND_ERROR("ulimit argument can't be empty");
ret = -1;
goto out;
}
if (val[0] == '=' || val[strlen(val) - 1] == '=') {
COMMAND_ERROR("Invalid ulimit argument: \"%s\", delimiter '=' can't"
" be the first or the last character", val);
ret = -1;
}
out:
return ret;
}
static void get_default_ulimit_split_parts(const char *val, char ***parts, size_t *parts_len, char deli)
{
*parts = util_string_split_multi(val, deli);
if (*parts == NULL) {
ERROR("Out of memory");
return;
}
*parts_len = util_array_len((const char **)(*parts));
}
static int parse_soft_hard_default_ulimit(const char *val, char **limitvals, size_t limitvals_len, int64_t *soft,
int64_t *hard)
{
int ret = 0;
// parse soft
ret = util_safe_llong(limitvals[0], (long long *)soft);
if (ret < 0) {
COMMAND_ERROR("Invalid ulimit soft value: \"%s\", parse int64 failed: %s", val, strerror(-ret));
ret = -1;
goto out;
}
// parse hard if exists
if (limitvals_len > 1) {
ret = util_safe_llong(limitvals[1], (long long *)hard);
if (ret < 0) {
COMMAND_ERROR("Invalid ulimit hard value: \"%s\", parse int64 failed: %s", val, strerror(-ret));
ret = -1;
goto out;
}
if (*soft > *hard) {
COMMAND_ERROR("Ulimit soft limit must be less than or equal to hard limit: %lld > %lld",
(long long int)(*soft), (long long int)(*hard));
ret = -1;
goto out;
}
} else {
*hard = *soft; // default to soft in case no hard was set
}
out:
return ret;
}
int check_default_ulimit_type(const char *type)
{
int ret = 0;
char **tmptype = NULL;
char *ulimit_valid_type[] = {
// "as", // Disabled since this doesn't seem usable with the way Docker inits a container.
"core", "cpu", "data", "fsize", "locks", "memlock", "msgqueue", "nice",
"nofile", "nproc", "rss", "rtprio", "rttime", "sigpending", "stack", NULL
};
for (tmptype = ulimit_valid_type; *tmptype != NULL; tmptype++) {
if (strcmp(type, *tmptype) == 0) {
break;
}
}
if (*tmptype == NULL) {
COMMAND_ERROR("Invalid ulimit type: %s", type);
ret = -1;
}
return ret;
}
static host_config_ulimits_element *parse_default_ulimit(const char *val)
{
int ret = 0;
int64_t soft = 0;
int64_t hard = 0;
size_t parts_len = 0;
size_t limitvals_len = 0;
char **parts = NULL;
char **limitvals = NULL;
host_config_ulimits_element *ulimit = NULL;
ret = check_default_ulimit_input(val);
if (ret != 0) {
return NULL;
}
get_default_ulimit_split_parts(val, &parts, &parts_len, '=');
if (parts == NULL) {
ERROR("Out of memory");
return NULL;
} else if (parts_len != 2) {
COMMAND_ERROR("Invalid ulimit argument: %s", val);
ret = -1;
goto out;
}
ret = check_default_ulimit_type(parts[0]);
if (ret != 0) {
ret = -1;
goto out;
}
if (parts[1][0] == ':' || parts[1][strlen(parts[1]) - 1] == ':') {
COMMAND_ERROR("Invalid ulimit value: \"%s\", delimiter ':' can't be the first"
" or the last character", val);
ret = -1;
goto out;
}
// parse value
get_default_ulimit_split_parts(parts[1], &limitvals, &limitvals_len, ':');
if (limitvals == NULL) {
ret = -1;
goto out;
}
if (limitvals_len > 2) {
COMMAND_ERROR("Too many limit value arguments - %s, can only have up to two, `soft[:hard]`",
parts[1]);
ret = -1;
goto out;
}
ret = parse_soft_hard_default_ulimit(val, limitvals, limitvals_len, &soft, &hard);
if (ret < 0) {
goto out;
}
ulimit = util_common_calloc_s(sizeof(host_config_ulimits_element));
if (ulimit == NULL) {
ret = -1;
goto out;
}
ulimit->name = util_strdup_s(parts[0]);
ulimit->hard = hard;
ulimit->soft = soft;
out:
util_free_array(parts);
util_free_array(limitvals);
if (ret != 0) {
free_host_config_ulimits_element(ulimit);
ulimit = NULL;
}
return ulimit;
}
int command_default_ulimit_append(command_option_t *option, const char *arg)
{
int ret = 0;
size_t ulimit_len;
host_config_ulimits_element *tmp = NULL;
host_config_ulimits_element **pos = NULL;
if (option == NULL) {
ret = -1;
goto out;
}
tmp = parse_default_ulimit(arg);
if (tmp == NULL) {
ERROR("parse default ulimit from arg failed");
ret = -1;
goto out;
}
for (pos = *(host_config_ulimits_element ***)(option->data); pos != NULL && *pos != NULL; pos++) {
if (strcmp((*pos)->name, tmp->name) == 0) {
break;
}
}
if (pos != NULL && *pos != NULL) {
(*pos)->hard = tmp->hard;
(*pos)->soft = tmp->soft;
goto out;
}
ulimit_len = ulimit_array_len(*(host_config_ulimits_element ***)(option->data));
if (ulimit_array_append(option->data, tmp, ulimit_len) != 0) {
ERROR("default ulimit append failed");
ret = -1;
}
out:
free_host_config_ulimits_element(tmp);
return ret;
}
int command_append_array(command_option_t *option, const char *arg)
{
if (option == NULL) {
return -1;
}
char ***array = option->data;
return util_array_append(array, arg);
}
int command_convert_u16(command_option_t *option, const char *arg)
{
int ret = 0;
if (option == NULL) {
return -1;
}
ret = util_safe_u16(arg, option->data);
if (ret != 0) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, option->large, strerror(-ret));
return EINVALIDARGS;
}
return 0;
}
int command_convert_llong(command_option_t *opt, const char *arg)
{
int ret;
if (opt == NULL) {
return -1;
}
ret = util_safe_llong(arg, opt->data);
if (ret != 0) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, opt->large, strerror(-ret));
return EINVALIDARGS;
}
return 0;
}
int command_convert_uint(command_option_t *opt, const char *arg)
{
int ret;
if (opt == NULL) {
return -1;
}
ret = util_safe_uint(arg, opt->data);
if (ret != 0) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, opt->large, strerror(-ret));
return EINVALIDARGS;
}
return 0;
}
int command_convert_int(command_option_t *option, const char *arg)
{
int ret = 0;
if (option == NULL) {
return -1;
}
ret = util_safe_int(arg, option->data);
if (ret != 0) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s: %s", arg, option->large, strerror(-ret));
return EINVALIDARGS;
}
return 0;
}
int command_convert_nanoseconds(command_option_t *option, const char *arg)
{
if (option == NULL) {
return -1;
}
if (util_parse_time_str_to_nanoseconds(arg, option->data)) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s", arg, option->large);
return EINVALIDARGS;
}
return 0;
}
int command_convert_membytes(command_option_t *option, const char *arg)
{
if (option == NULL) {
return -1;
}
if (util_parse_byte_size_string(arg, option->data) || (*(int64_t *)(option->data)) < 0) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s", arg, option->large);
return EINVALIDARGS;
}
return 0;
}
int command_convert_memswapbytes(command_option_t *option, const char *arg)
{
if (option == NULL) {
return -1;
}
if (strcmp(arg, "-1") == 0) {
*(int64_t *)(option->data) = -1;
return 0;
}
if (command_convert_membytes(option, arg)) {
return EINVALIDARGS;
}
return 0;
}
int command_convert_swappiness(command_option_t *option, const char *arg)
{
if (option == NULL) {
return -1;
}
if (strcmp(arg, "-1") == 0) {
*(int64_t *)(option->data) = -1;
return 0;
}
if (util_parse_byte_size_string(arg, option->data) || (*(int64_t *)(option->data)) < 0 ||
(*(int64_t *)(option->data)) > 100) {
COMMAND_ERROR("Invalid value \"%s\" for flag --%s. Valid memory swappiness range is 0-100", arg, option->large);
return EINVALIDARGS;
}
return 0;
}
size_t ulimit_array_len(host_config_ulimits_element **default_ulimit)
{
size_t len = 0;
host_config_ulimits_element **pos = NULL;
for (pos = default_ulimit; pos != NULL && *pos != NULL; pos++) {
len++;
}
return len;
}
int ulimit_array_append(host_config_ulimits_element ***ulimit_array, const host_config_ulimits_element *element,
const size_t len)
{
int ret;
size_t old_size, new_size;
host_config_ulimits_element *new_element = NULL;
host_config_ulimits_element **new_ulimit_array = NULL;
if (ulimit_array == NULL || element == NULL) {
return -1;
}
// let new len to len + 2 for element and null
if (len > SIZE_MAX / sizeof(host_config_ulimits_element *) - 2) {
ERROR("Too many ulimit elements!");
return -1;
}
new_size = (len + 2) * sizeof(host_config_ulimits_element *);
old_size = len * sizeof(host_config_ulimits_element *);
ret = mem_realloc((void **)(&new_ulimit_array), new_size, (void *)*ulimit_array, old_size);
if (ret != 0) {
ERROR("Failed to realloc memory for append ulimit");
return -1;
}
*ulimit_array = new_ulimit_array;
new_element = util_common_calloc_s(sizeof(host_config_ulimits_element));
if (new_element == NULL) {
ERROR("Out of memory");
free_default_ulimit(*ulimit_array);
*ulimit_array = NULL;
return -1;
}
new_element->name = util_strdup_s(element->name);
new_element->hard = element->hard;
new_element->soft = element->soft;
new_ulimit_array[len] = new_element;
return 0;
}
void free_default_ulimit(host_config_ulimits_element **default_ulimit)
{
host_config_ulimits_element **p = NULL;
for (p = default_ulimit; p != NULL && *p != NULL; p++) {
free_host_config_ulimits_element(*p);
}
free(default_ulimit);
}

View File

@ -1,126 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2017-11-22
* Description: provide command definition
******************************************************************************/
#ifndef __COMMANDER_H_
#define __COMMANDER_H_
#include <unistd.h>
#include <stdio.h>
#include <stdbool.h>
#include "host_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef COMMANDER_MAX_OPTIONS
#define COMMANDER_MAX_OPTIONS 64
#endif
typedef enum {
/* no arguments */
CMD_OPT_TYPE_BOOL,
CMD_OPT_TYPE_BOOL_FALSE,
/* required arguments */
CMD_OPT_TYPE_STRING,
CMD_OPT_TYPE_STRING_DUP,
CMD_OPT_TYPE_CALLBACK
} command_option_type_t;
struct _command;
struct command_option;
typedef int(*command_callback_t)(struct command_option *options, const char *arg);
typedef struct command_option {
command_option_type_t type;
bool hasdata;
const char *large;
int small;
void *data;
const char *description;
command_callback_t cb;
} command_option_t;
typedef struct _command {
const char *type;
const char *usage;
const char *description;
const char *name;
const char *version;
int option_count;
command_option_t *options;
int argc;
const char **argv;
} command_t;
int command_valid_socket(command_option_t *option, const char *arg);
void command_init(command_t *self, command_option_t *opts, int opts_len, int argc, const char **argv,
const char *description, const char *usage);
int compare_options(const void *s1, const void *s2);
void print_options(int options_len, const command_option_t *options);
void command_help(command_t *self);
void command_option(command_t *self, command_option_type_t type, void *data,
int small, const char *large, const char *desc, command_callback_t cb);
int command_parse_args(command_t *self, int *argc, char * const **argv);
int have_short_options(command_t *self, char arg);
int command_valid_socket_append_array(command_option_t *option, const char *arg);
int command_append_array(command_option_t *option, const char *arg);
int command_convert_u16(command_option_t *option, const char *arg);
int command_convert_llong(command_option_t *opt, const char *arg);
int command_convert_uint(command_option_t *opt, const char *arg);
int command_convert_int(command_option_t *option, const char *arg);
int command_convert_nanoseconds(command_option_t *option, const char *arg);
int command_convert_membytes(command_option_t *option, const char *arg);
int command_convert_memswapbytes(command_option_t *option, const char *arg);
int command_default_ulimit_append(command_option_t *option, const char *arg);
size_t ulimit_array_len(host_config_ulimits_element **default_ulimit);
int ulimit_array_append(host_config_ulimits_element ***default_ulimit,
const host_config_ulimits_element *element,
const size_t len);
int check_default_ulimit_type(const char *type);
void free_default_ulimit(host_config_ulimits_element **default_ulimit);
int command_convert_swappiness(command_option_t *option, const char *arg);
#ifdef __cplusplus
}
#endif
#endif /* COMMANDER_H */

View File

@ -1,27 +0,0 @@
# get current directory sources files
add_subdirectory(base)
add_subdirectory(information)
add_subdirectory(extend)
add_subdirectory(stream)
add_subdirectory(images)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_srcs)
set(CMD_ISULA_SRCS
${isula_srcs}
${ISULA_BASE_SRCS}
${ISULA_EXTEND_SRCS}
${ISULA_IMAGES_SRCS}
${ISULA_INFORMATION_SRCS}
${ISULA_STREAM_SRCS}
PARENT_SCOPE
)
set(CMD_ISULA_INCS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/base
${CMAKE_CURRENT_SOURCE_DIR}/extend
${CMAKE_CURRENT_SOURCE_DIR}/images
${CMAKE_CURRENT_SOURCE_DIR}/information
${CMAKE_CURRENT_SOURCE_DIR}/stream
PARENT_SCOPE
)

View File

@ -1,272 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2017-11-22
* Description: provide container client arguments functions
******************************************************************************/
#include "arguments.h"
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include "error.h"
#include "commander.h"
#include "log.h"
#include "utils.h"
#include "constants.h"
client_connect_config_t get_connect_config(const struct client_arguments *args)
{
client_connect_config_t config = { 0 };
config.socket = args->socket;
// unix socket not support tls
if (strncmp(args->socket, "tcp://", strlen("tcp://"))) {
config.tls_verify = false;
config.tls = false;
config.ca_file = NULL;
config.cert_file = NULL;
config.key_file = NULL;
} else {
config.tls = args->tls;
config.tls_verify = args->tls_verify;
if (args->tls_verify) {
config.tls = true;
}
config.ca_file = args->ca_file;
config.cert_file = args->cert_file;
config.key_file = args->key_file;
}
return config;
}
static int set_default_tls_options(struct client_arguments *args)
{
int ret = -1;
char *tls = NULL;
char *tls_verify = NULL;
char *tmp_path = NULL;
char *cert_path = NULL;
char *ca_file = NULL;
char *cert_file = NULL;
char *key_file = NULL;
tls = getenv("ISULAD_TLS");
args->tls = (tls != NULL && strlen(tls) != 0 && strcmp(tls, "0") != 0);
tls = NULL;
tls_verify = getenv("ISULAD_TLS_VERIFY");
args->tls_verify = (tls_verify != NULL && strlen(tls_verify) != 0 && strcmp(tls_verify, "0") != 0);
tls_verify = NULL;
tmp_path = getenv("ISULAD_CERT_PATH");
if (tmp_path != NULL && strlen(tmp_path) != 0) {
cert_path = util_strdup_s(tmp_path);
ca_file = util_path_join(cert_path, DEFAULT_CA_FILE);
if (ca_file == NULL) {
goto out;
}
free(args->ca_file);
args->ca_file = ca_file;
key_file = util_path_join(cert_path, DEFAULT_KEY_FILE);
if (key_file == NULL) {
goto out;
}
free(args->key_file);
args->key_file = key_file;
cert_file = util_path_join(cert_path, DEFAULT_CERT_FILE);
if (cert_file == NULL) {
goto out;
}
free(args->cert_file);
args->cert_file = cert_file;
}
ret = 0;
out:
free(cert_path);
return ret;
}
/* client arguments init */
int client_arguments_init(struct client_arguments *args)
{
char *host = NULL;
if (args == NULL) {
return -1;
}
args->name = NULL;
args->create_rootfs = NULL;
args->log_file = NULL;
// maximum number of rotate files : 7
args->log_file_rotate = 7;
args->log_file_size = "30KB";
args->argc = 0;
args->argv = NULL;
host = getenv("ISULAD_HOST");
if (host != NULL && strlen(host) != 0) {
args->socket = util_strdup_s(host);
} else {
args->socket = util_strdup_s(DEFAULT_UNIX_SOCKET);
}
(void)memset(&args->custom_conf, 0, sizeof(struct custom_configs));
(void)memset(&args->cr, 0, sizeof(struct args_cgroup_resources));
if (set_default_tls_options(args) != 0) {
return -1;
}
// default swappiness should be set to -1
args->cr.swappiness = -1;
return 0;
}
/* client arguments free */
void client_arguments_free(struct client_arguments *args)
{
int i;
struct custom_configs *custom_conf = NULL;
if (args == NULL) {
return;
}
free(args->name);
args->name = NULL;
free(args->socket);
args->socket = NULL;
util_free_array(args->filters);
args->filters = NULL;
custom_conf = &(args->custom_conf);
if (custom_conf == NULL) {
return;
}
util_free_array(custom_conf->env);
custom_conf->env = NULL;
util_free_array(custom_conf->hugepage_limits);
custom_conf->hugepage_limits = NULL;
free(custom_conf->hook_spec);
custom_conf->hook_spec = NULL;
free(custom_conf->env_target_file);
custom_conf->env_target_file = NULL;
free(custom_conf->cgroup_parent);
custom_conf->cgroup_parent = NULL;
free(custom_conf->user);
custom_conf->user = NULL;
free(custom_conf->hostname);
custom_conf->hostname = NULL;
util_free_array(custom_conf->cap_adds);
custom_conf->cap_adds = NULL;
util_free_array(custom_conf->cap_drops);
custom_conf->cap_drops = NULL;
util_free_array(custom_conf->storage_opts);
custom_conf->storage_opts = NULL;
util_free_array(custom_conf->sysctls);
custom_conf->sysctls = NULL;
util_free_array(custom_conf->volumes);
custom_conf->volumes = NULL;
free(custom_conf->entrypoint);
custom_conf->entrypoint = NULL;
util_free_array(custom_conf->ulimits);
custom_conf->ulimits = NULL;
util_free_array(custom_conf->devices);
custom_conf->devices = NULL;
util_free_array(custom_conf->weight_devices);
custom_conf->weight_devices = NULL;
for (i = 0; i < NAMESPACE_MAX; i++) {
free(custom_conf->share_ns[i]);
custom_conf->share_ns[i] = NULL;
}
free(args->create_rootfs);
args->create_rootfs = NULL;
free_json_map_string_string(args->annotations);
args->annotations = NULL;
free(custom_conf->workdir);
custom_conf->workdir = NULL;
util_free_array(custom_conf->security);
custom_conf->security = NULL;
free(args->ca_file);
args->ca_file = NULL;
free(args->cert_file);
args->cert_file = NULL;
free(args->key_file);
args->key_file = NULL;
}
/* print common help */
void print_common_help()
{
struct client_arguments cmd_common_args = {};
struct command_option options[] = { COMMON_OPTIONS(cmd_common_args), VERSION_OPTIONS(cmd_common_args) };
size_t len = sizeof(options) / sizeof(options[0]);
qsort(options, len, sizeof(options[0]), compare_options);
fprintf(stdout, "COMMON OPTIONS :\n");
print_options((int)len, options);
}
/* client print error */
void client_print_error(uint32_t cc, uint32_t server_errono, const char *errmsg)
{
switch (server_errono) {
case ISULAD_SUCCESS:
if (errmsg != NULL) {
COMMAND_ERROR("%s", errmsg);
}
break;
default:
if (errmsg != NULL) {
COMMAND_ERROR("Error response from daemon: %s", errmsg);
} else {
COMMAND_ERROR("%s", errno_to_error_message(server_errono));
}
break;
}
}

View File

@ -1,369 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2017-11-22
* Description: provide container client arguments definition
******************************************************************************/
#ifndef __ISULA_ARGUMENTS_H
#define __ISULA_ARGUMENTS_H
#include <stdbool.h>
#include <getopt.h>
#include <stdio.h>
#include <stdint.h>
#include "commander.h"
#include "container_def.h"
#include "json_common.h"
#include "isula_connect.h"
#ifdef __cplusplus
extern "C" {
#endif
/* max arguments can be specify in client */
#define MAX_CLIENT_ARGS 1000
struct client_arguments;
struct custom_configs;
struct custom_configs {
/* environment variables */
char **env;
/* environment variables file */
char **env_file;
/* label */
char **label;
/* label file */
char **label_file;
/* hugepage limits */
char **hugepage_limits;
/* group add */
char **group_add;
/* hook-spec file */
char *hook_spec;
/* volumes to mount */
char **volumes;
/* mounts to attach a filesystem */
char **mounts;
/* pids limit */
int64_t pids_limit;
/* files limit */
int64_t files_limit;
/* shm size */
int64_t shm_size;
/* user and group */
char *user;
/* hostname */
char *hostname;
/* privileged */
bool privileged;
/* auto remove */
bool auto_remove;
/* readonly rootfs */
bool readonly;
/* alldevices */
bool all_devices;
/* system container */
bool system_container;
char *ns_change_opt;
/* user remap */
char *user_remap;
/* cap add */
char **cap_adds;
/* cap drop */
char **cap_drops;
/* storage opts */
char **storage_opts;
/* sysctls */
char **sysctls;
/* extra hosts */
char **extra_hosts;
/* dns */
char **dns;
/* dns options */
char **dns_options;
/* dns search */
char **dns_search;
/* tty */
bool tty;
/* open stdin of container */
bool open_stdin;
/* attach stdin of container */
bool attach_stdin;
/* attach stdout of container */
bool attach_stdout;
/* attach stderr of container */
bool attach_stderr;
/* entrypoint */
char *entrypoint;
/* populate devices */
char **devices;
/* ulimit options */
char **ulimits;
/* blkio weight devices */
char **weight_devices;
/* namespace mode */
char *share_ns[NAMESPACE_MAX];
/* work dir */
char *workdir;
/* security opt */
char **security;
/* health cmd */
char *health_cmd;
/* health interval */
int64_t health_interval;
/* health retries */
int health_retries;
/* health timeout */
int64_t health_timeout;
/* health start period */
int64_t health_start_period;
/* no healthcheck */
bool no_healthcheck;
/* exit on unhealthy */
bool exit_on_unhealthy;
/* oom kill disable */
bool oom_kill_disable;
/* create/run accel options */
char **accel;
/* env target file */
char *env_target_file;
/* cgroup parent */
char *cgroup_parent;
/* device read bps */
char **blkio_throttle_read_bps_device;
/* device write bps */
char **blkio_throttle_write_bps_device;
};
struct args_cgroup_resources {
uint16_t blkio_weight;
int64_t cpu_shares;
int64_t cpu_period;
int64_t cpu_quota;
int64_t cpu_rt_period;
int64_t cpu_rt_runtime;
int64_t oom_score_adj;
char *cpuset_cpus;
char *cpuset_mems;
int64_t memory_limit;
int64_t memory_swap;
int64_t memory_reservation;
int64_t kernel_memory_limit;
int64_t swappiness;
};
struct client_arguments {
const char *progname; /* main progname name */
const char *subcommand; /* sub command name */
const struct option *options;
// For common options
char *name; /* container name */
char *socket;
char *runtime;
char *restart;
char *host_channel;
// lcr create
char *external_rootfs;
char *create_rootfs;
char *image_name;
char *log_file;
char *log_file_size;
unsigned int log_file_rotate;
/* notes: we should free the mem in custom_conf by hand */
struct custom_configs custom_conf;
// isula run;
bool detach;
bool interactive;
// stop/kill/delete
bool force;
int time;
// delete
bool volume;
// events
char *since;
char *until;
// health check
char *service;
// list
bool dispname;
bool list_all;
char **filters;
bool no_trunc;
// inspect
char *format;
// stats
bool nostream;
bool showall;
// update
struct args_cgroup_resources cr;
// pull/rmi
char *ref;
bool plain_http;
// logs
bool follow;
/*
* tail < 0: show all logs
* tail = 0: do not show log
* tail > 0: show number of logs set by tail
* */
long long tail;
// kill
char *signal;
// load
char *file;
char *type;
char *tag;
// exec
char *exec_suffix;
// login/logout
char *username;
char *password;
char *server;
bool password_stdin;
/* extra environment variables used in exec */
char **extra_env;
// remaining arguments
char * const *argv;
int argc;
// top
char *ps_args;
json_map_string_string *annotations;
// gRPC tls config
bool tls;
bool tls_verify;
char *ca_file;
char *cert_file;
char *key_file;
};
#define LOG_OPTIONS(log) \
{ CMD_OPT_TYPE_BOOL_FALSE, false, "debug", 'D', &(log).quiet, "Enable debug mode", NULL }
#define COMMON_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING_DUP, false, "host", 'H', &(cmdargs).socket, \
"Daemon socket(s) to connect to", command_valid_socket }, \
{ CMD_OPT_TYPE_BOOL, false, "tls", 0, &(cmdargs).tls, \
"Use TLS; implied by --tlsverify", NULL}, \
{ CMD_OPT_TYPE_BOOL, false, "tlsverify", 0, &(cmdargs).tls_verify, \
"Use TLS and verify the remote", NULL}, \
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscacert", 0, &(cmdargs).ca_file, \
"Trust certs signed only by this CA (default \"/root/.iSulad/ca.pem\")", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "tlscert", 0, &(cmdargs).cert_file, \
"Path to TLS certificate file (default \"/root/.iSulad/cert.pem\")", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs).key_file, \
"Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "help", 0, NULL, "Print usage", NULL }
#define VERSION_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "version", 0, NULL, "Print version information and quit", NULL }
extern void print_common_help();
extern int client_arguments_init(struct client_arguments *args);
extern void client_arguments_free(struct client_arguments *args);
extern void isulad_screen_print(uint32_t cc, uint32_t server_errono,
struct client_arguments *args);
extern void client_print_error(uint32_t cc, uint32_t server_errono, const char *errmsg);
extern client_connect_config_t get_connect_config(const struct client_arguments *args);
#ifdef __cplusplus
}
#endif
#endif /* __ISULA_ARGUMENTS_H */

View File

@ -1,7 +0,0 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_base_srcs)
set(ISULA_BASE_SRCS
${isula_base_srcs}
PARENT_SCOPE
)

File diff suppressed because it is too large Load Diff

View File

@ -1,187 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2017-11-22
* Description: provide container create definition
******************************************************************************/
#ifndef __CMD_CREATE_H
#define __CMD_CREATE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CREATE_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_CALLBACK, false, "accel", 0, &(cmdargs).custom_conf.accel, \
"Accelerator bindings (format: [<name>=]<runtime>[@<driver>[,<options>]])", \
command_append_array }, \
{ CMD_OPT_TYPE_BOOL, false, "read-only", 0, &(cmdargs).custom_conf.readonly, \
"Make container rootfs readonly", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cap-add", 0, &(cmdargs).custom_conf.cap_adds, \
"Add Linux capabilities ('ALL' to add all capabilities)", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cap-drop", 0, &(cmdargs).custom_conf.cap_drops, \
"Drop Linux capabilities ('ALL' to drop all capabilities)", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
"CPU shares (relative weight)", command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
"CPUs in which to allow execution (e.g. 0-3, 0,1)", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "device-read-bps", 0, &(cmdargs).custom_conf.blkio_throttle_read_bps_device, \
"Limit read rate (bytes per second) from a device (default [])", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "device-write-bps", 0, &(cmdargs).custom_conf.blkio_throttle_write_bps_device, \
"Limit write rate (bytes per second) to a device (default [])", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "oom-score-adj", 0, &(cmdargs).cr.oom_score_adj, \
"Tune host's OOM preferences (-1000 to 1000)", command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "device", 0, &(cmdargs).custom_conf.devices, \
"Add a host device to the container", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "env", 'e', &(cmdargs).custom_conf.env, \
"Set environment variables", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "env-file", 0, &(cmdargs).custom_conf.env_file, \
"Read in a file of environment variables", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "label", 'l', &(cmdargs).custom_conf.label, \
"Set metadata on container (default [])", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "label-file", 0, &(cmdargs).custom_conf.label_file, \
"Read in a line delimited file of labels (default [])", command_append_array }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "entrypoint", 0, &(cmdargs).custom_conf.entrypoint, \
"Entrypoint to run when starting the container", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "external-rootfs", 0, &(cmdargs).external_rootfs, \
"Specify the custom rootfs that is not managed by isulad for the container, directory or block device", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "files-limit", 0, &(cmdargs).custom_conf.files_limit, \
"Tune container files limit (set -1 for unlimited)", command_convert_llong }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "hook-spec", 0, &(cmdargs).custom_conf.hook_spec, \
"File containing hook definition(prestart, poststart, poststop)", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "hostname", 'h', &(cmdargs).custom_conf.hostname, \
"Container host name", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "add-host", 0, &(cmdargs).custom_conf.extra_hosts, \
"Add a custom host-to-IP mapping (host:ip)", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "dns", 0, &(cmdargs).custom_conf.dns, \
"Set custom DNS servers", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "dns-opt", 0, &(cmdargs).custom_conf.dns_options, \
"Set DNS options", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "dns-search", 0, &(cmdargs).custom_conf.dns_search, \
"Set custom DNS search domains", command_append_array }, \
{ CMD_OPT_TYPE_STRING, false, "user-remap", 0, &(cmdargs).custom_conf.user_remap, \
"Set user remap for container", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "ipc", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_IPC], \
"IPC namespace to use", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "shm-size", 0, &(cmdargs).custom_conf.shm_size, \
"Size of /dev/shm, default value is 64MB", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
"Kernel memory limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "hugetlb-limit", 0, &(cmdargs).custom_conf.hugepage_limits, \
"Huge page limit (format: [size:]<limit>, e.g. --hugetlb-limit 2MB:32MB)", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "log-opt", 0, &(cmdargs), \
"Container log options, value formate: key=value", callback_log_opt }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
"Memory limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
"Memory soft limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swappiness", 0, &(cmdargs).cr.swappiness, \
"Tune container memory swappiness (0 to 100) (default -1)", command_convert_swappiness }, \
{ CMD_OPT_TYPE_CALLBACK, false, "mount", 0, &(cmdargs).custom_conf.mounts, \
"Attach a filesystem mount to the service", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "group-add", 0, &(cmdargs).custom_conf.group_add, \
"Add additional groups to join", command_append_array }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "name", 'n', &(cmdargs).name, "Name of the container", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "net", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_NET], \
"Connect a container to a network", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "pid", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_PID], \
"PID namespace to use", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "pids-limit", 0, &(cmdargs).custom_conf.pids_limit, \
"Tune container pids limit (set -1 for unlimited)", command_convert_llong }, \
{ CMD_OPT_TYPE_BOOL, false, "privileged", 0, &(cmdargs).custom_conf.privileged, \
"Give extended privileges to this container", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "tty", 't', &(cmdargs).custom_conf.tty, "Allocate a pseudo-TTY", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
"Restart policy to apply when a container exits(no, always, on-reboot, on-failure[:max-retries])", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "host-channel", 0, &(cmdargs).host_channel, \
"Create share memory between host and container", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \
"Runtime to use for containers(default: lcr)", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "user", 'u', &(cmdargs).custom_conf.user, \
"Username or UID (format: <name|uid>[:<group|gid>])", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "uts", 0, &(cmdargs).custom_conf.share_ns[NAMESPACE_UTS], \
"UTS namespace to use", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "volume", 'v', &(cmdargs).custom_conf.volumes, \
"Bind mount a volume", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "annotation", 0, &(cmdargs), \
"Set annotations on a container", callback_annotation }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "workdir", 0, &(cmdargs).custom_conf.workdir, \
"Working directory inside the container", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "system-container", 0, &(cmdargs).custom_conf.system_container, \
"Extend some features only needed by running system container", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "oom-kill-disable", 0, &(cmdargs).custom_conf.oom_kill_disable, \
"Disable OOM Killer", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "security-opt", 0, &(cmdargs).custom_conf.security, \
"Security Options (default [])", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "storage-opt", 0, &(cmdargs).custom_conf.storage_opts, \
"Storage driver options for the container", command_append_array }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "health-cmd", 0, &(cmdargs).custom_conf.health_cmd, \
"Command to run to check health", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "sysctl", 0, &(cmdargs).custom_conf.sysctls, \
"Sysctl options", command_append_array }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "env-target-file", 0, &(cmdargs).custom_conf.env_target_file, \
"Export env to target file path in rootfs", NULL }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "cgroup-parent", 0, &(cmdargs).custom_conf.cgroup_parent, \
"Optional parent cgroup for the container", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "health-interval", 0, &(cmdargs).custom_conf.health_interval, \
"Time between running the check (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
{ CMD_OPT_TYPE_CALLBACK, false, "health-retries", 0, &(cmdargs).custom_conf.health_retries, \
"Consecutive failures needed to report unhealthy (default 3)", command_convert_int }, \
{ CMD_OPT_TYPE_CALLBACK, false, "health-timeout", 0, &(cmdargs).custom_conf.health_timeout, \
"Maximum time to allow one check to run (ms|s|m|h) (default 30s)", command_convert_nanoseconds }, \
{ CMD_OPT_TYPE_CALLBACK, false, "health-start-period", 0, &(cmdargs).custom_conf.health_start_period, \
"Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) " \
"(default 0s)", command_convert_nanoseconds }, \
{ CMD_OPT_TYPE_BOOL, false, "no-healthcheck", 0, &(cmdargs).custom_conf.no_healthcheck, \
"Disable any container-specified HEALTHCHECK", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "health-exit-on-unhealthy", 0, &(cmdargs).custom_conf.exit_on_unhealthy, \
"Kill the container when it is detected to be unhealthy", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "ns-change-opt", 0, &(cmdargs).custom_conf.ns_change_opt, \
"Namespaced kernel param options for system container (default [])", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "ulimit", 0, &(cmdargs).custom_conf.ulimits, \
"Ulimit options (default [])", command_append_array }
#define CREATE_EXTEND_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "interactive", 'i', &(cmdargs).custom_conf.open_stdin, \
"Keep STDIN open even if not attached", NULL }
extern const char g_cmd_create_desc[];
extern const char g_cmd_create_usage[];
extern struct client_arguments g_cmd_create_args;
int create_parser(struct client_arguments *args, int c, char *arg);
int create_checker(struct client_arguments *args);
int client_create(struct client_arguments *args);
int callback_log_opt(command_option_t *option, const char *value);
int callback_annotation(command_option_t *option, const char *value);
int cmd_create_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_CREATE_H */

View File

@ -1,139 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container kill functions
******************************************************************************/
#include "error.h"
#include "arguments.h"
#include "kill.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_kill_desc[] = "Kill one or more running containers";
const char g_cmd_kill_usage[] = "kill [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_kill_args = {
.signal = "SIGKILL",
};
static int client_kill(const struct client_arguments *args)
{
int ret = 0;
int signal = -1;
isula_connect_ops *ops = NULL;
struct isula_kill_request request = { 0 };
struct isula_kill_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_kill_response));
if (response == NULL) {
ERROR("Kill: Out of memory");
return -1;
}
request.name = args->name;
signal = util_sig_parse(args->signal);
if (signal < 0) {
ERROR("Invalid signal number");
ret = -1;
goto out;
}
request.signal = (uint32_t)signal;
ops = get_connect_client_ops();
if (ops == NULL || ops->container.kill == NULL) {
ERROR("Unimplemented kill op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.kill(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
out:
isula_kill_response_free(response);
return ret;
}
int cmd_kill_main(int argc, const char **argv)
{
int signo;
int i = 0;
int status = 0;
command_t cmd;
struct log_config lconf = { 0 };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_kill_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_kill_args.progname = argv[0];
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_kill_args),
KILL_OPTIONS(g_cmd_kill_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_kill_desc,
g_cmd_kill_usage);
if (command_parse_args(&cmd, &g_cmd_kill_args.argc, &g_cmd_kill_args.argv)) {
exit(ECOMMON);
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed\n");
exit(ECOMMON);
}
signo = util_sig_parse(g_cmd_kill_args.signal);
if (signo == -1) {
COMMAND_ERROR("Invalid signal: %s", g_cmd_kill_args.signal);
exit(ECOMMON);
}
if (!util_valid_signal(signo)) {
COMMAND_ERROR("The Linux daemon does not support signal %d", signo);
exit(ECOMMON);
}
if (g_cmd_kill_args.argc == 0) {
COMMAND_ERROR("Kill requires at least 1 container names");
exit(EINVALIDARGS);
}
if (g_cmd_kill_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to kill.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_kill_args.argc; i++) {
g_cmd_kill_args.name = g_cmd_kill_args.argv[i];
if (client_kill(&g_cmd_kill_args)) {
ERROR("Container \"%s\" kill failed", g_cmd_kill_args.name);
status = -1;
continue;
}
printf("%s\n", g_cmd_kill_args.name);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,39 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container kill definition
******************************************************************************/
#ifndef __CMD_KILL_H
#define __CMD_KILL_H
#include "arguments.h"
#include "wait.h"
#ifdef __cplusplus
extern "C" {
#endif
#define KILL_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "signal", 's', &(cmdargs).signal, \
"Signal to send to the container (default \"SIGKILL\")", NULL }
extern const char g_cmd_kill_desc[];
extern const char g_cmd_kill_usage[];
extern struct client_arguments g_cmd_kill_args;
int cmd_kill_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,98 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container stop functions
******************************************************************************/
#include "rename.h"
#include "arguments.h"
#include "log.h"
#include "utils.h"
#include "isula_connect.h"
const char g_cmd_rename_desc[] = "Rename a container";
const char g_cmd_rename_usage[] =
"rename [OPTIONS] OLD_NAME NEW_NAME";
struct client_arguments g_cmd_rename_args = { 0 };
static int client_rename(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_rename_request request = { 0 };
struct isula_rename_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(*response));
if (response == NULL) {
ERROR("Stop: Out of memory");
return -1;
}
request.old_name = args->argv[0];
request.new_name = args->argv[1];
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.rename) {
ERROR("Unimplemented stop op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.rename(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_rename_response_free(response);
return ret;
}
int cmd_rename_main(int argc, const char **argv)
{
struct log_config lconf = {0};
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_rename_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_rename_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_rename_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]),
argc,
(const char **)argv, g_cmd_rename_desc, g_cmd_rename_usage);
if (command_parse_args(&cmd, &g_cmd_rename_args.argc, &g_cmd_rename_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed\n");
exit(ECOMMON);
}
if (g_cmd_rename_args.argc != 2) {
COMMAND_ERROR("\"rename\" requires 2 arguments.");
exit(ECOMMON);
}
if (client_rename(&g_cmd_rename_args)) {
ERROR("Container \"%s\" rename failed", g_cmd_rename_args.argv[0]);
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container rename definition
******************************************************************************/
#ifndef __CMD_RENAME_H
#define __CMD_RENAME_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_rename_desc[];
extern const char g_cmd_rename_usage[];
extern struct client_arguments g_cmd_rename_args;
int cmd_rename_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,119 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container restart functions
******************************************************************************/
#include <unistd.h>
#include "restart.h"
#include "arguments.h"
#include "log.h"
#include "utils.h"
#include "isula_connect.h"
const char g_cmd_restart_desc[] = "Restart one or more containers";
const char g_cmd_restart_usage[] = "restart [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_restart_args = {
.force = false,
.time = 10,
};
static int client_restart(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_restart_request request = { 0 };
struct isula_restart_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_restart_response));
if (response == NULL) {
ERROR("Out of memory");
return -1;
}
request.name = args->name;
request.timeout = (unsigned int)args->time;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.restart) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.restart(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_restart_response_free(response);
return ret;
}
int cmd_restart_main(int argc, const char **argv)
{
int i = 0;
int status = 0;
command_t cmd;
struct log_config lconf = { 0 };
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_restart_args),
RESTART_OPTIONS(g_cmd_restart_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_restart_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_restart_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_restart_desc,
g_cmd_restart_usage);
if (command_parse_args(&cmd, &g_cmd_restart_args.argc, &g_cmd_restart_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Restart: log init failed");
exit(ECOMMON);
}
if (g_cmd_restart_args.argc == 0) {
COMMAND_ERROR("Restart requires at least 1 container names");
exit(EINVALIDARGS);
}
if (g_cmd_restart_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to restart.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_restart_args.argc; i++) {
g_cmd_restart_args.name = g_cmd_restart_args.argv[i];
if (client_restart(&g_cmd_restart_args)) {
status = -1;
continue;
}
printf("%s\n", g_cmd_restart_args.name);
}
if (status != 0) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,36 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container restart definition
******************************************************************************/
#ifndef __CMD_RESTART_H
#define __CMD_RESTART_H
#ifdef __cplusplus
extern "C" {
#endif
#define RESTART_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
extern const char g_cmd_restart_desc[];
extern const char g_cmd_restart_usage[];
extern struct client_arguments g_cmd_restart_args;
int cmd_restart_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_RESTART_H */

View File

@ -1,161 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container remove functions
******************************************************************************/
#include <limits.h>
#include "rm.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
#include "commands.h"
#include "console.h"
#include "utils.h"
const char g_cmd_delete_desc[] = "Remove one or more containers";
const char g_cmd_delete_usage[] = "rm [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_delete_args = {
.force = false,
.volume = false,
};
/*
* Create a rm request message and call RPC
*/
static int client_delete(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_delete_request request = { 0 };
struct isula_delete_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_delete_response));
if (response == NULL) {
ERROR("RM: Out of memory");
return -1;
}
request.name = args->name;
request.force = args->force;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.remove) {
ERROR("Unimplemented rm op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.remove(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
if (response->name != NULL) {
free(g_cmd_delete_args.name);
g_cmd_delete_args.name = util_strdup_s(response->name);
}
out:
isula_delete_response_free(response);
return ret;
}
static void do_delete_console_fifo(const char *name, const char *stdflag)
{
int ret = 0;
char fifo_dir[PATH_MAX] = { 0 };
char fifo_name[PATH_MAX] = { 0 };
ret = console_fifo_name(CLIENT_RUNDIR, name, stdflag, fifo_name, sizeof(fifo_name), fifo_dir,
sizeof(fifo_dir), false);
if (ret != 0) {
ERROR("Failed to get console fifo name.");
goto out;
}
console_fifo_delete(fifo_name);
if (util_recursive_rmdir(fifo_dir, 0)) {
ERROR("Failed to delete FIFO path:%s", fifo_dir);
}
out:
return;
}
static void delete_console_fifo(const char *name)
{
do_delete_console_fifo(name, "in");
do_delete_console_fifo(name, "out");
do_delete_console_fifo(name, "err");
return;
}
int cmd_delete_main(int argc, const char **argv)
{
int i = 0;
bool status = false;
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_delete_args),
DELETE_OPTIONS(g_cmd_delete_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_delete_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_delete_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_delete_desc,
g_cmd_delete_usage);
if (command_parse_args(&cmd, &g_cmd_delete_args.argc, &g_cmd_delete_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Rm: log init failed");
exit(ECOMMON);
}
if (g_cmd_delete_args.argc == 0) {
COMMAND_ERROR("\"%s rm\" requires at least 1 argument(s).", g_cmd_delete_args.progname);
COMMAND_ERROR("See '%s rm --help'.", g_cmd_delete_args.progname);
exit(ECOMMON);
}
if (g_cmd_delete_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to remove.");
exit(ECOMMON);
}
for (i = 0; i < g_cmd_delete_args.argc; i++) {
free(g_cmd_delete_args.name);
g_cmd_delete_args.name = util_strdup_s(g_cmd_delete_args.argv[i]);
if (client_delete(&g_cmd_delete_args)) {
ERROR("Container \"%s\" rm failed", g_cmd_delete_args.name);
status = true;
continue;
}
delete_console_fifo(g_cmd_delete_args.name);
printf("%s\n", g_cmd_delete_args.name);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,40 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container remove definition
******************************************************************************/
#ifndef __CMD_DELETE_H
#define __CMD_DELETE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DELETE_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, \
"Force the removal of a running container (uses SIGKILL)", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "volumes", 'v', &(cmdargs).volume, \
"Remove the volumes associated with the container", NULL }
extern const char g_cmd_delete_desc[];
extern const char g_cmd_delete_usage[];
extern struct client_arguments g_cmd_delete_args;
int cmd_delete_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_DELETE_H */

View File

@ -1,317 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container run functions
******************************************************************************/
#include <sys/ioctl.h>
#include <unistd.h>
#include <pthread.h>
#include <termios.h>
#include "run.h"
#include "arguments.h"
#include "log.h"
#include "utils.h"
#include "isula_connect.h"
#include "console.h"
#include "error.h"
const char g_cmd_run_desc[] = "Run a command in a new container";
const char g_cmd_run_usage[] = "run [OPTIONS] ROOTFS|IMAGE [COMMAND] [ARG...]";
static int run_checker(struct client_arguments *args);
struct client_arguments g_cmd_run_args = {
.runtime = "",
.restart = "no",
.log_file = NULL,
.log_file_size = "1MB",
.log_file_rotate = 7,
};
static int local_cmd_start(struct client_arguments *args, uint32_t *exit_code)
{
int ret = 0;
bool reset_tty = false;
struct termios oldtios;
struct command_fifo_config *console_fifos = NULL;
ret = client_start(&g_cmd_run_args, &reset_tty, &oldtios, &console_fifos);
if (ret != 0) {
goto free_out;
}
if (!g_cmd_run_args.detach) {
ret = client_wait(&g_cmd_run_args, exit_code);
if (ret != 0) {
goto free_out;
}
ret = (int)(*exit_code);
}
client_wait_fifo_exit(&g_cmd_run_args);
free_out:
client_restore_console(reset_tty, &oldtios, console_fifos);
return ret;
}
static int remote_cmd_start_set_tty(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios)
{
int istty = 0;
istty = isatty(0);
if (istty && args->custom_conf.tty && args->custom_conf.attach_stdin) {
if (setup_tios(0, oldtios)) {
ERROR("Failed to setup terminal properties");
return -1;
}
*reset_tty = true;
}
return 0;
}
static int remote_cmd_start(const struct client_arguments *args, uint32_t *exit_code)
{
int ret = 0;
bool reset_tty = false;
isula_connect_ops *ops = NULL;
struct isula_start_request request = { 0 };
struct isula_start_response *response = NULL;
client_connect_config_t config = { 0 };
struct termios oldtios;
ops = get_connect_client_ops();
if (ops == NULL || ops->container.remote_start == NULL) {
ERROR("Unimplemented ops");
ret = ECOMMON;
goto out;
}
if (remote_cmd_start_set_tty(args, &reset_tty, &oldtios) != 0) {
ret = ECOMMON;
goto out;
}
request.name = args->name;
request.attach_stdin = args->custom_conf.attach_stdin;
request.attach_stdout = args->custom_conf.attach_stdout;
request.attach_stderr = args->custom_conf.attach_stderr;
response = util_common_calloc_s(sizeof(struct isula_start_response));
if (response == NULL) {
ERROR("Out of memory");
ret = ECOMMON;
goto out;
}
config = get_connect_config(args);
ret = ops->container.remote_start(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = ECOMMON;
if (response->server_errono ||
(response->errmsg && !strcmp(response->errmsg, errno_to_error_message(ISULAD_ERR_CONNECT)))) {
ret = ESERVERERROR;
}
goto out;
}
out:
isula_start_response_free(response);
if (reset_tty && tcsetattr(0, TCSAFLUSH, &oldtios) < 0) {
ERROR("Failed to reset terminal properties");
return -1;
}
return ret;
}
static int do_resize_run_console(const struct client_arguments *args, unsigned int height, unsigned int width)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_resize_request request = { 0 };
struct isula_resize_response *response = NULL;
client_connect_config_t config = { 0 };
ops = get_connect_client_ops();
if (ops == NULL || ops->container.resize == NULL) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
request.id = args->name;
request.height = height;
request.width = width;
response = util_common_calloc_s(sizeof(struct isula_resize_response));
if (response == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.resize(&request, response, &config);
if (ret != 0) {
ERROR("Failed to call resize");
goto out;
}
out:
isula_resize_response_free(response);
return ret;
}
static void *run_console_resize_thread(void *arg)
{
int ret = 0;
const struct client_arguments *args = arg;
static struct winsize s_pre_wsz;
struct winsize wsz;
if (!isatty(STDIN_FILENO)) {
goto out;
}
ret = pthread_detach(pthread_self());
if (ret != 0) {
CRIT("Start: set thread detach fail");
goto out;
}
while (true) {
sleep(1); // check the windows size per 1s
ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz);
if (ret < 0) {
WARN("Failed to get window size");
continue;
}
if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) {
continue;
}
ret = do_resize_run_console(args, wsz.ws_row, wsz.ws_col);
if (ret != 0) {
continue;
}
s_pre_wsz.ws_row = wsz.ws_row;
s_pre_wsz.ws_col = wsz.ws_col;
}
out:
return NULL;
}
int run_client_console_resize_thread(struct client_arguments *args)
{
int res = 0;
pthread_t a_thread;
res = pthread_create(&a_thread, NULL, run_console_resize_thread, (void *)(args));
if (res != 0) {
CRIT("Thread creation failed");
return -1;
}
return 0;
}
int cmd_run_main(int argc, const char **argv)
{
int ret = 0;
unsigned int exit_code = 0;
command_t cmd = { 0 };
struct log_config lconf = { 0 };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_run_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_run_args.custom_conf.attach_stdout = true;
g_cmd_run_args.custom_conf.attach_stderr = true;
g_cmd_run_args.progname = argv[0];
g_cmd_run_args.subcommand = argv[1];
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_run_args),
CREATE_OPTIONS(g_cmd_run_args),
CREATE_EXTEND_OPTIONS(g_cmd_run_args),
RUN_OPTIONS(g_cmd_run_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_run_desc,
g_cmd_run_usage);
if (command_parse_args(&cmd, &g_cmd_run_args.argc, &g_cmd_run_args.argv) || run_checker(&g_cmd_run_args)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
}
ret = client_create(&g_cmd_run_args);
if (ret) {
ERROR("Container \"%s\" create failed", g_cmd_run_args.name);
exit(ret);
}
if (g_cmd_run_args.detach) {
printf("%s\n", g_cmd_run_args.name);
}
if (g_cmd_run_args.custom_conf.tty && isatty(STDIN_FILENO)) {
(void)run_client_console_resize_thread(&g_cmd_run_args);
}
if (strncmp(g_cmd_run_args.socket, "tcp://", strlen("tcp://")) == 0) {
ret = remote_cmd_start(&g_cmd_run_args, &exit_code);
if (ret != 0) {
ERROR("Failed to execute command with remote run");
goto free_out;
}
} else {
ret = local_cmd_start(&g_cmd_run_args, &exit_code);
if (ret != 0) {
ERROR("Failed to execute command with local run");
goto free_out;
}
}
free_out:
exit(ret);
}
static int run_checker(struct client_arguments *args)
{
int ret = 0;
ret = create_checker(args);
if (ret) {
goto out;
}
/* Make detach option a high priority than terminal */
if (args->detach) {
args->custom_conf.attach_stdin = false;
args->custom_conf.attach_stdout = false;
args->custom_conf.attach_stderr = false;
}
if (args->custom_conf.auto_remove && ((args->restart != NULL) && (strcmp("no", args->restart) != 0))) {
COMMAND_ERROR("Conflicting options: --restart and --rm");
ret = -1;
goto out;
}
out:
return ret;
}

View File

@ -1,42 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container run definition
******************************************************************************/
#ifndef __CMD_RUN_H
#define __CMD_RUN_H
#include "create.h"
#include "start.h"
#include "wait.h"
#ifdef __cplusplus
extern "C" {
#endif
#define RUN_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "detach", 'd', &(cmdargs).detach, \
"Run container in background and print container ID", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "rm", 0, &(cmdargs).custom_conf.auto_remove, \
"Automatically remove the container when it exits", NULL }
extern const char g_cmd_run_desc[];
extern const char g_cmd_run_usage[];
extern struct client_arguments g_cmd_run_args;
int cmd_run_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_RUN_H */

View File

@ -1,245 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide container start functions
******************************************************************************/
#include <semaphore.h>
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#include <malloc.h>
#include "error.h"
#include "arguments.h"
#include "commander.h"
#include "start.h"
#include "log.h"
#include "isula_connect.h"
#include "console.h"
#include "utils.h"
#include "commands.h"
const char g_cmd_start_desc[] = "Start one or more stopped containers";
const char g_cmd_start_usage[] = "start [OPTIONS] CONTAINER [CONTAINER...]";
sem_t g_console_waitopen_sem;
sem_t g_console_waitexit_sem;
struct client_arguments g_cmd_start_args = {};
static int start_cmd_init(const struct client_arguments *args)
{
if (sem_init(&g_console_waitopen_sem, 0, 0)) {
ERROR("Container %s Semaphore initialization failed", args->name);
return ECOMMON;
}
if (sem_init(&g_console_waitexit_sem, 0, 0)) {
ERROR("Container %s Semaphore initialization failed", args->name);
sem_destroy(&g_console_waitopen_sem);
return ECOMMON;
}
return 0;
}
static int start_prepare_console(const struct client_arguments *args, struct termios *oldtios, bool *reset_tty,
struct command_fifo_config **console_fifos)
{
int ret = 0;
int istty = 0;
istty = isatty(0);
if (istty && args->custom_conf.tty && args->custom_conf.attach_stdin) {
if (setup_tios(0, oldtios)) {
ERROR("Failed to setup terminal properties");
ret = ECOMMON;
goto out;
}
*reset_tty = true;
}
if (!istty) {
INFO("The input device is not a TTY");
}
if (args->custom_conf.attach_stdin || args->custom_conf.attach_stdout || args->custom_conf.attach_stderr) {
if (create_console_fifos(args->custom_conf.attach_stdin, args->custom_conf.attach_stdout,
args->custom_conf.attach_stderr, args->name, "start", console_fifos)) {
ERROR("Container \"%s\" create console FIFO failed", args->name);
ret = ECOMMON;
goto out;
}
(*console_fifos)->wait_open = &g_console_waitopen_sem;
(*console_fifos)->wait_exit = &g_console_waitexit_sem;
if (start_client_console_thread(*console_fifos, args->custom_conf.tty)) {
ERROR("Container \"%s\" start console thread failed", args->name);
ret = ECOMMON;
goto out;
}
}
out:
return ret;
}
static int do_client_start(const struct client_arguments *args, struct command_fifo_config **console_fifos)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_start_request request = { 0 };
struct isula_start_response *response = NULL;
client_connect_config_t config = { 0 };
ops = get_connect_client_ops();
if (ops == NULL || ops->container.start == NULL) {
ERROR("Unimplemented ops");
ret = ECOMMON;
goto out;
}
request.name = args->name;
if (console_fifos != NULL && *console_fifos != NULL) {
request.stdin = (*console_fifos)->stdin_name;
request.stdout = (*console_fifos)->stdout_name;
request.stderr = (*console_fifos)->stderr_name;
}
request.attach_stdin = args->custom_conf.attach_stdin;
request.attach_stdout = args->custom_conf.attach_stdout;
request.attach_stderr = args->custom_conf.attach_stderr;
response = util_common_calloc_s(sizeof(struct isula_start_response));
if (response == NULL) {
ERROR("Out of memory");
ret = ECOMMON;
goto out;
}
config = get_connect_config(args);
ret = ops->container.start(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
if (response->server_errono ||
(response->errmsg && !strcmp(response->errmsg, errno_to_error_message(ISULAD_ERR_CONNECT)))) {
ret = ESERVERERROR;
util_contain_errmsg(response->errmsg, &ret);
} else {
ret = ECOMMON;
}
goto out;
}
out:
isula_start_response_free(response);
response = NULL;
return ret;
}
/*
* Create a create request message and call RPC
*/
int client_start(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios,
struct command_fifo_config **console_fifos)
{
int ret = 0;
ret = start_cmd_init(args);
if (ret != 0) {
return ret;
}
if (oldtios != NULL && console_fifos != NULL && reset_tty != NULL) {
ret = start_prepare_console(args, oldtios, reset_tty, console_fifos);
if (ret != 0) {
goto out;
}
}
ret = do_client_start(args, console_fifos);
if (ret != 0) {
goto out;
}
out:
return ret;
}
void client_wait_fifo_exit(const struct client_arguments *args)
{
if (args->custom_conf.attach_stdin || args->custom_conf.attach_stdout || args->custom_conf.attach_stderr) {
sem_wait(&g_console_waitexit_sem);
}
}
void client_restore_console(bool reset_tty, const struct termios *oldtios, struct command_fifo_config *console_fifos)
{
if (reset_tty && tcsetattr(0, TCSAFLUSH, oldtios) < 0) {
WARN("Failed to reset terminal properties: %s.", strerror(errno));
}
free_command_fifo_config(console_fifos);
sem_destroy(&g_console_waitopen_sem);
sem_destroy(&g_console_waitexit_sem);
}
int cmd_start_main(int argc, const char **argv)
{
int ret = 0;
int i = 0;
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_start_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_start_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_start_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_start_desc,
g_cmd_start_usage);
if (command_parse_args(&cmd, &g_cmd_start_args.argc, &g_cmd_start_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Start: log init failed");
exit(ECOMMON);
}
if (g_cmd_start_args.argc == 0) {
COMMAND_ERROR("\"start\" requires at least 1 argument");
exit(EINVALIDARGS);
}
if (g_cmd_start_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to start.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_start_args.argc; i++) {
g_cmd_start_args.name = g_cmd_start_args.argv[i];
if (client_start(&g_cmd_start_args, NULL, NULL, NULL)) {
ERROR("Container \"%s\" start failed", g_cmd_start_args.name);
ret = ECOMMON;
continue;
}
if (g_cmd_start_args.detach) {
printf("Container \"%s\" started\n", g_cmd_start_args.name);
}
}
return ret;
}

View File

@ -1,41 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide container start definition
******************************************************************************/
#ifndef __CMD_START_H
#define __CMD_START_H
#include "arguments.h"
#include "commands.h"
#include <termios.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_start_desc[];
extern struct client_arguments g_cmd_start_args;
void client_wait_fifo_exit(const struct client_arguments *args);
void client_restore_console(bool reset_tty, const struct termios *oldtios, struct command_fifo_config *console_fifos);
int client_start(const struct client_arguments *args, bool *reset_tty, struct termios *oldtios,
struct command_fifo_config **console_fifos);
int cmd_start_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_START_H */

View File

@ -1,123 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container stop functions
******************************************************************************/
#include "stop.h"
#include "arguments.h"
#include "log.h"
#include "utils.h"
#include "isula_connect.h"
const char g_cmd_stop_desc[] = "Stop one or more containers";
const char g_cmd_stop_usage[] = "stop [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_stop_args = {
.force = false,
.time = 10,
};
/*
* Create a stop request message and call RPC
*/
static int client_stop(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_stop_request request = { 0 };
struct isula_stop_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_stop_response));
if (response == NULL) {
ERROR("Stop: Out of memory");
return -1;
}
request.name = args->name;
request.force = args->force;
request.timeout = args->time;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.stop) {
ERROR("Unimplemented stop op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.stop(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_stop_response_free(response);
return ret;
}
int cmd_stop_main(int argc, const char **argv)
{
int i = 0;
int status = 0;
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_stop_args),
STOP_OPTIONS(g_cmd_stop_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_stop_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_stop_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_stop_desc,
g_cmd_stop_usage);
if (command_parse_args(&cmd, &g_cmd_stop_args.argc, &g_cmd_stop_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
}
if (g_cmd_stop_args.force) {
g_cmd_stop_args.time = 0;
}
if (g_cmd_stop_args.argc == 0) {
COMMAND_ERROR("Stop requires minimum of 1 container name");
exit(EINVALIDARGS);
}
if (g_cmd_stop_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to stop.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_stop_args.argc; i++) {
g_cmd_stop_args.name = g_cmd_stop_args.argv[i];
if (client_stop(&g_cmd_stop_args)) {
ERROR("Container \"%s\" stop failed", g_cmd_stop_args.name);
status = -1;
continue;
}
printf("%s\n", g_cmd_stop_args.name);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,40 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container stop definition
******************************************************************************/
#ifndef __CMD_STOP_H
#define __CMD_STOP_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define STOP_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Stop by force killing", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
"Seconds to wait for stop before killing it (default 10)", command_convert_int }
extern const char g_cmd_stop_desc[];
extern const char g_cmd_stop_usage[];
extern struct client_arguments g_cmd_stop_args;
int cmd_stop_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_STOP_H */

View File

@ -1,433 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2017-11-22
* Description: provide container command functions
******************************************************************************/
#include "commands.h"
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <pthread.h>
#include <syslog.h>
#include "arguments.h"
#include "config.h"
#include "log.h"
#include "utils.h"
#include "console.h"
#include "constants.h"
static void send_msg_to_syslog(int argc, const char **argv)
{
int nret = 0;
int fd = -1;
int i = 0;
bool found = false;
ssize_t len = 0;
pid_t ppid = -1;
char cmdline_path[PATH_MAX] = { 0 };
char cmdline[MAX_BUFFER_SIZE + 1] = { 0 };
char *msg = NULL;
const char *target_command[] = { "kill", "restart", "rm", "stop", NULL };
if (argc < 2) {
COMMAND_ERROR("Invalid arguments to send syslog");
return;
}
for (; target_command[i] != NULL; i++) {
if (strcmp(argv[1], target_command[i]) == 0) {
found = true;
break;
}
}
if (!found) {
return;
}
ppid = getppid();
// get parent cmdline, "/proc/ppid/cmdline"
nret = snprintf(cmdline_path, PATH_MAX, "/proc/%d/cmdline", ppid);
if (nret < 0 || nret >= PATH_MAX) {
COMMAND_ERROR("Get parent '%d' cmdline path failed", ppid);
return;
}
fd = util_open(cmdline_path, O_RDONLY, DEFAULT_SECURE_FILE_MODE);
if (fd < 0) {
COMMAND_ERROR("Open parent '%d' cmdline path failed", ppid);
return;
}
len = util_read_nointr(fd, cmdline, MAX_BUFFER_SIZE);
if (len < 0) {
COMMAND_ERROR("Read cmdline failed");
goto free_out;
}
msg = util_string_join(" ", argv, (size_t)argc);
if (msg == NULL) {
msg = util_strdup_s(argv[1]);
}
openlog("isulad-client", LOG_PID, LOG_USER);
syslog(LOG_DEBUG, "received command [%s] from parent [%d] cmdline [%s]", msg, ppid, cmdline);
closelog();
free_out:
close(fd);
free(msg);
}
static void print_version()
{
printf("Version %s, commit %s\n", VERSION, ISULAD_GIT_COMMIT);
}
/* compare commands */
int compare_commands(const void *s1, const void *s2)
{
return strcmp((*(const struct command *)s1).name, (*(const struct command *)s2).name);
}
const struct command *command_by_name(const struct command *cmds, const char * const name)
{
size_t i = 0;
if (cmds == NULL) {
return NULL;
}
while (1) {
if (cmds[i].name == NULL) {
return NULL;
}
if (strcmp(cmds[i].name, name) == 0) {
return cmds + i;
}
++i;
}
}
// Default help command if implementation doesn't provide one
int command_default_help(const char * const program_name, struct command *commands, int argc, const char **argv)
{
const struct command *command = NULL;
if (commands == NULL) {
return 1;
}
if (argc == 0) {
size_t i = 0;
size_t max_size = 0;
printf("USAGE:\n");
printf("\t%s <command> [args...]\n", program_name);
printf("\n");
printf("COMMANDS:\n");
for (i = 0; commands[i].name != NULL; i++) {
size_t cmd_size = strlen(commands[i].name);
if (cmd_size > max_size) {
max_size = cmd_size;
}
}
qsort(commands, i, sizeof(commands[0]), compare_commands);
for (i = 0; commands[i].name != NULL; i++) {
printf("\t%*s\t%s\n", -(int)max_size, commands[i].name, commands[i].description);
}
printf("\n");
print_common_help();
return 0;
} else if (argc > 1) {
printf("%s: unrecognized argument: \"%s\"\n", program_name, argv[1]);
return 1;
}
command = command_by_name(commands, argv[0]);
if (command == NULL) {
printf("%s: sub-command \"%s\" not found\n", program_name, argv[0]);
printf("run `isula --help` for a list of sub-commands\n");
return 1;
}
if (command->longdesc != NULL) {
printf("%s\n", command->longdesc);
}
return 0;
}
/* run command */
int run_command(struct command *commands, int argc, const char **argv)
{
const struct command *command = NULL;
if (argc == 1) {
return command_default_help(argv[0], commands, argc - 1, (const char **)(argv + 1));
}
if (strcmp(argv[1], "--help") == 0) {
// isula help command format: isula --help args
return command_default_help(argv[0], commands, argc - 2, (const char **)(argv + 2));
}
if (strcmp(argv[1], "--version") == 0) {
print_version();
return 0;
}
command = command_by_name(commands, argv[1]);
if (command != NULL) {
send_msg_to_syslog(argc, argv);
return command->executor(argc, (const char **)argv);
}
printf("%s: command \"%s\" not found\n", argv[0], argv[1]);
printf("run `%s --help` for a list of sub-commands\n", argv[0]);
return 1;
}
/* free command fifo names */
void free_command_fifo_config(struct command_fifo_config *fifos)
{
if (fifos != NULL) {
if (fifos->stdin_path != NULL) {
free(fifos->stdin_path);
fifos->stdin_path = NULL;
}
if (fifos->stdout_path != NULL) {
free(fifos->stdout_path);
fifos->stdout_path = NULL;
}
if (fifos->stderr_path != NULL) {
free(fifos->stderr_path);
fifos->stderr_path = NULL;
}
if (fifos->stdin_name != NULL) {
free(fifos->stdin_name);
fifos->stdin_name = NULL;
}
if (fifos->stdout_name != NULL) {
free(fifos->stdout_name);
fifos->stdout_name = NULL;
}
if (fifos->stderr_name != NULL) {
free(fifos->stderr_name);
fifos->stderr_name = NULL;
}
free(fifos);
}
}
/* delete command fifo */
void delete_command_fifo(struct command_fifo_config *fifos)
{
int ret;
if (fifos == NULL) {
return;
}
ret = console_fifo_delete(fifos->stdin_name);
if (ret) {
WARN("Delete fifo failed: %s", fifos->stdin_name);
}
ret = console_fifo_delete(fifos->stdout_name);
if (ret) {
WARN("Delete fifo failed: %s", fifos->stdout_name);
}
ret = console_fifo_delete(fifos->stderr_name);
if (ret) {
WARN("Delete fifo failed: %s", fifos->stderr_name);
}
ret = util_recursive_rmdir(fifos->stdin_path, 0);
if (ret) {
WARN("Remove directory failed: %s", fifos->stdin_path);
}
ret = util_recursive_rmdir(fifos->stdout_path, 0);
if (ret) {
WARN("Remove directory failed: %s", fifos->stdout_path);
}
ret = util_recursive_rmdir(fifos->stderr_path, 0);
if (ret) {
WARN("Remove directory failed: %s", fifos->stderr_path);
}
free_command_fifo_config(fifos);
}
static int do_create_console_fifo(const char *subpath, const char *stdflag, char **out_fifo_dir, char **out_fifo_name)
{
int ret = 0;
char fifo_dir[PATH_MAX] = { 0 };
char fifo_name[PATH_MAX] = { 0 };
ret = console_fifo_name(CLIENT_RUNDIR, subpath, stdflag, fifo_name, sizeof(fifo_name), fifo_dir,
sizeof(fifo_dir), true);
if (ret != 0) {
ERROR("Failed to get console fifo name.");
ret = -1;
goto out;
}
if (console_fifo_create(fifo_name)) {
ERROR("Failed to create console fifo.");
ret = -1;
goto out;
}
*out_fifo_dir = util_strdup_s(fifo_dir);
*out_fifo_name = util_strdup_s(fifo_name);
out:
return ret;
}
int create_console_fifos(bool attach_stdin, bool attach_stdout, bool attach_stderr, const char *name, const char *type,
struct command_fifo_config **pconsole_fifos)
{
int ret = 0;
char subpath[PATH_MAX] = { 0 };
struct command_fifo_config *fifos = NULL;
fifos = util_common_calloc_s(sizeof(struct command_fifo_config));
if (fifos == NULL) {
ERROR("Failed to malloc memory for FIFO names.");
return -1;
}
ret = snprintf(subpath, sizeof(subpath), "%s/%s-%u-%u", name, type, (unsigned int)getpid(),
(unsigned int)pthread_self());
if (ret < 0 || (size_t)ret >= sizeof(subpath)) {
ERROR("Path is too long");
goto cleanup;
}
if (attach_stdin) {
ret = do_create_console_fifo(subpath, "in", &fifos->stdin_path, &fifos->stdin_name);
if (ret != 0) {
goto cleanup;
}
INFO("FIFO:%s create for start success.", fifos->stdin_name);
}
if (attach_stdout) {
ret = do_create_console_fifo(subpath, "out", &fifos->stdout_path, &fifos->stdout_name);
if (ret != 0) {
goto cleanup;
}
INFO("FIFO:%s create for start success.", fifos->stdout_name);
}
if (attach_stderr) {
ret = do_create_console_fifo(subpath, "err", &fifos->stderr_path, &fifos->stderr_name);
if (ret != 0) {
goto cleanup;
}
INFO("FIFO:%s create for start success.", fifos->stderr_name);
}
*pconsole_fifos = fifos;
return 0;
cleanup:
console_fifo_delete(fifos->stdin_name);
console_fifo_delete(fifos->stdout_name);
console_fifo_delete(fifos->stderr_name);
free_command_fifo_config(fifos);
return -1;
}
struct console_loop_thread_args {
struct command_fifo_config *fifo_config;
bool tty;
};
static void *client_console_loop_thread(void *arg)
{
int ret = 0;
int fifoinfd = -1;
int fifooutfd = -1;
int fifoerrfd = -1;
const struct console_loop_thread_args *args = arg;
bool tty = args->tty;
struct command_fifo_config *fifo_config = args->fifo_config;
sem_t *wait_open = fifo_config->wait_open;
sem_t *wait_exit = fifo_config->wait_exit;
ret = pthread_detach(pthread_self());
if (ret != 0) {
CRIT("Start: set thread detach fail");
goto err1;
}
if (fifo_config->stdin_name) {
if (console_fifo_open_withlock(fifo_config->stdin_name, &fifoinfd, O_RDWR | O_NONBLOCK)) {
ERROR("Start: failed to open console fifo.");
goto err2;
}
INFO("FIFO:%s open success for start.", fifo_config->stdin_name);
}
if (fifo_config->stdout_name) {
if (console_fifo_open(fifo_config->stdout_name, &fifooutfd, O_RDONLY | O_NONBLOCK)) {
ERROR("Failed to open console fifo.");
goto err2;
}
INFO("FIFO:%s open success for start.", fifo_config->stdout_name);
}
if (fifo_config->stderr_name) {
if (console_fifo_open(fifo_config->stderr_name, &fifoerrfd, O_RDONLY | O_NONBLOCK)) {
ERROR("Start: failed to open console fifo.");
goto err2;
}
INFO("FIFO:%s open success for start.", fifo_config->stderr_name);
}
sem_post(wait_open);
client_console_loop(0, 1, 2, fifoinfd, fifooutfd, fifoerrfd, 1, tty);
err2:
if (fifoinfd >= 0) {
console_fifo_close(fifoinfd);
}
if (fifooutfd >= 0) {
console_fifo_close(fifooutfd);
}
if (fifoerrfd >= 0) {
console_fifo_close(fifoerrfd);
}
err1:
sem_post(wait_open);
sem_post(wait_exit);
return NULL;
}
int start_client_console_thread(struct command_fifo_config *console_fifos, bool tty)
{
int res = 0;
pthread_t a_thread;
struct console_loop_thread_args args;
args.fifo_config = console_fifos;
args.tty = tty;
res = pthread_create(&a_thread, NULL, client_console_loop_thread, (void *)(&args));
if (res != 0) {
CRIT("Thread creation failed");
return -1;
}
sem_wait(console_fifos->wait_open);
return 0;
}

View File

@ -1,82 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2017-11-22
* Description: provide container commands definition
******************************************************************************/
#ifndef __COMMAND_H
#define __COMMAND_H
#include "arguments.h"
#include <semaphore.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CLIENT_RUNDIR "/var/run/isula"
// A command is described by:
// @name: The name which should be passed as a second parameter
// @executor: The function that will be executed if the command
// matches. Receives the argc of the program minus two, and
// the rest os argv
// @description: Brief description, will show in help messages
// @longdesc: Long descripton to show when you run `help <command>`
struct command {
const char * const name;
int(*executor)(int, const char **);
const char * const description;
const char * const longdesc;
struct client_arguments *args;
};
struct command_fifo_config {
char *stdin_path;
char *stdout_path;
char *stderr_path;
char *stdin_name;
char *stdout_name;
char *stderr_name;
sem_t *wait_open;
sem_t *wait_exit;
};
int create_console_fifos(bool attach_stdin, bool attach_stdout, bool attach_stderr, const char *name,
const char *type, struct command_fifo_config **pconsole_fifos);
int start_client_console_thread(struct command_fifo_config *console_fifos, bool tty);
void free_command_fifo_config(struct command_fifo_config *fifos);
void delete_command_fifo(struct command_fifo_config *fifos);
// Gets a pointer to a command, to allow implementing custom behavior
// returns null if not found.
//
// NOTE: Command arrays must end in a command with all member is NULL
const struct command *command_by_name(const struct command *cmds,
const char * const name);
// Default help command if implementation doesn't prvide one
int commmand_default_help(const char * const program_name,
struct command *commands,
int argc,
const char **argv);
int run_command(struct command *commands, int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __COMMAND_H */

View File

@ -1,7 +0,0 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_extend_srcs)
set(ISULA_EXTEND_SRCS
${isula_extend_srcs}
PARENT_SCOPE
)

View File

@ -1,238 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container events functions
******************************************************************************/
#include "error.h"
#include "events.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_events_desc[] = "Get real time events from the server";
const char g_cmd_events_usage[] = "events [command options]";
struct client_arguments g_cmd_events_args = {
.since = NULL,
.until = NULL,
};
static size_t calacute_annotations_msg_len(const container_events_format_t *event)
{
size_t annos_msg_len = 0;
size_t i;
for (i = 0; i < event->annotations_len; i++) {
annos_msg_len += strlen(event->annotations[i]);
}
annos_msg_len += event->annotations_len * 2;
return annos_msg_len;
}
static size_t calacute_event_msg_len(const container_events_format_t *event, const char *timebuffer)
{
size_t msg_len = 0;
// format : timestamp (container|image opt) id (annotaions)
msg_len += strlen(timebuffer) + 1 + strlen(event->opt) + 1 + strlen(event->id) + 1;
msg_len += calacute_annotations_msg_len(event);
msg_len += 1; // '\0'
return msg_len;
}
static int generate_annotations_msg(const container_events_format_t *event, char **anno_msg)
{
size_t i;
size_t anno_msg_len = calacute_annotations_msg_len(event) + 1;
if (anno_msg_len == 1) {
return 0;
}
*anno_msg = (char *)util_common_calloc_s(anno_msg_len);
if (*anno_msg == NULL) {
ERROR("Event: Out of memory");
return -1;
}
(void)strcat(*anno_msg, "(");
for (i = 0; i < event->annotations_len; i++) {
(void)strcat(*anno_msg, event->annotations[i]);
if (i != event->annotations_len - 1) {
(void)strcat(*anno_msg, ", ");
}
}
(void)strcat(*anno_msg, ")");
(*anno_msg)[anno_msg_len - 1] = '\0';
return 0;
}
static char *generate_event_msg(const container_events_format_t *event, const char *timebuffer, size_t len)
{
int nret = 0;
char *anno_msg = NULL;
char *msg = NULL;
if (generate_annotations_msg(event, &anno_msg) != 0) {
ERROR("Event: Failed to generate annotations msg");
return NULL;
}
msg = (char *)util_common_calloc_s(len);
if (msg == NULL) {
ERROR("Event: Out of memory");
goto err_out;
}
if (anno_msg != NULL) {
nret = snprintf(msg, len, "%s %s %s %s", timebuffer, event->opt, event->id, anno_msg);
} else {
nret = snprintf(msg, len, "%s %s %s", timebuffer, event->opt, event->id);
}
if (nret < 0 || (size_t)nret >= len) {
ERROR("Event: compose event massage failed");
goto err_out;
}
msg[len - 1] = '\0';
free(anno_msg);
return msg;
err_out:
free(anno_msg);
free(msg);
return NULL;
}
static void print_events_callback(const container_events_format_t *event)
{
char timebuffer[512] = { 0 };
char *msg = NULL;
size_t msg_len = 0;
if (event == NULL) {
return;
}
if (!get_time_buffer(&(event->timestamp), timebuffer, sizeof(timebuffer))) {
(void)strcpy(timebuffer, "-");
}
msg_len = calacute_event_msg_len(event, timebuffer);
msg = generate_event_msg(event, timebuffer, msg_len);
if (msg == NULL) {
printf("generate event message failed\n");
return;
}
printf("%s\n", msg);
free(msg);
}
/*
* Create a delete request message and call RPC
*/
static int client_event(struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_events_request request = { 0 };
struct isula_events_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_events_response));
if (response == NULL) {
ERROR("Event: Out of memory");
return -1;
}
request.cb = print_events_callback;
request.id = args->name;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.events) {
ERROR("Unimplemented event op");
ret = -1;
goto out;
}
if (args->since && !get_timestamp(args->since, &request.since)) {
COMMAND_ERROR("Failed to get since timestamp");
ret = -1;
goto out;
}
if (args->until && !get_timestamp(args->until, &request.until)) {
COMMAND_ERROR("Failed to get until timestamp");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.events(&request, response, &config);
if (ret != 0) {
COMMAND_ERROR("Failed to get container events, %s",
response->errmsg ? response->errmsg : errno_to_error_message(response->cc));
}
out:
isula_events_response_free(response);
return ret;
}
int cmd_events_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_events_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_events_args.progname = argv[0];
struct command_option options[] = {
LOG_OPTIONS(lconf),
EVENTS_OPTIONS(g_cmd_events_args),
COMMON_OPTIONS(g_cmd_events_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_events_desc,
g_cmd_events_usage);
if (command_parse_args(&cmd, &g_cmd_events_args.argc, &g_cmd_events_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Events: log init failed");
exit(ECOMMON);
}
if (g_cmd_events_args.socket == NULL) {
COMMAND_ERROR("Missing --host,-H option");
exit(EINVALIDARGS);
}
if (client_event(&g_cmd_events_args)) {
if (g_cmd_events_args.name != NULL) {
ERROR("Container \"%s\" event failed", g_cmd_events_args.name);
} else {
ERROR("Container events failed");
}
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,42 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container events definition
******************************************************************************/
#ifndef __CMD_EVENT_H
#define __CMD_EVENT_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define EVENTS_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "name", 'n', &(cmdargs).name, \
"Name of the container", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "since", 'S', &(cmdargs).since, \
"Show all events created since this timestamp", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "until", 'U', &(cmdargs).until, \
"Show all events created until this timestamp", NULL }
extern const char g_cmd_events_desc[];
extern const char g_cmd_events_usage[];
extern struct client_arguments g_cmd_events_args;
int cmd_events_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_EVENT_H */

View File

@ -1,129 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2019-04-04
* Description: provide container export functions
******************************************************************************/
#include "export.h"
#include <limits.h>
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_export_desc[] = "export container";
const char g_cmd_export_usage[] = "export [command options] [ID|NAME]";
struct client_arguments g_cmd_export_args = {};
/*
* Create a export request message and call RPC
*/
static int client_export(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_export_request request;
struct isula_export_response *response = NULL;
client_connect_config_t config = { 0 };
(void)memset(&request, 0, sizeof(request));
response = util_common_calloc_s(sizeof(struct isula_export_response));
if (response == NULL) {
ERROR("Resume: Out of memory");
return -1;
}
request.name = args->name;
request.file = args->file;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.export_rootfs) {
ERROR("Unimplemented export op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.export_rootfs(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_export_response_free(response);
return ret;
}
int cmd_export_main(int argc, const char **argv)
{
int i = 0;
char file[PATH_MAX] = { 0 };
struct log_config lconf = { 0 };
lconf.name = argv[0];
lconf.quiet = true;
lconf.driver = "stdout";
lconf.file = NULL;
lconf.priority = "ERROR";
if (log_init(&lconf)) {
COMMAND_ERROR("Export: log init failed");
exit(ECOMMON);
}
command_t cmd;
if (client_arguments_init(&g_cmd_export_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_export_args.progname = argv[0];
struct command_option options[] = { COMMON_OPTIONS(g_cmd_export_args), EXPORT_OPTIONS(g_cmd_export_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_export_desc,
g_cmd_export_usage);
if (command_parse_args(&cmd, &g_cmd_export_args.argc, &g_cmd_export_args.argv)) {
exit(EINVALIDARGS);
}
if (g_cmd_export_args.argc != 1) {
COMMAND_ERROR("Export requires exactly 1 container name");
exit(EINVALIDARGS);
}
if (g_cmd_export_args.file == NULL) {
COMMAND_ERROR("Missing output file, use -o,--output option");
exit(EINVALIDARGS);
}
/* If it's not a absolute path, add cwd to be absolute path */
if (g_cmd_export_args.file[0] != '/') {
int sret;
char cwd[PATH_MAX] = { 0 };
if (!getcwd(cwd, sizeof(cwd))) {
COMMAND_ERROR("get cwd failed:%s", strerror(errno));
exit(ECOMMON);
}
sret = snprintf(file, sizeof(file), "%s/%s", cwd, g_cmd_export_args.file);
if (sret < 0 || (size_t)sret >= sizeof(file)) {
COMMAND_ERROR("filename too long");
exit(EINVALIDARGS);
}
g_cmd_export_args.file = file;
}
g_cmd_export_args.name = g_cmd_export_args.argv[i];
if (client_export(&g_cmd_export_args)) {
ERROR("Container \"%s\" export failed", g_cmd_export_args.name);
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,37 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2019-04-04
* Description: provide container resume definition
******************************************************************************/
#ifndef __CMD_EXPORT_H
#define __CMD_EXPORT_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define EXPORT_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "output", 'o', &(cmdargs).file, "Write to a file", NULL }
extern const char g_cmd_export_desc[];
extern const char g_cmd_export_usage[];
extern struct client_arguments g_cmd_export_args;
int cmd_export_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,118 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container pause functions
******************************************************************************/
#include "pause.h"
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_pause_desc[] = "Pause all processes within one or more containers";
const char g_cmd_pause_usage[] = "pause [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_pause_args = {};
/*
* Create a pause request message and call RPC
*/
static int client_pause(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_pause_request request = { 0 };
struct isula_pause_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_pause_response));
if (response == NULL) {
ERROR("Pause: Out of memory");
return -1;
}
request.name = args->name;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.pause) {
ERROR("Unimplemented pause op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.pause(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_pause_response_free(response);
return ret;
}
int cmd_pause_main(int argc, const char **argv)
{
int i = 0;
int status = 0;
struct log_config lconf = { 0 };
lconf.name = argv[0];
lconf.quiet = true;
lconf.file = NULL;
lconf.priority = "ERROR";
lconf.driver = "stdout";
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
}
command_t cmd;
if (client_arguments_init(&g_cmd_pause_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_pause_args.progname = argv[0];
struct command_option options[] = { COMMON_OPTIONS(g_cmd_pause_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_pause_desc,
g_cmd_pause_usage);
if (command_parse_args(&cmd, &g_cmd_pause_args.argc, &g_cmd_pause_args.argv)) {
exit(EINVALIDARGS);
}
if (g_cmd_pause_args.argc == 0) {
COMMAND_ERROR("Pause requires at least 1 container names");
exit(EINVALIDARGS);
}
if (g_cmd_pause_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to pause.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_pause_args.argc; i++) {
g_cmd_pause_args.name = g_cmd_pause_args.argv[i];
if (client_pause(&g_cmd_pause_args)) {
ERROR("Container \"%s\" pause failed", g_cmd_pause_args.name);
status = -1;
continue;
}
printf("%s\n", g_cmd_pause_args.name);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container pause definition
******************************************************************************/
#ifndef __CMD_PAUSE_H
#define __CMD_PAUSE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_pause_desc[];
extern const char g_cmd_pause_usage[];
extern struct client_arguments g_cmd_pause_args;
int cmd_pause_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,118 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container resume functions
******************************************************************************/
#include "resume.h"
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_resume_desc[] = "Unpause all processes within one or more containers";
const char g_cmd_resume_usage[] = "unpause [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_resume_args = {};
/*
* Create a resume request message and call RPC
*/
static int client_resume(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
struct isula_resume_request request = { 0 };
struct isula_resume_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_resume_response));
if (response == NULL) {
ERROR("Resume: Out of memory");
return -1;
}
request.name = args->name;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.resume) {
ERROR("Unimplemented resume op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.resume(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
out:
isula_resume_response_free(response);
return ret;
}
int cmd_resume_main(int argc, const char **argv)
{
int i = 0;
int status = 0;
struct log_config lconf = { 0 };
lconf.name = argv[0];
lconf.quiet = true;
lconf.driver = "stdout";
lconf.file = NULL;
lconf.priority = "ERROR";
if (log_init(&lconf)) {
COMMAND_ERROR("Resume: log init failed");
exit(ECOMMON);
}
command_t cmd;
if (client_arguments_init(&g_cmd_resume_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_resume_args.progname = argv[0];
struct command_option options[] = { COMMON_OPTIONS(g_cmd_resume_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_resume_desc,
g_cmd_resume_usage);
if (command_parse_args(&cmd, &g_cmd_resume_args.argc, &g_cmd_resume_args.argv)) {
exit(EINVALIDARGS);
}
if (g_cmd_resume_args.argc == 0) {
COMMAND_ERROR("Pause requires at least 1 container names");
exit(EINVALIDARGS);
}
if (g_cmd_resume_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to resume.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_resume_args.argc; i++) {
g_cmd_resume_args.name = g_cmd_resume_args.argv[i];
if (client_resume(&g_cmd_resume_args)) {
ERROR("Container \"%s\" resume failed", g_cmd_resume_args.name);
status = -1;
continue;
}
printf("%s\n", g_cmd_resume_args.name);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container resume definition
******************************************************************************/
#ifndef __CMD_RESUME_H
#define __CMD_RESUME_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_resume_desc[];
extern const char g_cmd_resume_usage[];
extern struct client_arguments g_cmd_resume_args;
int cmd_resume_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,256 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container stats functions
******************************************************************************/
#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <termios.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include "error.h"
#include "arguments.h"
#include "stats.h"
#include "utils.h"
#include "log.h"
#include "isula_connect.h"
#define ESC "\033"
#define TERMCLEAR ESC "[H" ESC "[J"
#define TERMNORM ESC "[0m"
#define TERMBOLD ESC "[1m"
#define TERMRVRS ESC "[7m"
const char g_cmd_stats_desc[] = "Display a live stream of container(s) resource usage statistics";
const char g_cmd_stats_usage[] = "stats [OPTIONS] [CONTAINER...]";
struct client_arguments g_cmd_stats_args = {
.showall = false,
.nostream = false,
.runtime = "lcr",
};
static struct isula_stats_response *g_oldstats = NULL;
static void isula_size_humanize(unsigned long long val, char *buf, size_t bufsz)
{
int ret = 0;
if (val > 1024 * 1024 * 1024) {
ret = snprintf(buf, bufsz, "%u.%.2u GiB", (unsigned int)(val >> 30),
(unsigned int)(val & ((1 << 30) - 1)) / 10737419);
} else if (val > 1024 * 1024) {
unsigned long long x = val + 5243; /* for rounding */
ret = snprintf(buf, bufsz, "%u.%.2u MiB", (unsigned int)(x >> 20),
(unsigned int)(((x & ((1 << 20) - 1)) * 100) >> 20));
} else if (val > 1024) {
unsigned long long x = val + 5; /* for rounding */
ret = snprintf(buf, bufsz, "%u.%.2u KiB", (unsigned int)(x >> 10),
(unsigned int)(((x & ((1 << 10) - 1)) * 100) >> 10));
} else {
ret = snprintf(buf, bufsz, "%u.00 B", (unsigned int)val);
}
if (ret < 0 || (size_t)ret >= bufsz) {
ERROR("Humanize sprintf failed!");
}
}
static void stats_print_header(void)
{
printf(TERMRVRS TERMBOLD);
printf("%-16s %-10s %-26s %-10s %-26s %-10s", "CONTAINER", "CPU %", "MEM USAGE / LIMIT", "MEM %",
"BLOCK I / O", "PIDS");
printf("\n");
printf(TERMNORM);
}
static void stats_print(const struct isula_container_info *stats)
{
#define SHORTIDLEN 12
#define PERCENT 100
char iosb_str[63];
char iosb_read_str[20];
char iosb_write_str[20];
char mem_str[63];
char mem_used_str[20];
char mem_limit_str[20];
int len;
double cpu_percent = 0.0;
char *short_id = NULL;
isula_size_humanize(stats->blkio_read, iosb_read_str, sizeof(iosb_read_str));
isula_size_humanize(stats->blkio_write, iosb_write_str, sizeof(iosb_write_str));
isula_size_humanize(stats->mem_used, mem_used_str, sizeof(mem_used_str));
isula_size_humanize(stats->mem_limit, mem_limit_str, sizeof(mem_limit_str));
len = snprintf(iosb_str, sizeof(iosb_str), "%s / %s", iosb_read_str, iosb_write_str);
if (len < 0 || (size_t)len >= sizeof(iosb_str)) {
ERROR("Sprintf iosb_str failed");
return;
}
len = snprintf(mem_str, sizeof(mem_str), "%s / %s", mem_used_str, mem_limit_str);
if (len < 0 || (size_t)len >= sizeof(mem_str)) {
ERROR("Sprintf mem_str failed");
return;
}
if (g_oldstats != NULL) {
size_t i;
uint64_t d_sys_use = 0;
uint64_t d_cpu_use = 0;
for (i = 0; i < g_oldstats->container_num; i++) {
if (strcmp(stats->id, g_oldstats->container_stats[i].id) != 0) {
continue;
}
if (stats->cpu_system_use > g_oldstats->container_stats[i].cpu_system_use) {
d_sys_use = stats->cpu_system_use - g_oldstats->container_stats[i].cpu_system_use;
}
if (stats->cpu_use_nanos > g_oldstats->container_stats[i].cpu_use_nanos) {
d_cpu_use = stats->cpu_use_nanos - g_oldstats->container_stats[i].cpu_use_nanos;
}
if (d_sys_use > 0 && stats->online_cpus > 0) {
cpu_percent = ((double)d_cpu_use / d_sys_use) * stats->online_cpus * PERCENT;
}
}
}
short_id = util_strdup_s(stats->id);
if (strlen(short_id) > SHORTIDLEN) {
short_id[SHORTIDLEN] = '\0';
}
printf("%-16s %-10.2f %-26s %-10.2f %-26s %-10llu", short_id, cpu_percent, mem_str,
stats->mem_limit ? ((double)stats->mem_used / stats->mem_limit) * PERCENT : 0.00, iosb_str,
(unsigned long long)stats->pids_current);
free(short_id);
}
static void stats_output(const struct client_arguments *args, struct isula_stats_response **response)
{
size_t i;
printf(TERMCLEAR);
stats_print_header();
for (i = 0; i < (*response)->container_num; i++) {
stats_print(&((*response)->container_stats[i]));
printf("\n");
}
fflush(stdout);
isula_stats_response_free(g_oldstats);
g_oldstats = *response;
*response = NULL;
}
static int client_stats_mainloop(const struct client_arguments *args, const struct isula_stats_request *request)
{
int ret = 0;
isula_connect_ops *ops = NULL;
client_connect_config_t config;
if (args == NULL) {
return -1;
}
ops = get_connect_client_ops();
if (ops == NULL || ops->container.stats == NULL) {
ERROR("Unimplemented ops");
return -1;
}
config = get_connect_config(args);
while (1) {
struct isula_stats_response *response = NULL;
response = util_common_calloc_s(sizeof(struct isula_stats_response));
if (response == NULL) {
ERROR("Out of memory");
ret = -1;
goto err_out;
}
ret = ops->container.stats(request, response, &config);
if (ret) {
ERROR("Failed to stats containers info");
client_print_error(response->cc, response->server_errono, response->errmsg);
isula_stats_response_free(response);
ret = -1;
goto err_out;
}
stats_output(args, &response);
isula_stats_response_free(response);
if (args->nostream) {
goto err_out;
}
sleep(1);
}
err_out:
isula_stats_response_free(g_oldstats);
g_oldstats = NULL;
return ret;
}
/*
* Create a stats request message and call RPC
*/
static int client_stats(const struct client_arguments *args)
{
struct isula_stats_request request = { 0 };
request.all = args->showall;
request.containers = (char **)(args->argv);
request.containers_len = (size_t)(args->argc);
return client_stats_mainloop(args, &request);
}
int cmd_stats_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
STATUS_OPTIONS(g_cmd_stats_args),
COMMON_OPTIONS(g_cmd_stats_args)
};
if (client_arguments_init(&g_cmd_stats_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_stats_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_stats_desc,
g_cmd_stats_usage);
set_default_command_log_config(argv[0], &lconf);
if (command_parse_args(&cmd, &g_cmd_stats_args.argc, &g_cmd_stats_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Stats: log init failed");
exit(ECOMMON);
}
if (client_stats(&g_cmd_stats_args)) {
ERROR("Can not stats containers");
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,40 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container stats definition
******************************************************************************/
#ifndef __CMD_STATS_H
#define __CMD_STATS_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define STATUS_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
"Show all containers (default shows just running)", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
"Disable streaming stats and only pull the first result", NULL }
extern const char g_cmd_stats_desc[];
extern const char g_cmd_stats_usage[];
extern struct client_arguments g_cmd_stats_args;
int cmd_stats_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_STATS_H */

View File

@ -1,166 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container update functions
******************************************************************************/
#include <string.h>
#include <errno.h>
#include "arguments.h"
#include "update.h"
#include "utils.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_update_desc[] = "Update configuration of one or more containers";
const char g_cmd_update_usage[] = "update [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_update_args = {
.restart = NULL,
};
static int pack_update_request(const struct client_arguments *args, struct isula_update_request *request)
{
int ret = 0;
request->updateconfig->restart_policy = args->restart;
request->updateconfig->cr->blkio_weight = args->cr.blkio_weight;
request->updateconfig->cr->cpu_shares = args->cr.cpu_shares;
request->updateconfig->cr->cpu_period = args->cr.cpu_period;
request->updateconfig->cr->cpu_quota = args->cr.cpu_quota;
request->updateconfig->cr->cpuset_cpus = args->cr.cpuset_cpus;
request->updateconfig->cr->cpuset_mems = args->cr.cpuset_mems;
request->updateconfig->cr->memory = args->cr.memory_limit;
request->updateconfig->cr->memory_swap = args->cr.memory_swap;
request->updateconfig->cr->memory_reservation = args->cr.memory_reservation;
request->updateconfig->cr->kernel_memory = args->cr.kernel_memory_limit;
return ret;
}
static int client_update(const struct client_arguments *args)
{
int ret = 0;
isula_connect_ops *ops = NULL;
container_cgroup_resources_t cr = { 0 };
isula_update_config_t updateconfig = { 0 };
struct isula_update_request request = { 0 };
struct isula_update_response *response = NULL;
client_connect_config_t config = { 0 };
response = util_common_calloc_s(sizeof(struct isula_update_response));
if (response == NULL) {
ERROR("Out of memory");
return -1;
}
updateconfig.cr = &cr;
request.updateconfig = &updateconfig;
request.name = args->name;
ret = pack_update_request(args, &request);
if (ret) {
ret = -1;
goto out;
}
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.update) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.update(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
out:
isula_update_response_free(response);
return ret;
}
int cmd_update_main(int argc, const char **argv)
{
int ret = 0;
int i = 0;
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
UPDATE_OPTIONS(g_cmd_update_args),
COMMON_OPTIONS(g_cmd_update_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_update_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_update_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_update_desc,
g_cmd_update_usage);
if (command_parse_args(&cmd, &g_cmd_update_args.argc, &g_cmd_update_args.argv) ||
update_checker(&g_cmd_update_args)) {
exit(EINVALIDARGS);
}
if (argc <= 3) {
COMMAND_ERROR("You must provide one or more udpate flags when using this command\n");
exit(ECOMMON);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Update: log init failed");
exit(ECOMMON);
}
if (g_cmd_update_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to update.");
exit(ECOMMON);
}
for (i = 0; i < g_cmd_update_args.argc; i++) {
g_cmd_update_args.name = g_cmd_update_args.argv[i];
if (client_update(&g_cmd_update_args)) {
ERROR("Update container \"%s\" failed\n", g_cmd_update_args.name);
ret = ECOMMON;
continue;
}
printf("%s\n", g_cmd_update_args.name);
}
return ret;
}
int update_checker(const struct client_arguments *args)
{
int ret = 0;
if (args->argc == 0) {
COMMAND_ERROR("Update requires at least 1 container names");
return EINVALIDARGS;
}
return ret;
}

View File

@ -1,57 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container update definition
******************************************************************************/
#ifndef __CMD_UPDATE_H
#define __CMD_UPDATE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define UPDATE_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-shares", 0, &(cmdargs).cr.cpu_shares, \
"CPU shares (relative weight)", command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-period", 0, &(cmdargs).cr.cpu_period, \
"Limit CPU CFS (Completely Fair Scheduler) period", command_convert_llong }, \
{ CMD_OPT_TYPE_CALLBACK, false, "cpu-quota", 0, &(cmdargs).cr.cpu_quota, \
"Limit CPU CFS (Completely Fair Scheduler) quota", command_convert_llong }, \
{ CMD_OPT_TYPE_STRING, false, "cpuset-cpus", 0, &(cmdargs).cr.cpuset_cpus, \
"CPUs in which to allow execution (0-3, 0,1)", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "cpuset-mems", 0, &(cmdargs).cr.cpuset_mems, \
"MEMs in which to allow execution (0-3, 0,1)", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "kernel-memory", 0, &(cmdargs).cr.kernel_memory_limit, \
"Kernel memory limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory", 'm', &(cmdargs).cr.memory_limit, \
"Memory limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory-reservation", 0, &(cmdargs).cr.memory_reservation, \
"Memory soft limit", command_convert_membytes }, \
{ CMD_OPT_TYPE_CALLBACK, false, "memory-swap", 0, &(cmdargs).cr.memory_swap, \
"Swap limit equal to memory plus swap: '-1' to enable unlimited swap", command_convert_memswapbytes }, \
{ CMD_OPT_TYPE_STRING, false, "restart", 0, &(cmdargs).restart, \
"Restart policy to apply when a container exits", NULL }
extern const char g_cmd_update_desc[];
extern const char g_cmd_update_usage[];
extern struct client_arguments g_cmd_update_args;
int cmd_update_main(int argc, const char **argv);
int update_checker(const struct client_arguments *args);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_UPDATE_H */

View File

@ -1,7 +0,0 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_images_srcs)
set(ISULA_IMAGES_SRCS
${isula_images_srcs}
PARENT_SCOPE
)

View File

@ -1,337 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container image functions
******************************************************************************/
#include "images.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
#define IMAGES_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "quiet", 'q', &((cmdargs).dispname), "Only display image names", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "filter", 'f', &(cmdargs).filters, \
"Filter output based on conditions provided", command_append_array }
#define CREATED_DISPLAY_FORMAT "YYYY-MM-DD HH:MM:SS"
#define SHORT_DIGEST_LEN 12
const char g_cmd_images_desc[] = "List images";
const char g_cmd_images_usage[] = "images";
struct client_arguments g_cmd_images_args = {};
/* keep track of field widths for printing. */
struct lengths {
unsigned int registry_length;
unsigned int tag_length;
unsigned int digest_length;
unsigned int created_length;
unsigned int size_length;
};
/* trans time */
static char *trans_time(int64_t created)
{
struct tm t;
int nret = 0;
char formated_time[sizeof(CREATED_DISPLAY_FORMAT)] = { 0 };
time_t created_time = (time_t)created;
if (!localtime_r(&created_time, &t)) {
ERROR("translate time for created failed: %s", strerror(errno));
return NULL;
}
nret = snprintf(formated_time, sizeof(formated_time), "%04d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900,
t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
if (nret < 0 || nret >= sizeof(formated_time)) {
ERROR("format created time failed");
return NULL;
}
return util_strdup_s(formated_time);
}
/* list print table */
static void list_print_table(struct isula_image_info *images_list, const size_t size, const struct lengths *length)
{
const struct isula_image_info *in = NULL;
size_t i = 0;
char *created = NULL;
char *digest = NULL;
char *image_size = NULL;
if (length == NULL) {
return;
}
/* print header */
printf("%-*s ", (int)length->registry_length, "REPOSITORY");
printf("%-*s ", (int)length->tag_length, "TAG");
printf("%-*s ", (int)length->digest_length, "IMAGE ID");
printf("%-*s ", (int)length->created_length, "CREATED");
printf("%-*s ", (int)length->size_length, "SIZE");
printf("\n");
for (i = 0, in = images_list; i < size && in != NULL; i++, in++) {
if (in->imageref == NULL || strcmp(in->imageref, "-") == 0) {
printf("%-*s ", (int)length->registry_length, "<none>");
printf("%-*s ", (int)length->tag_length, "<none>");
} else {
char *copy_name = util_strdup_s(in->imageref);
char *tag_pos = util_tag_pos(copy_name);
if (tag_pos == NULL) {
printf("%-*s ", (int)length->registry_length, copy_name);
printf("%-*s ", (int)length->tag_length, "<none>");
} else {
*tag_pos = '\0';
tag_pos++;
printf("%-*s ", (int)length->registry_length, copy_name);
printf("%-*s ", (int)length->tag_length, tag_pos);
tag_pos--;
*tag_pos = ':';
}
free(copy_name);
}
digest = util_short_digest(in->digest);
printf("%-*s ", (int)length->digest_length, digest ? digest : "-");
free(digest);
created = trans_time(in->created);
printf("%-*s ", (int)length->created_length, created ? created : "-");
free(created);
image_size = util_human_size_decimal(in->size);
printf("%-*s ", (int)length->size_length, image_size ? image_size : "-");
free(image_size);
printf("\n");
}
}
static int update_image_ref_width(const struct isula_image_info *in, struct lengths *l)
{
size_t len;
char *copy_name = util_strdup_s(in->imageref);
char *tag_pos = util_tag_pos(copy_name);
if (tag_pos == NULL) {
len = strlen(copy_name);
if (len > l->registry_length) {
l->registry_length = (unsigned int)len;
}
len = strlen("<none>");
if (len > l->tag_length) {
l->tag_length = (unsigned int)len;
}
} else {
*tag_pos = '\0';
tag_pos++;
len = strlen(copy_name);
if (len > l->registry_length) {
l->registry_length = (unsigned int)len;
}
len = strlen(tag_pos);
if (len > l->tag_length) {
l->tag_length = (unsigned int)len;
}
tag_pos--;
*tag_pos = ':';
}
free(copy_name);
return 0;
}
/* list field width */
static void list_field_width(const struct isula_image_info *images_list, const size_t size, struct lengths *l)
{
const struct isula_image_info *in = NULL;
size_t i = 0;
char tmpbuffer[30];
for (i = 0, in = images_list; i < size && in != NULL; i++, in++) {
size_t len;
int slen;
if (in->imageref) {
if (update_image_ref_width(in, l) != 0) {
return;
}
}
if (in->digest) {
len = SHORT_DIGEST_LEN;
if (len > l->digest_length) {
l->digest_length = (unsigned int)len;
}
}
if (in->created) {
len = strlen(CREATED_DISPLAY_FORMAT);
if (len > l->created_length) {
l->created_length = (unsigned int)len;
}
}
slen = snprintf(tmpbuffer, sizeof(tmpbuffer), "%.2f", (float)(in->size) / (1024 * 1024));
if (slen < 0 || (size_t)slen >= sizeof(tmpbuffer)) {
ERROR("sprintf tmpbuffer failed");
return;
}
if ((unsigned int)slen > l->size_length) {
l->size_length = (unsigned int)slen;
}
}
}
/*
* list all images from isulad
*/
static void images_info_print(const struct isula_list_images_response *response)
{
struct lengths max_len = {
.registry_length = 30, /* registry */
.tag_length = 10, /* tag */
.digest_length = 20, /* digest */
.created_length = 20, /* created */
.size_length = 10, /* size */
};
list_field_width(response->images_list, (size_t)response->images_num, &max_len);
list_print_table(response->images_list, (size_t)response->images_num, &max_len);
}
/* images info print quiet */
static void images_info_print_quiet(const struct isula_list_images_response *response)
{
const struct isula_image_info *in = NULL;
size_t i = 0;
for (i = 0, in = response->images_list; in != NULL && i < response->images_num; i++, in++) {
char *digest = util_short_digest(in->digest);
printf("%-*s", SHORT_DIGEST_LEN, digest ? digest : "<none>");
printf("\n");
free(digest);
}
}
/*
* used by qsort function for comparing image created time
*/
static inline int isula_image_cmp(struct isula_image_info *first, struct isula_image_info *second)
{
if (second->created > first->created) {
return 1;
} else if (second->created < first->created) {
return -1;
} else {
return second->created_nanos > first->created_nanos;
}
}
/*
* list the images from remote
*/
static int list_images(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_list_images_request request = { 0 };
struct isula_list_images_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_list_images_response));
if (response == NULL) {
ERROR("Imagelist: Out of memory");
return -1;
}
ops = get_connect_client_ops();
if (ops == NULL || ops->image.list == NULL) {
ERROR("Unimplemented image list op");
ret = -1;
goto out;
}
if (args->filters != NULL) {
request.filters = isula_filters_parse_args((const char **)args->filters,
util_array_len((const char **)(args->filters)));
if (request.filters == NULL) {
ERROR("Failed to parse filters args");
ret = -1;
goto out;
}
}
config = get_connect_config(args);
ret = ops->image.list(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
if (response->images_list != NULL && response->images_num > 0) {
qsort(response->images_list, (size_t)(response->images_num), sizeof(struct isula_image_info),
(int (*)(const void *, const void *))isula_image_cmp);
}
if (args->dispname) {
images_info_print_quiet(response);
} else {
images_info_print(response);
}
out:
isula_filters_free(request.filters);
isula_list_images_response_free(response);
return ret;
}
/* cmd images main */
int cmd_images_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
int exit_code = ECOMMON;
command_t cmd;
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_images_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_images_args.progname = argv[0];
struct command_option options[] = {
LOG_OPTIONS(lconf),
IMAGES_OPTIONS(g_cmd_images_args),
COMMON_OPTIONS(g_cmd_images_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_images_desc,
g_cmd_images_usage);
if (command_parse_args(&cmd, &g_cmd_images_args.argc, &g_cmd_images_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Images: log init failed");
exit(exit_code);
}
if (list_images(&g_cmd_images_args)) {
ERROR("Can not list any images");
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container images definition
******************************************************************************/
#ifndef __CMD_IMAGES_LIST_H
#define __CMD_IMAGES_LIST_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_images_desc[];
extern const char g_cmd_images_usage[];
extern struct client_arguments g_cmd_images_args;
int cmd_images_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_IMAGES_LIST_H */

View File

@ -1,175 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container load functions
******************************************************************************/
#include "load.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
#ifdef ENABLE_EMBEDDED_IMAGE
const char g_cmd_load_desc[] = "load an image from a manifest or a tar archive";
const char g_cmd_load_usage[] = "load [OPTIONS] --input=FILE --type=TYPE";
#else
const char g_cmd_load_desc[] = "load an image from a tar archive";
const char g_cmd_load_usage[] = "load [OPTIONS] --input=FILE";
#endif
struct client_arguments g_cmd_load_args = { 0 };
/*
* load the image from a manifest or a tar archive
*/
static int client_load_image(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_load_request request = { 0 };
struct isula_load_response response = { 0 };
client_connect_config_t config = { 0 };
int ret = 0;
request.file = args->file;
request.type = args->type;
request.tag = args->tag;
ops = get_connect_client_ops();
if (ops == NULL || !ops->image.load) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->image.load(&request, &response, &config);
if (ret) {
client_print_error(response.cc, response.server_errono, response.errmsg);
if (response.server_errono) {
ret = ESERVERERROR;
}
goto out;
}
out:
return ret;
}
/* Waring: This function may modify image type */
static bool valid_param()
{
if (g_cmd_load_args.argc > 0) {
COMMAND_ERROR("%s: \"load\" requires 0 arguments.", g_cmd_load_args.progname);
return false;
}
if (g_cmd_load_args.file == NULL) {
COMMAND_ERROR("missing image input, use -i,--input option");
return false;
}
if (g_cmd_load_args.type != NULL) {
if ((strcmp(g_cmd_load_args.type, "docker") != 0) &&
(strcmp(g_cmd_load_args.type, "embedded") != 0)) {
COMMAND_ERROR("Invalid image type: image type must be embedded or docker, got %s",
g_cmd_load_args.type);
return false;
}
}
#ifdef ENABLE_EMBEDDED_IMAGE
/* Treat the tar as docker archive if type is empty */
if (g_cmd_load_args.type == NULL || strncmp(g_cmd_load_args.type, "docker", 7) == 0) {
/* Docker archive tar is loaded into oci type. */
/* Do not free type here because type is not a allocated memory. */
g_cmd_load_args.type = "oci";
} else {
if (g_cmd_load_args.tag != NULL) {
COMMAND_ERROR("Option --tag can be used only when type is docker");
return false;
}
}
#else
g_cmd_load_args.type = "oci";
#endif
return true;
}
int cmd_load_main(int argc, const char **argv)
{
int ret = 0;
char file[PATH_MAX] = { 0 };
struct log_config lconf = { 0 };
int exit_code = ECOMMON;
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_load_args),
LOAD_OPTIONS(g_cmd_load_args),
#ifdef ENABLE_EMBEDDED_IMAGE
EMBEDDED_OPTIONS(g_cmd_load_args),
#endif
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_load_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_load_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_load_desc,
g_cmd_load_usage);
if (command_parse_args(&cmd, &g_cmd_load_args.argc, &g_cmd_load_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Load: log init failed");
exit(exit_code);
}
if (valid_param() != true) {
exit(exit_code);
}
/* If it's not a absolute path, add cwd to be absolute path */
if (g_cmd_load_args.file[0] != '/') {
char cwd[PATH_MAX] = { 0 };
int len;
if (!getcwd(cwd, sizeof(cwd))) {
COMMAND_ERROR("get cwd failed:%s", strerror(errno));
exit(exit_code);
}
len = snprintf(file, sizeof(file), "%s/%s", cwd, g_cmd_load_args.file);
if (len < 0 || (size_t)len >= sizeof(file)) {
COMMAND_ERROR("filename too long");
exit(exit_code);
}
g_cmd_load_args.file = file;
}
ret = client_load_image(&g_cmd_load_args);
if (ret) {
exit(exit_code);
}
printf("Load image from \"%s\" success\n", g_cmd_load_args.file);
exit(EXIT_SUCCESS);
}

View File

@ -1,41 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container load definition
******************************************************************************/
#ifndef __CMD_LOAD_H
#define __CMD_LOAD_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LOAD_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "input", 'i', &(cmdargs).file, "Read from a manifest or an archive", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "tag", 0, &(cmdargs).tag, \
"Name and optionally a tag in the 'name:tag' format, valid if type is docker", NULL }
#define EMBEDDED_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "type", 't', &(cmdargs).type, "Image type, embedded or docker(default)", NULL }
extern const char g_cmd_load_desc[];
extern struct client_arguments g_cmd_load_args;
int cmd_load_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_LOAD_H */

View File

@ -1,227 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2019-6-18
* Description: provide login
********************************************************************************/
#include "login.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
const char g_cmd_login_desc[] = "Log in to a Docker registry";
const char g_cmd_login_usage[] = "login [OPTIONS] SERVER";
struct client_arguments g_cmd_login_args = {};
/*
* Login to a docker registry.
*/
int client_login(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_login_request request = { 0 };
struct isula_login_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_login_response));
if (response == NULL) {
ERROR("Out of memory");
return ECOMMON;
}
// Support type oci only currently.
request.type = "oci";
request.server = args->server;
request.username = args->username;
request.password = args->password;
ops = get_connect_client_ops();
if (ops == NULL || ops->image.login == NULL) {
ERROR("Unimplemented ops");
ret = ECOMMON;
goto out;
}
config = get_connect_config(args);
ret = ops->image.login(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = ESERVERERROR;
goto out;
}
COMMAND_ERROR("Login Succeeded");
out:
isula_login_response_free(response);
return ret;
}
static int get_password_from_notty(struct client_arguments *args)
{
if (g_cmd_login_args.username == NULL && g_cmd_login_args.password_stdin) {
COMMAND_ERROR("Must provide --username with --password-stdin");
return -1;
}
if (g_cmd_login_args.password != NULL) {
printf("WARNING! Using --password via the CLI is insecure. Use --password-stdin.\n");
if (g_cmd_login_args.password_stdin) {
printf("--password and --password-stdin are mutually exclusive\n");
return -1;
}
}
// Try get password from notty input.
if (g_cmd_login_args.password_stdin) {
char password[LOGIN_PASSWORD_LEN + 1] = { 0 };
int n = util_input_readall(password, sizeof(password));
if (n == 0) {
COMMAND_ERROR("Error: Password Required");
return -1;
}
if (n < 0) {
COMMAND_ERROR("Get password from notty stdin failed: %s", strerror(errno));
return -1;
}
args->password = util_strdup_s(password);
(void)memset(password, 0, sizeof(password));
}
return 0;
}
static int get_auth_from_terminal(struct client_arguments *args)
{
int n;
if (args->username == NULL) {
char username[LOGIN_USERNAME_LEN + 1] = {0};
printf("Username: ");
n = util_input_echo(username, sizeof(username));
if (n == 0) {
ERROR("Error: Non-null Username Required\n");
return -1;
}
if (n < 0) {
if (errno == ENOTTY) {
COMMAND_ERROR("Error: Cannot perform an interactive login from a non TTY device");
return -1;
}
COMMAND_ERROR("Get username failed: %s", strerror(errno));
return -1;
}
args->username = util_strdup_s(username);
}
if (args->password == NULL) {
char password[LOGIN_PASSWORD_LEN + 1] = {0};
printf("Password: ");
n = util_input_noecho(password, sizeof(password));
if (n == 0) {
ERROR("Error: Password Required\n");
return -1;
}
if (n < 0) {
if (errno == ENOTTY) {
COMMAND_ERROR("Error: Cannot perform an interactive login from a non TTY device");
return -1;
}
COMMAND_ERROR("Get password failed: %s", strerror(errno));
return -1;
}
args->password = util_strdup_s(password);
(void)memset(password, 0, sizeof(password));
}
return 0;
}
static int get_auth(struct client_arguments *args)
{
// Try get password from notty input.
if (get_password_from_notty(&g_cmd_login_args)) {
return -1;
}
// Try get username and password from terminal.
if (get_auth_from_terminal(&g_cmd_login_args)) {
return -1;
}
if (args->username == NULL || args->password == NULL) {
// This should not happen.
COMMAND_ERROR("Missing username or password");
return -1;
}
return 0;
}
int cmd_login_main(int argc, const char **argv)
{
int ret = 0;
struct log_config lconf = { 0 };
int exit_code = 1; /* exit 1 if failed to login */
command_t cmd;
struct command_option options[] = {
COMMON_OPTIONS(g_cmd_login_args),
LOGIN_OPTIONS(g_cmd_login_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_login_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_login_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_login_desc,
g_cmd_login_usage);
if (command_parse_args(&cmd, &g_cmd_login_args.argc, &g_cmd_login_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("login: log init failed");
exit(exit_code);
}
if (g_cmd_login_args.argc != 1) {
COMMAND_ERROR("login requires 1 argument.");
exit(exit_code);
}
g_cmd_login_args.server = g_cmd_login_args.argv[0];
ret = get_auth(&g_cmd_login_args);
if (ret != 0) {
exit(exit_code);
}
ret = client_login(&g_cmd_login_args);
if (ret != 0) {
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,40 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Description: provide login definition
******************************************************************************/
#ifndef __CMD_LOGIN_H
#define __CMD_LOGIN_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LOGIN_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "username", 'u', &(cmdargs).username, "Username", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "password", 'p', &(cmdargs).password, "Password", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "password-stdin", 0, &(cmdargs).password_stdin, \
"Take the password from stdin", NULL }, \
extern const char g_cmd_login_desc[];
extern const char g_cmd_login_usage[];
extern struct client_arguments g_cmd_login_args;
int cmd_login_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_LOGIN_H */

View File

@ -1,114 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2019-6-18
* Description: provide logout
********************************************************************************/
#include "logout.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
const char g_cmd_logout_desc[] = "Log out from a Docker registry";
const char g_cmd_logout_usage[] = "logout SERVER";
struct client_arguments g_cmd_logout_args = {};
/*
* Logout from a docker registry.
*/
int client_logout(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_logout_request request = { 0 };
struct isula_logout_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_logout_response));
if (response == NULL) {
ERROR("Out of memory");
return ECOMMON;
}
// Support type oci only currently.
request.type = "oci";
request.server = args->server;
ops = get_connect_client_ops();
if (ops == NULL || ops->image.logout == NULL) {
ERROR("Unimplemented ops");
ret = ECOMMON;
goto out;
}
config = get_connect_config(args);
ret = ops->image.logout(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = ESERVERERROR;
goto out;
}
COMMAND_ERROR("Logout Succeeded");
out:
isula_logout_response_free(response);
return ret;
}
int cmd_logout_main(int argc, const char **argv)
{
int ret = 0;
struct log_config lconf = { 0 };
int exit_code = 1; /* exit 1 if failed to logout */
command_t cmd;
struct command_option options[] = { COMMON_OPTIONS(g_cmd_logout_args) };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_logout_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_logout_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_logout_desc,
g_cmd_logout_usage);
if (command_parse_args(&cmd, &g_cmd_logout_args.argc, &g_cmd_logout_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("logout: log init failed");
exit(exit_code);
}
if (g_cmd_logout_args.argc != 1) {
COMMAND_ERROR("logout requires 1 argument.");
exit(exit_code);
}
g_cmd_logout_args.server = g_cmd_logout_args.argv[0];
ret = client_logout(&g_cmd_logout_args);
if (ret != 0) {
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,33 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Description: provide logout definition
******************************************************************************/
#ifndef __CMD_LOGOUT_H
#define __CMD_LOGOUT_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_logout_desc[];
extern const char g_cmd_logout_usage[];
extern struct client_arguments g_cmd_logout_args;
int cmd_logout_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_LOGOUT_H */

View File

@ -1,113 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2019-3-29
* Description: provide pull image
********************************************************************************/
#include "pull.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
const char g_cmd_pull_desc[] = "Pull an image or a repository from a registry";
const char g_cmd_pull_usage[] = "pull [OPTIONS] NAME[:TAG|@DIGEST]";
struct client_arguments g_cmd_pull_args = {};
/*
* Pull an image or a repository from a registry
*/
int client_pull(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_pull_request request = { 0 };
struct isula_pull_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_pull_response));
if (response == NULL) {
ERROR("Out of memory");
return ECOMMON;
}
request.image_name = args->image_name;
ops = get_connect_client_ops();
if (ops == NULL || ops->image.pull == NULL) {
ERROR("Unimplemented ops");
ret = ECOMMON;
goto out;
}
COMMAND_ERROR("Image \"%s\" pulling", request.image_name);
config = get_connect_config(args);
ret = ops->image.pull(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = ESERVERERROR;
goto out;
}
COMMAND_ERROR("Image \"%s\" pulled", response->image_ref);
out:
isula_pull_response_free(response);
return ret;
}
int cmd_pull_main(int argc, const char **argv)
{
int ret = 0;
struct log_config lconf = { 0 };
int exit_code = 1; /* exit 1 if failed to pull */
command_t cmd;
struct command_option options[] = { COMMON_OPTIONS(g_cmd_pull_args) };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_pull_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_pull_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_pull_desc,
g_cmd_pull_usage);
if (command_parse_args(&cmd, &g_cmd_pull_args.argc, &g_cmd_pull_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Pull: log init failed");
exit(exit_code);
}
if (g_cmd_pull_args.argc != 1) {
COMMAND_ERROR("pull requires 1 argument.");
exit(exit_code);
}
g_cmd_pull_args.image_name = g_cmd_pull_args.argv[0];
ret = client_pull(&g_cmd_pull_args);
if (ret != 0) {
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,37 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2019-3-29
* Description: provide pull image
********************************************************************************/
#ifndef __CMD_PULL_IMAGE_H
#define __CMD_PULL_IMAGE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_pull_desc[];
extern const char g_cmd_pull_usage[];
extern struct client_arguments g_cmd_pull_args;
int client_pull(const struct client_arguments *args);
int cmd_pull_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_PULL_IMAGE_H */

View File

@ -1,131 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container remove functions
******************************************************************************/
#include "rmi.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
const char g_cmd_rmi_desc[] = "Remove one or more images";
const char g_cmd_rmi_usage[] = "rmi [OPTIONS] IMAGE [IMAGE...]";
struct client_arguments g_cmd_rmi_args = { .force = false };
/*
* remove a image from DB
*/
static int client_rmi(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_rmi_request request = { 0 };
struct isula_rmi_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
if (strcmp(args->image_name, "none") == 0 || strcmp(args->image_name, "none:latest") == 0) {
COMMAND_ERROR("Can not remove image '%s', image name 'none' or 'none:latest' is reserved", args->image_name);
return -1;
}
response = util_common_calloc_s(sizeof(struct isula_rmi_response));
if (response == NULL) {
ERROR("Out of memory");
return -1;
}
request.image_name = args->image_name;
request.force = args->force;
ops = get_connect_client_ops();
if (ops == NULL || !ops->image.remove) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->image.remove(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
if (response->server_errono) {
ret = ESERVERERROR;
}
goto out;
}
out:
isula_rmi_response_free(response);
return ret;
}
int cmd_rmi_main(int argc, const char **argv)
{
int i = 0;
int err = 0;
struct log_config lconf = { 0 };
int exit_code = 1; /* exit 1 if remove failed because docker return 1 */
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_rmi_args),
RMI_OPTIONS(g_cmd_rmi_args)
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_rmi_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_rmi_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_rmi_desc,
g_cmd_rmi_usage);
if (command_parse_args(&cmd, &g_cmd_rmi_args.argc, &g_cmd_rmi_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("RMI: log init failed");
exit(exit_code);
}
if (g_cmd_rmi_args.argc == 0) {
COMMAND_ERROR("\"rmi\" requires at least 1 image names");
exit(exit_code);
}
if (g_cmd_rmi_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many images to remove.");
exit(exit_code);
}
for (i = 0; i < g_cmd_rmi_args.argc; i++) {
g_cmd_rmi_args.image_name = g_cmd_rmi_args.argv[i];
int ret = client_rmi(&g_cmd_rmi_args);
if (ret != 0) {
ERROR("Image \"%s\" remove failed", g_cmd_rmi_args.image_name);
err = ret;
continue;
}
printf("Image \"%s\" removed\n", g_cmd_rmi_args.image_name);
}
if (err) {
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,37 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container remove definition
******************************************************************************/
#ifndef __CMD_REMOVE_IMAGE_H
#define __CMD_REMOVE_IMAGE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define RMI_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "force", 'f', &(cmdargs).force, "Force removal of the image", NULL }
extern const char g_cmd_rmi_desc[];
extern const char g_cmd_rmi_usage[];
extern struct client_arguments g_cmd_rmi_args;
int cmd_rmi_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_REMOVE_IMAGE_H */

View File

@ -1,123 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2020-04-15
* Description: provide image tag functions
******************************************************************************/
#include "tag.h"
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include "utils.h"
#include "arguments.h"
#include "isula_connect.h"
#include "log.h"
const char g_cmd_tag_desc[] = "Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE";
const char g_cmd_tag_usage[] = "tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]";
struct client_arguments g_cmd_tag_args = {};
/*
* Add a tag to the image
*/
static int client_tag(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_tag_request request = { 0 };
struct isula_tag_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_tag_response));
if (response == NULL) {
ERROR("Out of memory");
return -1;
}
request.src_name = args->image_name;
request.dest_name = args->tag;
ops = get_connect_client_ops();
if (ops == NULL || !ops->image.tag) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->image.tag(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
if (response->server_errono) {
ret = ESERVERERROR;
}
goto out;
}
out:
isula_tag_response_free(response);
return ret;
}
int cmd_tag_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
int exit_code = 1;
command_t cmd;
struct command_option options[] = {
LOG_OPTIONS(lconf),
COMMON_OPTIONS(g_cmd_tag_args),
};
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_tag_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_tag_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_tag_desc,
g_cmd_tag_usage);
if (command_parse_args(&cmd, &g_cmd_tag_args.argc, &g_cmd_tag_args.argv)) {
exit(exit_code);
}
if (log_init(&lconf)) {
COMMAND_ERROR("RMI: log init failed");
exit(exit_code);
}
if (g_cmd_tag_args.argc != 2) {
COMMAND_ERROR("\"tag\" requires exactly 2 arguments.");
exit(exit_code);
}
g_cmd_tag_args.image_name = g_cmd_tag_args.argv[0];
g_cmd_tag_args.tag = g_cmd_tag_args.argv[1];
if (!util_valid_image_name(g_cmd_tag_args.image_name)) {
COMMAND_ERROR("%s is not a valid image name", g_cmd_tag_args.image_name);
exit(exit_code);
}
if (!util_valid_tag(g_cmd_tag_args.tag)) {
COMMAND_ERROR("%s is not a valid tag", g_cmd_tag_args.tag);
exit(exit_code);
}
int ret = client_tag(&g_cmd_tag_args);
if (ret != 0) {
COMMAND_ERROR("Tag image \"%s\" to \"%s\" failed", g_cmd_tag_args.image_name, g_cmd_tag_args.tag);
exit(exit_code);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: wangfengtu
* Create: 2020-04-15
* Description: provide image tag definition
******************************************************************************/
#ifndef __CMD_TAG_IMAGE_H
#define __CMD_TAG_IMAGE_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_tag_desc[];
extern const char g_cmd_tag_usage[];
extern struct client_arguments g_cmd_tag_args;
int cmd_tag_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_TAG_IMAGE_H */

View File

@ -1,7 +0,0 @@
# get current directory sources files
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} isula_information_srcs)
set(ISULA_INFORMATION_SRCS
${isula_information_srcs}
PARENT_SCOPE
)

View File

@ -1,103 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container health functions
******************************************************************************/
#include "health.h"
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_health_check_desc[] = "iSulad health check";
const char g_cmd_health_check_usage[] = "health [command options]";
struct client_arguments g_cmd_health_check_args = {
.service = NULL,
};
/*
* Create a health check request message and call RPC
*/
static int client_health_check(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_health_check_request request = { 0 };
struct isula_health_check_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_health_check_response));
if (response == NULL) {
ERROR("Health: Out of memory");
return -1;
}
request.service = args->service;
ops = get_connect_client_ops();
if (ops == NULL || !ops->health.check) {
ERROR("Unimplemented health op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->health.check(&request, response, &config);
if (ret || response->health_status != HEALTH_SERVING_STATUS_SERVING) {
ret = -1;
}
out:
isula_health_check_response_free(response);
return ret;
}
int cmd_health_check_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
lconf.name = argv[0];
lconf.priority = "ERROR";
lconf.file = NULL;
lconf.quiet = true;
lconf.driver = "stdout";
if (log_init(&lconf)) {
COMMAND_ERROR("Health: log init failed");
exit(ECOMMON);
}
command_t cmd;
if (client_arguments_init(&g_cmd_health_check_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_health_check_args.progname = argv[0];
struct command_option options[] = {
HEALTH_OPTIONS(g_cmd_health_check_args),
COMMON_OPTIONS(g_cmd_health_check_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv,
g_cmd_health_check_desc, g_cmd_health_check_usage);
if (command_parse_args(&cmd, &g_cmd_health_check_args.argc, &g_cmd_health_check_args.argv)) {
exit(EINVALIDARGS);
}
if (client_health_check(&g_cmd_health_check_args)) {
printf("iSulad with socket name '%s' is NOT SERVING\n", g_cmd_health_check_args.socket);
exit(ECOMMON);
}
printf("iSulad with socket name '%s' is SERVING\n", g_cmd_health_check_args.socket);
exit(EXIT_SUCCESS);
}

View File

@ -1,37 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container health definition
******************************************************************************/
#ifndef __CMD_HEALTHCHECK_H
#define __CMD_HEALTHCHECK_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define HEALTH_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "service", 'S', &(cmdargs).service, "GRPC service name", NULL }
extern const char g_cmd_health_check_desc[];
extern const char g_cmd_health_check_usage[];
extern struct client_arguments g_cmd_health_check_args;
int cmd_health_check_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,180 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide container info functions
******************************************************************************/
#include "info.h"
#include <stdio.h>
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "config.h"
#include "isula_connect.h"
const char g_cmd_info_desc[] = "Display system-wide information";
const char g_cmd_info_usage[] = "info";
struct client_arguments g_cmd_info_args = {};
static void print_with_space(const char *info)
{
size_t i = 0;
size_t size = 0;
bool print_space = true;
if (info == NULL) {
return;
}
size = strlen(info);
for (i = 0; i < size; i++) {
if (print_space) {
printf(" ");
print_space = false;
}
if (info[i] == '\n') {
print_space = true;
}
printf("%c", info[i]);
}
return;
}
static void client_info_server(const struct isula_info_response *response)
{
printf("Containers: %u\n", (unsigned int)(response->containers_num));
printf(" Running: %u\n", (unsigned int)(response->c_running));
printf(" Paused: %u\n", (unsigned int)(response->c_paused));
printf(" Stopped: %u\n", (unsigned int)(response->c_stopped));
printf("Images: %u\n", (unsigned int)(response->images_num));
if (response->version != NULL) {
printf("Server Version: %s\n", response->version);
}
if (response->driver_name != NULL) {
printf("Storage Driver: %s\n", response->driver_name);
}
if (response->driver_status != NULL) {
print_with_space(response->driver_status);
}
if (response->logging_driver != NULL) {
printf("Logging Driver: %s\n", response->logging_driver);
}
if (response->cgroup_driver != NULL) {
printf("Cgroup Driverr: %s\n", response->cgroup_driver);
}
if (response->huge_page_size != NULL) {
printf("Hugetlb Pagesize: %s\n", response->huge_page_size);
}
if (response->kversion != NULL) {
printf("Kernel Version: %s\n", response->kversion);
}
if (response->operating_system != NULL) {
printf("Operating System: %s\n", response->operating_system);
}
if (response->os_type != NULL) {
printf("OSType: %s\n", response->os_type);
}
if (response->architecture != NULL) {
printf("Architecture: %s\n", response->architecture);
}
printf("CPUs: %u\n", (unsigned int)(response->cpus));
printf("Total Memory: %u GB\n", (unsigned int)(response->total_mem));
if (response->nodename != NULL) {
printf("Name: %s\n", response->nodename);
}
if (response->isulad_root_dir != NULL) {
printf("iSulad Root Dir: %s\n", response->isulad_root_dir);
}
if (response->http_proxy != NULL) {
printf("Http Proxy: %s\n", response->http_proxy);
}
if (response->https_proxy != NULL) {
printf("Https Proxy: %s\n", response->https_proxy);
}
if (response->no_proxy != NULL) {
printf("No Proxy: %s\n", response->no_proxy);
}
}
static int client_info(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_info_request request = { 0 };
struct isula_info_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_info_response));
if (response == NULL) {
ERROR("Info: Out of memory");
return -1;
}
ops = get_connect_client_ops();
if (ops == NULL || (ops->container.info) == NULL) {
ERROR("Unimplemented info op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.info(&request, response, &config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
client_info_server(response);
out:
isula_info_response_free(response);
return ret;
}
int cmd_info_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_info_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_info_args.progname = argv[0];
struct command_option options[] = { LOG_OPTIONS(lconf), COMMON_OPTIONS(g_cmd_info_args) };
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_info_desc,
g_cmd_info_usage);
if (command_parse_args(&cmd, &g_cmd_info_args.argc, &g_cmd_info_args.argv) != 0) {
exit(EINVALIDARGS);
}
if (log_init(&lconf) != 0) {
COMMAND_ERROR("Info: log init failed");
exit(ECOMMON);
}
if (g_cmd_info_args.argc > 0) {
COMMAND_ERROR("%s: \"info\" requires 0 arguments.", g_cmd_info_args.progname);
exit(ECOMMON);
}
if (client_info(&g_cmd_info_args) != 0) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: maoweiyong
* Create: 2018-11-08
* Description: provide container info definition
******************************************************************************/
#ifndef __CMD_INFO_H
#define __CMD_INFO_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_info_desc[];
extern const char g_cmd_info_usage[];
extern struct client_arguments g_cmd_info_args;
int cmd_info_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_INFO_H */

View File

@ -1,821 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container inspect functions
******************************************************************************/
#include "error.h"
#include "inspect.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
#include "console.h"
#include "utils.h"
#include "json_common.h"
#include <regex.h>
const char g_cmd_inspect_desc[] = "Return low-level information on a container or image";
const char g_cmd_inspect_usage[] = "inspect [options] CONTAINER|IMAGE [CONTAINER|IMAGE...]";
struct client_arguments g_cmd_inspect_args = {
.format = NULL,
.time = 120, // timeout time
};
#define PRINTF_TAB_LEN 4
#define TOP_LEVEL_OBJ 0x10
#define IS_TOP_LEVEL_OBJ(value) ((value)&TOP_LEVEL_OBJ)
#define LAST_ELEMENT_BIT 0x0F
#define NOT_LAST_ELEMENT 0x00
#define LAST_ELEMENT 0x01
#define IS_LAST_ELEMENT(value) (LAST_ELEMENT == ((value)&LAST_ELEMENT_BIT))
#define YAJL_TYPEOF(json) ((json)->type)
#define CONTAINER_INSPECT_ERR (-1)
#define CONTAINER_NOT_FOUND (-2)
typedef struct {
yajl_val tree_root; /* Should be free by yajl_tree_free() */
yajl_val tree_print; /* Point to the object be printf */
} container_tree_t;
static yajl_val inspect_get_json_info(yajl_val element, char *key_string);
static void print_json_aux(yajl_val element, int indent, int flags, bool json_format);
/*
* Parse text into a JSON tree. If text is valid JSON, returns a
* yajl_val structure, otherwise prints and error and returns null.
* Note: return tree need free by function yajl_tree_free (tree).
*/
#define ERR_BUF 1024
static yajl_val inspect_load_json(const char *json_data)
{
yajl_val tree = NULL;
char errbuf[ERR_BUF];
tree = yajl_tree_parse(json_data, errbuf, sizeof(errbuf));
if (tree == NULL) {
ERROR("Parse json data failed %s\n", errbuf);
return NULL;
}
return tree;
}
static yajl_val json_get_val(yajl_val tree, const char *name, yajl_type type)
{
const char *path[] = { name, NULL };
return yajl_tree_get(tree, path, type);
}
static yajl_val json_object(yajl_val element, char *key)
{
yajl_val node = NULL;
char *top_key = key;
char *next_context = NULL;
top_key = strtok_r(top_key, ".", &next_context);
if (top_key == NULL) {
return NULL;
}
node = json_get_val(element, top_key, yajl_t_any);
if (node) {
node = inspect_get_json_info(node, next_context);
}
return node;
}
static yajl_val json_array(yajl_val element, char *key)
{
if (element == NULL || key == NULL) {
return NULL;
}
size_t i = 0;
size_t size = 0;
yajl_val node = NULL;
yajl_val value = NULL;
char *top_key = key;
char *next_context = NULL;
if (YAJL_GET_ARRAY(element) != NULL) {
size = YAJL_GET_ARRAY(element)->len;
}
top_key = strtok_r(top_key, ".", &next_context);
if (top_key == NULL) {
return NULL;
}
for (i = 0; i < size; i++) {
value = element->u.array.values[i];
node = json_get_val(value, top_key, yajl_t_any);
if (node) {
node = inspect_get_json_info(node, next_context);
if (node) {
break;
}
}
}
return node;
}
static yajl_val inspect_get_json_info(yajl_val element, char *key_string)
{
yajl_val node = NULL;
if (element == NULL) {
return NULL;
}
/* If "key_string" equal to NULL, return the input element. */
if ((key_string == NULL) || (strlen(key_string) == 0)) {
return element;
}
switch (YAJL_TYPEOF(element)) {
case yajl_t_object:
node = json_object(element, key_string);
break;
case yajl_t_array:
node = json_array(element, key_string);
break;
case yajl_t_any:
case yajl_t_null:
case yajl_t_false:
case yajl_t_true:
case yajl_t_number:
case yajl_t_string:
default:
ERROR("unrecognized JSON type %d\n", YAJL_TYPEOF(element));
break;
}
return node;
}
static bool inspect_filter_done(yajl_val root, const char *filter, container_tree_t *tree_array)
{
yajl_val object = root;
char *key_string = NULL;
if (filter != NULL) {
key_string = util_strdup_s(filter);
object = inspect_get_json_info(root, key_string);
if (object == NULL) {
COMMAND_ERROR("Executing \"\" at <.%s>: map has no entry for key \"%s\"", filter, key_string);
free(key_string);
return false;
}
free(key_string);
}
tree_array->tree_print = object;
return true;
}
/*
* RETURN VALUE:
* 0: inspect container success
* CONTAINER_INSPECT_ERR: have the container, but failed to inspect due to other reasons
* CONTAINER_NOT_FOUND: no such container
*/
static int client_inspect_container(const struct isula_inspect_request *request,
struct isula_inspect_response *response,
client_connect_config_t *config, const isula_connect_ops *ops)
{
int ret = 0;
ret = ops->container.inspect(request, response, config);
if (ret != 0) {
if ((strstr(response->errmsg, "Inspect invalid name") != NULL) ||
(strstr(response->errmsg, "No such image or container or accelerator") != NULL)) {
return CONTAINER_NOT_FOUND;
}
/* have the container, but failed to inspect due to other reasons */
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = CONTAINER_INSPECT_ERR;
}
return ret;
}
static int client_inspect_image(const struct isula_inspect_request *request, struct isula_inspect_response *response,
client_connect_config_t *config, const isula_connect_ops *ops)
{
int ret = 0;
ret = ops->image.inspect(request, response, config);
if (ret != 0) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
return ret;
}
/*
* Create a inspect request message and call RPC
*/
static int client_inspect(const struct client_arguments *args, const char *filter, container_tree_t *tree_array)
{
isula_connect_ops *ops = NULL;
struct isula_inspect_request request = { 0 };
struct isula_inspect_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
yajl_val tree = NULL;
response = util_common_calloc_s(sizeof(struct isula_inspect_response));
if (response == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
request.name = args->name;
request.bformat = args->format ? true : false;
request.timeout = args->time;
ops = get_connect_client_ops();
if (ops == NULL || ops->container.inspect == NULL || ops->image.inspect == NULL) {
ERROR("Unimplemented ops");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = client_inspect_container(&request, response, &config, ops);
if (ret == CONTAINER_NOT_FOUND) {
isula_inspect_response_free(response);
response = NULL;
response = util_common_calloc_s(sizeof(struct isula_inspect_response));
if (response == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
ret = client_inspect_image(&request, response, &config, ops);
}
if (ret != 0) {
goto out;
}
if (response == NULL || response->json == NULL) {
ERROR("Container or image json is empty");
ret = -1;
goto out;
}
tree = inspect_load_json(response->json);
if (tree == NULL) {
ret = -1;
goto out;
}
if (!inspect_filter_done(tree, filter, tree_array)) {
ret = -1;
yajl_tree_free(tree);
goto out;
}
tree_array->tree_root = tree;
out:
isula_inspect_response_free(response);
return ret;
}
static void print_json_string(yajl_val element, int flags, bool json_format)
{
const char *str = YAJL_GET_STRING(element);
const char *hexchars = "0123456789ABCDEF";
char hex[7] = { '\\', 'u', '0', '0', '\0', '\0', '\0' };
if (json_format) {
putchar('"');
}
if (str == NULL) {
goto out;
}
for (; *str != '\0'; str++) {
const char *escapestr = NULL;
switch (*str) {
case '\r':
escapestr = "\\r";
break;
case '\n':
escapestr = "\\n";
break;
case '\\':
escapestr = "\\\\";
break;
case '"':
escapestr = "\\\"";
break;
case '\f':
escapestr = "\\f";
break;
case '\b':
escapestr = "\\b";
break;
case '\t':
escapestr = "\\t";
break;
default:
if ((unsigned char)(*str) < 0x20) {
hex[4] = hexchars[(unsigned char)(*str) >> 4];
hex[5] = hexchars[(unsigned char)(*str) & 0x0F];
escapestr = hex;
}
break;
}
if (escapestr != NULL) {
printf("%s", escapestr);
} else {
putchar(*str);
}
}
out:
if (json_format) {
putchar('"');
}
if (!IS_LAST_ELEMENT((unsigned int)flags)) {
putchar(',');
}
}
static void print_json_number(yajl_val element, int flags)
{
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("%s", YAJL_GET_NUMBER(element));
} else {
printf("%s,", YAJL_GET_NUMBER(element));
}
}
static void print_json_true(int flags)
{
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("true");
} else {
printf("true,");
}
}
static void print_json_false(int flags)
{
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("false");
} else {
printf("false,");
}
}
static void print_json_null(int flags)
{
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("null");
} else {
printf("null,");
}
}
static void print_json_indent(int indent, bool new_line)
{
int i = 0;
if (new_line) {
printf("\n");
}
for (i = 0; i < indent; i++) {
putchar(' ');
}
}
static void print_json_object(yajl_val element, int indent, int flags, bool json_format)
{
size_t size = 0;
const char *objkey = NULL;
yajl_val value = NULL;
size_t i = 0;
if (element == NULL) {
return;
}
if (YAJL_GET_OBJECT(element) != NULL) {
size = YAJL_GET_OBJECT(element)->len;
}
if (IS_TOP_LEVEL_OBJ((unsigned int)flags)) {
print_json_indent(indent, false);
}
if (size == 0) {
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("{}");
} else {
printf("{},");
}
return;
}
printf("{");
for (i = 0; i < size; i++) {
print_json_indent(indent + PRINTF_TAB_LEN, true);
objkey = element->u.object.keys[i];
value = element->u.object.values[i];
printf("\"%s\": ", objkey);
if ((i + 1) == size) {
print_json_aux(value, indent + PRINTF_TAB_LEN, LAST_ELEMENT, json_format);
} else {
print_json_aux(value, indent + PRINTF_TAB_LEN, NOT_LAST_ELEMENT, json_format);
}
}
print_json_indent(indent, true);
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("}");
} else {
printf("},");
}
}
static void print_json_array(yajl_val element, int indent, int flags, bool json_format)
{
size_t i = 0;
size_t size = 0;
yajl_val value = NULL;
if (element == NULL) {
return;
}
if (YAJL_GET_ARRAY(element) != NULL) {
size = YAJL_GET_ARRAY(element)->len;
}
if (IS_TOP_LEVEL_OBJ((unsigned int)flags)) {
print_json_indent(indent, false);
}
if (size == 0) {
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("[]");
} else {
printf("[],");
}
return;
}
printf("[");
for (i = 0; i < size; i++) {
print_json_indent(indent + PRINTF_TAB_LEN, true);
value = element->u.array.values[i];
if ((i + 1) == size) {
print_json_aux(value, indent + PRINTF_TAB_LEN, LAST_ELEMENT, json_format);
} else {
print_json_aux(value, indent + PRINTF_TAB_LEN, NOT_LAST_ELEMENT, json_format);
}
}
print_json_indent(indent, true);
if (IS_LAST_ELEMENT((unsigned int)flags)) {
printf("]");
} else {
printf("],");
}
}
static void print_json_aux(yajl_val element, int indent, int flags, bool json_format)
{
if (element == NULL) {
return;
}
switch (YAJL_TYPEOF(element)) {
case yajl_t_object:
print_json_object(element, indent, flags, json_format);
break;
case yajl_t_array:
print_json_array(element, indent, flags, json_format);
break;
case yajl_t_string:
print_json_string(element, flags, json_format);
break;
case yajl_t_number:
print_json_number(element, flags);
break;
case yajl_t_true:
print_json_true(flags);
break;
case yajl_t_false:
print_json_false(flags);
break;
case yajl_t_null:
print_json_null(flags);
break;
case yajl_t_any:
default:
ERROR("unrecognized JSON type %d\n", YAJL_TYPEOF(element));
break;
}
}
/*
* Print yajl tree as JSON format.
*/
static void print_json(yajl_val tree, int indent, bool json_format)
{
if (tree == NULL) {
return;
}
print_json_aux(tree, indent, LAST_ELEMENT | TOP_LEVEL_OBJ, json_format);
}
static void inspect_show_result(int show_nums, const container_tree_t *tree_array, const char *format, bool json_format)
{
int i = 0;
yajl_val tree = NULL;
int indent = 0;
if (show_nums == 0) {
if (format == NULL) {
printf("[]\n");
}
return;
}
if (format == NULL) {
printf("[\n");
indent = PRINTF_TAB_LEN;
}
for (i = 0; i < show_nums; i++) {
tree = tree_array[i].tree_print;
print_json(tree, indent, json_format);
if ((i + 1) != show_nums) {
if (format == NULL) {
printf(",\n");
} else {
printf("\n");
}
}
}
if (format == NULL) {
printf("\n]\n");
} else {
printf("\n");
}
}
static void inspect_free_trees(int tree_nums, container_tree_t *tree_array)
{
int i = 0;
for (i = 0; i < tree_nums; i++) {
if (tree_array[i].tree_root) {
yajl_tree_free(tree_array[i].tree_root);
tree_array[i].tree_root = NULL;
tree_array[i].tree_print = NULL;
}
}
}
/* arg string format: "{{json .State.Running}}"
* ret_string should be free outside by free().
*/
static char *inspect_pause_filter(const char *arg)
{
char *input_str = NULL;
char *p = NULL;
char *ret_string = NULL;
char *next_context = NULL;
input_str = util_strdup_s(arg);
p = strtok_r(input_str, ".", &next_context);
if (p == NULL) {
goto out;
}
p = next_context;
if (p == NULL) {
goto out;
}
p = strtok_r(p, " }", &next_context);
if (p == NULL) {
goto out;
}
ret_string = util_strdup_s(p);
out:
if (input_str != NULL) {
free(input_str);
}
return ret_string;
}
#define MATCH_NUM 1
#define CHECK_FAILED (-1)
#define JSON_ARGS "^\\s*\\{\\s*\\{\\s*(json)?\\s+[^\\s]+\\s*.*\\}\\s*\\}\\s*$"
static int inspect_check(const char *json_str, const char *regex)
{
int status = 0;
regmatch_t pmatch[MATCH_NUM] = { { 0 } };
regex_t reg;
if (json_str == NULL) {
ERROR("Filter string is NULL.");
return CHECK_FAILED;
}
regcomp(&reg, regex, REG_EXTENDED);
status = regexec(&reg, json_str, MATCH_NUM, pmatch, 0);
regfree(&reg);
if (status != 0) {
/* Log by caller */
return CHECK_FAILED;
}
return 0;
}
static int inspect_check_format_f(const char *json_str, bool *json_format)
{
int ret = 0;
if (json_str == NULL) {
ERROR("Filter string is NULL.");
return CHECK_FAILED;
}
/* check "{{json .xxx.xxx}}" */
ret = inspect_check(json_str, "^\\s*\\{\\s*\\{\\s*(json\\s+)?(\\.\\w+)+\\s*\\}\\s*\\}\\s*$");
if (ret == 0) {
if (inspect_check(json_str, "^\\s*\\{\\s*\\{\\s*json\\s+(\\.\\w+)+\\s*\\}\\s*\\}\\s*$") != 0) {
*json_format = false;
}
return 0;
}
/* check "{{ ... }}" */
ret = inspect_check(json_str, "^\\s*\\{\\s*\\{\\s*[^{}]*\\s*\\}\\s*\\}\\s*$");
if (ret != 0) {
COMMAND_ERROR("Unexpected \"{\" or \"}\" in operand, should be \"{{ ... }}\".");
goto out;
}
/* json args. */
ret = inspect_check(json_str, "^\\s*\\{\\s*\\{\\s*(json)?\\s*\\}\\s*\\}\\s*$");
if (ret == 0) {
COMMAND_ERROR("Executing \"\" at <json>: wrong number of args for json: want 1 got 0.");
goto out;
}
/* check "{{json... }}" */
ret = inspect_check(json_str, "^\\s*\\{\\s*\\{\\s*(json)?\\W.*\\s*\\}\\s*\\}\\s*$");
if (ret != 0) {
COMMAND_ERROR("Output mode error, E.g \"{{json ... }}\" or \"{{ ... }}\" is right.");
goto out;
}
/* json args. */
ret = inspect_check(json_str, JSON_ARGS);
if (ret != 0) {
COMMAND_ERROR("Executing \"\" at <json>: wrong number of args for json: want 1 got 0.");
goto out;
}
/* "{{json .xxx.xxx }}" check failed log */
COMMAND_ERROR("Unexpected <.> in operand. E.g \"{{json .xxx.xxx }}\" is right.");
out:
return CHECK_FAILED;
}
int cmd_inspect_main(int argc, const char **argv)
{
int i = 0;
int status = 0;
struct log_config lconf = { 0 };
int success_counts = 0;
char *filter_string = NULL;
container_tree_t *tree_array = NULL;
size_t array_size = 0;
command_t cmd;
bool json_format = true;
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_inspect_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_inspect_args.progname = argv[0];
struct command_option options[] = {
LOG_OPTIONS(lconf),
INSPECT_OPTIONS(g_cmd_inspect_args),
COMMON_OPTIONS(g_cmd_inspect_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_inspect_desc,
g_cmd_inspect_usage);
if (command_parse_args(&cmd, &g_cmd_inspect_args.argc, &g_cmd_inspect_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed");
exit(ECOMMON);
}
if (g_cmd_inspect_args.argc == 0) {
COMMAND_ERROR("\"inspect\" requires a minimum of 1 argument.");
exit(EINVALIDARGS);
}
if (g_cmd_inspect_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many arguments.");
exit(EINVALIDARGS);
}
if ((size_t)g_cmd_inspect_args.argc > SIZE_MAX / sizeof(container_tree_t) - 1) {
COMMAND_ERROR("The number of parameters of inspect is too large");
exit(ECOMMON);
}
array_size = sizeof(container_tree_t) * (size_t)(g_cmd_inspect_args.argc + 1);
tree_array = (container_tree_t *)util_common_calloc_s(array_size);
if (tree_array == NULL) {
ERROR("Malloc failed\n");
exit(ECOMMON);
}
if (g_cmd_inspect_args.format != NULL) {
int ret;
ret = inspect_check_format_f(g_cmd_inspect_args.format, &json_format);
if (ret != 0) {
free(tree_array);
tree_array = NULL;
exit(ECOMMON);
}
filter_string = inspect_pause_filter(g_cmd_inspect_args.format);
if (filter_string == NULL) {
COMMAND_ERROR("Inspect format parameter invalid: %s", g_cmd_inspect_args.format);
free(tree_array);
tree_array = NULL;
exit(EINVALIDARGS);
}
}
for (i = 0; i < g_cmd_inspect_args.argc; i++) {
g_cmd_inspect_args.name = g_cmd_inspect_args.argv[i];
if (client_inspect(&g_cmd_inspect_args, filter_string, &tree_array[i])) {
status = -1;
break;
}
success_counts++;
}
if (tree_array != NULL) {
inspect_show_result(success_counts, tree_array, g_cmd_inspect_args.format, json_format);
inspect_free_trees(success_counts, tree_array);
}
free(tree_array);
free(filter_string);
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,40 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container inspect definition
******************************************************************************/
#ifndef __CMD_INSPECT_H
#define __CMD_INSPECT_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define INSPECT_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_STRING, false, "format", 'f', &(cmdargs).format, \
"Format the output using the given go template", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "time", 't', &(cmdargs).time, \
"Seconds to wait for inspect timeout (default 120)", command_convert_int }
extern const char g_cmd_inspect_desc[];
extern const char g_cmd_inspect_usage[];
extern struct client_arguments g_cmd_inspect_args;
int cmd_inspect_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_INSPECT_H */

View File

@ -1,152 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container logs functions
******************************************************************************/
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <limits.h>
#include <errno.h>
#include "error.h"
#include "logs.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_logs_desc[] = "Fetch the logs of a container";
const char g_cmd_logs_usage[] = "logs [OPTIONS] CONTAINER";
struct client_arguments g_cmd_logs_args = {
.follow = false,
.tail = -1,
};
static int do_logs(const struct client_arguments *args)
{
#define DISABLE_ERR_MESSAGE "disable console log"
isula_connect_ops *ops = NULL;
struct isula_logs_request *request = NULL;
struct isula_logs_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_logs_response));
if (response == NULL) {
ERROR("Log: Out of memory");
return -1;
}
request = util_common_calloc_s(sizeof(struct isula_logs_request));
if (request == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
ops = get_connect_client_ops();
if (ops == NULL || ops->container.logs == NULL) {
ERROR("Unimplemented logs op");
ret = -1;
goto out;
}
request->id = util_strdup_s(args->name);
request->runtime = util_strdup_s(args->runtime);
request->follow = args->follow;
request->tail = (int64_t)args->tail;
config = get_connect_config(args);
ret = ops->container.logs(request, response, &config);
if (ret != 0) {
if (strncmp(response->errmsg, DISABLE_ERR_MESSAGE, strlen(DISABLE_ERR_MESSAGE)) == 0) {
fprintf(stdout, "[WARNING]: Container %s disable console log!\n", args->name);
ret = 0;
goto out;
}
client_print_error(response->cc, response->server_errono, response->errmsg);
ret = -1;
goto out;
}
out:
isula_logs_response_free(response);
isula_logs_request_free(request);
return ret;
}
int callback_tail(command_option_t *option, const char *arg)
{
if (util_safe_llong(arg, option->data)) {
*(long long *)option->data = -1;
}
return 0;
}
static int cmd_logs_init(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_logs_args)) {
COMMAND_ERROR("client arguments init failed\n");
return ECOMMON;
}
g_cmd_logs_args.progname = argv[0];
struct command_option options[] = {
LOG_OPTIONS(lconf),
LOGS_OPTIONS(g_cmd_logs_args),
COMMON_OPTIONS(g_cmd_logs_args)
};
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_logs_desc,
g_cmd_logs_usage);
if (command_parse_args(&cmd, &g_cmd_logs_args.argc, &g_cmd_logs_args.argv)) {
return EINVALIDARGS;
}
if (log_init(&lconf)) {
COMMAND_ERROR("log init failed\n");
g_cmd_logs_args.name = g_cmd_logs_args.argv[0];
return ECOMMON;
}
if (g_cmd_logs_args.argc != 1) {
COMMAND_ERROR("Logs needs one container name");
return ECOMMON;
}
return 0;
}
int cmd_logs_main(int argc, const char **argv)
{
int ret = 0;
ret = cmd_logs_init(argc, argv);
if (ret != 0) {
exit(ret);
}
g_cmd_logs_args.name = g_cmd_logs_args.argv[0];
ret = do_logs(&g_cmd_logs_args);
if (ret != 0) {
exit(ECOMMON);
}
return 0;
}

View File

@ -1,41 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container logs definition
******************************************************************************/
#ifndef __CMD_LOGS_H
#define __CMD_LOGS_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LOGS_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "follow", 'f', &(cmdargs).follow, "Follow log output", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "tail", 0, &(cmdargs).tail, \
"Number of lines to show from the end of the logs", callback_tail }
extern const char g_cmd_logs_desc[];
extern const char g_cmd_logs_usage[];
extern struct client_arguments g_cmd_logs_args;
int callback_tail(command_option_t *option, const char *arg);
int cmd_logs_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_LOGS_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container ps definition
******************************************************************************/
#ifndef __CMD_LIST_H
#define __CMD_LIST_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LIST_OPTIONS(cmdargs) \
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).list_all, \
"Display all containers (default shows just running)", NULL }, \
{ CMD_OPT_TYPE_BOOL, false, "quiet", 'q', &(cmdargs).dispname, "Only display numeric IDs", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "filter", 'f', &(cmdargs).filters, \
"Filter output based on conditions provided", command_append_array }, \
{ CMD_OPT_TYPE_BOOL, false, "no-trunc", 0, &(cmdargs).no_trunc, \
"Don't truncate output", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "format", 0, &(cmdargs).format, \
"Format the output using the given go template", NULL }
extern const char g_cmd_list_desc[];
extern const char g_cmd_list_usage[];
extern struct client_arguments g_cmd_list_args;
int cmd_list_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_LIST_H */

View File

@ -1,155 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container remove functions
******************************************************************************/
#include "top.h"
#include <limits.h>
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
#include "commands.h"
#include "console.h"
#include "utils.h"
#include "container_inspect.h"
#include "attach.h"
#include "commander.h"
const char g_cmd_top_desc[] = "Display the running processes of a container";
const char g_cmd_top_usage[] = "top [OPTIONS] CONTAINER [ps OPTIONS]";
struct client_arguments g_cmd_top_args = {};
static void client_top_info_server(const struct isula_top_response *response)
{
size_t i;
if (response->titles != NULL) {
printf("%s\n", response->titles);
}
if (response->processes_len == 0 || response->processes == NULL) {
return;
}
for (i = 0; i < response->processes_len; i++) {
printf("%s\n", response->processes[i]);
}
}
/*
* Create a rm request message and call RPC
*/
static int client_top(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_top_request request = { 0 };
struct isula_top_response *response = NULL;
container_inspect *inspect_data = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_top_response));
if (response == NULL) {
ERROR("TOP: Out of memory");
return -1;
}
if (inspect_container(args, &inspect_data)) {
ERROR("inspect data error");
ret = -1;
goto out;
}
if (inspect_data == NULL) {
ERROR("inspect data is null");
ret = -1;
goto out;
}
if (inspect_data->state != NULL && !inspect_data->state->running) {
COMMAND_ERROR("You cannot attach to a stopped container, start it first");
ret = -1;
goto out;
}
if (inspect_data->state != NULL && inspect_data->state->restarting) {
COMMAND_ERROR("You cannot attach to a restarting container, wait until it is running");
ret = -1;
goto out;
}
request.name = args->name;
request.ps_argc = args->argc;
request.ps_args = (char **)args->argv;
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.top) {
ERROR("Unimplemented top op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.top(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
}
client_top_info_server(response);
out:
free_container_inspect(inspect_data);
isula_top_response_free(response);
return ret;
}
int cmd_top_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf), COMMON_OPTIONS(g_cmd_top_args) };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_top_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_top_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_top_desc,
g_cmd_top_usage);
if (command_parse_args(&cmd, &g_cmd_top_args.argc, &g_cmd_top_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Top: log init failed");
exit(ECOMMON);
}
if (g_cmd_top_args.argc < 1) {
COMMAND_ERROR("\"%s top\" requires at least 1 argument(s).", g_cmd_top_args.progname);
COMMAND_ERROR("See '%s top --help'.", g_cmd_top_args.progname);
exit(EINVALIDARGS);
} else {
g_cmd_top_args.name = g_cmd_top_args.argv[0];
g_cmd_top_args.argc--;
g_cmd_top_args.argv++;
}
if (client_top(&g_cmd_top_args) != 0) {
ERROR("Container \"%s\" top failed", g_cmd_top_args.name);
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2018-11-08
* Description: provide container top definition
******************************************************************************/
#ifndef __CMD_TOP_H
#define __CMD_TOP_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_top_desc[];
extern const char g_cmd_top_usage[];
extern struct client_arguments g_cmd_top_args;
int cmd_top_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_TOP_H */

View File

@ -1,123 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-08
* Description: provide container version functions
******************************************************************************/
#include "version.h"
#include <stdio.h>
#include "utils.h"
#include "arguments.h"
#include "log.h"
#include "config.h"
#include "isula_connect.h"
const char g_cmd_version_desc[] = "Display information about isula";
const char g_cmd_version_usage[] = "version";
struct client_arguments g_cmd_version_args = {};
static void client_version_info_client()
{
printf("Client:\n");
printf(" Version:\t%s\n", VERSION);
printf(" Git commit:\t%s\n", ISULAD_GIT_COMMIT);
printf(" Built:\t%s\n", ISULAD_BUILD_TIME);
printf("\n");
}
static void client_version_info_oci_config()
{
printf("OCI config:\n");
printf(" Version:\t%s\n", OCI_VERSION);
printf(" Default file:\t%s\n", OCICONFIG_PATH);
printf("\n");
}
static void client_version_info_server(const struct isula_version_response *response)
{
printf("Server:\n");
printf(" Version:\t%s\n", response->version ? response->version : "");
printf(" Git commit:\t%s\n", response->git_commit ? response->git_commit : "");
printf(" Built:\t%s\n", response->build_time ? response->build_time : "");
printf("\n");
}
static int client_version(const struct client_arguments *args)
{
isula_connect_ops *ops = NULL;
struct isula_version_request request = { 0 };
struct isula_version_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_version_response));
if (response == NULL) {
ERROR("Version: Out of memory");
return -1;
}
client_version_info_client();
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.version) {
ERROR("Unimplemented version op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.version(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
goto out;
}
client_version_info_server(response);
client_version_info_oci_config();
out:
isula_version_response_free(response);
return ret;
}
int cmd_version_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf), COMMON_OPTIONS(g_cmd_version_args) };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_version_args)) {
COMMAND_ERROR("client arguments init failed\n");
exit(ECOMMON);
}
g_cmd_version_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_version_desc,
g_cmd_version_usage);
if (command_parse_args(&cmd, &g_cmd_version_args.argc, &g_cmd_version_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Version: log init failed");
exit(ECOMMON);
}
if (g_cmd_version_args.argc > 0) {
COMMAND_ERROR("%s: \"version\" requires 0 arguments.", g_cmd_version_args.progname);
exit(ECOMMON);
}
if (client_version(&g_cmd_version_args)) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,34 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-08
* Description: provide container version definition
******************************************************************************/
#ifndef __CMD_VERSION_H
#define __CMD_VERSION_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_version_desc[];
extern const char g_cmd_version_usage[];
extern struct client_arguments g_cmd_version_args;
int cmd_version_main(int argc, const char **argv);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_VERSION_H */

View File

@ -1,133 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-08
* Description: provide container wait functions
******************************************************************************/
#include "error.h"
#include "wait.h"
#include "arguments.h"
#include "log.h"
#include "isula_connect.h"
const char g_cmd_wait_desc[] = "Block until one or more containers stop, then print their exit codes";
const char g_cmd_wait_usage[] = "wait [OPTIONS] CONTAINER [CONTAINER...]";
struct client_arguments g_cmd_wait_args = {};
/*
* Create a delete request message and call RPC
*/
int client_wait(const struct client_arguments *args, unsigned int *exit_code)
{
isula_connect_ops *ops = NULL;
struct isula_wait_request request = { 0 };
struct isula_wait_response *response = NULL;
client_connect_config_t config = { 0 };
int ret = 0;
response = util_common_calloc_s(sizeof(struct isula_wait_response));
if (response == NULL) {
ERROR("Wait: Out of memory");
return -1;
}
request.id = args->name;
if (args->custom_conf.auto_remove == false) {
request.condition = WAIT_CONDITION_STOPPED;
} else {
request.condition = WAIT_CONDITION_REMOVED;
}
ops = get_connect_client_ops();
if (ops == NULL || !ops->container.wait) {
ERROR("Unimplemented wait op");
ret = -1;
goto out;
}
config = get_connect_config(args);
ret = ops->container.wait(&request, response, &config);
if (ret) {
client_print_error(response->cc, response->server_errono, response->errmsg);
if (response->cc) {
ret = ESERVERERROR;
} else {
ret = ECOMMON;
}
goto out;
}
if (exit_code != NULL) {
*exit_code = (unsigned int)response->exit_code;
}
out:
isula_wait_response_free(response);
return ret;
}
int cmd_wait_main(int argc, const char **argv)
{
struct log_config lconf = { 0 };
unsigned int exit_code = 0;
int i = 0;
int status = 0;
command_t cmd;
struct command_option options[] = { LOG_OPTIONS(lconf), COMMON_OPTIONS(g_cmd_wait_args) };
set_default_command_log_config(argv[0], &lconf);
if (client_arguments_init(&g_cmd_wait_args)) {
COMMAND_ERROR("client arguments init failed");
exit(ECOMMON);
}
g_cmd_wait_args.progname = argv[0];
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_wait_desc,
g_cmd_wait_usage);
if (command_parse_args(&cmd, &g_cmd_wait_args.argc, &g_cmd_wait_args.argv)) {
exit(EINVALIDARGS);
}
if (log_init(&lconf)) {
COMMAND_ERROR("Wait: log init failed");
exit(ECOMMON);
}
if (g_cmd_wait_args.socket == NULL) {
COMMAND_ERROR("Missing --host,-H option");
exit(EINVALIDARGS);
}
if (g_cmd_wait_args.argc == 0) {
COMMAND_ERROR("Wait requires at least 1 container names");
exit(EINVALIDARGS);
}
if (g_cmd_wait_args.argc >= MAX_CLIENT_ARGS) {
COMMAND_ERROR("You specify too many containers to wait.");
exit(EINVALIDARGS);
}
for (i = 0; i < g_cmd_wait_args.argc; i++) {
g_cmd_wait_args.name = g_cmd_wait_args.argv[i];
if (client_wait(&g_cmd_wait_args, &exit_code)) {
ERROR("Container \"%s\" wait failed", g_cmd_wait_args.name);
status = -1;
continue;
}
printf("%u\n", exit_code);
}
if (status) {
exit(ECOMMON);
}
exit(EXIT_SUCCESS);
}

View File

@ -1,35 +0,0 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: tanyifeng
* Create: 2018-11-08
* Description: provide container wait definition
******************************************************************************/
#ifndef __CMD_WAIT_H
#define __CMD_WAIT_H
#include "arguments.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char g_cmd_wait_desc[];
extern const char g_cmd_wait_usage[];
extern struct client_arguments g_cmd_wait_args;
int cmd_wait_main(int argc, const char **argv);
int client_wait(const struct client_arguments *args, unsigned int *exit_code);
#ifdef __cplusplus
}
#endif
#endif /* __CMD_WAIT_H */

Some files were not shown because too many files have changed in this diff Show More