summaryrefslogtreecommitdiff
path: root/ironic/objects
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2021-11-19 09:52:53 +1300
committerSteve Baker <sbaker@redhat.com>2021-12-03 14:49:33 +1300
commitd5eb6ee567befb36b2c353d002cbe25c83365e2a (patch)
tree2c0f5c0db583decaa73978520b761d6c63eca535 /ironic/objects
parent3197301dbab1be5500cd820c503717e64953cd95 (diff)
downloadironic-d5eb6ee567befb36b2c353d002cbe25c83365e2a.tar.gz
Refactor driver_internal_info updates to methods
Making updates to driver_internal_info can result in hard to read code due the requirement to assign the whole driver_internal_info back to the node to trigger the expected update operation. This change replaces driver_internal_info update operations with a new methods: - set_driver_internal_info - del_driver_internal_info - timestamp_driver_internal_info This change defines the functions and moves core conductor logic to use them. Subsequent changes in this series will move drivers to use the new functions. Change-Id: Ib8917c3c674e77cd3aba6a1e73c65162e3ee1141
Diffstat (limited to 'ironic/objects')
-rw-r--r--ironic/objects/node.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/ironic/objects/node.py b/ironic/objects/node.py
index cc8479b8c..cdb218301 100644
--- a/ironic/objects/node.py
+++ b/ironic/objects/node.py
@@ -15,6 +15,7 @@
from oslo_config import cfg
from oslo_log import log
from oslo_utils import strutils
+from oslo_utils import timeutils
from oslo_utils import uuidutils
from oslo_utils import versionutils
from oslo_versionedobjects import base as object_base
@@ -691,6 +692,43 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat):
self._convert_network_data_field(target_version,
remove_unavailable_fields)
+ def set_driver_internal_info(self, key, value):
+ """Set a `driver_internal_info` value.
+
+ Setting a `driver_internal_info` dict value via this method
+ ensures that this field will be flagged for saving.
+
+ :param key: Key of item to set
+ :param value: Value of item to set
+ """
+ self.driver_internal_info[key] = value
+ self._changed_fields.add('driver_internal_info')
+
+ def del_driver_internal_info(self, key, default_value=None):
+ """Pop a value from the driver_internal_info.
+
+ Removing a `driver_internal_info` dict value via this method
+ ensures that this field will be flagged for saving.
+
+ :param key: Key of item to pop off the `driver_internal_info` dict
+ :param default_value: Value to return if the key doesn't exist
+ :returns: The removed value, or `default_value`
+ """
+ if key in self.driver_internal_info:
+ self._changed_fields.add('driver_internal_info')
+ return self.driver_internal_info.pop(key, default_value)
+ return default_value
+
+ def timestamp_driver_internal_info(self, key):
+ """Set a `driver_internal_info` value with the current timestamp.
+
+ Setting a `driver_internal_info` timestamp value via this method
+ ensures that this field will be flagged for saving.
+
+ :param key: Key of item to set the timestamp on
+ """
+ self.set_driver_internal_info(key, timeutils.utcnow().isoformat())
+
@base.IronicObjectRegistry.register
class NodePayload(notification.NotificationPayloadBase):