Struct nmstate::NetworkState

source ·
#[non_exhaustive]
pub struct NetworkState { pub hostname: Option<HostNameState>, pub dns: DnsState, pub rules: RouteRules, pub routes: Routes, pub interfaces: Interfaces, pub ovsdb: OvsDbGlobalConfig, pub prop_list: Vec<&'static str>, /* private fields */ }
Expand description

The NetworkState represents the whole network state including both kernel status and configurations provides by backends(NetworkManager, OpenvSwitch databas, and etc).

Example yaml(many lines omitted) serialized NetworkState would be:

hostname:
  running: host.example.org
  config: host.example.org
dns-resolver:
  config:
    server:
    - 2001:db8:1::
    - 192.0.2.1
    search: []
route-rules:
  config:
  - ip-from: 2001:db8:b::/64
    priority: 30000
    route-table: 200
  - ip-from: 192.0.2.2/32
    priority: 30000
    route-table: 200
routes:
  config:
  - destination: 2001:db8:a::/64
    next-hop-interface: eth1
    next-hop-address: 2001:db8:1::2
    metric: 108
    table-id: 200
  - destination: 192.168.2.0/24
    next-hop-interface: eth1
    next-hop-address: 192.168.1.3
    metric: 108
    table-id: 200
interfaces:
- name: eth1
  type: ethernet
  state: up
  mac-address: 0E:F9:2B:28:42:D9
  mtu: 1500
  ipv4:
    enabled: true
    dhcp: false
    address:
    - ip: 192.168.1.3
      prefix-length: 24
  ipv6:
    enabled: true
    dhcp: false
    autoconf: false
    address:
    - ip: 2001:db8:1::1
      prefix-length: 64
ovs-db:
  external_ids:
    hostname: host.example.org
    rundir: /var/run/openvswitch
    system-id: 176866c7-6dc8-400f-98ac-c658509ec09f
  other_config: {}

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§hostname: Option<HostNameState>

Hostname of current host.

§dns: DnsState

DNS resolver status, deserialize and serialize from/to dns-resolver.

§rules: RouteRules

Route rule, deserialize and serialize from/to route-rules.

§routes: Routes

Route

§interfaces: Interfaces

Network interfaces

§ovsdb: OvsDbGlobalConfig

The global configurations of OpenvSwitach daemon

§prop_list: Vec<&'static str>

Only for internal use. TODO: should changed to pub(crate)

Implementations§

Generate offline network configurations. Currently only support generate NetworkManager key file out of NetworkState.

The output is a HashMap with backend name as key and Vec<(config_file_name, config_content>)> as value.

The backend name for NetworkManager is NetworkManager.

Whether to perform kernel actions(also known as kernel only mode through the document this project) only or not. When set to false, nmstate will contact NetworkManager plugin for querying/applying the network state. Default is false.

By default(true), When nmstate applying the network state, after applied the network state, nmstate will verify whether the outcome network configuration matches with desired, if not, will rollback to state before apply(only when NetworkState::set_kernel_only() set to false. When set to false, no verification will be performed.

Only available when NetworkState::set_kernel_only() set to false. When set to false, the network configuration will not commit persistently, and will rollback after timeout defined by NetworkState::set_timeout(). Default to true for making the network state persistent.

Only available when NetworkState::set_commit() set to false. The time to wait before rolling back the network state to the state before [NetworkState::apply()` invoked.

Whether to include secrets(like password) in NetworkState::retrieve() Default is false.

Deprecated. No use at all.

Query activated/running network configuration excluding:

  • IP address retrieved by DHCP or IPv6 auto configuration.
  • DNS client resolver retrieved by DHCP or IPv6 auto configuration.
  • Routes retrieved by DHCPv4 or IPv6 router advertisement.
  • LLDP neighbor information.

When set to true, the network state be applied and only stored in memory which will be purged after system reboot.

Create empty NetworkState

Wrapping function of serde_json::from_str() with error mapped to NmstateError.

Append Interface into NetworkState

Replace secret string with <_password_hid_by_nmstate>

Rollback a checkpoint. Not available for kernel only mode. Only available for feature query_apply.

Commit a checkpoint. Not available for kernel only mode. Only available for feature query_apply.

Retrieve the NetworkState. Only available for feature query_apply.

Apply the NetworkState. Only available for feature query_apply.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The none-equivalent value.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.