use crate::models;
use crate::opts::ImageOpt;
use containers_api::opts::{Filter, FilterItem};
use containers_api::{
impl_field, impl_filter_func, impl_map_field, impl_opts_builder, impl_str_enum_field,
impl_str_field, impl_url_bool_field, impl_url_field, impl_url_str_field, impl_url_vec_field,
impl_vec_field,
};
use std::fmt;
impl_opts_builder!(url =>
ContainerList
);
#[derive(Debug)]
pub enum ContainerListFilter {
Ancestor(ImageOpt),
Before(String),
Expose(String),
Exited(i32),
Health(models::ContainerHealth),
Id(crate::Id),
IsTask(bool),
LabelKey(String),
LabelKeyVal(String, String),
NoLabelKey(String),
NoLabelKeyVal(String, String),
Name(String),
Network(String),
Pod(String),
Publish(String),
Since(String),
Status(models::ContainerStatus),
Volume(String),
}
impl Filter for ContainerListFilter {
fn query_item(&self) -> FilterItem {
use ContainerListFilter::*;
match &self {
Ancestor(ancestor) => FilterItem::new("ancestor", ancestor.to_string()),
Before(container) => FilterItem::new("before", container.clone()),
Expose(port) => FilterItem::new("expose", port.clone()),
Exited(code) => FilterItem::new("exited", code.to_string()),
Health(health) => FilterItem::new("health", health.as_ref().to_string()),
Id(id) => FilterItem::new("id", id.to_string()),
IsTask(is_task) => FilterItem::new("is-task", is_task.to_string()),
LabelKey(key) => FilterItem::new("label", key.clone()),
LabelKeyVal(key, val) => FilterItem::new("label", format!("{}={}", key, val)),
NoLabelKey(key) => FilterItem::new("label!", key.clone()),
NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{}={}", key, val)),
Name(name) => FilterItem::new("name", name.clone()),
Network(net) => FilterItem::new("network", net.clone()),
Pod(pod) => FilterItem::new("pod", pod.clone()),
Publish(port) => FilterItem::new("publish", port.clone()),
Since(container) => FilterItem::new("since", container.clone()),
Status(status) => FilterItem::new("status", status.as_ref().to_string()),
Volume(vol) => FilterItem::new("volume", vol.clone()),
}
}
}
impl ContainerListOptsBuilder {
impl_url_bool_field!(
all => "all"
);
impl_url_field!(
limit: usize => "limit"
);
impl_url_bool_field!(
size => "size"
);
impl_url_bool_field!(
sync => "sync"
);
impl_filter_func!(ContainerListFilter);
}
impl_opts_builder!(url =>
ContainerStop
);
impl ContainerStopOptsBuilder {
impl_url_bool_field!(
all => "all"
);
impl_url_bool_field!(
ignore => "Ignore"
);
impl_url_field!(
timeout: usize => "Timeout"
);
}
impl_opts_builder!(url =>
ContainerDelete
);
impl ContainerDeleteOptsBuilder {
impl_url_bool_field!(
force => "force"
);
impl_url_bool_field!(
volumes => "v"
);
}
impl_opts_builder!(url =>
ContainerCheckpoint
);
impl ContainerCheckpointOpts {
pub(crate) fn for_export(&self) -> Self {
let mut new = self.clone();
new.params.insert("export", true.to_string());
new
}
}
impl ContainerCheckpointOptsBuilder {
impl_url_bool_field!(
ignore_root_fs => "ignoreRootFS"
);
impl_url_bool_field!(
keep => "keep"
);
impl_url_bool_field!(
leave_running => "leaveRunning"
);
impl_url_bool_field!(
print_stats => "printStats"
);
impl_url_bool_field!(
tcp_established => "tcpEstablished"
);
}
impl_opts_builder!(url =>
ContainerCommit
);
impl ContainerCommitOpts {
pub(crate) fn for_container(&self, container: crate::Id) -> Self {
let mut new = self.clone();
new.params.insert("container", container.to_string());
new
}
}
impl ContainerCommitOptsBuilder {
impl_url_str_field!(
author => "author"
);
impl_url_vec_field!(
changes => "changes"
);
impl_url_str_field!(
comment => "comment"
);
impl_url_str_field!(
format => "format"
);
impl_url_bool_field!(
pause => "pause"
);
impl_url_str_field!(
repo => "repo"
);
impl_url_str_field!(
tag => "tag"
);
}
impl_opts_builder!(url =>
ContainerWait
);
impl ContainerWaitOptsBuilder {
pub fn conditions(
mut self,
conditions: impl IntoIterator<Item = models::ContainerStatus>,
) -> Self {
let joined = conditions
.into_iter()
.map(|it| format!("\"{}\"", it.as_ref()))
.collect::<Vec<_>>()
.join(",");
self.params.insert("condition", format!("[{}]", joined));
self
}
impl_url_str_field!(
interval => "interval"
);
}
impl_opts_builder!(json =>
ContainerCreate
);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageVolumeMode {
Ignore,
Tmpfs,
Anonymous,
}
impl Default for ImageVolumeMode {
fn default() -> Self {
ImageVolumeMode::Anonymous
}
}
impl AsRef<str> for ImageVolumeMode {
fn as_ref(&self) -> &str {
match self {
ImageVolumeMode::Ignore => "ignore",
ImageVolumeMode::Tmpfs => "tmpfs",
ImageVolumeMode::Anonymous => "anonymous",
}
}
}
impl fmt::Display for ImageVolumeMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SocketNotifyMode {
Container,
Conmon,
Ignore,
}
impl AsRef<str> for SocketNotifyMode {
fn as_ref(&self) -> &str {
match self {
SocketNotifyMode::Container => "container",
SocketNotifyMode::Conmon => "conmon",
SocketNotifyMode::Ignore => "ignore",
}
}
}
impl fmt::Display for SocketNotifyMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SeccompPolicy {
Empty,
Default,
Image,
}
impl AsRef<str> for SeccompPolicy {
fn as_ref(&self) -> &str {
match self {
SeccompPolicy::Empty => "empty",
SeccompPolicy::Default => "default",
SeccompPolicy::Image => "image",
}
}
}
impl Default for SeccompPolicy {
fn default() -> Self {
SeccompPolicy::Default
}
}
impl fmt::Display for SeccompPolicy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SystemdEnabled {
True,
False,
Always,
}
impl Default for SystemdEnabled {
fn default() -> Self {
SystemdEnabled::False
}
}
impl AsRef<str> for SystemdEnabled {
fn as_ref(&self) -> &str {
match self {
SystemdEnabled::True => "true",
SystemdEnabled::False => "false",
SystemdEnabled::Always => "always",
}
}
}
impl fmt::Display for SystemdEnabled {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContainerRestartPolicy {
Always,
No,
OnFailure,
UnlessStopped,
}
impl Default for ContainerRestartPolicy {
fn default() -> Self {
ContainerRestartPolicy::No
}
}
impl AsRef<str> for ContainerRestartPolicy {
fn as_ref(&self) -> &str {
match self {
ContainerRestartPolicy::Always => "always",
ContainerRestartPolicy::No => "no",
ContainerRestartPolicy::OnFailure => "on-failure",
ContainerRestartPolicy::UnlessStopped => "unless-stopped",
}
}
}
impl fmt::Display for ContainerRestartPolicy {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_ref())
}
}
impl ContainerCreateOptsBuilder {
impl_map_field!(json
annotations => "annotations"
);
impl_str_field!(
apparmor_profile => "apparmor_profile"
);
impl_vec_field!(
add_capabilities => "cap_add"
);
impl_vec_field!(
drop_capabilities => "cap_drop"
);
impl_str_field!(
cgroup_parent => "cgroup_parent"
);
impl_field!(
cgroup_namespace: models::Namespace => "cgroupns"
);
impl_str_field!(
cgroup_mode => "cgroups_mode"
);
impl_vec_field!(
chroot_directories => "chroot_directories"
);
impl_vec_field!(
command => "command"
);
impl_str_field!(
common_pid_file => "common_pid_file"
);
impl_vec_field!(
create_command => "containerCreateCommand"
);
impl_field!(
cpu_period: u64 => "cpu_period"
);
impl_field!(
cpu_quota: i64 => "cpu_quota"
);
impl_field!(
create_working_dir: bool => "create_working_dir"
);
impl_vec_field!(
dependency_containers => "dependencyContainers"
);
impl_vec_field!(
device_cgroup_rule : models::LinuxDeviceCgroup => "device_cgroup_rule"
);
impl_vec_field!(
devices : models::LinuxDevice => "devices"
);
impl_vec_field!(
devices_from => "device_from"
);
impl_vec_field!(
dns_option => "dns_option"
);
impl_vec_field!(
dns_search => "dns_search"
);
impl_vec_field!(
dns_server => "dns_server"
);
impl_vec_field!(
entrypoint => "entrypoint"
);
impl_map_field!(json
env => "env"
);
impl_field!(
env_host: bool => "env_host"
);
impl_vec_field!(
envmerge => "envmerge"
);
impl_vec_field!(
groups => "groups"
);
impl_field!(
health_check_on_failure_action: i64 => "health_check_on_failure_action"
);
impl_field!(
health_config: models::Schema2HealthConfig => "healthconfig"
);
impl_vec_field!(
host_device_list : models::LinuxDevice => "host_device_list"
);
impl_vec_field!(
hosts_add => "hostadd"
);
impl_str_field!(
hostname => "hostname"
);
impl_vec_field!(
hostusers => "hostusers"
);
impl_field!(
http_proxy: bool => "httpproxy"
);
impl_field!(
id_mappings: models::IdMappingOptions => "idmappings"
);
impl_str_field!(
image => "image"
);
impl_str_field!(
image_arch => "image_arch"
);
impl_str_field!(
image_os => "image_os"
);
impl_str_field!(
image_variant => "image_variant"
);
impl_str_enum_field!(
image_volume_mode: ImageVolumeMode => "image_volume_mode"
);
impl_vec_field!(
image_volumes : models::ImageVolume => "image_volumes"
);
impl_field!(
init: bool => "init"
);
impl_str_field!(
init_container_type => "init_container_type"
);
impl_str_field!(
init_path => "init_path"
);
impl_field!(
ipc_namespace: models::Namespace => "ipcns"
);
impl_map_field!(json
labels => "labels"
);
impl_field!(
log_configuration: models::LogConfig => "log_configuration"
);
impl_field!(
manage_password: bool => "manage_password"
);
impl_vec_field!(
mask => "mask"
);
impl_vec_field!(
mounts: models::ContainerMount => "mounts"
);
impl_str_field!(
name => "name"
);
impl_str_field!(
namespace => "namespace"
);
impl_field!(
net_namespace: models::Namespace => "netns"
);
impl_map_field!(json
network_options => "network_options"
);
impl_map_field!(json
networks => "Networks"
);
impl_field!(
no_new_privilages: bool => "no_new_privilages"
);
impl_str_field!(
oci_runtime => "oci_runtime"
);
impl_field!(
oom_score_adj: i64 => "oom_score_adj"
);
impl_vec_field!(
overlay_volumes : models::OverlayVolume => "overlay_volumes"
);
impl_str_field!(
passwd_entry => "passwd_entry"
);
impl_field!(
personality: models::LinuxPersonality => "personality"
);
impl_field!(
pid_namespace: models::Namespace => "pidns"
);
impl_str_field!(
pod => "pod"
);
impl_vec_field!(
portmappings: models::PortMapping => "portmappings"
);
impl_field!(
privileged: bool => "privileged"
);
impl_vec_field!(
procfs_opts => "procfs_opts"
);
impl_field!(
publish_image_ports: bool => "publish_image_ports"
);
impl_vec_field!(
r_limits : models::PosixRlimit => "r_limits"
);
impl_str_field!(
raw_image_name => "raw_image_name"
);
impl_field!(
read_only_fs: bool => "read_only_filesystem"
);
impl_field!(
remove: bool => "remove"
);
impl_field!(
resource_limits: models::LinuxResources => "resource_limits"
);
impl_str_enum_field!(
restart_policy: ContainerRestartPolicy => "restart_policy"
);
impl_field!(
restart_tries: u64 => "restart_tries"
);
impl_str_field!(
rootfs => "rootfs"
);
impl_field!(
rootfs_overlay: bool => "rootfs_overlay"
);
impl_str_field!(
rootfs_propagation => "rootfs_propagation"
);
impl_str_enum_field!(
sdnotify_mode: SocketNotifyMode => "sdnotifyMode"
);
impl_str_enum_field!(
seccomp_policy: SeccompPolicy => "seccomp_policy"
);
impl_str_field!(
seccomp_profile_path => "seccomp_profile_path"
);
impl_map_field!(json
secret_env => "secret_env"
);
impl_vec_field!(
secrets :models::Secret => "secrets"
);
impl_vec_field!(
selinux_opts => "selinux_opts"
);
impl_field!(
shm_size: i64 => "shm_size"
);
impl_field!(
stdin: bool => "stdin"
);
impl_field!(
stop_signal: i64 => "stop_signal"
);
impl_field!(
stop_timeout: u64 => "stop_timeout"
);
impl_map_field!(json
storage_opts => "storage_opts"
);
impl_map_field!(json
sysctl => "sysctl"
);
impl_str_enum_field!(
systemd: SystemdEnabled => "systemd"
);
impl_field!(
terminal: bool => "terminal"
);
impl_map_field!(json
throttle_read_bps_device => "throttleReadBpsDevice"
);
impl_map_field!(json
throttle_read_iops_device => "throttleReadIOPSDevice"
);
impl_map_field!(json
throttle_write_bps_device => "throttleWriteBpsDevice"
);
impl_map_field!(json
throttle_write_iops_device => "throttleWriteIOPSDevice"
);
impl_field!(
timeout: u64 => "timeout"
);
impl_str_field!(
timezone => "timezone"
);
impl_str_field!(
umask => "umask"
);
impl_map_field!(json
unified => "unified"
);
impl_vec_field!(
unmask => "unmask"
);
impl_vec_field!(
unset_env => "unsetenv"
);
impl_field!(
unset_env_all: bool => "unsetenvall"
);
impl_field!(
use_image_hosts: bool => "use_image_hosts"
);
impl_field!(
use_image_resolv_conf: bool => "use_image_resolv_conf"
);
impl_str_field!(
user => "user"
);
impl_field!(
user_namespace: models::Namespace => "userns"
);
impl_field!(
uts_namespace: models::Namespace => "utsns"
);
impl_field!(
volatile: bool => "volatile"
);
impl_vec_field!(
volumes: models::NamedVolume => "volumes"
);
impl_vec_field!(
volumes_from => "volumes_from"
);
impl_field!(
weight_device: models::LinuxWeightDevice => "weightDevice"
);
impl_str_field!(
work_dir => "work_dir"
);
}
impl_opts_builder!(url =>
ContainerAttach
);
impl ContainerAttachOpts {
pub(crate) fn stream(&self) -> Self {
let mut new = self.clone();
new.params.insert("stream", true.to_string());
new
}
}
impl ContainerAttachOptsBuilder {
impl_url_str_field!(
detach_keys => "detachKeys"
);
impl_url_bool_field!(
stderr => "stderr"
);
impl_url_bool_field!(
stdin => "stdin"
);
impl_url_bool_field!(
stdout => "stdout"
);
}
impl_opts_builder!(url =>
ContainerLogs
);
impl ContainerLogsOptsBuilder {
impl_url_bool_field!(
follow => "follow"
);
impl_url_str_field!(
since => "since"
);
impl_url_bool_field!(
stderr => "stderr"
);
impl_url_bool_field!(
stdout => "stdout"
);
impl_url_str_field!(
tail => "tail"
);
impl_url_bool_field!(
timestamps => "timestamps"
);
impl_url_str_field!(
until => "until"
);
}
impl_opts_builder!(url =>
ContainerStats
);
impl ContainerStatsOpts {
pub(crate) fn oneshot(&self) -> Self {
let mut new = self.clone();
new.params.insert("stream", false.to_string());
new
}
pub(crate) fn stream(&self) -> Self {
let mut new = self.clone();
new.params.insert("stream", true.to_string());
new
}
}
impl ContainerStatsOptsBuilder {
impl_url_vec_field!(
containers => "containers"
);
impl_url_field!(
interval: usize => "interval"
);
}
impl_opts_builder!(url =>
ContainerTop
);
impl ContainerTopOpts {
pub(crate) fn oneshot(&self) -> Self {
let mut new = self.clone();
new.params.insert("stream", false.to_string());
new
}
pub(crate) fn stream(&self) -> Self {
let mut new = self.clone();
new.params.insert("stream", true.to_string());
new
}
}
impl ContainerTopOptsBuilder {
impl_url_field!(
delay: usize => "delay"
);
impl_url_str_field!(
ps_args => "ps_args"
);
}
#[derive(Debug)]
pub enum ContainerPruneFilter {
Until(String),
LabelKey(String),
LabelKeyVal(String, String),
NoLabelKey(String),
NoLabelKeyVal(String, String),
}
impl Filter for ContainerPruneFilter {
fn query_item(&self) -> FilterItem {
use ContainerPruneFilter::*;
match &self {
Until(until) => FilterItem::new("until", until.to_string()),
LabelKey(key) => FilterItem::new("label", key.clone()),
LabelKeyVal(key, val) => FilterItem::new("label", format!("{}={}", key, val)),
NoLabelKey(key) => FilterItem::new("label!", key.clone()),
NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{}={}", key, val)),
}
}
}
impl_opts_builder!(url =>
ContainerPrune
);
impl ContainerPruneOptsBuilder {
impl_filter_func!(
ContainerPruneFilter
);
}
impl_opts_builder!(url =>
ContainerRestore
);
impl ContainerRestoreOptsBuilder {
impl_url_bool_field!(
ignore_root_fs => "ignoreRootFS"
);
impl_url_bool_field!(
ignore_static_ip => "ignoreStaticIP"
);
impl_url_bool_field!(
ignore_static_mac => "ignoreStaticMac"
);
impl_url_bool_field!(
import => "import"
);
impl_url_bool_field!(
keep => "keep"
);
impl_url_bool_field!(
leave_running => "leaveRunning"
);
impl_url_str_field!(
name => "name"
);
impl_url_str_field!(
pod => "pod"
);
impl_url_bool_field!(
print_stats => "printStats"
);
impl_url_bool_field!(
tcp_established => "tcpEstablished"
);
}