Skip to main content

Host

Struct Host 

Source
pub struct Host { /* private fields */ }
Expand description

Represents a single host in the inventory with connection parameters and metadata.

A Host defines the configuration for connecting to and managing a single network device or server. It contains optional connection parameters (hostname, port, credentials, platform), group membership information, arbitrary data, and connection-specific overrides.

Hosts are the fundamental unit of the inventory system. They can inherit configuration from groups and defaults through the inventory hierarchy, with host-level settings taking highest precedence during parameter resolution.

§Fields

  • hostname - Optional hostname or IP address for the host. This is the primary identifier used for network connections. If not specified, it may be inherited from groups or defaults.

  • port - Optional port number for connections. If not specified, defaults may be applied during connection parameter resolution or connection implementations may use their default ports.

  • username - Optional username for authentication. Used for establishing connections to the host. Can be inherited from groups or defaults if not specified.

  • password - Optional password for authentication. Used in conjunction with username for connection authentication. Can be inherited from groups or defaults if not specified.

  • platform - Optional platform identifier (e.g., “linux”, “cisco_ios”, “junos”). Used to determine platform-specific behavior and connection handling. Can be inherited from groups or defaults if not specified.

  • groups - Optional parent group names that this host belongs to. Groups provide inherited configuration through the inventory hierarchy. Multiple groups can be specified, and their configurations are merged in order.

  • data - Optional arbitrary JSON data associated with the host. Allows storing custom metadata and configuration that doesn’t fit standard fields. Can be merged with group and default data during resolution.

  • connection_options - Optional map of connection-specific overrides keyed by connection type (e.g., “ssh”, “netconf”, “http”). Allows per-connection-plugin-name customization of connection parameters, overriding base host settings for specific connection plugin names.

§Deserialization

  • Unknown fields are rejected via #[serde(deny_unknown_fields)] to catch configuration errors
  • All fields are optional, allowing minimal host definitions
  • Connection options accept arbitrary map keys for different connection plugin names

§Examples

let host = Host::builder()
    .hostname("10.0.0.1")
    .port(22)
    .username("admin")
    .platform("linux")
    .build();

assert_eq!(host.hostname(), Some("10.0.0.1"));
assert_eq!(host.port(), Some(22));

Implementations§

Source§

impl Host

Source

pub fn new() -> Host

Source

pub fn builder() -> HostBuilder

Source

pub fn to_builder(&self) -> HostBuilder

Converts this Host instance into a builder for modification.

This method creates a new HostBuilder initialized with all the current values from this Host instance. This is useful when you need to create a modified copy of an existing host while preserving most of the original configuration.

§Returns

Returns a HostBuilder with all fields initialized to match the current Host instance. The builder can then be used to modify specific fields before calling build() to create a new Host instance.

§Examples
let host = Host::builder()
    .hostname("10.0.0.1")
    .port(22)
    .username("admin")
    .build();

let modified = host.to_builder()
    .port(2222)
    .build();

assert_eq!(modified.hostname(), Some("10.0.0.1"));
assert_eq!(modified.port(), Some(2222));
assert_eq!(modified.username(), Some("admin"));
Source

pub fn hostname(&self) -> Option<&str>

Source

pub fn port(&self) -> Option<u16>

Source

pub fn username(&self) -> Option<&str>

Source

pub fn password(&self) -> Option<&str>

Source

pub fn platform(&self) -> Option<&str>

Source

pub fn groups(&self) -> Option<&ParentGroups>

Source

pub fn data(&self) -> Option<&Data>

Source

pub fn connection_options(&self) -> Option<&CustomTreeMap<ConnectionOptions>>

Source

pub fn resolve_connection_params( &self, connection_type: &str, ) -> ResolvedConnectionParams

Resolves connection parameters for a specific connection plugin name by merging host-level settings with connection-specific overrides.

This method uses only the fields on this Host. It does not apply defaults or group inheritance. To include those, use Inventory::resolve_connection_params (see the second example below).

This method creates a complete set of connection parameters by starting with the host’s base connection fields (hostname, port, username, password, platform) and then applying any connection-specific overrides from the connection_options map. Connection-specific options take precedence over base host fields.

§Parameters
  • connection_type - A string identifying the connection plugin name to resolve parameters for (e.g., “ssh”, “netconf”, “http”). This is used as the key to lookup connection-specific options in the host’s connection_options map.
§Returns

Returns a ResolvedConnectionParams struct containing the fully resolved connection parameters. If the host has connection-specific options for the given connection_type, those values override the corresponding base host fields. Fields not specified in either location will be None (except hostname, which defaults to an empty string if not set).

§Examples
let options = ConnectionOptions::builder().port(830).build();

let host = Host::builder()
    .hostname("10.0.0.1")
    .port(22)
    .connection_options("netconf", options)
    .build();

let params = host.resolve_connection_params("netconf");
assert_eq!(params.hostname, "10.0.0.1");
assert_eq!(params.port, Some(830)); // Connection-specific port overrides base port

The following example shows how to resolve parameters through Inventory, which applies defaults and group inheritance before connection-specific overrides.

let mut hosts = Hosts::new();
let options = ConnectionOptions::builder().port(830).build();
let host = Host::builder()
    .hostname("10.0.0.1")
    .port(22)
    .connection_options("netconf", options)
    .build();
hosts.add_host("router1", host);
let inventory = Inventory::builder().hosts(hosts).build();

let params = inventory
    .resolve_connection_params("router1", "netconf")
    .expect("resolved params");
assert_eq!(params.port, Some(830));

Trait Implementations§

Source§

impl BaseMethods for Host

Source§

fn schema() -> String
where Self: Sized + JsonSchema,

Source§

impl Clone for Host

Source§

fn clone(&self) -> Host

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Host

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Host

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Host

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Host

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Host

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Host

§

impl RefUnwindSafe for Host

§

impl Send for Host

§

impl Sync for Host

§

impl Unpin for Host

§

impl UnsafeUnpin for Host

§

impl UnwindSafe for Host

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.