diff options
author | Kaifeng Wang <kaifeng.w@gmail.com> | 2018-11-23 17:12:03 +0800 |
---|---|---|
committer | Kaifeng Wang <kaifeng.w@gmail.com> | 2018-11-29 10:25:16 +0800 |
commit | e2a768f0cd2abf6f2ac456949a8c46628b27b5ef (patch) | |
tree | 1720abdd541c51c74973ff2d7ecf1da02f962de7 /ironic/db | |
parent | c5414620c5c3bd9b7085fd64f1dac40e83ec22df (diff) | |
download | ironic-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')
-rw-r--r-- | ironic/db/api.py | 21 | ||||
-rw-r--r-- | ironic/db/sqlalchemy/api.py | 14 |
2 files changed, 29 insertions, 6 deletions
diff --git a/ironic/db/api.py b/ironic/db/api.py index 518c8dea7..0ca10c1db 100644 --- a/ironic/db/api.py +++ b/ironic/db/api.py @@ -493,12 +493,29 @@ class Connection(object): """ @abc.abstractmethod - def get_conductor(self, hostname): + def get_conductor_list(self, limit=None, marker=None, + sort_key=None, sort_dir=None): + """Return a list of conductors. + + :param limit: Maximum number of conductors to return. + :param marker: the last item of the previous page; we return the next + result set. + :param sort_key: Attribute by which results should be sorted. + :param sort_dir: direction in which results should be sorted. + (asc, desc) + """ + + @abc.abstractmethod + def get_conductor(self, hostname, online=True): """Retrieve a conductor's service record from the database. :param hostname: The hostname of the conductor service. + :param online: Specify the filter value on the `online` field when + querying conductors. The ``online`` field is ignored if + this value is set to None. :returns: A conductor. - :raises: ConductorNotFound + :raises: ConductorNotFound if the conductor with given hostname does + not exist or doesn't meet the specified online expectation. """ @abc.abstractmethod 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) |