Skip to content

Adapt network to the new config based HTTP API.#2840

Closed
teclator wants to merge 20 commits intoapi-v2from
api-v2_network
Closed

Adapt network to the new config based HTTP API.#2840
teclator wants to merge 20 commits intoapi-v2from
api-v2_network

Conversation

@teclator
Copy link
Copy Markdown
Contributor

@teclator teclator commented Oct 31, 2025

Problem

There is a new config based HTTP API and all the services needs to be adapted. The aim of this PR is to adapt network.

Solution

  • Implement the support for using the new HTTP API using the already implemented Network service instead of the new services.
  • Adapted the web to consume the new storage HTTP API.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 76.11% (+11.6%) from 64.486%
when pulling df57b0a on api-v2_network
into 973191e on api-v2.

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 3, 2025

Coverage Status

coverage: 76.091% (+12.0%) from 64.118%
when pulling bb17a26 on api-v2_network
into a6c2788 on api-v2.

@teclator teclator marked this pull request as ready for review November 10, 2025 12:59
Copy link
Copy Markdown
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! But it will be a long review (due to the size of the changes). I have submitted a first round of comments.

#[error(transparent)]
Storage(#[from] storage::start::Error),
#[error(transparent)]
NetworkSystem(#[from] network::NetworkSystemError),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NetworkSystem(#[from] network::NetworkSystemError),
Network(#[from] network::NetworkSystemError),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, why are you using NetworkSystemError? Just mentioning because you already have a agama_network::error:Error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to move it to agama_network::error::Error instead of NetworkSystemError or NetworkAdapterError but probably defined it but didn't moved it yet.

impl TryFrom<ConnectionCollection> for NetworkConnectionsCollection {
type Error = NetworkStateError;

fn try_from(collection: ConnectionCollection) -> Result<Self, Self::Error> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function really fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same mentioned above, it should be a From instead of TryFrom but inherited from what we had for the Connection.

if let Some(bridge) = &net_conn.bridge {
ports = bridge.ports.clone();
}
if let Some(bond) = &net_conn.bond {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see logic like this one in several places. I wonder if we could have some higher level API for that).

}

for (port, uuid) in controller_ports {
let default = Connection::new(port.clone(), DeviceType::Ethernet);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not get me wrong, this is fine, but you are creating a struct that you might not use at the end. What about something like:

let mut conn = conns
    .iter()
    .find(|c| c.id == port || c.interface.as_ref() == Some(&port))
    .cloned()
    .unwrap_or_else(|| Connection::new(port, DeviceType::Ethernet));

}
}

impl TryFrom<NetworkState> for NetworkConnectionsCollection {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression that we are abusing TryFrom. This or the implementation of TryFrom<NetworkState> for SystemInfo are some examples.

impl TryFrom<NetworkState> for NetworkConnectionsCollection {
type Error = NetworkStateError;

fn try_from(state: NetworkState) -> Result<Self, Self::Error> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same comments I did for TryFrom<ConnectionCollection> for NetworkConnectionsCollection still apply.

teclator added a commit that referenced this pull request Nov 11, 2025
## Problem

There is a new config based HTTP API and all the services needs to be
adapted. The aim of this PR is to adapt the network backend service
(replace #2840).

- #2715

## Solution

In the new architecture all the Agama modules will live in its own
package implementing the actors/service as described in
(#2715), but as network was
already using a actors model using an enums approach it was decided to
use the current service in the first iteration of changes.

### Changes done

- Added the actions for getting the system, proposal and current network
configuration using the actual actions passing messages system based on
enums.
- All the structs or types that are related to the API (needs to be
serialized) has been moved to agama-utils, it was decided to not depend
on agama-lib anymore. The types will be re-exported to be used by
agama-network when needed.
- As the current merge is concatenating the connections array, the patch
**(updateConfig)** will replace the connections with the given one when
present, but is something we need to revisit and decide how to do it in
a better way.
- Removed the network web service.
- As the proposal, system info and config contains similar collections
and just change the absence or presence of some of them we have
introduced the **NetworkCollection** and
**NetworkConnectionCollections** in order to do the conversion between
them.

### TODO

- Move to the actors/service model using traits instead of enums and
adding the issues and progress monitor to the network service.
- Remove all the actions which are not needed anymore (old network web
service).
- Add unit tests covering the new approach.
@teclator
Copy link
Copy Markdown
Contributor Author

As commented this PR has been replaced by #2862 and a following PR for adapting the UI.

@teclator teclator closed this Nov 20, 2025
@teclator teclator deleted the api-v2_network branch November 20, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants