diff --git a/Sources/ContainerCommands/Network/NetworkList.swift b/Sources/ContainerCommands/Network/NetworkList.swift index 53a5cdb0..70b172a9 100644 --- a/Sources/ContainerCommands/Network/NetworkList.swift +++ b/Sources/ContainerCommands/Network/NetworkList.swift @@ -90,12 +90,14 @@ extension NetworkState { public struct PrintableNetwork: Codable { let id: String + let createdAt: Date let state: String let config: NetworkConfiguration let status: NetworkStatus? public init(_ network: NetworkState) { self.id = network.id + self.createdAt = network.createdAt self.state = network.state switch network { case .created(let config): diff --git a/Sources/Services/ContainerNetworkService/NetworkConfiguration.swift b/Sources/Services/ContainerNetworkService/NetworkConfiguration.swift index d9c03fd8..b065a0ea 100644 --- a/Sources/Services/ContainerNetworkService/NetworkConfiguration.swift +++ b/Sources/Services/ContainerNetworkService/NetworkConfiguration.swift @@ -16,6 +16,7 @@ import ContainerizationError import ContainerizationExtras +import Foundation /// Configuration parameters for network creation. public struct NetworkConfiguration: Codable, Sendable, Identifiable { @@ -24,6 +25,9 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable { /// The network type public let mode: NetworkMode + + /// When the network was created. + public let createdAt: Date /// The preferred CIDR address for the subnet, if specified public let subnet: String? @@ -39,6 +43,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable { labels: [String: String] = [:] ) throws { self.id = id + self.createdAt = Date() self.mode = mode self.subnet = subnet self.labels = labels @@ -47,6 +52,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable { enum CodingKeys: String, CodingKey { case id + case createdAt case mode case subnet case labels @@ -58,6 +64,7 @@ public struct NetworkConfiguration: Codable, Sendable, Identifiable { let container = try decoder.container(keyedBy: CodingKeys.self) id = try container.decode(String.self, forKey: .id) + createdAt = try container.decode(Date.self, forKey: .createdAt) mode = try container.decode(NetworkMode.self, forKey: .mode) subnet = try container.decodeIfPresent(String.self, forKey: .subnet) labels = try container.decodeIfPresent([String: String].self, forKey: .labels) ?? [:] diff --git a/Sources/Services/ContainerNetworkService/NetworkState.swift b/Sources/Services/ContainerNetworkService/NetworkState.swift index 8626ff0e..f5ca9d00 100644 --- a/Sources/Services/ContainerNetworkService/NetworkState.swift +++ b/Sources/Services/ContainerNetworkService/NetworkState.swift @@ -53,4 +53,11 @@ public enum NetworkState: Codable, Sendable { case .running(let configuration, _): configuration.id } } + + public var createdAt: Date { + switch self { + case .created(let configuration): configuration.createdAt + case .running(let configuration, _): configuration.createdAt + } + } } diff --git a/Tests/CLITests/Utilities/CLITest.swift b/Tests/CLITests/Utilities/CLITest.swift index 42fd7dc2..548489e1 100644 --- a/Tests/CLITests/Utilities/CLITest.swift +++ b/Tests/CLITests/Utilities/CLITest.swift @@ -42,6 +42,7 @@ class CLITest { struct NetworkInspectOutput: Codable { let id: String + let createdAt: Date let state: String let config: NetworkConfiguration let status: NetworkStatus?