ts fn can go. its getting less uses!
This commit is contained in:
+10
-6
@@ -39,8 +39,11 @@ pub enum Command {
|
|||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
pub struct LeasesArgs {
|
pub struct LeasesArgs {
|
||||||
/// Include best-known current neighbor state for each lease IP.
|
/// Legacy: include neighbor state on lease rows. Prefer `wakey inventory`.
|
||||||
#[arg(long)]
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "Deprecated: include neighbor state on lease rows. Prefer `wakey inventory`."
|
||||||
|
)]
|
||||||
pub include_state: bool,
|
pub include_state: bool,
|
||||||
/// Print machine-readable JSON instead of a table.
|
/// Print machine-readable JSON instead of a table.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
@@ -201,10 +204,11 @@ pub async fn run(cli: Cli) -> Result<()> {
|
|||||||
json = args.json,
|
json = args.json,
|
||||||
"dispatching leases command"
|
"dispatching leases command"
|
||||||
);
|
);
|
||||||
let leases = wakey::get_leases(wakey_core::LeaseQuery {
|
let leases = if args.include_state {
|
||||||
include_state: args.include_state,
|
wakey::get_leases_with_neighbor_state().await?
|
||||||
})
|
} else {
|
||||||
.await?;
|
wakey::get_leases().await?
|
||||||
|
};
|
||||||
if args.json {
|
if args.json {
|
||||||
println!("{}", serde_json::to_string_pretty(&leases)?);
|
println!("{}", serde_json::to_string_pretty(&leases)?);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@ pub use wakey_linux;
|
|||||||
|
|
||||||
pub use service::{
|
pub use service::{
|
||||||
broadcast_wake_targets, get_interface_summaries, get_interface_summary, get_ips, get_leases,
|
broadcast_wake_targets, get_interface_summaries, get_interface_summary, get_ips, get_leases,
|
||||||
inventory, leases_without_state, local_observation_to_fact, merge_devices,
|
get_leases_with_neighbor_state, inventory, leases_without_state, local_observation_to_fact,
|
||||||
merge_devices_with_observations, resolve_devices, resolve_query, resolve_selector,
|
merge_devices, merge_devices_with_observations, resolve_devices, resolve_query,
|
||||||
resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
|
resolve_selector, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
|
||||||
};
|
};
|
||||||
pub use wakey_linux::dhcp::{list_local_observations, observe_dhcp_event, observe_neighbor_event};
|
pub use wakey_linux::dhcp::{list_local_observations, observe_dhcp_event, observe_neighbor_event};
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ pub async fn resolve_devices(input: impl Into<String>) -> Result<Vec<Device>> {
|
|||||||
/// directly from raw Linux source rows.
|
/// directly from raw Linux source rows.
|
||||||
pub async fn inventory(query: InventoryQuery) -> Result<DeviceInventory> {
|
pub async fn inventory(query: InventoryQuery) -> Result<DeviceInventory> {
|
||||||
let neighbors = wakey_linux::devices::query_neighbors(&query).await?;
|
let neighbors = wakey_linux::devices::query_neighbors(&query).await?;
|
||||||
let leases = get_leases(wakey_core::LeaseQuery {
|
let leases = get_leases().await?;
|
||||||
include_state: false,
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
let observations = match wakey_linux::dhcp::list_local_observations().await {
|
let observations = match wakey_linux::dhcp::list_local_observations().await {
|
||||||
Ok(observations) => observations
|
Ok(observations) => observations
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|||||||
+14
-8
@@ -1,16 +1,22 @@
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use wakey_core::{DhcpLease, DhcpLeaseWithState, LeaseQuery};
|
use wakey_core::{DhcpLease, DhcpLeaseWithState};
|
||||||
|
|
||||||
/// Read DHCP leases and optionally enrich them with current neighbor-state data.
|
/// Read DHCP leases from dnsmasq plus remembered hook names.
|
||||||
pub async fn get_leases(query: LeaseQuery) -> Result<Vec<DhcpLeaseWithState>> {
|
pub async fn get_leases() -> Result<Vec<DhcpLeaseWithState>> {
|
||||||
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
|
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
|
||||||
.await
|
.await
|
||||||
.context("failed to read DHCP leases")?;
|
.context("failed to read DHCP leases")?;
|
||||||
if query.include_state {
|
Ok(leases_without_state(leases))
|
||||||
Ok(wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await)
|
}
|
||||||
} else {
|
|
||||||
Ok(leases_without_state(leases))
|
/// Read DHCP leases and enrich them with current neighbor state.
|
||||||
}
|
///
|
||||||
|
/// Prefer inventory for device status; this exists for the legacy leases view.
|
||||||
|
pub async fn get_leases_with_neighbor_state() -> Result<Vec<DhcpLeaseWithState>> {
|
||||||
|
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
|
||||||
|
.await
|
||||||
|
.context("failed to read DHCP leases")?;
|
||||||
|
Ok(wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrap raw DHCP leases in the current service output shape without neighbor state.
|
/// Wrap raw DHCP leases in the current service output shape without neighbor state.
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ pub use inventory::{
|
|||||||
inventory, local_observation_to_fact, merge_devices, merge_devices_with_observations,
|
inventory, local_observation_to_fact, merge_devices, merge_devices_with_observations,
|
||||||
resolve_devices,
|
resolve_devices,
|
||||||
};
|
};
|
||||||
pub use leases::{get_leases, leases_without_state};
|
pub use leases::{get_leases, get_leases_with_neighbor_state, leases_without_state};
|
||||||
pub use query::{resolve_query, resolve_selector};
|
pub use query::{resolve_query, resolve_selector};
|
||||||
pub use wake::{
|
pub use wake::{
|
||||||
broadcast_wake_targets, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
|
broadcast_wake_targets, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
|
||||||
|
|||||||
+1
-1
@@ -293,7 +293,7 @@ function buildCommandPayload(
|
|||||||
return { command: { kind: "devs", dev: null, up_only: false } };
|
return { command: { kind: "devs", dev: null, up_only: false } };
|
||||||
}
|
}
|
||||||
if (kind === "leases") {
|
if (kind === "leases") {
|
||||||
return { command: { kind: "leases", include_state: true } };
|
return { command: { kind: "leases", include_state: false } };
|
||||||
}
|
}
|
||||||
if (kind === "inventory") {
|
if (kind === "inventory") {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -25,8 +25,13 @@ pub struct DhcpLeaseWithState {
|
|||||||
pub nud_state: Option<NeighborState>,
|
pub nud_state: Option<NeighborState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options for lease retrieval from the service layer.
|
/// Legacy options for lease retrieval from the service layer.
|
||||||
|
///
|
||||||
|
/// Prefer inventory for device state; lease rows are now best treated as a raw
|
||||||
|
/// dnsmasq snapshot.
|
||||||
|
#[deprecated(note = "prefer get_leases() or inventory; neighbor state belongs in inventory")]
|
||||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct LeaseQuery {
|
pub struct LeaseQuery {
|
||||||
|
#[deprecated(note = "prefer inventory for device state")]
|
||||||
pub include_state: bool,
|
pub include_state: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ mod query;
|
|||||||
mod wake;
|
mod wake;
|
||||||
|
|
||||||
pub use device::{Device, DeviceId, DeviceInventory, DeviceObservationFact, Presence};
|
pub use device::{Device, DeviceId, DeviceInventory, DeviceObservationFact, Presence};
|
||||||
pub use dhcp::{DhcpLease, DhcpLeaseWithState, LeaseQuery};
|
#[allow(deprecated)]
|
||||||
|
pub use dhcp::LeaseQuery;
|
||||||
|
pub use dhcp::{DhcpLease, DhcpLeaseWithState};
|
||||||
pub use interface::{InterfaceAddr, InterfaceSummary};
|
pub use interface::{InterfaceAddr, InterfaceSummary};
|
||||||
pub use neighbor::{NeighborEntry, NeighborParseError, NeighborState, parse_neighbor_line};
|
pub use neighbor::{NeighborEntry, NeighborParseError, NeighborState, parse_neighbor_line};
|
||||||
pub use query::{InventoryQuery, InventoryQueryBuilder, NamePath, Query, QueryInput};
|
pub use query::{InventoryQuery, InventoryQueryBuilder, NamePath, Query, QueryInput};
|
||||||
|
|||||||
@@ -109,9 +109,7 @@ pub async fn list_local_observations_from_path(
|
|||||||
Ok(list_local_observations_from_store(store))
|
Ok(list_local_observations_from_store(store))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_local_observations_from_store(
|
fn list_local_observations_from_store(store: LocalObservationStore) -> Vec<LocalDeviceObservation> {
|
||||||
store: LocalObservationStore,
|
|
||||||
) -> Vec<LocalDeviceObservation> {
|
|
||||||
let mut out = Vec::with_capacity(store.dhcp_clients.len() + store.neighbors.len());
|
let mut out = Vec::with_capacity(store.dhcp_clients.len() + store.neighbors.len());
|
||||||
out.extend(
|
out.extend(
|
||||||
store
|
store
|
||||||
|
|||||||
Reference in New Issue
Block a user