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
impl Host
pub fn new() -> Host
pub fn builder() -> HostBuilder
Sourcepub fn to_builder(&self) -> HostBuilder
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"));pub fn hostname(&self) -> Option<&str>
pub fn port(&self) -> Option<u16>
pub fn username(&self) -> Option<&str>
pub fn password(&self) -> Option<&str>
pub fn platform(&self) -> Option<&str>
pub fn groups(&self) -> Option<&ParentGroups>
pub fn data(&self) -> Option<&Data>
pub fn connection_options(&self) -> Option<&CustomTreeMap<ConnectionOptions>>
Sourcepub fn resolve_connection_params(
&self,
connection_type: &str,
) -> ResolvedConnectionParams
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’sconnection_optionsmap.
§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 portThe 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
impl BaseMethods for Host
Source§impl<'de> Deserialize<'de> for Host
impl<'de> Deserialize<'de> for Host
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Host
impl JsonSchema for Host
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more