Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions openstack_tui/.config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ mode_keybindings:
action:
ShowResource: "network.security_group_rule"
description: Rules
"ctrl-n":
action:
ResourceOp:
key: "network.security_group"
op: Create
description: Create
"ctrl-e":
action:
ResourceOp:
key: "network.security_group"
op: Update
description: Edit
"ctrl-d":
action:
ResourceOp:
key: "network.security_group"
op: Delete
description: Delete
"Resource(network.security_group_rule)":
"y":
action: DescribeApiResponse
Expand Down
1 change: 1 addition & 0 deletions openstack_tui/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ where
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ResourceOp {
Create,
Update,
Delete,
}

Expand Down
15 changes: 14 additions & 1 deletion openstack_tui/src/cloud_worker/network/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use openstack_sdk::AsyncOpenStack;

use crate::action::Action;
use crate::cloud_worker::common::CloudWorkerError;
use crate::cloud_worker::types::{ApiRequest, ExecuteApiRequest};
use crate::cloud_worker::types::{ApiRequest, ConfirmableRequest, ExecuteApiRequest};

pub mod network;
pub mod quota;
Expand Down Expand Up @@ -99,6 +99,19 @@ impl From<NetworkSubnetApiRequest> for NetworkApiRequest {
}
}

impl ConfirmableRequest for NetworkApiRequest {
fn get_confirm_message(&self) -> Option<String> {
match &self {
NetworkApiRequest::Network(req) => req.get_confirm_message(),
NetworkApiRequest::Router(req) => req.get_confirm_message(),
NetworkApiRequest::SecurityGroup(req) => req.get_confirm_message(),
NetworkApiRequest::SecurityGroupRule(req) => req.get_confirm_message(),
NetworkApiRequest::Subnet(req) => req.get_confirm_message(),
_ => None,
}
}
}

impl ExecuteApiRequest for NetworkApiRequest {
async fn execute_request(
&self,
Expand Down
11 changes: 10 additions & 1 deletion openstack_tui/src/cloud_worker/network/v2/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use openstack_sdk::AsyncOpenStack;
use crate::action::Action;
use crate::cloud_worker::NetworkApiRequest;
use crate::cloud_worker::common::CloudWorkerError;
use crate::cloud_worker::types::{ApiRequest, ExecuteApiRequest};
use crate::cloud_worker::types::{ApiRequest, ConfirmableRequest, ExecuteApiRequest};

pub mod delete;
pub mod list;
Expand All @@ -48,6 +48,15 @@ impl From<NetworkNetworkApiRequest> for ApiRequest {
}
}

impl ConfirmableRequest for NetworkNetworkApiRequest {
fn get_confirm_message(&self) -> Option<String> {
match &self {
NetworkNetworkApiRequest::Delete(req) => req.get_confirm_message(),
_ => None,
}
}
}

impl ExecuteApiRequest for NetworkNetworkApiRequest {
async fn execute_request(
&self,
Expand Down
11 changes: 10 additions & 1 deletion openstack_tui/src/cloud_worker/network/v2/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use openstack_sdk::AsyncOpenStack;
use crate::action::Action;
use crate::cloud_worker::NetworkApiRequest;
use crate::cloud_worker::common::CloudWorkerError;
use crate::cloud_worker::types::{ApiRequest, ExecuteApiRequest};
use crate::cloud_worker::types::{ApiRequest, ConfirmableRequest, ExecuteApiRequest};

pub mod delete;
pub mod list;
Expand All @@ -48,6 +48,15 @@ impl From<NetworkRouterApiRequest> for ApiRequest {
}
}

impl ConfirmableRequest for NetworkRouterApiRequest {
fn get_confirm_message(&self) -> Option<String> {
match &self {
NetworkRouterApiRequest::Delete(req) => req.get_confirm_message(),
_ => None,
}
}
}

impl ExecuteApiRequest for NetworkRouterApiRequest {
async fn execute_request(
&self,
Expand Down
27 changes: 25 additions & 2 deletions openstack_tui/src/cloud_worker/network/v2/security_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! `/v2.0/security-groups/{id}` REST operations bindings of Network
//! `/v2.0/security-groups` REST operations bindings of Network

use eyre::Result;
use serde::{Deserialize, Serialize};
Expand All @@ -26,20 +26,28 @@ use openstack_sdk::AsyncOpenStack;
use crate::action::Action;
use crate::cloud_worker::NetworkApiRequest;
use crate::cloud_worker::common::CloudWorkerError;
use crate::cloud_worker::types::{ApiRequest, ExecuteApiRequest};
use crate::cloud_worker::types::{ApiRequest, ConfirmableRequest, ExecuteApiRequest};

pub mod create;
pub mod delete;
pub mod list;
pub mod set;

pub use create::*;
pub use delete::*;
pub use list::*;
pub use set::*;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum NetworkSecurityGroupApiRequest {
/// Create
Create(Box<NetworkSecurityGroupCreate>),
/// Delete
Delete(Box<NetworkSecurityGroupDelete>),
/// List
List(Box<NetworkSecurityGroupList>),
/// Set
Set(Box<NetworkSecurityGroupSet>),
}

impl From<NetworkSecurityGroupApiRequest> for ApiRequest {
Expand All @@ -48,6 +56,15 @@ impl From<NetworkSecurityGroupApiRequest> for ApiRequest {
}
}

impl ConfirmableRequest for NetworkSecurityGroupApiRequest {
fn get_confirm_message(&self) -> Option<String> {
match &self {
NetworkSecurityGroupApiRequest::Delete(req) => req.get_confirm_message(),
_ => None,
}
}
}

impl ExecuteApiRequest for NetworkSecurityGroupApiRequest {
async fn execute_request(
&self,
Expand All @@ -56,12 +73,18 @@ impl ExecuteApiRequest for NetworkSecurityGroupApiRequest {
app_tx: &UnboundedSender<Action>,
) -> Result<(), CloudWorkerError> {
match self {
NetworkSecurityGroupApiRequest::Create(req) => {
req.execute_request(session, request, app_tx).await?;
}
NetworkSecurityGroupApiRequest::Delete(req) => {
req.execute_request(session, request, app_tx).await?;
}
NetworkSecurityGroupApiRequest::List(req) => {
req.execute_request(session, request, app_tx).await?;
}
NetworkSecurityGroupApiRequest::Set(req) => {
req.execute_request(session, request, app_tx).await?;
}
}
Ok(())
}
Expand Down
140 changes: 140 additions & 0 deletions openstack_tui/src/cloud_worker/network/v2/security_group/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

use derive_builder::Builder;
use eyre::{Report, Result, WrapErr};
use serde::{Deserialize, Serialize};
use std::fmt;
use tokio::sync::mpsc::UnboundedSender;

use crate::action::Action;
use crate::cloud_worker::common::CloudWorkerError;
use crate::cloud_worker::types::{ApiRequest, ExecuteApiRequest};

use openstack_sdk::api::network::v2::security_group::create::RequestBuilder;
use openstack_sdk::{AsyncOpenStack, api::QueryAsync};

#[derive(Builder, Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)]
#[builder(setter(strip_option))]
pub struct NetworkSecurityGroupCreate {
/// A `security_group` object.
security_group: SecurityGroup,
}

impl NetworkSecurityGroupCreate {
/// JSON Schema of the request body (verbatim from the OpenAPI spec, before
/// any codegen-side simplification -- keeps `required`, `oneOf`/mutex
/// constraints, `enum`, ranges and descriptions that the generated
/// struct's `Option<T>` fields alone do not express).
pub const BODY_SCHEMA: &'static str = "{\"description\": \"Request of the security-groups:post operation\", \"properties\": {\"security_group\": {\"description\": \"A `security_group` object.\", \"properties\": {\"description\": {\"description\": \"A human-readable description for the resource.\\nDefault is an empty string.\", \"maxLength\": 255, \"type\": \"string\"}, \"name\": {\"description\": \"Human-readable name of the resource.\", \"maxLength\": 255, \"type\": \"string\"}, \"stateful\": {\"description\": \"Indicates if the security group is stateful or stateless.\", \"type\": [\"boolean\", \"string\"]}, \"tenant_id\": {\"description\": \"The ID of the project.\", \"maxLength\": 255, \"type\": \"string\"}}, \"type\": \"object\"}}, \"type\": \"object\"}";
/// Commented YAML template for the create/edit-via-external-editor flow,
/// derived from the same raw OpenAPI request-body schema as
/// `BODY_SCHEMA` -- required fields uncommented, optional fields
/// commented out, enum values and descriptions inline as comments.
pub const EDITOR_TEMPLATE: &'static str = "security_group:\n # A human-readable description for the resource.\n # Default is an empty string.\n # description:\n # Human-readable name of the resource.\n # name:\n # Indicates if the security group is stateful or stateless.\n # stateful:\n # The ID of the project.\n # tenant_id:\n";
}
/// SecurityGroup data
#[derive(Builder, Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[builder(setter(strip_option))]
pub struct SecurityGroup {
/// A human-readable description for the resource. Default is an empty
/// string.
#[builder(default, setter(into))]
pub description: Option<String>,

/// Human-readable name of the resource.
#[builder(default, setter(into))]
pub name: Option<String>,

/// Indicates if the security group is stateful or stateless.
#[builder(default, setter(into))]
pub stateful: Option<bool>,

/// The ID of the project.
#[builder(default, setter(into))]
pub tenant_id: Option<String>,
}

impl TryFrom<&SecurityGroup>
for openstack_sdk::api::network::v2::security_group::create::SecurityGroupBuilder<'_>
{
type Error = Report;
fn try_from(value: &SecurityGroup) -> Result<Self, Self::Error> {
let mut ep_builder = Self::default();
if let Some(val) = &value.description {
ep_builder.description(val.clone());
}
if let Some(val) = &value.name {
ep_builder.name(val.clone());
}
if let Some(val) = &value.stateful {
ep_builder.stateful(*val);
}
if let Some(val) = &value.tenant_id {
ep_builder.tenant_id(val.clone());
}
Ok(ep_builder)
}
}
impl TryFrom<&SecurityGroup>
for openstack_sdk::api::network::v2::security_group::create::SecurityGroup<'_>
{
type Error = Report;
fn try_from(value: &SecurityGroup) -> Result<Self, Self::Error> {
let ep_builder: openstack_sdk::api::network::v2::security_group::create::SecurityGroupBuilder = TryFrom::try_from(value)?;
ep_builder
.build()
.wrap_err("cannot prepare request element `SecurityGroup`")
}
}

impl fmt::Display for NetworkSecurityGroupCreate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let parts: Vec<String> = Vec::new();
write!(f, "{}", parts.join(","))
}
}

impl TryFrom<&NetworkSecurityGroupCreate> for RequestBuilder<'_> {
type Error = Report;
fn try_from(value: &NetworkSecurityGroupCreate) -> Result<Self, Self::Error> {
let mut ep_builder = Self::default();
ep_builder.security_group(TryInto::<
openstack_sdk::api::network::v2::security_group::create::SecurityGroup,
>::try_into(&value.security_group)?);

Ok(ep_builder)
}
}

impl ExecuteApiRequest for NetworkSecurityGroupCreate {
async fn execute_request(
&self,
session: &mut AsyncOpenStack,
request: &ApiRequest,
app_tx: &UnboundedSender<Action>,
) -> Result<(), CloudWorkerError> {
let ep = TryInto::<RequestBuilder>::try_into(self)?
.build()
.wrap_err("Cannot prepare request")?;
app_tx.send(Action::ApiResponseData {
request: request.clone(),
data: ep.query_async(session).await?,
})?;
Ok(())
}
}
Loading