ovirt: Resolve also list of hrefs (#57299)
This commit is contained in:
parent
6e94b472e8
commit
d88739367e
2 changed files with 21 additions and 13 deletions
3
changelogs/fragments/ovirt_fetch_also_list_of_hrefs.yaml
Normal file
3
changelogs/fragments/ovirt_fetch_also_list_of_hrefs.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- When using `fetch_nested` fetch also list of href, instead only single object hrefs.
|
|
@ -61,19 +61,7 @@ def get_dict_of_struct(struct, connection=None, fetch_nested=False, attributes=N
|
||||||
"""
|
"""
|
||||||
res = {}
|
res = {}
|
||||||
|
|
||||||
def remove_underscore(val):
|
def resolve_href(value):
|
||||||
if val.startswith('_'):
|
|
||||||
val = val[1:]
|
|
||||||
remove_underscore(val)
|
|
||||||
return val
|
|
||||||
|
|
||||||
def convert_value(value):
|
|
||||||
nested = False
|
|
||||||
|
|
||||||
if isinstance(value, sdk.Struct):
|
|
||||||
if not fetch_nested or not value.href:
|
|
||||||
return get_dict_of_struct(value)
|
|
||||||
|
|
||||||
# Fetch nested values of struct:
|
# Fetch nested values of struct:
|
||||||
try:
|
try:
|
||||||
value = connection.follow_link(value)
|
value = connection.follow_link(value)
|
||||||
|
@ -86,6 +74,21 @@ def get_dict_of_struct(struct, connection=None, fetch_nested=False, attributes=N
|
||||||
nested_obj['id'] = getattr(value, 'id', None)
|
nested_obj['id'] = getattr(value, 'id', None)
|
||||||
nested_obj['href'] = getattr(value, 'href', None)
|
nested_obj['href'] = getattr(value, 'href', None)
|
||||||
return nested_obj
|
return nested_obj
|
||||||
|
|
||||||
|
def remove_underscore(val):
|
||||||
|
if val.startswith('_'):
|
||||||
|
val = val[1:]
|
||||||
|
remove_underscore(val)
|
||||||
|
return val
|
||||||
|
|
||||||
|
def convert_value(value):
|
||||||
|
nested = False
|
||||||
|
|
||||||
|
if isinstance(value, sdk.Struct):
|
||||||
|
if not fetch_nested or not value.href:
|
||||||
|
return get_dict_of_struct(value)
|
||||||
|
return resolve_href(value)
|
||||||
|
|
||||||
elif isinstance(value, Enum) or isinstance(value, datetime):
|
elif isinstance(value, Enum) or isinstance(value, datetime):
|
||||||
return str(value)
|
return str(value)
|
||||||
elif isinstance(value, list) or isinstance(value, sdk.List):
|
elif isinstance(value, list) or isinstance(value, sdk.List):
|
||||||
|
@ -99,7 +102,9 @@ def get_dict_of_struct(struct, connection=None, fetch_nested=False, attributes=N
|
||||||
ret = []
|
ret = []
|
||||||
for i in value:
|
for i in value:
|
||||||
if isinstance(i, sdk.Struct):
|
if isinstance(i, sdk.Struct):
|
||||||
if not nested:
|
if fetch_nested and i.href:
|
||||||
|
ret.append(resolve_href(i))
|
||||||
|
elif not nested:
|
||||||
ret.append(get_dict_of_struct(i))
|
ret.append(get_dict_of_struct(i))
|
||||||
else:
|
else:
|
||||||
nested_obj = dict(
|
nested_obj = dict(
|
||||||
|
|
Loading…
Add table
Reference in a new issue