summaryrefslogtreecommitdiff
path: root/ironic/db
diff options
context:
space:
mode:
authorzshi <zshi@redhat.com>2017-10-12 15:14:58 +0800
committerZenghui Shi <zshi@redhat.com>2018-04-17 16:27:57 +0800
commit61b04cfd38654b13edfcaff253008eb06274247e (patch)
tree835060429f8639991fc61b02d76843948dc9a5d9 /ironic/db
parentc7e938cd57ac53ba2aa578c76e1f5d67c071a9b4 (diff)
downloadironic-61b04cfd38654b13edfcaff253008eb06274247e.tar.gz
BIOS Settings: Add DB API
Adds the following methods to DB API: * create_bios_setting_list * update_bios_setting_list * delete_bios_setting * get_bios_setting * get_bios_setting_list Adds two exceptions: * BIOSSettingAlreadyExists * BIOSSettingNotFound This patch also deletes BIOS setting records associated with a node when it's destroyed. Co-Authored-By: Yolanda Robla Mota <yroblamo@redhat.com> Change-Id: Ibbca0a30baaae1e19e015b4dddbbac0189ff80ba Story: #1712032
Diffstat (limited to 'ironic/db')
-rw-r--r--ironic/db/api.py83
-rw-r--r--ironic/db/sqlalchemy/api.py71
2 files changed, 154 insertions, 0 deletions
diff --git a/ironic/db/api.py b/ironic/db/api.py
index 273ef6059..9d9b55d96 100644
--- a/ironic/db/api.py
+++ b/ironic/db/api.py
@@ -995,3 +995,86 @@ class Connection(object):
:returns: True if the trait exists otherwise False.
:raises: NodeNotFound if the node is not found.
"""
+
+ @abc.abstractmethod
+ def create_bios_setting_list(self, node_id, settings, version):
+ """Create a list of BIOSSetting records for a given node.
+
+ :param node_id: The node id.
+ :param settings: A list of BIOS Settings to be created.
+
+ ::
+
+ [
+ {
+ 'name': String,
+ 'value': String,
+ },
+ {
+ 'name': String,
+ 'value': String,
+ },
+ ...
+ ]
+ :param version: the version of the object.BIOSSetting.
+ :returns: A list of BIOSSetting object.
+ :raises: NodeNotFound if the node is not found.
+ :raises: BIOSSettingAlreadyExists if any of the setting records
+ already exists.
+ """
+
+ @abc.abstractmethod
+ def update_bios_setting_list(self, node_id, settings, version):
+ """Update a list of BIOSSetting records.
+
+ :param node_id: The node id.
+ :param settings: A list of BIOS Settings to be updated.
+
+ ::
+
+ [
+ {
+ 'name': String,
+ 'value': String,
+ },
+ {
+ 'name': String,
+ 'value': String,
+ },
+ ...
+ ]
+ :param version: the version of the object.BIOSSetting.
+ :returns: A list of BIOSSetting objects.
+ :raises: NodeNotFound if the node is not found.
+ :raises: BIOSSettingNotFound if any of the settings is not found.
+ """
+
+ @abc.abstractmethod
+ def delete_bios_setting(self, node_id, name):
+ """Delete BIOS setting.
+
+ :param node_id: The node id.
+ :param name: String containing name of bios setting to be deleted.
+ :raises: NodeNotFound if the node is not found.
+ :raises: BIOSSettingNotFound if the bios setting is not found.
+ """
+
+ @abc.abstractmethod
+ def get_bios_setting(self, node_id, name):
+ """Retrieve BIOS setting value.
+
+ :param node_id: The node id.
+ :param name: String containing name of bios setting to be retrieved.
+ :returns: The BIOSSetting object.
+ :raises: NodeNotFound if the node is not found.
+ :raises: BIOSSettingNotFound if the bios setting is not found.
+ """
+
+ @abc.abstractmethod
+ def get_bios_setting_list(self, node_id):
+ """Retrieve BIOS settings of a given node.
+
+ :param node_id: The node id.
+ :returns: A list of BIOSSetting objects.
+ :raises: NodeNotFound if the node is not found.
+ """
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index 7e6eecd27..36f54dbe1 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -445,6 +445,11 @@ class Connection(api.Connection):
models.VolumeTarget).filter_by(node_id=node_id)
volume_target_query.delete()
+ # delete all bios attached to the node
+ bios_settings_query = model_query(
+ models.BIOSSetting).filter_by(node_id=node_id)
+ bios_settings_query.delete()
+
query.delete()
def update_node(self, node_id, values):
@@ -1383,3 +1388,69 @@ class Connection(api.Connection):
q = model_query(
models.NodeTrait).filter_by(node_id=node_id, trait=trait)
return model_query(q.exists()).scalar()
+
+ @oslo_db_api.retry_on_deadlock
+ def create_bios_setting_list(self, node_id, settings, version):
+ self._check_node_exists(node_id)
+ bios_settings = []
+ with _session_for_write() as session:
+ try:
+ for setting in settings:
+ bios_setting = models.BIOSSetting(
+ node_id=node_id,
+ name=setting['name'],
+ value=setting['value'],
+ version=version)
+ bios_settings.append(bios_setting)
+ session.add(bios_setting)
+ session.flush()
+ except db_exc.DBDuplicateEntry:
+ raise exception.BIOSSettingAlreadyExists(
+ node=node_id, name=setting['name'])
+ return bios_settings
+
+ @oslo_db_api.retry_on_deadlock
+ def update_bios_setting_list(self, node_id, settings, version):
+ self._check_node_exists(node_id)
+ bios_settings = []
+ with _session_for_write() as session:
+ try:
+ for setting in settings:
+ query = model_query(models.BIOSSetting).filter_by(
+ node_id=node_id, name=setting['name'])
+ ref = query.one()
+ ref.update({'value': setting['value'],
+ 'version': version})
+ bios_settings.append(ref)
+ session.flush()
+ except NoResultFound:
+ raise exception.BIOSSettingNotFound(
+ node=node_id, name=setting['name'])
+ return bios_settings
+
+ @oslo_db_api.retry_on_deadlock
+ def delete_bios_setting(self, node_id, name):
+ self._check_node_exists(node_id)
+ with _session_for_write():
+ count = model_query(models.BIOSSetting).filter_by(
+ node_id=node_id, name=name).delete()
+ if count == 0:
+ raise exception.BIOSSettingNotFound(
+ node=node_id, name=name)
+
+ def get_bios_setting(self, node_id, name):
+ self._check_node_exists(node_id)
+ query = model_query(models.BIOSSetting).filter_by(
+ node_id=node_id, name=name)
+ try:
+ ref = query.one()
+ except NoResultFound:
+ raise exception.BIOSSettingNotFound(node=node_id, name=name)
+ return ref
+
+ def get_bios_setting_list(self, node_id):
+ self._check_node_exists(node_id)
+ result = (model_query(models.BIOSSetting)
+ .filter_by(node_id=node_id)
+ .all())
+ return result