komodo_client 2.3.1

Client for the Komodo build and deployment system
Documentation
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::entities::{
  ResourceTarget, SearchCombinator, U64,
  docker::{
    container::{
      Container, ContainerListItem, ContainerSortBy,
      ContainerStateStatusEnum,
    },
    image::{Image, ImageHistoryResponseItem, ImageListItem},
    network::{Network, NetworkListItem},
    volume::{Volume, VolumeListItem},
  },
  stack::ComposeProject,
  update::Log,
};

use super::KomodoReadRequest;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetContainersSummary",
  description = "Gets a summary of data relating to all containers.",
  request_body(content = GetContainersSummary),
  responses(
    (status = 200, description = "The containers summary", body = GetContainersSummaryResponse),
  ),
)]
pub fn get_containers_summary() {}

/// Gets a summary of data relating to all containers.
/// Response: [GetContainersSummaryResponse].
///
/// Pre v2.3.0, called `GetDockerContainersSummary`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetContainersSummaryResponse)]
#[error(mogh_error::Error)]
pub struct GetContainersSummary {}

/// Response for [GetContainersSummary]
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetContainersSummaryResponse {
  /// The total number of Containers
  pub total: u32,
  /// The number of Containers with Running state
  pub running: u32,
  /// The number of Containers with Stopped or Paused or Created state
  pub stopped: u32,
  /// The number of Containers with Restarting or Dead state
  pub unhealthy: u32,
  /// The number of Containers with Unknown state
  pub unknown: u32,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListAllContainers",
  description = "List all containers on the target servers.",
  request_body(content = ListAllContainers),
  responses(
    (status = 200, description = "The list of containers", body = ListAllContainersResponse),
  ),
)]
pub fn list_all_containers() {}

/// List all containers on the target servers.
/// Response: [ListAllContainersResponse].
///
/// Pre v2.3.0, called `ListAllDockerContainers`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListAllContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListAllContainers {
  /// Filter by server id or name.
  #[serde(default)]
  pub servers: Vec<String>,

  /// Filter servers by tag.
  #[serde(default)]
  pub tags: Vec<String>,

  /// Filter by container name.
  /// Returned containers have names which contain all terms.
  #[serde(default)]
  pub terms: Vec<String>,

  /// Filter by container state.
  #[serde(default)]
  pub state: Vec<ContainerStateStatusEnum>,

  /// Retrieve more results by incrementing the page.
  /// `page: 0` is default.
  #[serde(default)]
  pub page: U64,

  /// Set the limit for number of containers per-page.
  /// If not provided, uses the Core config
  /// `default_pagination_limit` (default: 30).
  ///
  /// Passing `limit: 0` returns all results (unlimited).
  ///
  /// Note: the page logic relies on this being consistent
  /// across queries for more pages.
  pub limit: Option<U64>,

  /// Sort the results by this field.
  /// Defaults to Name.
  #[serde(default)]
  pub sort_by: ContainerSortBy,

  /// Reverse the sort direction.
  #[serde(default)]
  pub sort_desc: bool,
}

#[typeshare]
pub type ListAllContainersResponse = Vec<ContainerListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListContainers",
  description = "List all containers on the target server.",
  request_body(content = ListContainers),
  responses(
    (status = 200, description = "The list of containers", body = ListContainersResponse),
  ),
)]
pub fn list_containers() {}

/// List all containers on the target server.
/// Response: [ListContainersResponse].
///
/// Pre v2.3.0, called `ListDockerContainers`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListContainersResponse)]
#[error(mogh_error::Error)]
pub struct ListContainers {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
}

#[typeshare]
pub type ListContainersResponse = Vec<ContainerListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectContainer",
  description = "Inspect a container on the server.",
  request_body(content = InspectContainer),
  responses(
    (status = 200, description = "The container", body = InspectContainerResponse),
  ),
)]
pub fn inspect_container() {}

/// Inspect a container on the server. Response: [Container].
///
/// Pre v2.3.0, called `InspectDockerContainer`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectContainerResponse)]
#[error(mogh_error::Error)]
pub struct InspectContainer {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The container name
  pub container: String,
}

#[typeshare]
pub type InspectContainerResponse = Container;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetResourceMatchingContainer",
  description = "Find the attached resource for a container.",
  request_body(content = GetResourceMatchingContainer),
  responses(
    (status = 200, description = "The resource matching the container", body = GetResourceMatchingContainerResponse),
  ),
)]
pub fn get_resource_matching_container() {}

/// Find the attached resource for a container. Either Deployment or Stack. Response: [GetResourceMatchingContainerResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetResourceMatchingContainerResponse)]
#[error(mogh_error::Error)]
pub struct GetResourceMatchingContainer {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The container name
  pub container: String,
}

/// Response for [GetResourceMatchingContainer]. Resource is either Deployment, Stack, or None.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetResourceMatchingContainerResponse {
  pub resource: Option<ResourceTarget>,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetContainerLog",
  description = "Get the container log's tail, split by stdout/stderr.",
  request_body(content = GetContainerLog),
  responses(
    (status = 200, description = "The container log", body = GetContainerLogResponse),
  ),
)]
pub fn get_container_log() {}

/// Get the container log's tail, split by stdout/stderr.
/// Response: [Log].
///
/// Note. This call will hit the underlying server directly for most up to date log.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetContainerLogResponse)]
#[error(mogh_error::Error)]
pub struct GetContainerLog {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The container name
  pub container: String,
  /// The number of lines of the log tail to include.
  /// Default: 100.
  /// Max: 5000.
  #[serde(default = "default_tail")]
  pub tail: U64,
  /// Enable `--timestamps`
  #[serde(default)]
  pub timestamps: bool,
}

fn default_tail() -> u64 {
  50
}

#[typeshare]
pub type GetContainerLogResponse = Log;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/SearchContainerLog",
  description = "Search the container log's tail using `grep`.",
  request_body(content = SearchContainerLog),
  responses(
    (status = 200, description = "The search results", body = SearchContainerLogResponse),
  ),
)]
pub fn search_container_log() {}

/// Search the container log's tail using `grep`. All lines go to stdout.
/// Response: [Log].
///
/// Note. This call will hit the underlying server directly for most up to date log.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(SearchContainerLogResponse)]
#[error(mogh_error::Error)]
pub struct SearchContainerLog {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The container name
  pub container: String,
  /// The terms to search for.
  pub terms: Vec<String>,
  /// When searching for multiple terms, can use `AND` or `OR` combinator.
  ///
  /// - `AND`: Only include lines with **all** terms present in that line.
  /// - `OR`: Include lines that have one or more matches in the terms.
  #[serde(default)]
  pub combinator: SearchCombinator,
  /// Invert the results, ie return all lines that DON'T match the terms / combinator.
  #[serde(default)]
  pub invert: bool,
  /// Enable `--timestamps`
  #[serde(default)]
  pub timestamps: bool,
}

#[typeshare]
pub type SearchContainerLogResponse = Log;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListComposeProjects",
  description = "List all compose projects on the target server.",
  request_body(content = ListComposeProjects),
  responses(
    (status = 200, description = "The list of compose projects", body = ListComposeProjectsResponse),
  ),
)]
pub fn list_compose_projects() {}

/// List all compose projects on the target server.
/// Response: [ListComposeProjectsResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListComposeProjectsResponse)]
#[error(mogh_error::Error)]
pub struct ListComposeProjects {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
}

#[typeshare]
pub type ListComposeProjectsResponse = Vec<ComposeProject>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListNetworks",
  description = "List the container networks on the server.",
  request_body(content = ListNetworks),
  responses(
    (status = 200, description = "The list of networks", body = ListNetworksResponse),
  ),
)]
pub fn list_networks() {}

/// List the container networks on the server. Response: [ListNetworksResponse].
///
/// Pre v2.3.0, called `ListDockerNetworks`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListNetworksResponse)]
#[error(mogh_error::Error)]
pub struct ListNetworks {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
}

#[typeshare]
pub type ListNetworksResponse = Vec<NetworkListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectNetwork",
  description = "Inspect a container network on the server.",
  request_body(content = InspectNetwork),
  responses(
    (status = 200, description = "The network", body = InspectNetworkResponse),
  ),
)]
pub fn inspect_network() {}

/// Inspect a container network on the server. Response: [InspectNetworkResponse].
///
/// Pre v2.3.0, called `InspectDockerNetwork`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectNetworkResponse)]
#[error(mogh_error::Error)]
pub struct InspectNetwork {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The network name
  pub network: String,
}

#[typeshare]
pub type InspectNetworkResponse = Network;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListImages",
  description = "List the container images locally cached on the target server.",
  request_body(content = ListImages),
  responses(
    (status = 200, description = "The list of images", body = ListImagesResponse),
  ),
)]
pub fn list_images() {}

/// List the container images locally cached on the target server.
/// Response: [ListImagesResponse].
///
/// Pre v2.3.0, called `ListDockerImages`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListImagesResponse)]
#[error(mogh_error::Error)]
pub struct ListImages {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
}

#[typeshare]
pub type ListImagesResponse = Vec<ImageListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectImage",
  description = "Inspect a container image on the server.",
  request_body(content = InspectImage),
  responses(
    (status = 200, description = "The image", body = InspectImageResponse),
  ),
)]
pub fn inspect_image() {}

/// Inspect a container image on the server. Response: [Image].
///
/// Pre v2.3.0, called `InspectDockerImage`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectImageResponse)]
#[error(mogh_error::Error)]
pub struct InspectImage {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The image name
  pub image: String,
}

#[typeshare]
pub type InspectImageResponse = Image;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListImageHistory",
  description = "Get image history from the server.",
  request_body(content = ListImageHistory),
  responses(
    (status = 200, description = "The image history", body = ListImageHistoryResponse),
  ),
)]
pub fn list_image_history() {}

/// Get image history from the server. Response: [ListImageHistoryResponse].
///
/// Pre v2.3.0, called `ListDockerImageHistory`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListImageHistoryResponse)]
#[error(mogh_error::Error)]
pub struct ListImageHistory {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The image name
  pub image: String,
}

#[typeshare]
pub type ListImageHistoryResponse = Vec<ImageHistoryResponseItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListVolumes",
  description = "List all container volumes on the target server.",
  request_body(content = ListVolumes),
  responses(
    (status = 200, description = "The list of volumes", body = ListVolumesResponse),
  ),
)]
pub fn list_volumes() {}

/// List all container volumes on the target server.
/// Response: [ListVolumesResponse].
///
/// Pre v2.3.0, called `ListDockerVolumes`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListVolumesResponse)]
#[error(mogh_error::Error)]
pub struct ListVolumes {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
}

#[typeshare]
pub type ListVolumesResponse = Vec<VolumeListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectVolume",
  description = "Inspect a container volume on the server.",
  request_body(content = InspectVolume),
  responses(
    (status = 200, description = "The volume", body = InspectVolumeResponse),
  ),
)]
pub fn inspect_volume() {}

/// Inspect a container volume on the server. Response: [Volume].
///
/// Pre v2.3.0, called `InspectDockerVolume`
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectVolumeResponse)]
#[error(mogh_error::Error)]
pub struct InspectVolume {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub server: String,
  /// The volume name
  pub volume: String,
}

#[typeshare]
pub type InspectVolumeResponse = Volume;