openstack_cli_network/v2/agent/
set.rs1use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::network::v2::agent::set;
33use openstack_types::network::v2::agent::response;
34
35#[derive(Args)]
41#[command(about = "Update agent")]
42pub struct AgentCommand {
43 #[command(flatten)]
45 query: QueryParameters,
46
47 #[command(flatten)]
49 path: PathParameters,
50
51 #[command(flatten)]
52 agent: Agent,
53}
54
55#[derive(Args)]
57struct QueryParameters {}
58
59#[derive(Args)]
61struct PathParameters {
62 #[arg(
64 help_heading = "Path parameters",
65 id = "path_param_id",
66 value_name = "ID"
67 )]
68 id: String,
69}
70#[derive(Args, Clone)]
72struct Agent {
73 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
76 admin_state_up: Option<bool>,
77
78 #[arg(help_heading = "Body parameters", long)]
81 description: Option<String>,
82
83 #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
85 no_description: bool,
86}
87
88impl AgentCommand {
89 pub async fn take_action<C: CliArgs>(
91 &self,
92 parsed_args: &C,
93 client: &mut AsyncOpenStack,
94 ) -> Result<(), OpenStackCliError> {
95 info!("Set Agent");
96
97 let op = OutputProcessor::from_args(parsed_args, Some("network.agent"), Some("set"));
98 op.validate_args(parsed_args)?;
99
100 let mut ep_builder = set::Request::builder();
101
102 ep_builder.id(&self.path.id);
103
104 let args = &self.agent;
107 let mut agent_builder = set::AgentBuilder::default();
108 if let Some(val) = &args.admin_state_up {
109 agent_builder.admin_state_up(*val);
110 }
111
112 if let Some(val) = &args.description {
113 agent_builder.description(Some(val.into()));
114 } else if args.no_description {
115 agent_builder.description(None);
116 }
117
118 ep_builder.agent(
119 agent_builder
120 .build()
121 .wrap_err("error preparing the request data")?,
122 );
123
124 let ep = ep_builder
125 .build()
126 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
127
128 let data: serde_json::Value = ep.query_async(client).await?;
129
130 op.output_single::<response::set::AgentResponse>(data.clone())?;
131 op.show_command_hint()?;
133 Ok(())
134 }
135}