diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-06-21 17:33:41 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-06-22 15:01:15 +0200 |
commit | f545ed486e4df7f1508f62a0e0a35c8f92550937 (patch) | |
tree | 83a82a8f6d11fd03b4cb0695d727899ddd039629 | |
parent | 46d2168393a8876098567a629d5baf59d6bf01d4 (diff) | |
download | NetworkManager-f545ed486e4df7f1508f62a0e0a35c8f92550937.tar.gz |
cli: ask NMSettingConnection properties first in questionnaire mode
Since properties are asked only when the connection has the related
setting, ensure that the connection type is set early so that the base
type gets added to the connection before evaluating other settings.
After NMSettingConnection properties, ask properties for the base
setting and then all other settings.
-rw-r--r-- | clients/cli/connections.c | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index f2f4adecf7..84f80741c9 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -4595,47 +4595,81 @@ again: goto again; } -static void -questionnaire_mandatory (NmCli *nmc, NMConnection *connection) +static NMMetaSettingType +connection_get_base_meta_setting_type (NMConnection *connection) { - NMMetaSettingType s; + const char *connection_type; + NMSetting *base_setting; + const NMMetaSettingInfoEditor *editor; - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; + connection_type = nm_connection_get_connection_type (connection); + nm_assert (connection_type); + base_setting = nm_connection_get_setting_by_name (connection, connection_type); + nm_assert (base_setting); + editor = nm_meta_setting_info_editor_find_by_setting (base_setting); + nm_assert (editor); - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; + return editor - nm_meta_setting_infos_editor; +} - if (_meta_property_needs_bond_hack (property_info)) { - guint i; +static void +questionnaire_mandatory_ask_setting (NmCli *nmc, NMConnection *connection, NMMetaSettingType type) +{ + const NMMetaSettingInfoEditor *editor; + const NMMetaPropertyInfo *property_info; + guint p; - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + editor = &nm_meta_setting_infos_editor[type]; + if (!editor->properties) + return; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) - continue; - if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); - } - } else { - if (!property_info->is_cli_option) - continue; + for (p = 0; editor->properties[p]; p++) { + property_info = editor->properties[p]; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) + if (_meta_property_needs_bond_hack (property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) continue; - if ( (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) property_info) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) property_info); + if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) + ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); } + } else { + if (!property_info->is_cli_option) + continue; + + if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) + continue; + if ( (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get ((const NMMetaAbstractInfo *) property_info) & PROPERTY_INF_FLAG_ENABLED)) + ask_option (nmc, connection, (const NMMetaAbstractInfo *) property_info); } } } +static void +questionnaire_mandatory (NmCli *nmc, NMConnection *connection) +{ + NMMetaSettingType s, base; + + /* First ask connection properties */ + questionnaire_mandatory_ask_setting (nmc, connection, NM_META_SETTING_TYPE_CONNECTION); + + /* Ask properties of the base setting */ + base = connection_get_base_meta_setting_type (connection); + questionnaire_mandatory_ask_setting (nmc, connection, base); + + /* Remaining settings */ + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + if (!NM_IN_SET (s, NM_META_SETTING_TYPE_CONNECTION, base)) + questionnaire_mandatory_ask_setting (nmc, connection, s); + } +} + static gboolean want_provide_opt_args (const char *type, int num) { @@ -4659,33 +4693,44 @@ want_provide_opt_args (const char *type, int num) static gboolean questionnaire_one_optional (NmCli *nmc, NMConnection *connection) { - NMMetaSettingType s; + NMMetaSettingType base; gs_unref_ptrarray GPtrArray *infos = NULL; - guint i; + guint i, j; gboolean already_confirmed = FALSE; NMMetaSettingType s_asking = NM_META_SETTING_TYPE_UNKNOWN; + NMMetaSettingType settings[_NM_META_SETTING_TYPE_NUM]; + + base = connection_get_base_meta_setting_type (connection); + + i = 0; + settings[i++] = NM_META_SETTING_TYPE_CONNECTION; + settings[i++] = base; + for (j = 0; j < _NM_META_SETTING_TYPE_NUM; j++) { + if (!NM_IN_SET (j, NM_META_SETTING_TYPE_CONNECTION, base)) + settings[i++] = j; + } infos = g_ptr_array_new (); /* Find first setting with relevant options and count them. */ again: - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { const NMMetaPropertyInfo *const*property_infos; guint p; if ( s_asking != NM_META_SETTING_TYPE_UNKNOWN - && s != s_asking) + && settings[i] != s_asking) continue; - property_infos = nm_meta_setting_infos_editor[s].properties; + property_infos = nm_meta_setting_infos_editor[settings[i]].properties; if (!property_infos) continue; for (p = 0; property_infos[p]; p++) { const NMMetaPropertyInfo *property_info = property_infos[p]; if (_meta_property_needs_bond_hack (property_info)) { - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + for (j = 0; j < nm_meta_property_typ_data_bond.nested_len; j++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[j]; if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) continue; @@ -4700,7 +4745,7 @@ again: } } if (infos->len) { - s_asking = s; + s_asking = settings[i]; break; } } |