Allow to pass global request id in port and volume

This change also allows passing ironic API microversion in places
where it was not possible previously, for consistency.

Story: 2007611
Task: 39602
Change-Id: Iaee01b6f774d52184c7b4bb085f542cbb8228002
This commit is contained in:
Vladyslav Drok 2020-05-06 18:39:58 +02:00
parent 86f3972828
commit 4449f7184f
4 changed files with 146 additions and 50 deletions

View File

@ -34,7 +34,8 @@ class PortManager(base.CreateManager):
def list(self, address=None, limit=None, marker=None, sort_key=None, def list(self, address=None, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False, fields=None, node=None, sort_dir=None, detail=False, fields=None, node=None,
portgroup=None): portgroup=None, os_ironic_api_version=None,
global_request_id=None):
"""Retrieve a list of ports. """Retrieve a list of ports.
:param address: Optional, MAC address of a port, to get :param address: Optional, MAC address of a port, to get
@ -69,6 +70,12 @@ class PortManager(base.CreateManager):
:param portgroup: Optional, name or UUID of a portgroup. Used to get :param portgroup: Optional, name or UUID of a portgroup. Used to get
ports of this portgroup. ports of this portgroup.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: A list of ports. :returns: A list of ports.
""" """
@ -93,24 +100,31 @@ class PortManager(base.CreateManager):
path += 'detail' path += 'detail'
if filters: if filters:
path += '?' + '&'.join(filters) path += '?' + '&'.join(filters)
header_values = {"os_ironic_api_version": os_ironic_api_version,
"global_request_id": global_request_id}
if limit is None: if limit is None:
return self._list(self._path(path), "ports") return self._list(self._path(path), "ports", **header_values)
else: else:
return self._list_pagination(self._path(path), "ports", return self._list_pagination(self._path(path), "ports",
limit=limit) limit=limit, **header_values)
def get(self, port_id, fields=None): def get(self, port_id, fields=None, os_ironic_api_version=None,
return self._get(resource_id=port_id, fields=fields) global_request_id=None):
return self._get(resource_id=port_id, fields=fields,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def get_by_address(self, address, fields=None): def get_by_address(self, address, fields=None, os_ironic_api_version=None,
global_request_id=None):
path = '?address=%s' % address path = '?address=%s' % address
if fields is not None: if fields is not None:
path += '&fields=' + ','.join(fields) path += '&fields=' + ','.join(fields)
else: else:
path = 'detail' + path path = 'detail' + path
ports = self._list(self._path(path), 'ports') ports = self._list(self._path(path), 'ports',
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
# get all the details of the port assuming that filtering by # get all the details of the port assuming that filtering by
# address returns a collection of one port if successful. # address returns a collection of one port if successful.
if len(ports) == 1: if len(ports) == 1:
@ -118,8 +132,14 @@ class PortManager(base.CreateManager):
else: else:
raise exc.NotFound() raise exc.NotFound()
def delete(self, port_id): def delete(self, port_id, os_ironic_api_version=None,
return self._delete(resource_id=port_id) global_request_id=None):
return self._delete(resource_id=port_id,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def update(self, port_id, patch): def update(self, port_id, patch, os_ironic_api_version=None,
return self._update(resource_id=port_id, patch=patch) global_request_id=None):
return self._update(resource_id=port_id, patch=patch,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)

View File

@ -30,7 +30,8 @@ class PortgroupManager(base.CreateManager):
'standalone_ports_supported', 'mode', 'properties'] 'standalone_ports_supported', 'mode', 'properties']
def list(self, node=None, address=None, limit=None, marker=None, def list(self, node=None, address=None, limit=None, marker=None,
sort_key=None, sort_dir=None, detail=False, fields=None): sort_key=None, sort_dir=None, detail=False, fields=None,
os_ironic_api_version=None, global_request_id=None):
"""Retrieve a list of portgroups. """Retrieve a list of portgroups.
:param node: Optional, UUID or name of a node, to get :param node: Optional, UUID or name of a node, to get
@ -61,6 +62,12 @@ class PortgroupManager(base.CreateManager):
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: A list of portgroups. :returns: A list of portgroups.
:raises: InvalidAttribute if a subset of fields is requested with :raises: InvalidAttribute if a subset of fields is requested with
detail option set. detail option set.
@ -85,15 +92,17 @@ class PortgroupManager(base.CreateManager):
path += 'detail' path += 'detail'
if filters: if filters:
path += '?' + '&'.join(filters) path += '?' + '&'.join(filters)
header_values = {"os_ironic_api_version": os_ironic_api_version,
"global_request_id": global_request_id}
if limit is None: if limit is None:
return self._list(self._path(path), "portgroups") return self._list(self._path(path), "portgroups", **header_values)
else: else:
return self._list_pagination(self._path(path), "portgroups", return self._list_pagination(self._path(path), "portgroups",
limit=limit) limit=limit, **header_values)
def list_ports(self, portgroup_id, marker=None, limit=None, sort_key=None, def list_ports(self, portgroup_id, marker=None, limit=None, sort_key=None,
sort_dir=None, detail=False, fields=None): sort_dir=None, detail=False, fields=None,
os_ironic_api_version=None, global_request_id=None):
"""List all the ports for a given portgroup. """List all the ports for a given portgroup.
:param portgroup_id: Name or UUID of the portgroup. :param portgroup_id: Name or UUID of the portgroup.
@ -121,6 +130,12 @@ class PortgroupManager(base.CreateManager):
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: A list of ports. :returns: A list of ports.
""" """
@ -140,33 +155,46 @@ class PortgroupManager(base.CreateManager):
if filters: if filters:
path += '?' + '&'.join(filters) path += '?' + '&'.join(filters)
header_values = {"os_ironic_api_version": os_ironic_api_version,
"global_request_id": global_request_id}
if limit is None: if limit is None:
return self._list(self._path(path), "ports") return self._list(self._path(path), "ports", **header_values)
else: else:
return self._list_pagination(self._path(path), "ports", return self._list_pagination(self._path(path), "ports",
limit=limit) limit=limit, **header_values)
def get(self, portgroup_id, fields=None): def get(self, portgroup_id, fields=None, os_ironic_api_version=None,
global_request_id=None):
"""Get a port group with the specified identifier. """Get a port group with the specified identifier.
:param portgroup_id: The UUID or name of a portgroup. :param portgroup_id: The UUID or name of a portgroup.
:param fields: Optional, a list with a specified set of fields :param fields: Optional, a list with a specified set of fields
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: a :class:`Portgroup` object. :returns: a :class:`Portgroup` object.
""" """
return self._get(resource_id=portgroup_id, fields=fields) return self._get(resource_id=portgroup_id, fields=fields,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def get_by_address(self, address, fields=None): def get_by_address(self, address, fields=None, os_ironic_api_version=None,
global_request_id=None):
"""Get a port group with the specified MAC address. """Get a port group with the specified MAC address.
:param address: The MAC address of a portgroup. :param address: The MAC address of a portgroup.
:param fields: Optional, a list with a specified set of fields :param fields: Optional, a list with a specified set of fields
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: a :class:`Portgroup` object. :returns: a :class:`Portgroup` object.
@ -177,7 +205,9 @@ class PortgroupManager(base.CreateManager):
else: else:
path = 'detail' + path path = 'detail' + path
portgroups = self._list(self._path(path), 'portgroups') portgroups = self._list(self._path(path), 'portgroups',
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
# get all the details of the portgroup assuming that # get all the details of the portgroup assuming that
# filtering by address returns a collection of one portgroup # filtering by address returns a collection of one portgroup
# if successful. # if successful.
@ -186,19 +216,31 @@ class PortgroupManager(base.CreateManager):
else: else:
raise exc.NotFound() raise exc.NotFound()
def delete(self, portgroup_id): def delete(self, portgroup_id, os_ironic_api_version=None,
global_request_id=None):
"""Delete the Portgroup from the DB. """Delete the Portgroup from the DB.
:param portgroup_id: The UUID or name of a portgroup. :param portgroup_id: The UUID or name of a portgroup.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
""" """
return self._delete(resource_id=portgroup_id) return self._delete(resource_id=portgroup_id,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def update(self, portgroup_id, patch): def update(self, portgroup_id, patch, os_ironic_api_version=None,
global_request_id=None):
"""Update the Portgroup. """Update the Portgroup.
:param portgroup_id: The UUID or name of a portgroup. :param portgroup_id: The UUID or name of a portgroup.
:param patch: The patch request with updates. :param patch: The patch request with updates.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
""" """
return self._update(resource_id=portgroup_id, patch=patch) return self._update(resource_id=portgroup_id, patch=patch,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)

View File

@ -30,7 +30,8 @@ class VolumeConnectorManager(base.CreateManager):
_resource_name = 'volume/connectors' _resource_name = 'volume/connectors'
def list(self, node=None, limit=None, marker=None, sort_key=None, def list(self, node=None, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False, fields=None): sort_dir=None, detail=False, fields=None,
os_ironic_api_version=None, global_request_id=None):
"""Retrieve a list of volume connector. """Retrieve a list of volume connector.
:param node: Optional, UUID or name of a node, to get volume :param node: Optional, UUID or name of a node, to get volume
@ -59,6 +60,12 @@ class VolumeConnectorManager(base.CreateManager):
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: A list of volume connectors. :returns: A list of volume connectors.
""" """
@ -78,18 +85,28 @@ class VolumeConnectorManager(base.CreateManager):
path = '' path = ''
if filters: if filters:
path += '?' + '&'.join(filters) path += '?' + '&'.join(filters)
header_values = {"os_ironic_api_version": os_ironic_api_version,
"global_request_id": global_request_id}
if limit is None: if limit is None:
return self._list(self._path(path), "connectors") return self._list(self._path(path), "connectors", **header_values)
else: else:
return self._list_pagination(self._path(path), "connectors", return self._list_pagination(self._path(path), "connectors",
limit=limit) limit=limit, **header_values)
def get(self, volume_connector_id, fields=None): def get(self, volume_connector_id, fields=None,
return self._get(resource_id=volume_connector_id, fields=fields) os_ironic_api_version=None, global_request_id=None):
return self._get(resource_id=volume_connector_id, fields=fields,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def delete(self, volume_connector_id): def delete(self, volume_connector_id, os_ironic_api_version=None,
return self._delete(resource_id=volume_connector_id) global_request_id=None):
return self._delete(resource_id=volume_connector_id,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def update(self, volume_connector_id, patch): def update(self, volume_connector_id, patch, os_ironic_api_version=None,
return self._update(resource_id=volume_connector_id, patch=patch) global_request_id=None):
return self._update(resource_id=volume_connector_id, patch=patch,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)

View File

@ -31,7 +31,8 @@ class VolumeTargetManager(base.CreateManager):
_resource_name = 'volume/targets' _resource_name = 'volume/targets'
def list(self, node=None, limit=None, marker=None, sort_key=None, def list(self, node=None, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False, fields=None): sort_dir=None, detail=False, fields=None,
os_ironic_api_version=None, global_request_id=None):
"""Retrieve a list of volume target. """Retrieve a list of volume target.
:param node: Optional, UUID or name of a node, to get volume :param node: Optional, UUID or name of a node, to get volume
@ -60,6 +61,12 @@ class VolumeTargetManager(base.CreateManager):
of the resource to be returned. Can not be used of the resource to be returned. Can not be used
when 'detail' is set. when 'detail' is set.
:param os_ironic_api_version: String version (e.g. "1.35") to use for
the request. If not specified, the client's default is used.
:param global_request_id: String containing global request ID header
value (in form "req-<UUID>") to use for the request.
:returns: A list of volume targets. :returns: A list of volume targets.
""" """
@ -79,18 +86,28 @@ class VolumeTargetManager(base.CreateManager):
path = '' path = ''
if filters: if filters:
path += '?' + '&'.join(filters) path += '?' + '&'.join(filters)
header_values = {"os_ironic_api_version": os_ironic_api_version,
"global_request_id": global_request_id}
if limit is None: if limit is None:
return self._list(self._path(path), "targets") return self._list(self._path(path), "targets", **header_values)
else: else:
return self._list_pagination(self._path(path), "targets", return self._list_pagination(self._path(path), "targets",
limit=limit) limit=limit, **header_values)
def get(self, volume_target_id, fields=None): def get(self, volume_target_id, fields=None, os_ironic_api_version=None,
return self._get(resource_id=volume_target_id, fields=fields) global_request_id=None):
return self._get(resource_id=volume_target_id, fields=fields,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def delete(self, volume_target_id): def delete(self, volume_target_id, os_ironic_api_version=None,
return self._delete(resource_id=volume_target_id) global_request_id=None):
return self._delete(resource_id=volume_target_id,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)
def update(self, volume_target_id, patch): def update(self, volume_target_id, patch, os_ironic_api_version=None,
return self._update(resource_id=volume_target_id, patch=patch) global_request_id=None):
return self._update(resource_id=volume_target_id, patch=patch,
os_ironic_api_version=os_ironic_api_version,
global_request_id=global_request_id)