-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the networking API over HTTP #1064
Changes from 4 commits
b6e9ff0
e58deb8
f35ef04
af3ce48
0a4634e
9506e1f
4c9f50a
de963bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
use crate::network::model::Connection; | ||
use crate::network::model::{AccessPoint, Connection, Device}; | ||
use agama_lib::network::types::DeviceType; | ||
use tokio::sync::oneshot; | ||
use uuid::Uuid; | ||
use zbus::zvariant::OwnedObjectPath; | ||
|
||
use super::{error::NetworkStateError, NetworkAdapterError}; | ||
use super::{error::NetworkStateError, model::GeneralState, NetworkAdapterError}; | ||
|
||
pub type Responder<T> = oneshot::Sender<T>; | ||
pub type ControllerConnection = (Connection, Vec<String>); | ||
|
@@ -21,11 +21,18 @@ pub enum Action { | |
DeviceType, | ||
Responder<Result<OwnedObjectPath, NetworkStateError>>, | ||
), | ||
/// Gets a connection | ||
/// Add a new connection | ||
NewConnection( | ||
Connection, | ||
Responder<Result<OwnedObjectPath, NetworkStateError>>, | ||
), | ||
/// Gets a connection by its Uuid | ||
GetConnection(Uuid, Responder<Option<Connection>>), | ||
/// Gets a connection | ||
GetConnections(Responder<Vec<Connection>>), | ||
/// Gets a connection path | ||
GetConnectionPath(Uuid, Responder<Option<OwnedObjectPath>>), | ||
/// Gets a connection | ||
/// Gets a connection path by id | ||
GetConnectionPathById(String, Responder<Option<OwnedObjectPath>>), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another candidate to drop :-) |
||
/// Get connections paths | ||
GetConnectionsPaths(Responder<Vec<OwnedObjectPath>>), | ||
|
@@ -34,19 +41,32 @@ pub enum Action { | |
Uuid, | ||
Responder<Result<ControllerConnection, NetworkStateError>>, | ||
), | ||
/// Gets all scanned access points | ||
GetAccessPoints(Responder<Vec<AccessPoint>>), | ||
/// Gets a device by its name | ||
GetDevice(String, Responder<Option<Device>>), | ||
/// Gets all the existent devices | ||
GetDevices(Responder<Vec<Device>>), | ||
/// Gets a device path | ||
GetDevicePath(String, Responder<Option<OwnedObjectPath>>), | ||
/// Get devices paths | ||
GetDevicesPaths(Responder<Vec<OwnedObjectPath>>), | ||
GetGeneralState(Responder<GeneralState>), | ||
/// Sets a controller's ports. It uses the Uuid of the controller and the IDs or interface names | ||
/// of the ports. | ||
SetPorts( | ||
Uuid, | ||
Box<Vec<String>>, | ||
Responder<Result<(), NetworkStateError>>, | ||
), | ||
/// Update a connection (replacing the old one). | ||
/// Updates a connection (replacing the old one). | ||
UpdateConnection(Box<Connection>), | ||
/// Updates the general network configuration | ||
UpdateGeneralState(GeneralState), | ||
/// Forces a wireless networks scan refresh | ||
RefreshScan(Responder<Result<(), NetworkAdapterError>>), | ||
/// Remove the connection with the given Uuid. | ||
RemoveConnection(Uuid), | ||
RemoveConnection(Uuid, Responder<Result<(), NetworkStateError>>), | ||
/// Apply the current configuration. | ||
Apply(Responder<Result<(), NetworkAdapterError>>), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,10 @@ impl Tree { | |
self.objects.devices_paths() | ||
} | ||
|
||
pub fn device_path(&self, name: &str) -> Option<OwnedObjectPath> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we want to evolve the D-Bus interface even more. We should be dropping most of it (and just keeping the signals). |
||
self.objects.device_path(name).map(|o| o.into()) | ||
} | ||
|
||
/// Returns all connection paths. | ||
pub fn connections_paths(&self) -> Vec<OwnedObjectPath> { | ||
self.objects.connections_paths() | ||
|
@@ -237,6 +241,12 @@ impl ObjectsRegistry { | |
path | ||
} | ||
|
||
/// Returns the path for a device. | ||
/// | ||
/// * `name`: device name. | ||
pub fn device_path(&self, name: &str) -> Option<ObjectPath> { | ||
self.devices.get(name).map(|p| p.as_ref()) | ||
} | ||
/// Returns the path for a connection. | ||
/// | ||
/// * `uuid`: connection ID. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent, it should be named
AddConnection
. I know it collides with theAddConnection
action for the D-Bus part, but perhaps it is time to start dropping them. But we can handle that in a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I planned to add this new method, but at the end used the AddConnection + UpdateConnection, but as you commented maybe it is the time to remove them and any DBUS specific action.