Struct nmstate::NetworkState

source ·
#[non_exhaustive]
pub struct NetworkState { pub description: String, pub hostname: Option<HostNameState>, pub dns: Option<DnsState>, pub rules: RouteRules, pub routes: Routes, pub interfaces: Interfaces, pub ovsdb: Option<OvsDbGlobalConfig>, pub ovn: OvnConfiguration, /* 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.
§description: String

Description for the whole desire state. Currently it will not be persisted by network backend and will be ignored during applying or querying.

§hostname: Option<HostNameState>

Hostname of current host.

§dns: Option<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: Option<OvsDbGlobalConfig>

The global configurations of OpenvSwitach daemon

§ovn: OvnConfiguration

The OVN configuration in the system

Implementations§

source§

impl NetworkState

source

pub fn gen_conf( &self, ) -> Result<HashMap<String, Vec<(String, String)>>, NmstateError>

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.

source§

impl NetworkState

source

pub fn is_empty(&self) -> bool

source

pub fn set_kernel_only(&mut self, value: bool) -> &mut Self

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.

source

pub fn kernel_only(&self) -> bool

source

pub fn set_verify_change(&mut self, value: bool) -> &mut Self

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.

source

pub fn set_commit(&mut self, value: bool) -> &mut Self

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.

source

pub fn set_timeout(&mut self, value: u32) -> &mut Self

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.

source

pub fn set_include_secrets(&mut self, value: bool) -> &mut Self

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

source

pub fn set_include_status_data(&mut self, value: bool) -> &mut Self

Deprecated. No use at all.

source

pub fn set_running_config_only(&mut self, value: bool) -> &mut Self

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.
source

pub fn set_memory_only(&mut self, value: bool) -> &mut Self

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

source

pub fn new() -> Self

Create empty NetworkState

source

pub fn new_from_json(net_state_json: &str) -> Result<Self, NmstateError>

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

source

pub fn new_from_yaml(net_state_yaml: &str) -> Result<Self, NmstateError>

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

source

pub fn append_interface_data(&mut self, iface: Interface)

Append Interface into NetworkState

source

pub fn hide_secrets(&mut self)

Replace secret string with <_password_hid_by_nmstate>

source§

impl NetworkState

source

pub fn checkpoint_rollback(checkpoint: &str) -> Result<(), NmstateError>

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

source

pub fn checkpoint_commit(checkpoint: &str) -> Result<(), NmstateError>

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

source

pub fn retrieve(&mut self) -> Result<&mut Self, NmstateError>

Retrieve the NetworkState. Only available for feature query_apply.

source

pub async fn retrieve_async(&mut self) -> Result<&mut Self, NmstateError>

Retrieve the NetworkState. Only available for feature query_apply.

source

pub fn apply(&self) -> Result<(), NmstateError>

Apply the NetworkState. Only available for feature query_apply.

source

pub async fn apply_async(&self) -> Result<(), NmstateError>

Apply the NetworkState. Only available for feature query_apply.

source

pub fn gen_diff(&self, current: &Self) -> Result<Self, NmstateError>

Generate new NetworkState contains only changed properties

source§

impl NetworkState

source

pub fn generate_revert(&self, current: &Self) -> Result<Self, NmstateError>

source§

impl NetworkState

source

pub fn merge_desire(&mut self, new_desire: &Self)

Only used for statistics by merging multiple desire states to generate the final statistics.

source

pub fn statistic( &self, current: &Self, ) -> Result<NmstateStatistic, NmstateError>

Trait Implementations§

source§

impl Clone for NetworkState

source§

fn clone(&self) -> NetworkState

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for NetworkState

source§

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

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

impl Default for NetworkState

source§

fn default() -> NetworkState

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

impl<'de> Deserialize<'de> for NetworkState

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 PartialEq for NetworkState

source§

fn eq(&self, other: &NetworkState) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for NetworkState

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
source§

impl TryFrom<NetworkPolicy> for NetworkState

§

type Error = NmstateError

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

fn try_from(policy: NetworkPolicy) -> Result<Self, NmstateError>

Performs the conversion.
source§

impl Eq for NetworkState

source§

impl StructuralPartialEq for NetworkState

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> NoneValue for T
where T: Default,

§

type NoneType = T

source§

fn null_value() -> T

The none-equivalent value.
source§

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

§

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>,

§

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>,

§

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,