parse.h

Parsing Netplan YAML configuration into NetplanParser data structures.

Functions

NetplanParser *netplan_parser_new()

Allocate and initialize a new NetplanParser object.

Note

This contains unvalidated Netplan configuration from raw input, like Netplan YAML or NetworkManager keyfile.

Returns:

An empty NetplanParser

void netplan_parser_reset(NetplanParser *npp)

Reset a NetplanParser to its initial default values.

Freeing any dynamically allocated parsing data.

Parameters:
void netplan_parser_clear(NetplanParser **npp)

Free a NetplanParser, including any dynamically allocated data.

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

Parameters:
gboolean netplan_parser_set_flags(NetplanParser *npp, unsigned int flags, NetplanError **error)

Set NetplanParser flags.

Parser flags are used to change the default behavior of the parser.

Parameters:
Returns:

Indication of success or failure

unsigned int netplan_parser_get_flags(const NetplanParser *npp)

Get NetplanParser flags.

Parser flags are used to change the default behavior of the parser.

Parameters:
Returns:

The current flags set in the parser.

unsigned int netplan_parser_get_error_count(const NetplanParser *npp)

Get NetplanParser error count.

The number of errors that were ignored when the IGNORE_ERRORS is used.

Parameters:
Returns:

The current error count.

gboolean netplan_parser_load_yaml(NetplanParser *npp, const char *filename, NetplanError **error)

Parse a given YAML file and create or update the list of NetplanNetDefinition inside npp.

Parameters:
  • npp -- [in] The NetplanParser object that should contain the parsed data

  • filename -- [in] Full path to a Netplan YAML configuration file

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

Returns:

Indication of success or failure

gboolean netplan_parser_load_yaml_from_fd(NetplanParser *npp, int input_fd, NetplanError **error)

Parse a given YAML file from a file descriptor and create or update the list of NetplanNetDefinition inside npp.

Parameters:
  • npp -- [in] The NetplanParser object that should contain the parsed data

  • input_fd -- [in] File descriptor reference to a Netplan YAML configuration file

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

Returns:

Indication of success or failure

gboolean netplan_parser_load_yaml_hierarchy(NetplanParser *npp, const char *rootdir, NetplanError **error)

Parse a full hierarchy of /{usr/lib,etc,run}/netplan/\*.yaml files inside rootdir and create or update the list of NetplanNetDefinition inside npp.

Note

Files with “asciibetically” higher names override/append settings from earlier ones (in all Netplan config directories); files in /run/netplan/ shadow files in /etc/netplan/, which shadow files in /usr/lib/netplan/.

Parameters:
  • npp -- [in] The NetplanParser object that should contain the parsed data

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

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

Returns:

Indication of success or failure

gboolean netplan_parser_load_nullable_fields(NetplanParser *npp, int input_fd, NetplanError **error)

Parse a Netplan YAML configuration file from a file descriptor, containing settings that are about to be deleted (e.g. some.setting=NULL).

The NULL-settings are ignored when parsing subsequent YAML files.

Parameters:
  • npp -- [in] The NetplanParser object that should contain the parsed data

  • input_fd -- [in] File descriptor reference to a Netplan YAML configuration file

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

Returns:

Indication of success or failure

gboolean netplan_parser_load_nullable_overrides(NetplanParser *npp, int input_fd, const char *constraint, NetplanError **error)

Parse a Netplan YAML configuration file from a file descriptor, containing special settings that are to be overriden inside the YAML hierarchy by the resulting “origin-hint” output file.

Global settings (like renderer) or NetplanNetDefinition, defined in input_fd are ignored in the existing YAML hierarchy because the input_fd configuration overrides those settings via the “origin-hint” output file.

Note

Those settings are supposed to be parsed from the “origin-hint” output file given in constraint only.

Parameters:
  • npp -- [in] The NetplanParser object that should contain the parsed data

  • input_fd -- [in] File descriptor reference to a Netplan YAML configuration file, which would become the “origin-hint” output file afterwards

  • constraint -- [in] Basename of the “origin-hint” output file

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

Returns:

Indication of success or failure