Skip to content

Commit

Permalink
parse: handle redefinition of a place holder netdef
Browse files Browse the repository at this point in the history
If we find an interface with the same name of a place holder created
earlier, we just change the place holder type to the type of the
new interface and use it to store the configuration.

Without this logic the parser would fail if it finds an interface with
the same name of the place holder but of a different type.
  • Loading branch information
daniloegea committed Jun 28, 2023
1 parent fd1fd44 commit b4d5627
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3071,8 +3071,13 @@ handle_network_type(NetplanParser* npp, yaml_node_t* node, const char* key_prefi
npp->current.netdef = npp->parsed_defs ? g_hash_table_lookup(npp->parsed_defs, scalar(key)) : NULL;
if (npp->current.netdef) {
/* already exists, overriding/amending previous definition */
if (npp->current.netdef->type != GPOINTER_TO_UINT(data))
return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key));
if (npp->current.netdef->type != GPOINTER_TO_UINT(data)) {
/* If the existing netdef is a place holder, we just repurpose it */
if (npp->current.netdef->type == NETPLAN_DEF_TYPE_NM_PLACEHOLDER_)
npp->current.netdef->type = GPOINTER_TO_UINT(data);
else
return yaml_error(npp, key, error, "Updated definition '%s' changes device type", scalar(key));
}
} else {
npp->current.netdef = netplan_netdef_new(npp, scalar(key), GPOINTER_TO_UINT(data), npp->current.backend);
}
Expand Down

0 comments on commit b4d5627

Please sign in to comment.