summaryrefslogtreecommitdiff
path: root/ironic/db
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2019-01-08 17:02:55 +0100
committerDmitry Tantsur <divius.inside@gmail.com>2019-01-09 13:21:30 +0100
commit1b019ddf84586fd2012f29b473b38ec271b928f2 (patch)
treebd409182e382aa9d7a786535149e41f5fa86c8d7 /ironic/db
parentcea8d74914db22cb8478d6382e281140dd071253 (diff)
downloadironic-1b019ddf84586fd2012f29b473b38ec271b928f2.tar.gz
Allocation API: allow picking random conductor for RPC topic
Allocations are not initially tied to nodes, so to process them we need to pick a random alive conductor. This change enables that. Change-Id: I6c950bc4f49aa03026bc7925f8c699d10cedc310 Story: #2004341
Diffstat (limited to 'ironic/db')
-rw-r--r--ironic/db/api.py7
-rw-r--r--ironic/db/sqlalchemy/api.py12
2 files changed, 15 insertions, 4 deletions
diff --git a/ironic/db/api.py b/ironic/db/api.py
index e43dc55da..c21d7454d 100644
--- a/ironic/db/api.py
+++ b/ironic/db/api.py
@@ -556,6 +556,13 @@ class Connection(object):
"""
@abc.abstractmethod
+ def get_online_conductors(self):
+ """Get a list conductor hostnames that are online and active.
+
+ :returns: A list of conductor hostnames.
+ """
+
+ @abc.abstractmethod
def list_conductor_hardware_interfaces(self, conductor_id):
"""List all registered hardware interfaces for a conductor.
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index beaca9339..65c436e96 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -916,10 +916,14 @@ class Connection(api.Connection):
def get_offline_conductors(self):
interval = CONF.conductor.heartbeat_timeout
limit = timeutils.utcnow() - datetime.timedelta(seconds=interval)
- result = (model_query(models.Conductor).filter_by()
- .filter(models.Conductor.updated_at < limit)
- .all())
- return [row['hostname'] for row in result]
+ result = (model_query(models.Conductor.hostname)
+ .filter(models.Conductor.updated_at < limit))
+ return [row[0] for row in result]
+
+ def get_online_conductors(self):
+ query = model_query(models.Conductor.hostname)
+ query = _filter_active_conductors(query)
+ return [row[0] for row in query]
def list_conductor_hardware_interfaces(self, conductor_id):
query = (model_query(models.ConductorHardwareInterfaces)