summaryrefslogtreecommitdiff
path: root/ironic/db/sqlalchemy/api.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-07-24 15:06:16 +0000
committerGerrit Code Review <review@openstack.org>2020-07-24 15:06:16 +0000
commit51112dd04a69a81506c35c322d96e0d5b16bb056 (patch)
treea2feea17f110f316d432c0d7d450a4b3bcb5bf5c /ironic/db/sqlalchemy/api.py
parent3e92fd054bf1e513bc92272e08a010b45de4e527 (diff)
parentcf9188c2d9794a205ec4e09c75d1b890afb86e5d (diff)
downloadironic-51112dd04a69a81506c35c322d96e0d5b16bb056.tar.gz
Merge "Allow node lessee to see node's ports"
Diffstat (limited to 'ironic/db/sqlalchemy/api.py')
-rw-r--r--ironic/db/sqlalchemy/api.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index a0ca90ef1..374898bdb 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -155,6 +155,13 @@ def add_port_filter_by_node_owner(query, value):
return query.filter(models.Node.owner == value)
+def add_port_filter_by_node_project(query, value):
+ query = query.join(models.Node,
+ models.Port.node_id == models.Node.id)
+ return query.filter((models.Node.owner == value)
+ | (models.Node.lessee == value))
+
+
def add_portgroup_filter(query, value):
"""Adds a portgroup-specific filter to a query.
@@ -687,38 +694,49 @@ class Connection(api.Connection):
except NoResultFound:
raise exception.PortNotFound(port=port_uuid)
- def get_port_by_address(self, address, owner=None):
+ def get_port_by_address(self, address, owner=None, project=None):
query = model_query(models.Port).filter_by(address=address)
if owner:
query = add_port_filter_by_node_owner(query, owner)
+ elif project:
+ query = add_port_filter_by_node_project(query, project)
try:
return query.one()
except NoResultFound:
raise exception.PortNotFound(port=address)
def get_port_list(self, limit=None, marker=None,
- sort_key=None, sort_dir=None, owner=None):
+ sort_key=None, sort_dir=None, owner=None,
+ project=None):
query = model_query(models.Port)
if owner:
query = add_port_filter_by_node_owner(query, owner)
+ elif project:
+ query = add_port_filter_by_node_project(query, project)
return _paginate_query(models.Port, limit, marker,
sort_key, sort_dir, query)
def get_ports_by_node_id(self, node_id, limit=None, marker=None,
- sort_key=None, sort_dir=None, owner=None):
+ sort_key=None, sort_dir=None, owner=None,
+ project=None):
query = model_query(models.Port)
query = query.filter_by(node_id=node_id)
if owner:
query = add_port_filter_by_node_owner(query, owner)
+ elif project:
+ query = add_port_filter_by_node_project(query, project)
return _paginate_query(models.Port, limit, marker,
sort_key, sort_dir, query)
def get_ports_by_portgroup_id(self, portgroup_id, limit=None, marker=None,
- sort_key=None, sort_dir=None, owner=None):
+ sort_key=None, sort_dir=None, owner=None,
+ project=None):
query = model_query(models.Port)
query = query.filter_by(portgroup_id=portgroup_id)
if owner:
query = add_port_filter_by_node_owner(query, owner)
+ elif project:
+ query = add_port_filter_by_node_project(query, project)
return _paginate_query(models.Port, limit, marker,
sort_key, sort_dir, query)