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
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§
source§impl NetworkState
impl NetworkState
sourcepub fn gen_conf(
&self
) -> Result<HashMap<String, Vec<(String, String)>>, NmstateError>
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
impl NetworkState
pub fn is_empty(&self) -> bool
sourcepub fn set_kernel_only(&mut self, value: bool) -> &mut Self
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.
sourcepub fn set_verify_change(&mut self, value: bool) -> &mut Self
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.
sourcepub fn set_commit(&mut self, value: bool) -> &mut Self
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.
sourcepub fn set_timeout(&mut self, value: u32) -> &mut Self
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.
sourcepub fn set_include_secrets(&mut self, value: bool) -> &mut Self
pub fn set_include_secrets(&mut self, value: bool) -> &mut Self
Whether to include secrets(like password) in NetworkState::retrieve() Default is false.
sourcepub fn set_include_status_data(&mut self, value: bool) -> &mut Self
pub fn set_include_status_data(&mut self, value: bool) -> &mut Self
Deprecated. No use at all.
sourcepub fn set_running_config_only(&mut self, value: bool) -> &mut Self
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.
sourcepub fn set_memory_only(&mut self, value: bool) -> &mut Self
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.
sourcepub fn new() -> Self
pub fn new() -> Self
Create empty NetworkState
sourcepub fn new_from_json(net_state_json: &str) -> Result<Self, NmstateError>
pub fn new_from_json(net_state_json: &str) -> Result<Self, NmstateError>
Wrapping function of serde_json::from_str() with error mapped to NmstateError.
sourcepub fn append_interface_data(&mut self, iface: Interface)
pub fn append_interface_data(&mut self, iface: Interface)
Append Interface into NetworkState
sourcepub fn hide_secrets(&mut self)
pub fn hide_secrets(&mut self)
Replace secret string with <_password_hid_by_nmstate>
source§impl NetworkState
impl NetworkState
sourcepub fn checkpoint_rollback(checkpoint: &str) -> Result<(), NmstateError>
pub fn checkpoint_rollback(checkpoint: &str) -> Result<(), NmstateError>
Rollback a checkpoint.
Not available for kernel only
mode.
Only available for feature query_apply
.
sourcepub fn checkpoint_commit(checkpoint: &str) -> Result<(), NmstateError>
pub fn checkpoint_commit(checkpoint: &str) -> Result<(), NmstateError>
Commit a checkpoint.
Not available for kernel only
mode.
Only available for feature query_apply
.
sourcepub fn retrieve(&mut self) -> Result<&mut Self, NmstateError>
pub fn retrieve(&mut self) -> Result<&mut Self, NmstateError>
Retrieve the NetworkState
.
Only available for feature query_apply
.
sourcepub fn apply(&self) -> Result<(), NmstateError>
pub fn apply(&self) -> Result<(), NmstateError>
Apply the NetworkState
.
Only available for feature query_apply
.
Trait Implementations§
source§impl Clone for NetworkState
impl Clone for NetworkState
source§fn clone(&self) -> NetworkState
fn clone(&self) -> NetworkState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NetworkState
impl Debug for NetworkState
source§impl Default for NetworkState
impl Default for NetworkState
source§fn default() -> NetworkState
fn default() -> NetworkState
source§impl<'de> Deserialize<'de> for NetworkState
impl<'de> Deserialize<'de> for NetworkState
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 PartialEq<NetworkState> for NetworkState
impl PartialEq<NetworkState> for NetworkState
source§fn eq(&self, other: &NetworkState) -> bool
fn eq(&self, other: &NetworkState) -> bool
source§impl Serialize for NetworkState
impl Serialize for NetworkState
source§impl TryFrom<NetworkPolicy> for NetworkState
impl TryFrom<NetworkPolicy> for NetworkState
§type Error = NmstateError
type Error = NmstateError
source§fn try_from(policy: NetworkPolicy) -> Result<Self, NmstateError>
fn try_from(policy: NetworkPolicy) -> Result<Self, NmstateError>
impl Eq for NetworkState
impl StructuralEq for NetworkState
impl StructuralPartialEq for NetworkState
Auto Trait Implementations§
impl RefUnwindSafe for NetworkState
impl Send for NetworkState
impl Sync for NetworkState
impl Unpin for NetworkState
impl UnwindSafe for NetworkState
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.