Skip to content

Commit 84cd8a0

Browse files
authored
feat: Add port set and binding commands (#1231)
1 parent 64494ce commit 84cd8a0

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

openstack_cli/src/network/v2/port.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ use openstack_sdk::AsyncOpenStack;
2020

2121
use crate::{Cli, OpenStackCliError};
2222

23+
pub mod binding;
2324
pub mod create;
2425
pub mod delete;
2526
pub mod list;
27+
pub mod set;
2628
pub mod show;
2729
pub mod tag;
2830

@@ -38,9 +40,11 @@ pub struct PortCommand {
3840
#[allow(missing_docs)]
3941
#[derive(Subcommand)]
4042
pub enum PortCommands {
43+
Binding(Box<binding::BindingCommand>),
4144
Create(Box<create::PortCommand>),
4245
Delete(delete::PortCommand),
4346
List(Box<list::PortsCommand>),
47+
Set(Box<set::PortCommand>),
4448
Show(Box<show::PortCommand>),
4549
Tag(Box<tag::TagCommand>),
4650
}
@@ -53,9 +57,11 @@ impl PortCommand {
5357
session: &mut AsyncOpenStack,
5458
) -> Result<(), OpenStackCliError> {
5559
match &self.command {
60+
PortCommands::Binding(cmd) => cmd.take_action(parsed_args, session).await,
5661
PortCommands::Create(cmd) => cmd.take_action(parsed_args, session).await,
5762
PortCommands::Delete(cmd) => cmd.take_action(parsed_args, session).await,
5863
PortCommands::List(cmd) => cmd.take_action(parsed_args, session).await,
64+
PortCommands::Set(cmd) => cmd.take_action(parsed_args, session).await,
5965
PortCommands::Show(cmd) => cmd.take_action(parsed_args, session).await,
6066
PortCommands::Tag(cmd) => cmd.take_action(parsed_args, session).await,
6167
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
//
13+
// SPDX-License-Identifier: Apache-2.0
14+
15+
//! Binding binding commands
16+
17+
use clap::{Parser, Subcommand};
18+
19+
use openstack_sdk::AsyncOpenStack;
20+
21+
use crate::{Cli, OpenStackCliError};
22+
23+
pub mod activate;
24+
pub mod create;
25+
pub mod delete;
26+
pub mod list;
27+
//pub mod set;
28+
//pub mod show;
29+
30+
/// Binding commands
31+
#[derive(Parser)]
32+
pub struct BindingCommand {
33+
/// subcommand
34+
#[command(subcommand)]
35+
command: BindingCommands,
36+
}
37+
38+
/// Supported subcommands
39+
#[allow(missing_docs)]
40+
#[derive(Subcommand)]
41+
pub enum BindingCommands {
42+
Activate(Box<activate::BindingCommand>),
43+
Create(Box<create::BindingCommand>),
44+
Delete(delete::BindingCommand),
45+
List(Box<list::BindingsCommand>),
46+
// Set(Box<set::BindingCommand>),
47+
// Show(Box<show::BindingCommand>),
48+
}
49+
50+
impl BindingCommand {
51+
/// Perform command action
52+
pub async fn take_action(
53+
&self,
54+
parsed_args: &Cli,
55+
session: &mut AsyncOpenStack,
56+
) -> Result<(), OpenStackCliError> {
57+
match &self.command {
58+
BindingCommands::Activate(cmd) => cmd.take_action(parsed_args, session).await,
59+
BindingCommands::Create(cmd) => cmd.take_action(parsed_args, session).await,
60+
BindingCommands::Delete(cmd) => cmd.take_action(parsed_args, session).await,
61+
BindingCommands::List(cmd) => cmd.take_action(parsed_args, session).await,
62+
// BindingCommands::Set(cmd) => cmd.take_action(parsed_args, session).await,
63+
// BindingCommands::Show(cmd) => cmd.take_action(parsed_args, session).await,
64+
}
65+
}
66+
}

openstack_cli/src/network/v2/port/set.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ use crate::output::OutputProcessor;
3030

3131
use crate::common::parse_key_val;
3232
use clap::ValueEnum;
33-
use eyre::WrapErr;
3433
use openstack_sdk::api::QueryAsync;
3534
use openstack_sdk::api::find;
3635
use openstack_sdk::api::network::v2::port::find;
3736
use openstack_sdk::api::network::v2::port::set;
3837
use openstack_types::network::v2::port::response::set::PortResponse;
3938
use serde_json::Value;
40-
use std::collections::BTreeMap;
4139

4240
/// Updates a port.
4341
///
@@ -370,7 +368,7 @@ impl PortCommand {
370368
v.as_object()
371369
.expect("Is a valid Json object")
372370
.into_iter()
373-
.map(|(k, v)| (k.into(), v.clone().into()))
371+
.map(|(k, v)| (k.into(), v.clone()))
374372
.collect::<BTreeMap<_, Value>>()
375373
})
376374
.collect::<Vec<_>>(),

openstack_cli/tests/network/v2/port/binding/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ mod activate_autogen;
1616
mod create_autogen;
1717
mod delete_autogen;
1818
mod list_autogen;
19-
mod set_autogen;
20-
mod show_autogen;
19+
// mod set_autogen;
20+
// mod show_autogen;
2121

2222
use assert_cmd::prelude::*;
2323
use std::process::Command;
@@ -26,7 +26,7 @@ use std::process::Command;
2626
fn help() -> Result<(), Box<dyn std::error::Error>> {
2727
let mut cmd = Command::cargo_bin("osc")?;
2828

29-
cmd.arg("network").arg("port")..arg("binding").arg("--help");
29+
cmd.args(["network", "port", "binding", "--help"]);
3030
cmd.assert().success();
3131

3232
Ok(())

openstack_cli/tests/network/v2/port/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
// mod add_allowed_address_pairs_autogen;
16-
// mod binding;
16+
mod binding;
1717
mod create_autogen;
1818
mod delete_autogen;
1919
mod list;
2020
mod list_autogen;
21-
// mod set_autogen;
21+
mod set_autogen;
2222
mod show_autogen;
2323
mod tag;
2424

@@ -29,7 +29,7 @@ use std::process::Command;
2929
fn help() -> Result<(), Box<dyn std::error::Error>> {
3030
let mut cmd = Command::cargo_bin("osc")?;
3131

32-
cmd.arg("network").arg("port").arg("--help");
32+
cmd.args(["network", "port", "--help"]);
3333
cmd.assert().success();
3434

3535
Ok(())

0 commit comments

Comments
 (0)