From 4449f7184fa9be0bcc6eed7bd65fcaa9e7cda8de Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Wed, 6 May 2020 18:39:58 +0200 Subject: [PATCH] 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 --- ironicclient/v1/port.py | 44 +++++++++++----- ironicclient/v1/portgroup.py | 78 ++++++++++++++++++++++------- ironicclient/v1/volume_connector.py | 37 ++++++++++---- ironicclient/v1/volume_target.py | 37 ++++++++++---- 4 files changed, 146 insertions(+), 50 deletions(-) diff --git a/ironicclient/v1/port.py b/ironicclient/v1/port.py index bffcf5a16..403c22320 100644 --- a/ironicclient/v1/port.py +++ b/ironicclient/v1/port.py @@ -34,7 +34,8 @@ class PortManager(base.CreateManager): def list(self, address=None, limit=None, marker=None, sort_key=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. :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 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-") to use for the request. + :returns: A list of ports. """ @@ -93,24 +100,31 @@ class PortManager(base.CreateManager): path += 'detail' if filters: path += '?' + '&'.join(filters) - + header_values = {"os_ironic_api_version": os_ironic_api_version, + "global_request_id": global_request_id} if limit is None: - return self._list(self._path(path), "ports") + return self._list(self._path(path), "ports", **header_values) else: return self._list_pagination(self._path(path), "ports", - limit=limit) + limit=limit, **header_values) - def get(self, port_id, fields=None): - return self._get(resource_id=port_id, fields=fields) + def get(self, port_id, fields=None, os_ironic_api_version=None, + 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 if fields is not None: path += '&fields=' + ','.join(fields) else: 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 # address returns a collection of one port if successful. if len(ports) == 1: @@ -118,8 +132,14 @@ class PortManager(base.CreateManager): else: raise exc.NotFound() - def delete(self, port_id): - return self._delete(resource_id=port_id) + def delete(self, port_id, os_ironic_api_version=None, + 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): - return self._update(resource_id=port_id, patch=patch) + def update(self, port_id, patch, os_ironic_api_version=None, + 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) diff --git a/ironicclient/v1/portgroup.py b/ironicclient/v1/portgroup.py index c590ed054..18b01dabe 100644 --- a/ironicclient/v1/portgroup.py +++ b/ironicclient/v1/portgroup.py @@ -30,7 +30,8 @@ class PortgroupManager(base.CreateManager): 'standalone_ports_supported', 'mode', 'properties'] 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. :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 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-") to use for the request. + :returns: A list of portgroups. :raises: InvalidAttribute if a subset of fields is requested with detail option set. @@ -85,15 +92,17 @@ class PortgroupManager(base.CreateManager): path += 'detail' if filters: path += '?' + '&'.join(filters) - + header_values = {"os_ironic_api_version": os_ironic_api_version, + "global_request_id": global_request_id} if limit is None: - return self._list(self._path(path), "portgroups") + return self._list(self._path(path), "portgroups", **header_values) else: 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, - 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. :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 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-") to use for the request. + :returns: A list of ports. """ @@ -140,33 +155,46 @@ class PortgroupManager(base.CreateManager): if filters: path += '?' + '&'.join(filters) - + header_values = {"os_ironic_api_version": os_ironic_api_version, + "global_request_id": global_request_id} if limit is None: - return self._list(self._path(path), "ports") + return self._list(self._path(path), "ports", **header_values) else: 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. :param portgroup_id: The UUID or name of a portgroup. :param fields: Optional, a list with a specified set of fields of the resource to be returned. Can not be used 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-") to use for the request. :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. :param address: The MAC address of a portgroup. :param fields: Optional, a list with a specified set of fields of the resource to be returned. Can not be used 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-") to use for the request. :returns: a :class:`Portgroup` object. @@ -177,7 +205,9 @@ class PortgroupManager(base.CreateManager): else: 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 # filtering by address returns a collection of one portgroup # if successful. @@ -186,19 +216,31 @@ class PortgroupManager(base.CreateManager): else: 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. :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-") 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. :param portgroup_id: The UUID or name of a portgroup. :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-") 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) diff --git a/ironicclient/v1/volume_connector.py b/ironicclient/v1/volume_connector.py index f1c9d96ed..de52464c2 100644 --- a/ironicclient/v1/volume_connector.py +++ b/ironicclient/v1/volume_connector.py @@ -30,7 +30,8 @@ class VolumeConnectorManager(base.CreateManager): _resource_name = 'volume/connectors' 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. :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 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-") to use for the request. + :returns: A list of volume connectors. """ @@ -78,18 +85,28 @@ class VolumeConnectorManager(base.CreateManager): path = '' if filters: path += '?' + '&'.join(filters) - + header_values = {"os_ironic_api_version": os_ironic_api_version, + "global_request_id": global_request_id} if limit is None: - return self._list(self._path(path), "connectors") + return self._list(self._path(path), "connectors", **header_values) else: return self._list_pagination(self._path(path), "connectors", - limit=limit) + limit=limit, **header_values) - def get(self, volume_connector_id, fields=None): - return self._get(resource_id=volume_connector_id, fields=fields) + def get(self, volume_connector_id, fields=None, + 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): - return self._delete(resource_id=volume_connector_id) + def delete(self, volume_connector_id, os_ironic_api_version=None, + 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): - return self._update(resource_id=volume_connector_id, patch=patch) + def update(self, volume_connector_id, patch, os_ironic_api_version=None, + 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) diff --git a/ironicclient/v1/volume_target.py b/ironicclient/v1/volume_target.py index 7a7bf50aa..4121d34da 100644 --- a/ironicclient/v1/volume_target.py +++ b/ironicclient/v1/volume_target.py @@ -31,7 +31,8 @@ class VolumeTargetManager(base.CreateManager): _resource_name = 'volume/targets' 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. :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 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-") to use for the request. + :returns: A list of volume targets. """ @@ -79,18 +86,28 @@ class VolumeTargetManager(base.CreateManager): path = '' if filters: path += '?' + '&'.join(filters) - + header_values = {"os_ironic_api_version": os_ironic_api_version, + "global_request_id": global_request_id} if limit is None: - return self._list(self._path(path), "targets") + return self._list(self._path(path), "targets", **header_values) else: return self._list_pagination(self._path(path), "targets", - limit=limit) + limit=limit, **header_values) - def get(self, volume_target_id, fields=None): - return self._get(resource_id=volume_target_id, fields=fields) + def get(self, volume_target_id, fields=None, os_ironic_api_version=None, + 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): - return self._delete(resource_id=volume_target_id) + def delete(self, volume_target_id, os_ironic_api_version=None, + 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): - return self._update(resource_id=volume_target_id, patch=patch) + def update(self, volume_target_id, patch, os_ironic_api_version=None, + 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)