mirror of
https://github.com/moghtech/komodo.git
synced 2025-12-05 19:17:36 -06:00
add schemas for swarm commands
This commit is contained in:
@@ -198,7 +198,7 @@ impl Resolve<ReadArgs> for InspectSwarmNode {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmNode {
|
||||
name: self.node,
|
||||
node: self.node,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -241,7 +241,7 @@ impl Resolve<ReadArgs> for InspectSwarmService {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmService {
|
||||
name: self.service,
|
||||
service: self.service,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -340,7 +340,7 @@ impl Resolve<ReadArgs> for InspectSwarmTask {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmTask {
|
||||
id: self.task,
|
||||
task: self.task,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -383,7 +383,7 @@ impl Resolve<ReadArgs> for InspectSwarmSecret {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmSecret {
|
||||
id: self.secret,
|
||||
secret: self.secret,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -426,7 +426,7 @@ impl Resolve<ReadArgs> for InspectSwarmConfig {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmConfig {
|
||||
id: self.config,
|
||||
config: self.config,
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -469,7 +469,7 @@ impl Resolve<ReadArgs> for InspectSwarmStack {
|
||||
swarm_request(
|
||||
&swarm.config.server_ids,
|
||||
periphery_client::api::swarm::InspectSwarmStack {
|
||||
name: self.stack,
|
||||
stack: self.stack,
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -90,10 +90,7 @@ impl PeripheryConnectionArgs<'_> {
|
||||
}
|
||||
});
|
||||
|
||||
Ok(PeripheryClient {
|
||||
id,
|
||||
responses,
|
||||
})
|
||||
Ok(PeripheryClient { id, responses })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,9 @@ impl ToToml for Swarm {
|
||||
.map(|(key, value)| {
|
||||
#[allow(clippy::single_match)]
|
||||
match key.as_str() {
|
||||
"server_ids" => return Ok((String::from("servers"), value)),
|
||||
"server_ids" => {
|
||||
return Ok((String::from("servers"), value));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok((key, value))
|
||||
|
||||
@@ -69,7 +69,7 @@ impl Resolve<super::Args> for InspectSwarmNode {
|
||||
.iter()
|
||||
.next()
|
||||
.context("Could not connect to docker client")?;
|
||||
client.inspect_swarm_node(&self.name).await
|
||||
client.inspect_swarm_node(&self.node).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ impl Resolve<super::Args> for InspectSwarmService {
|
||||
.iter()
|
||||
.next()
|
||||
.context("Could not connect to docker client")?;
|
||||
client.inspect_swarm_service(&self.name).await
|
||||
client.inspect_swarm_service(&self.service).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ impl Resolve<super::Args> for InspectSwarmTask {
|
||||
.iter()
|
||||
.next()
|
||||
.context("Could not connect to docker client")?;
|
||||
client.inspect_swarm_task(&self.id).await
|
||||
client.inspect_swarm_task(&self.task).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ impl Resolve<super::Args> for InspectSwarmSecret {
|
||||
.iter()
|
||||
.next()
|
||||
.context("Could not connect to docker client")?;
|
||||
client.inspect_swarm_secret(&self.id).await
|
||||
client.inspect_swarm_secret(&self.secret).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ impl Resolve<super::Args> for InspectSwarmConfig {
|
||||
self,
|
||||
_: &super::Args,
|
||||
) -> anyhow::Result<Vec<SwarmConfig>> {
|
||||
inspect_swarm_config(&self.id).await
|
||||
inspect_swarm_config(&self.config).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +214,6 @@ impl Resolve<super::Args> for InspectSwarmStack {
|
||||
self,
|
||||
_: &super::Args,
|
||||
) -> anyhow::Result<SwarmStackLists> {
|
||||
inspect_swarm_stack(self.name).await
|
||||
inspect_swarm_stack(self.stack).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,12 +75,7 @@ fn convert_node(node: bollard::models::Node) -> SwarmNode {
|
||||
version: node.version.map(super::convert_object_version),
|
||||
created_at: node.created_at,
|
||||
updated_at: node.updated_at,
|
||||
spec: node.spec.map(|spec| NodeSpec {
|
||||
name: spec.name,
|
||||
labels: spec.labels,
|
||||
role: spec.role.map(convert_role),
|
||||
availability: spec.availability.map(convert_availability),
|
||||
}),
|
||||
spec: node.spec.map(convert_node_spec),
|
||||
description: node.description.map(|description| {
|
||||
NodeDescription {
|
||||
hostname: description.hostname,
|
||||
@@ -129,6 +124,15 @@ fn convert_node(node: bollard::models::Node) -> SwarmNode {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_node_spec(spec: bollard::models::NodeSpec) -> NodeSpec {
|
||||
NodeSpec {
|
||||
name: spec.name,
|
||||
labels: spec.labels,
|
||||
role: spec.role.map(convert_role),
|
||||
availability: spec.availability.map(convert_availability),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_role(
|
||||
role: bollard::secret::NodeSpecRoleEnum,
|
||||
) -> NodeSpecRoleEnum {
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use komodo_client::entities::{
|
||||
SearchCombinator,
|
||||
docker::{
|
||||
SwarmLists, config::SwarmConfig, node::SwarmNode,
|
||||
secret::SwarmSecret, service::SwarmService,
|
||||
stack::SwarmStackLists, swarm::SwarmInspectInfo, task::SwarmTask,
|
||||
SwarmLists,
|
||||
config::SwarmConfig,
|
||||
node::{NodeSpecAvailabilityEnum, NodeSpecRoleEnum, SwarmNode},
|
||||
secret::SwarmSecret,
|
||||
service::SwarmService,
|
||||
stack::SwarmStackLists,
|
||||
swarm::SwarmInspectInfo,
|
||||
task::SwarmTask,
|
||||
},
|
||||
update::Log,
|
||||
};
|
||||
@@ -30,7 +37,36 @@ pub struct PollSwarmStatusResponse {
|
||||
#[response(SwarmNode)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmNode {
|
||||
pub name: String,
|
||||
pub node: String,
|
||||
}
|
||||
|
||||
/// `docker node rm [OPTIONS] NODE [NODE...]`
|
||||
///
|
||||
/// https://docs.docker.com/reference/cli/docker/node/rm/
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Resolve)]
|
||||
#[response(Log)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct RmSwarmNodes {
|
||||
pub nodes: Vec<String>,
|
||||
pub force: bool,
|
||||
}
|
||||
|
||||
/// `docker node update [OPTIONS] NODE`
|
||||
///
|
||||
/// https://docs.docker.com/reference/cli/docker/node/update/
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Resolve)]
|
||||
#[response(Log)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct UpdateSwarmNode {
|
||||
pub node: String,
|
||||
pub availability: Option<NodeSpecAvailabilityEnum>,
|
||||
/// Add metadata to a swarm node using node labels (`key=value`).
|
||||
/// You can specify a node label as a key with an empty value.
|
||||
pub label_add: Option<HashMap<String, Option<String>>>,
|
||||
/// Remove labels by the label key.
|
||||
pub label_rm: Option<Vec<String>>,
|
||||
/// Update the node role (`worker`, `manager`)
|
||||
pub role: Option<NodeSpecRoleEnum>,
|
||||
}
|
||||
|
||||
// =========
|
||||
@@ -41,7 +77,7 @@ pub struct InspectSwarmNode {
|
||||
#[response(SwarmService)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmService {
|
||||
pub name: String,
|
||||
pub service: String,
|
||||
}
|
||||
|
||||
/// Get a swarm service's logs.
|
||||
@@ -110,6 +146,16 @@ pub struct GetSwarmServiceLogSearch {
|
||||
pub details: bool,
|
||||
}
|
||||
|
||||
/// `docker service rm SERVICE [SERVICE...]`
|
||||
///
|
||||
/// https://docs.docker.com/reference/cli/docker/service/rm/
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Resolve)]
|
||||
#[response(Log)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct RmSwarmServices {
|
||||
pub services: Vec<String>,
|
||||
}
|
||||
|
||||
// ======
|
||||
// Task
|
||||
// ======
|
||||
@@ -118,7 +164,7 @@ pub struct GetSwarmServiceLogSearch {
|
||||
#[response(SwarmTask)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmTask {
|
||||
pub id: String,
|
||||
pub task: String,
|
||||
}
|
||||
|
||||
// ========
|
||||
@@ -129,7 +175,7 @@ pub struct InspectSwarmTask {
|
||||
#[response(SwarmSecret)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmSecret {
|
||||
pub id: String,
|
||||
pub secret: String,
|
||||
}
|
||||
|
||||
// ========
|
||||
@@ -140,7 +186,7 @@ pub struct InspectSwarmSecret {
|
||||
#[response(Vec<SwarmConfig>)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmConfig {
|
||||
pub id: String,
|
||||
pub config: String,
|
||||
}
|
||||
|
||||
// =======
|
||||
@@ -152,5 +198,17 @@ pub struct InspectSwarmConfig {
|
||||
#[error(anyhow::Error)]
|
||||
pub struct InspectSwarmStack {
|
||||
/// The swarm stack name
|
||||
pub name: String,
|
||||
pub stack: String,
|
||||
}
|
||||
|
||||
/// `docker stack rm [OPTIONS] STACK [STACK...]`
|
||||
///
|
||||
/// https://docs.docker.com/reference/cli/docker/stack/rm/
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Resolve)]
|
||||
#[response(Log)]
|
||||
#[error(anyhow::Error)]
|
||||
pub struct RmSwarmStacks {
|
||||
pub stacks: Vec<String>,
|
||||
/// Do not wait for stack removal
|
||||
pub detach: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user