forked from platypush/platypush
[linode] Recursively expand MappedObjects before serializing.
This commit is contained in:
parent
bd7644b7cc
commit
fe3d3d6c16
2 changed files with 18 additions and 3 deletions
|
@ -66,14 +66,29 @@ class LinodePlugin(RunnablePlugin, CloudInstanceEntityManager, EnumSwitchEntityM
|
||||||
assert instances, f'No such Linode instance: {instance}'
|
assert instances, f'No such Linode instance: {instance}'
|
||||||
return instances[0]
|
return instances[0]
|
||||||
|
|
||||||
def _linode_instance_to_dict(self, instance: Instance) -> dict:
|
@classmethod
|
||||||
|
def _expand_mapped_objects(cls, data: dict) -> dict:
|
||||||
|
"""
|
||||||
|
Expand the mapped objects in a :class:`linode_api4.Instance` to
|
||||||
|
dictionaries.
|
||||||
|
"""
|
||||||
|
for key, value in data.items():
|
||||||
|
if isinstance(value, objects.MappedObject):
|
||||||
|
value = data[key] = value.dict
|
||||||
|
if isinstance(value, dict):
|
||||||
|
data[key] = cls._expand_mapped_objects(value)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _linode_instance_to_dict(cls, instance: Instance) -> dict:
|
||||||
"""
|
"""
|
||||||
Convert an internal :class:`linode_api4.Instance` to a
|
Convert an internal :class:`linode_api4.Instance` to a
|
||||||
dictionary representation that can be used to create a
|
dictionary representation that can be used to create a
|
||||||
:class:`platypush.entities.cloud.CloudInstance` object.
|
:class:`platypush.entities.cloud.CloudInstance` object.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
key: (value.dict if isinstance(value, objects.MappedObject) else value)
|
key: cls._expand_mapped_objects(value)
|
||||||
for key, value in instance.__dict__.items()
|
for key, value in instance.__dict__.items()
|
||||||
if not key.startswith('_')
|
if not key.startswith('_')
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ class LinodeInstanceBackups:
|
||||||
|
|
||||||
available: bool
|
available: bool
|
||||||
enabled: bool
|
enabled: bool
|
||||||
schedule: LinodeInstanceBackupSchedule
|
schedule: Optional[LinodeInstanceBackupSchedule] = None
|
||||||
last_successful: Optional[datetime] = None
|
last_successful: Optional[datetime] = None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue