examples: support older libnm without NM.SettingOvsOtherConfig in "ovs-external-ids.py"
This example script is used by our NM-ci. Make it work also with libnm versions that don't yet support NM.SettingOvsOtherConfig.
This commit is contained in:
@@ -236,11 +236,13 @@ DataTypeE = DataTypeTuple(
|
|||||||
NM.SettingOvsExternalIDs,
|
NM.SettingOvsExternalIDs,
|
||||||
NM.SETTING_OVS_EXTERNAL_IDS_DATA,
|
NM.SETTING_OVS_EXTERNAL_IDS_DATA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
o = getattr(NM, "SettingOvsOtherConfig", None)
|
||||||
DataTypeO = DataTypeTuple(
|
DataTypeO = DataTypeTuple(
|
||||||
"other-config",
|
"other-config",
|
||||||
"ovs-other-config",
|
"ovs-other-config",
|
||||||
NM.SettingOvsOtherConfig,
|
o,
|
||||||
NM.SETTING_OVS_OTHER_CONFIG_DATA,
|
NM.SETTING_OVS_OTHER_CONFIG_DATA if o else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -420,12 +422,13 @@ def ids_select(ids, mode, ids_arg):
|
|||||||
|
|
||||||
def connection_print(connection, mode, ids_arg, dbus_path, prefix=""):
|
def connection_print(connection, mode, ids_arg, dbus_path, prefix=""):
|
||||||
def _num_str(connection, data_type):
|
def _num_str(connection, data_type):
|
||||||
|
if data_type.setting_type is None:
|
||||||
|
return "n/a"
|
||||||
sett = connection.get_setting(data_type.setting_type)
|
sett = connection.get_setting(data_type.setting_type)
|
||||||
num_str = "none"
|
if sett is None:
|
||||||
if sett is not None:
|
return "none"
|
||||||
all_ids = list(sett.get_data_keys())
|
all_ids = list(sett.get_data_keys())
|
||||||
num_str = "%s" % (len(all_ids))
|
return "%s" % (len(all_ids),)
|
||||||
return num_str
|
|
||||||
|
|
||||||
_print(
|
_print(
|
||||||
"%s%s [e:%s, o:%s]"
|
"%s%s [e:%s, o:%s]"
|
||||||
@@ -441,18 +444,17 @@ def connection_print(connection, mode, ids_arg, dbus_path, prefix=""):
|
|||||||
|
|
||||||
for data_type in [DataTypeE, DataTypeO]:
|
for data_type in [DataTypeE, DataTypeO]:
|
||||||
|
|
||||||
sett = connection.get_setting(data_type.setting_type)
|
if data_type.setting_type is None:
|
||||||
if sett is not None:
|
continue
|
||||||
all_ids = list(sett.get_data_keys())
|
|
||||||
keys, requested = ids_select(all_ids, mode, ids_arg)
|
|
||||||
else:
|
|
||||||
keys = []
|
|
||||||
requested = []
|
|
||||||
|
|
||||||
if sett is not None:
|
sett = connection.get_setting(data_type.setting_type)
|
||||||
dd = sett.get_property(data_type.property_name)
|
if sett is None:
|
||||||
else:
|
continue
|
||||||
dd = {}
|
|
||||||
|
all_ids = list(sett.get_data_keys())
|
||||||
|
keys, requested = ids_select(all_ids, mode, ids_arg)
|
||||||
|
|
||||||
|
dd = sett.get_property(data_type.property_name)
|
||||||
for k in keys:
|
for k in keys:
|
||||||
v = sett.get_data(k)
|
v = sett.get_data(k)
|
||||||
assert v is not None
|
assert v is not None
|
||||||
@@ -478,6 +480,11 @@ def sett_update(connection, ids_arg):
|
|||||||
else:
|
else:
|
||||||
data_type = DataTypeE
|
data_type = DataTypeE
|
||||||
|
|
||||||
|
if data_type.setting_type is None:
|
||||||
|
raise Exception(
|
||||||
|
"%s is not supported by this version of libnm" % (data_type.name,)
|
||||||
|
)
|
||||||
|
|
||||||
sett = connection.get_setting(data_type.setting_type)
|
sett = connection.get_setting(data_type.setting_type)
|
||||||
|
|
||||||
oldval = None
|
oldval = None
|
||||||
|
Reference in New Issue
Block a user