Skip to main content

PoolGuard

Struct PoolGuard 

Source
pub struct PoolGuard<'a> { /* private fields */ }
Expand description

A checked-out connection from the pool.

Dereferences to Client for direct use. Automatically returns the connection to the pool when dropped (if the session is still alive). Broken sessions are discarded.

Implementations§

Source§

impl<'a> PoolGuard<'a>

Source

pub fn discard(&mut self)

Mark the connection as broken — it will be discarded on drop.

Methods from Deref<Target = Client>§

Source

pub async fn rpc(&mut self, rpc_content: &str) -> Result<String, NetconfError>

Send an arbitrary RPC and return the raw XML response content.

The rpc_content is wrapped in <rpc> tags with a message-id, sent to the device, and the inner content of <rpc-reply> is returned.

Use this for vendor-specific RPCs not covered by the standard NETCONF operations (get-config, edit-config, etc.).

Source

pub fn supports(&self, capability_uri: &str) -> bool

Check if the device supports a specific capability URI.

Source

pub fn vendor_name(&self) -> &str

Get the detected or configured vendor name (e.g., “junos”, “generic”).

Source

pub fn capabilities(&self) -> Option<&Capabilities>

Get the device’s capabilities.

Source

pub fn facts(&self) -> &Facts

Get the device facts (hostname, model, version, serial number).

Returns an empty Facts if gather_facts(false) was used during connection and gather_facts() hasn’t been called yet.

Source

pub async fn gather_facts(&mut self) -> Result<(), NetconfError>

Gather device facts by sending the vendor-specific facts RPC.

Use this to manually populate facts after connecting with gather_facts(false). Can also be called to refresh facts.

Source

pub fn session_alive(&self) -> bool

Check if the session is alive (established and not closed).

This is a fast in-memory check — it does not send any RPC to the device. Use this to detect sessions that have been explicitly closed or marked dead by a failed keepalive probe.

For a thorough check that verifies the transport is responsive, see probe_session().

Source

pub async fn probe_session(&mut self) -> bool

Probe the session by sending a lightweight RPC to verify the transport is responsive.

Returns true if the device responded, false if the probe failed (in which case the session is marked dead).

Source

pub async fn reconnect(&mut self) -> Result<(), NetconfError>

Re-establish the NETCONF session using the original connection parameters.

Closes the current session (if still open) and creates a fresh SSH connection, performs the hello exchange, and optionally gathers facts (matching the original gather_facts setting).

This is idempotent — safe to call even if the session is already dead.

Source

pub async fn get_config( &mut self, source: Datastore, ) -> Result<String, NetconfError>

Fetch configuration from a datastore.

Source

pub async fn get_config_filtered( &mut self, source: Datastore, filter: &str, ) -> Result<String, NetconfError>

Fetch configuration with a subtree filter.

Source

pub async fn get( &mut self, filter: Option<&str>, ) -> Result<String, NetconfError>

Fetch operational and configuration data.

Source

pub fn edit_config(&mut self, target: Datastore) -> EditConfigBuilder<'_>

Start building an edit-config operation.

Source

pub async fn lock(&mut self, target: Datastore) -> Result<(), NetconfError>

Lock a datastore.

Source

pub async fn unlock(&mut self, target: Datastore) -> Result<(), NetconfError>

Unlock a datastore.

Source

pub async fn discard_changes(&mut self) -> Result<(), NetconfError>

Discard uncommitted candidate changes.

Source

pub async fn commit(&mut self) -> Result<(), NetconfError>

Commit the candidate configuration.

Source

pub async fn validate(&mut self, source: Datastore) -> Result<(), NetconfError>

Validate a datastore.

Source

pub async fn close_session(&mut self) -> Result<(), NetconfError>

Close the NETCONF session gracefully.

Source

pub async fn kill_session( &mut self, session_id: u32, ) -> Result<(), NetconfError>

Kill another NETCONF session by ID.

Source

pub async fn confirmed_commit( &mut self, confirm_timeout: u32, ) -> Result<(), NetconfError>

Confirmed commit with automatic rollback timeout.

The device applies the candidate configuration but automatically rolls back if confirming_commit is not called within confirm_timeout seconds.

Requires the :confirmed-commit capability.

Source

pub async fn confirming_commit(&mut self) -> Result<(), NetconfError>

Confirm a previous confirmed-commit, making it permanent.

Source

pub async fn lock_or_kill_stale( &mut self, target: Datastore, ) -> Result<Option<u32>, NetconfError>

Lock a datastore, killing a stale session if the lock is held.

If the lock is denied because another (possibly crashed) session holds it, extracts the blocking session-id from the error and kills that session, then retries the lock.

Returns Ok(Some(killed_session_id)) if a stale session was killed, or Ok(None) if the lock was acquired without contention.

Source

pub async fn rpc_with_warnings( &mut self, rpc_content: &str, ) -> Result<(String, Vec<RpcErrorInfo>), NetconfError>

Send an arbitrary RPC, returning both the response and any warnings.

Like rpc(), but returns warnings alongside the data.

Source

pub async fn open_configuration( &mut self, mode: OpenConfigurationMode, ) -> Result<(), NetconfError>

Open a private or exclusive configuration database (Junos).

Required on chassis-clustered Junos devices before loading configuration. On standalone devices this is optional but harmless.

Source

pub async fn close_configuration(&mut self) -> Result<(), NetconfError>

Close a previously opened configuration database (Junos).

Source

pub async fn commit_configuration(&mut self) -> Result<(), NetconfError>

Commit using the Junos-native <commit-configuration/> RPC.

Use this instead of commit() on Junos devices, especially when a private/exclusive configuration database is open.

Source

pub async fn rollback_configuration( &mut self, rollback: u32, ) -> Result<(), NetconfError>

Rollback the candidate configuration to a previous commit (Junos).

rollback is the rollback index (0 = most recent commit, up to 49).

Source

pub async fn get_configuration_compare( &mut self, rollback: u32, ) -> Result<String, NetconfError>

Get the diff between candidate and a previous commit (Junos).

Returns the text-format diff. rollback is the rollback index (0 = most recent commit).

Source

pub async fn load_configuration( &mut self, action: LoadAction, format: LoadFormat, config: &str, ) -> Result<String, NetconfError>

Load configuration using the Junos <load-configuration> RPC.

On chassis-clustered devices, call open_configuration() first.

Source

pub fn requires_open_configuration(&self) -> bool

Whether this device requires <open-configuration> before loading config.

Returns true for Junos chassis-clustered devices.

Source

pub async fn create_subscription( &mut self, stream: Option<&str>, filter: Option<&str>, start_time: Option<&str>, stop_time: Option<&str>, ) -> Result<(), NetconfError>

Create a notification subscription (RFC 5277).

Requires the :notification capability. After subscription, the device sends <notification> messages asynchronously. Retrieve them with drain_notifications() or recv_notification().

Source

pub fn drain_notifications(&mut self) -> Vec<Notification>

Drain all buffered notifications, returning them and clearing the buffer.

Notifications are buffered when they arrive during RPC exchanges.

Source

pub async fn recv_notification( &mut self, ) -> Result<Option<Notification>, NetconfError>

Wait for the next notification from the device.

Returns Ok(None) if the connection is closed.

Source

pub fn has_notifications(&self) -> bool

Check if any notifications are buffered without blocking.

Source

pub fn has_subscription(&self) -> bool

Whether this session has an active notification subscription.

Trait Implementations§

Source§

impl<'a> Deref for PoolGuard<'a>

Source§

type Target = Client

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Client

Dereferences the value.
Source§

impl<'a> DerefMut for PoolGuard<'a>

Source§

fn deref_mut(&mut self) -> &mut Client

Mutably dereferences the value.
Source§

impl<'a> Drop for PoolGuard<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for PoolGuard<'a>

§

impl<'a> !RefUnwindSafe for PoolGuard<'a>

§

impl<'a> Send for PoolGuard<'a>

§

impl<'a> Sync for PoolGuard<'a>

§

impl<'a> Unpin for PoolGuard<'a>

§

impl<'a> UnsafeUnpin for PoolGuard<'a>

§

impl<'a> !UnwindSafe for PoolGuard<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more