state.h

Functions for manipulating NetplanState objects, validating Netplan configurations and writing them to disk.

Functions

NetplanState *netplan_state_new()

Allocate and initialize a new NetplanState object.

Can be used to validate and carry pre-parsed Netplan configuration.

Returns:

An empty NetplanState

void netplan_state_reset(NetplanState *np_state)

Reset a NetplanState to its initial default values.

Freeing any dynamically allocated configuration data.

Parameters:
void netplan_state_clear(NetplanState **np_state)

Free a NetplanState, including any dynamically allocated data.

Similar to netplan_state_reset, but also free and nullify the object itself.

Parameters:
gboolean netplan_state_import_parser_results(NetplanState *np_state, NetplanParser *npp, NetplanError **error)

Validate pre-parsed Netplan configuration data inside a NetplanParser and import them into a NetplanState.

This transfers ownership of the contained data from npp to np_state and cleans up by calling netplan_parser_reset.

Parameters:
  • np_state -- [in] The NetplanState to be filled with validated Netplan configuration from npp

  • npp -- [in] The NetplanParser containing unvalidated Netplan configuration from raw inputs

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

guint netplan_state_get_netdefs_size(const NetplanState *np_state)

Get the number of NetplanNetDefinition configurations stored in this NetplanState.

Note

Each NetplanNetDefinition is identified by a unique Netplan ID.

Parameters:
Returns:

Number of unique NetplanNetDefinition configurations

NetplanNetDefinition *netplan_state_get_netdef(const NetplanState *np_state, const char *id)

Get a specific NetplanNetDefinition from this NetplanState.

Parameters:
Returns:

A handle to the specified NetplanNetDefinition or NULL if not found

NetplanBackend netplan_state_get_backend(const NetplanState *np_state)

Get the global NetplanBackend defined in this NetplanState.

Note

This is the default fallback backend to render any contained NetplanNetDefinition on, if not otherwise specified.

Parameters:
Returns:

Enumeration value, specifiying the NetplanBackend

gboolean netplan_state_write_yaml_file(const NetplanState *np_state, const char *filename, const char *rootdir, NetplanError **error)

Write the selected YAML file filtered to the data relevant to this file.

Writes all NetplanNetDefinition settings that originate from the specified file, as well as those without any given origin. Any data that’s assigned to another file is ignored.

Parameters:
  • np_state -- [in] The NetplanState for which to generate the config

  • filename -- [in] Relevant file basename (e.g. origin-hint.yaml)

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

gboolean netplan_state_update_yaml_hierarchy(const NetplanState *np_state, const char *default_filename, const char *rootdir, NetplanError **error)

Update all the YAML files that were used to create this NetplanState.

Data that has no associated filepath uses the default_filename output file in the standard configuration directory.

Parameters:
  • np_state -- [in] The NetplanState for which to generate the configuration

  • default_filename -- [in] Default configuration file; cannot be NULL or empty

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

gboolean netplan_state_dump_yaml(const NetplanState *np_state, int output_fd, NetplanError **error)

Dump the whole NetplanState into a single YAML file.

Ignoring the origin of each NetplanNetDefinition.

Parameters:
  • np_state -- [in] The NetplanState for which to generate the configuration

  • out_fd -- [in] File descriptor to an opened file into which to dump the content

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

gboolean netplan_netdef_write_yaml(const NetplanState *np_state, const NetplanNetDefinition *netdef, const char *rootdir, NetplanError **error)

Generate the Netplan YAML configuration for the selected NetplanNetDefinition.

Parameters:
  • np_state -- [in] NetplanState (as pointer), the global state to which the netdef belongs

  • netdef -- [in] NetplanNetDefinition (as pointer), the data to be serialized

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

void netplan_state_iterator_init(const NetplanState *np_state, NetplanStateIterator *iter)

Initialize a NetplanStateIterator for walking through a list of NetplanNetDefinition inside np_state.

Parameters:
NetplanNetDefinition *netplan_state_iterator_next(NetplanStateIterator *iter)

Get the next NetplanNetDefinition in the list of a NetplanState object.

Parameters:
Returns:

The next NetplanNetDefinition or NULL

gboolean netplan_state_iterator_has_next(const NetplanStateIterator *iter)

Check if there is any next NetplanNetDefinition in the list of a NetplanState object.

Parameters:
Returns:

Indication if this NetplanStateIterator contains any further NetplanNetDefinition

gboolean netplan_state_finish_nm_write(const NetplanState *np_state, const char *rootdir, NetplanError **error)

Write generic NetworkManager configuration to disk.

This configures global settings, independent of NetplanNetDefinition data, such as udev blocklisting to make NetworkManager ignore certain interfaces using [device].managed=false or NM_MANAGED=0.

Parameters:
  • np_state -- [in] The NetplanState to read settings from

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

gboolean netplan_state_finish_ovs_write(const NetplanState *np_state, const char *rootdir, NetplanError **error)

Write generic Open vSwitch configuration to disk.

This configures global settings, independent of NetplanNetDefinition data, such as patch ports, SSL configuration or the netplan-ovs-cleanup.service unit.

Parameters:
  • np_state -- [in] The NetplanState to read settings from

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure

gboolean netplan_state_finish_sriov_write(const NetplanState *np_state, const char *rootdir, NetplanError **error)

Write generic SR-IOV configuration to disk.

This configures global settings, independent of NetplanNetDefinition data, such as udev rules or the netplan-sriov-rebind.service unit.

Parameters:
  • np_state -- [in] The NetplanState to read settings from

  • rootdir -- [in] If not NULL, generate configuration in this root directory (useful for testing)

  • error -- [out] Filled with a NetplanError in case of failure

Returns:

Indication of success or failure