diff options
author | Tzu-Mainn Chen <tzumainn@redhat.com> | 2020-05-22 15:43:41 +0000 |
---|---|---|
committer | Tzu-Mainn Chen <tzumainn@redhat.com> | 2020-07-23 17:01:10 +0000 |
commit | cf9188c2d9794a205ec4e09c75d1b890afb86e5d (patch) | |
tree | 9dc536d09d33656ab6a06b73c56b8aaf0a48bcb2 /ironic/db | |
parent | e461e36ee9bbdd9ff06d91cbc4a898d594545488 (diff) | |
download | ironic-cf9188c2d9794a205ec4e09c75d1b890afb86e5d.tar.gz |
Allow node lessee to see node's ports
Update the port node's filter to allow both owner and lessee to
see a node's ports. This filter is only used when listing ports.
Change-Id: I568e8d23375239d9c044df95b4bc24d5174c145b
Diffstat (limited to 'ironic/db')
-rw-r--r-- | ironic/db/sqlalchemy/api.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py index e8f4c737a..4eca24c49 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) |