summaryrefslogtreecommitdiff
path: root/ironic/db/sqlalchemy/api.py
diff options
context:
space:
mode:
authorKaifeng Wang <kaifeng.w@gmail.com>2018-11-23 17:12:03 +0800
committerKaifeng Wang <kaifeng.w@gmail.com>2018-11-29 10:25:16 +0800
commite2a768f0cd2abf6f2ac456949a8c46628b27b5ef (patch)
tree1720abdd541c51c74973ff2d7ecf1da02f962de7 /ironic/db/sqlalchemy/api.py
parentc5414620c5c3bd9b7085fd64f1dac40e83ec22df (diff)
downloadironic-e2a768f0cd2abf6f2ac456949a8c46628b27b5ef.tar.gz
Expose conductors: db and rpc
This patch lays some ground work around db and rpc to provide conductors information from the API. Changes in the db api and Conductor object is used to support the implementation of /v1/conductors. Adds an argument "online" to Conductor.get_by_hostname, so that we can get the conductor object from database even it's not online, this is required for the implementation of /v1/conductors/{hostname}. Adds a new interface get_conductor_for() to get the hostname of the conductor which is servicing the given node, it will be used for the implementation of /v1/nodes* endpoints, as well as listing nodes by given conductor. Story: 1724474 Task: 28064 Change-Id: I39a7a47c5ae649f6c3200e772a9357023f21a7c4
Diffstat (limited to 'ironic/db/sqlalchemy/api.py')
-rw-r--r--ironic/db/sqlalchemy/api.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index 297a81d76..e702a38ad 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -792,11 +792,17 @@ class Connection(api.Connection):
'online': True})
return ref
- def get_conductor(self, hostname):
+ def get_conductor_list(self, limit=None, marker=None,
+ sort_key=None, sort_dir=None):
+ return _paginate_query(models.Conductor, limit, marker,
+ sort_key, sort_dir)
+
+ def get_conductor(self, hostname, online=True):
try:
- return (model_query(models.Conductor)
- .filter_by(hostname=hostname, online=True)
- .one())
+ query = model_query(models.Conductor).filter_by(hostname=hostname)
+ if online is not None:
+ query = query.filter_by(online=online)
+ return query.one()
except NoResultFound:
raise exception.ConductorNotFound(conductor=hostname)