@@ -43,12 +43,14 @@ static gchar* rootdir;
4343static gchar * * files ;
4444static gboolean any_networkd = FALSE;
4545static gboolean any_nm = FALSE;
46+ static gboolean nm_only = FALSE;
4647static gboolean ignore_errors = FALSE;
4748
4849static GOptionEntry options [] = {
4950 {"root-dir" , 'r' , 0 , G_OPTION_ARG_FILENAME , & rootdir , "Search for and generate configuration files in this root directory instead of /" , NULL },
5051 {G_OPTION_REMAINING , 0 , 0 , G_OPTION_ARG_FILENAME_ARRAY , & files , "Read configuration from this/these file(s) instead of /etc/netplan/*.yaml" , "[config file ..]" },
5152 {"ignore-errors" , 'i' , 0 , G_OPTION_ARG_NONE , & ignore_errors , "Ignores files and/or network definitions that fail parsing." , NULL },
53+ {"networkmanager-only" , 'N' , 0 , G_OPTION_ARG_NONE , & nm_only , "Write only NetworkManager configuration." , NULL },
5254 {NULL }
5355};
5456
@@ -167,29 +169,29 @@ int main(int argc, char** argv)
167169 CHECK_CALL (netplan_state_import_parser_results (np_state , npp , & error ), ignore_errors );
168170
169171 /* Clean up generated config from previous runs */
170- _netplan_networkd_cleanup (rootdir );
172+ if (! nm_only ) _netplan_networkd_cleanup (rootdir );
171173 _netplan_nm_cleanup (rootdir );
172- _netplan_ovs_cleanup (rootdir );
173- _netplan_sriov_cleanup (rootdir );
174+ if (! nm_only ) _netplan_ovs_cleanup (rootdir );
175+ if (! nm_only ) _netplan_sriov_cleanup (rootdir );
174176
175177 /* Generate backend specific configuration files from merged data. */
176178 // sd-generator late-stage validation
177- CHECK_CALL (_netplan_state_finish_sd_ovs_write (np_state , _VALIDATION_ONLY , & error ), ignore_errors );
178- CHECK_CALL (netplan_state_finish_ovs_write (np_state , rootdir , & error ), ignore_errors ); // OVS cleanup unit is always written
179+ if (! nm_only ) CHECK_CALL (_netplan_state_finish_sd_ovs_write (np_state , _VALIDATION_ONLY , & error ), ignore_errors );
180+ if (! nm_only ) CHECK_CALL (netplan_state_finish_ovs_write (np_state , rootdir , & error ), ignore_errors ); // OVS cleanup unit is always written
179181 if (np_state -> netdefs ) {
180182 g_debug ("Generating output files.." );
181183 for (GList * iterator = np_state -> netdefs_ordered ; iterator ; iterator = iterator -> next ) {
182184 NetplanNetDefinition * def = (NetplanNetDefinition * ) iterator -> data ;
183185 gboolean has_been_written = FALSE;
184186 // sd-generator late-stage validation
185- CHECK_CALL (_netplan_netdef_generate_networkd (np_state , def , _VALIDATION_ONLY , & has_been_written , & error ), ignore_errors );
187+ if (! nm_only ) CHECK_CALL (_netplan_netdef_generate_networkd (np_state , def , _VALIDATION_ONLY , & has_been_written , & error ), ignore_errors );
186188 any_networkd = any_networkd || has_been_written ;
187- CHECK_CALL (_netplan_netdef_write_networkd (np_state , def , rootdir , & has_been_written , & error ), ignore_errors );
189+ if (! nm_only ) CHECK_CALL (_netplan_netdef_write_networkd (np_state , def , rootdir , & has_been_written , & error ), ignore_errors );
188190 any_networkd = any_networkd || has_been_written ;
189191
190192 // sd-generator late-stage validation
191- CHECK_CALL (_netplan_netdef_write_sd_ovs (np_state , def , _VALIDATION_ONLY , & has_been_written , & error ), ignore_errors );
192- CHECK_CALL (_netplan_netdef_write_ovs (np_state , def , rootdir , & has_been_written , & error ), ignore_errors );
193+ if (! nm_only ) CHECK_CALL (_netplan_netdef_write_sd_ovs (np_state , def , _VALIDATION_ONLY , & has_been_written , & error ), ignore_errors );
194+ if (! nm_only ) CHECK_CALL (_netplan_netdef_write_ovs (np_state , def , rootdir , & has_been_written , & error ), ignore_errors );
193195 // We don't have any _netplan_netdef_generate_nm() function for sd-generator late-stage validation
194196 CHECK_CALL (_netplan_netdef_write_nm (np_state , def , rootdir , & has_been_written , & error ), ignore_errors );
195197 any_nm = any_nm || has_been_written ;
@@ -198,15 +200,17 @@ int main(int argc, char** argv)
198200 // We don't have any _netplan_state_finish_sd_nm_write() function for sd-generator late-stage validation
199201 CHECK_CALL (netplan_state_finish_nm_write (np_state , rootdir , & error ), ignore_errors );
200202 // sd-generator late-stage validation
201- CHECK_CALL (_netplan_state_finish_sd_sriov_write (np_state , _VALIDATION_ONLY , & error ), ignore_errors );
202- CHECK_CALL (netplan_state_finish_sriov_write (np_state , rootdir , & error ), ignore_errors );
203+ if (! nm_only ) CHECK_CALL (_netplan_state_finish_sd_sriov_write (np_state , _VALIDATION_ONLY , & error ), ignore_errors );
204+ if (! nm_only ) CHECK_CALL (netplan_state_finish_sriov_write (np_state , rootdir , & error ), ignore_errors );
203205 }
204206
205207 /* Disable /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
206208 * (which restricts NM to wifi and wwan) if "renderer: NetworkManager" is used anywhere */
207209 if (netplan_state_get_backend (np_state ) == NETPLAN_BACKEND_NM || any_nm )
208210 _netplan_g_string_free_to_file (g_string_new (NULL ), rootdir , "/run/NetworkManager/conf.d/10-globally-managed-devices.conf" , NULL );
209211
212+ if (nm_only ) goto cleanup ;
213+
210214 gboolean enable_wait_online = FALSE;
211215 if (any_networkd ) {
212216 // _netplan_networkd_write_wait_online() is currently a no-op in the ./configure binary
0 commit comments