1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use bytesize::ByteSize;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::Merge;

/// Determines the "swappiness" of memory.
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub enum MemorySwappinessV1 {
    /// Always allow the memory to be swapped to disk.
    #[serde(rename = "always")]
    Always,
    /// Never allow the memory to be swapped to disk.
    #[serde(rename = "never")]
    Never,
}

impl Merge for MemorySwappinessV1 {
    fn merge_extend(self, _other: &Self) -> Self {
        self
    }
}

/// Configuration for swap memory.
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct CapabilityMemorySwapV1 {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub swappiness: Option<MemorySwappinessV1>,
    /// A unique id for the memory.
    ///
    /// Only useful for shared memories.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory_id: Option<Uuid>,
    #[schemars(with = "String")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maximum_size: Option<ByteSize>,
}

impl Merge for CapabilityMemorySwapV1 {
    fn merge_extend(self, other: &Self) -> Self {
        Self {
            swappiness: self.swappiness.merge_extend(&other.swappiness),
            memory_id: self.memory_id.merge_extend(&other.memory_id),
            maximum_size: self.maximum_size.merge_extend(&other.maximum_size),
        }
    }
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, schemars::JsonSchema)]
pub struct CapabilityPersistentMemoryV1 {
    /// Volumes to be mounted inside memory.
    // TODO: use a `VolumeConfig` type here.
    #[serde(default)]
    pub volumes: Vec<()>,
}

impl Merge for CapabilityPersistentMemoryV1 {
    fn merge_extend(self, _other: &Self) -> Self {
        self
    }
}