proxy: Add 'wait_for_*' helpers to all proxy APIs

These are very useful but were inconsistently available. Correct this.

Change-Id: I9977427e83136ed4a0b3058887aba4cee4ace6a6
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2025-02-19 10:49:15 +00:00
parent 561e8cb8cd
commit 6395008300
29 changed files with 1765 additions and 429 deletions

View File

@ -10,14 +10,19 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.accelerator.v2 import accelerator_request as _arq from openstack.accelerator.v2 import accelerator_request as _arq
from openstack.accelerator.v2 import deployable as _deployable from openstack.accelerator.v2 import deployable as _deployable
from openstack.accelerator.v2 import device as _device from openstack.accelerator.v2 import device as _device
from openstack.accelerator.v2 import device_profile as _device_profile from openstack.accelerator.v2 import device_profile as _device_profile
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
# ========== Deployables ==========
def deployables(self, **query): def deployables(self, **query):
"""Retrieve a generator of deployables. """Retrieve a generator of deployables.
@ -48,6 +53,8 @@ class Proxy(proxy.Proxy):
self, patch self, patch
) )
# ========== Devices ==========
def devices(self, **query): def devices(self, **query):
"""Retrieve a generator of devices. """Retrieve a generator of devices.
@ -81,6 +88,8 @@ class Proxy(proxy.Proxy):
""" """
return self._get(_device.Device, uuid) return self._get(_device.Device, uuid)
# ========== Device profiles ==========
def device_profiles(self, **query): def device_profiles(self, **query):
"""Retrieve a generator of device profiles. """Retrieve a generator of device profiles.
@ -129,6 +138,8 @@ class Proxy(proxy.Proxy):
""" """
return self._get(_device_profile.DeviceProfile, uuid) return self._get(_device_profile.DeviceProfile, uuid)
# ========== Accelerator requests ==========
def accelerator_requests(self, **query): def accelerator_requests(self, **query):
"""Retrieve a generator of accelerator requests. """Retrieve a generator of accelerator requests.
@ -192,3 +203,66 @@ class Proxy(proxy.Proxy):
return self._get_resource(_arq.AcceleratorRequest, uuid).patch( return self._get_resource(_arq.AcceleratorRequest, uuid).patch(
self, properties self, properties
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -27,6 +27,7 @@ from openstack.baremetal.v1 import volume_connector as _volumeconnector
from openstack.baremetal.v1 import volume_target as _volumetarget from openstack.baremetal.v1 import volume_target as _volumetarget
from openstack import exceptions from openstack import exceptions
from openstack import proxy from openstack import proxy
from openstack import resource
from openstack import utils from openstack import utils
@ -69,6 +70,8 @@ class Proxy(proxy.Proxy):
**kwargs, **kwargs,
) )
# ========== Chassis ==========
def chassis(self, details=False, **query): def chassis(self, details=False, **query):
"""Retrieve a generator of chassis. """Retrieve a generator of chassis.
@ -186,6 +189,8 @@ class Proxy(proxy.Proxy):
_chassis.Chassis, chassis, ignore_missing=ignore_missing _chassis.Chassis, chassis, ignore_missing=ignore_missing
) )
# ========== Drivers ==========
def drivers(self, details=False, **query): def drivers(self, details=False, **query):
"""Retrieve a generator of drivers. """Retrieve a generator of drivers.
@ -248,6 +253,8 @@ class Proxy(proxy.Proxy):
self, verb, method, body self, verb, method, body
) )
# ========== Nodes ==========
def nodes(self, details=False, **query): def nodes(self, details=False, **query):
"""Retrieve a generator of nodes. """Retrieve a generator of nodes.
@ -718,6 +725,114 @@ class Proxy(proxy.Proxy):
""" """
return self._delete(_node.Node, node, ignore_missing=ignore_missing) return self._delete(_node.Node, node, ignore_missing=ignore_missing)
# ========== Node actions ==========
def add_node_trait(self, node, trait):
"""Add a trait to a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param trait: trait to remove from the node.
:returns: The updated node
"""
res = self._get_resource(_node.Node, node)
return res.add_trait(self, trait)
def remove_node_trait(self, node, trait, ignore_missing=True):
"""Remove a trait from a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param trait: trait to remove from the node.
:param bool ignore_missing: When set to ``False``, an exception
:class:`~openstack.exceptions.NotFoundException` will be raised
when the trait could not be found. When set to ``True``, no
exception will be raised when attempting to delete a non-existent
trait.
:returns: The updated :class:`~openstack.baremetal.v1.node.Node`
"""
res = self._get_resource(_node.Node, node)
return res.remove_trait(self, trait, ignore_missing=ignore_missing)
def call_node_vendor_passthru(self, node, verb, method, body=None):
"""Calls vendor_passthru for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param verb: The HTTP verb, one of GET, SET, POST, DELETE.
:param method: The method to call using vendor_passthru.
:param body: The JSON body in the HTTP call.
:returns: The raw response from the method.
"""
res = self._get_resource(_node.Node, node)
return res.call_vendor_passthru(self, verb, method, body)
def list_node_vendor_passthru(self, node):
"""Lists vendor_passthru for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: A list of vendor_passthru methods for the node.
"""
res = self._get_resource(_node.Node, node)
return res.list_vendor_passthru(self)
def get_node_console(self, node):
"""Get the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: Connection information for the console.
"""
res = self._get_resource(_node.Node, node)
return res.get_node_console(self)
def enable_node_console(self, node):
"""Enable the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: None
"""
res = self._get_resource(_node.Node, node)
return res.set_console_mode(self, True)
def disable_node_console(self, node):
"""Disable the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: None
"""
res = self._get_resource(_node.Node, node)
return res.set_console_mode(self, False)
def set_node_traits(self, node, traits):
"""Set traits for a node.
Removes any existing traits and adds the traits passed in to this
method.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param traits: list of traits to add to the node.
:returns: The updated :class:`~openstack.baremetal.v1.node.Node`
"""
res = self._get_resource(_node.Node, node)
return res.set_traits(self, traits)
def list_node_firmware(self, node):
"""Lists firmware components for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: A list of the node's firmware components.
"""
res = self._get_resource(_node.Node, node)
return res.list_firmware(self)
# ========== Ports ==========
def ports(self, details=False, **query): def ports(self, details=False, **query):
"""Retrieve a generator of ports. """Retrieve a generator of ports.
@ -843,6 +958,8 @@ class Proxy(proxy.Proxy):
""" """
return self._delete(_port.Port, port, ignore_missing=ignore_missing) return self._delete(_port.Port, port, ignore_missing=ignore_missing)
# ========== Port groups ==========
def port_groups(self, details=False, **query): def port_groups(self, details=False, **query):
"""Retrieve a generator of port groups. """Retrieve a generator of port groups.
@ -970,6 +1087,8 @@ class Proxy(proxy.Proxy):
_portgroup.PortGroup, port_group, ignore_missing=ignore_missing _portgroup.PortGroup, port_group, ignore_missing=ignore_missing
) )
# ========== VIFs ==========
def attach_vif_to_node( def attach_vif_to_node(
self, self,
node: ty.Union[_node.Node, str], node: ty.Union[_node.Node, str],
@ -1049,6 +1168,8 @@ class Proxy(proxy.Proxy):
res = self._get_resource(_node.Node, node) res = self._get_resource(_node.Node, node)
return res.list_vifs(self) return res.list_vifs(self)
# ========== Allocations ==========
def allocations(self, **query): def allocations(self, **query):
"""Retrieve a generator of allocations. """Retrieve a generator of allocations.
@ -1175,109 +1296,7 @@ class Proxy(proxy.Proxy):
res = self._get_resource(_allocation.Allocation, allocation) res = self._get_resource(_allocation.Allocation, allocation)
return res.wait(self, timeout=timeout, ignore_error=ignore_error) return res.wait(self, timeout=timeout, ignore_error=ignore_error)
def add_node_trait(self, node, trait): # ========== Volume connectors ==========
"""Add a trait to a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param trait: trait to remove from the node.
:returns: The updated node
"""
res = self._get_resource(_node.Node, node)
return res.add_trait(self, trait)
def remove_node_trait(self, node, trait, ignore_missing=True):
"""Remove a trait from a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param trait: trait to remove from the node.
:param bool ignore_missing: When set to ``False``, an exception
:class:`~openstack.exceptions.NotFoundException` will be raised
when the trait could not be found. When set to ``True``, no
exception will be raised when attempting to delete a non-existent
trait.
:returns: The updated :class:`~openstack.baremetal.v1.node.Node`
"""
res = self._get_resource(_node.Node, node)
return res.remove_trait(self, trait, ignore_missing=ignore_missing)
def call_node_vendor_passthru(self, node, verb, method, body=None):
"""Calls vendor_passthru for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param verb: The HTTP verb, one of GET, SET, POST, DELETE.
:param method: The method to call using vendor_passthru.
:param body: The JSON body in the HTTP call.
:returns: The raw response from the method.
"""
res = self._get_resource(_node.Node, node)
return res.call_vendor_passthru(self, verb, method, body)
def list_node_vendor_passthru(self, node):
"""Lists vendor_passthru for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: A list of vendor_passthru methods for the node.
"""
res = self._get_resource(_node.Node, node)
return res.list_vendor_passthru(self)
def get_node_console(self, node):
"""Get the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: Connection information for the console.
"""
res = self._get_resource(_node.Node, node)
return res.get_node_console(self)
def enable_node_console(self, node):
"""Enable the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: None
"""
res = self._get_resource(_node.Node, node)
return res.set_console_mode(self, True)
def disable_node_console(self, node):
"""Disable the console for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: None
"""
res = self._get_resource(_node.Node, node)
return res.set_console_mode(self, False)
def set_node_traits(self, node, traits):
"""Set traits for a node.
Removes any existing traits and adds the traits passed in to this
method.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:param traits: list of traits to add to the node.
:returns: The updated :class:`~openstack.baremetal.v1.node.Node`
"""
res = self._get_resource(_node.Node, node)
return res.set_traits(self, traits)
def list_node_firmware(self, node):
"""Lists firmware components for a node.
:param node: The value can be the name or ID of a node or a
:class:`~openstack.baremetal.v1.node.Node` instance.
:returns: A list of the node's firmware components.
"""
res = self._get_resource(_node.Node, node)
return res.list_firmware(self)
def volume_connectors(self, details=False, **query): def volume_connectors(self, details=False, **query):
"""Retrieve a generator of volume_connector. """Retrieve a generator of volume_connector.
@ -1426,6 +1445,8 @@ class Proxy(proxy.Proxy):
ignore_missing=ignore_missing, ignore_missing=ignore_missing,
) )
# ========== Volume targets ==========
def volume_targets(self, details=False, **query): def volume_targets(self, details=False, **query):
"""Retrieve a generator of volume_target. """Retrieve a generator of volume_target.
@ -1568,6 +1589,8 @@ class Proxy(proxy.Proxy):
ignore_missing=ignore_missing, ignore_missing=ignore_missing,
) )
# ========== Deploy templates ==========
def deploy_templates(self, details=False, **query): def deploy_templates(self, details=False, **query):
"""Retrieve a generator of deploy_templates. """Retrieve a generator of deploy_templates.
@ -1678,6 +1701,8 @@ class Proxy(proxy.Proxy):
_deploytemplates.DeployTemplate, deploy_template _deploytemplates.DeployTemplate, deploy_template
).patch(self, patch) ).patch(self, patch)
# ========== Conductors ==========
def conductors(self, details=False, **query): def conductors(self, details=False, **query):
"""Retrieve a generator of conductors. """Retrieve a generator of conductors.
@ -1705,3 +1730,66 @@ class Proxy(proxy.Proxy):
return self._get_with_fields( return self._get_with_fields(
_conductor.Conductor, conductor, fields=fields _conductor.Conductor, conductor, fields=fields
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack import _log from openstack import _log
from openstack.baremetal.v1 import node as _node from openstack.baremetal.v1 import node as _node
from openstack.baremetal_introspection.v1 import introspection as _introspect from openstack.baremetal_introspection.v1 import introspection as _introspect
@ -18,6 +20,7 @@ from openstack.baremetal_introspection.v1 import (
) )
from openstack import exceptions from openstack import exceptions
from openstack import proxy from openstack import proxy
from openstack import resource
_logger = _log.setup_logging('openstack') _logger = _log.setup_logging('openstack')
@ -29,6 +32,8 @@ class Proxy(proxy.Proxy):
"introspection_rule": _introspection_rule.IntrospectionRule, "introspection_rule": _introspection_rule.IntrospectionRule,
} }
# ========== Introspections ==========
def introspections(self, **query): def introspections(self, **query):
"""Retrieve a generator of introspection records. """Retrieve a generator of introspection records.
@ -155,6 +160,8 @@ class Proxy(proxy.Proxy):
res = self._get_resource(_introspect.Introspection, introspection) res = self._get_resource(_introspect.Introspection, introspection)
return res.wait(self, timeout=timeout, ignore_error=ignore_error) return res.wait(self, timeout=timeout, ignore_error=ignore_error)
# ========== Introspection ruless ==========
def create_introspection_rule(self, **attrs): def create_introspection_rule(self, **attrs):
"""Create a new introspection rules from attributes. """Create a new introspection rules from attributes.
@ -227,3 +234,66 @@ class Proxy(proxy.Proxy):
objects objects
""" """
return self._list(_introspection_rule.IntrospectionRule, **query) return self._list(_introspection_rule.IntrospectionRule, **query)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
import warnings import warnings
from openstack.block_storage import _base_proxy from openstack.block_storage import _base_proxy
@ -29,7 +30,18 @@ from openstack import warnings as os_warnings
class Proxy(_base_proxy.BaseBlockStorageProxy): class Proxy(_base_proxy.BaseBlockStorageProxy):
# ====== SNAPSHOTS ====== # ========== Extensions ==========
def extensions(self):
"""Return a generator of extensions
:returns: A generator of extension
:rtype: :class:`~openstack.block_storage.v2.extension.Extension`
"""
return self._list(_extension.Extension)
# ========== Snapshots ==========
def get_snapshot(self, snapshot): def get_snapshot(self, snapshot):
"""Get a single snapshot """Get a single snapshot
@ -142,7 +154,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
_snapshot.Snapshot, snapshot, ignore_missing=ignore_missing _snapshot.Snapshot, snapshot, ignore_missing=ignore_missing
) )
# ====== SNAPSHOT ACTIONS ====== # ========== Snapshot actions ==========
def reset_snapshot(self, snapshot, status): def reset_snapshot(self, snapshot, status):
"""Reset status of the snapshot """Reset status of the snapshot
@ -155,7 +168,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
snapshot = self._get_resource(_snapshot.Snapshot, snapshot) snapshot = self._get_resource(_snapshot.Snapshot, snapshot)
snapshot.reset(self, status) snapshot.reset(self, status)
# ====== TYPES ====== # ========== Types ==========
def get_type(self, type): def get_type(self, type):
"""Get a single type """Get a single type
@ -260,7 +274,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
res = self._get_resource(_type.Type, type) res = self._get_resource(_type.Type, type)
return res.remove_private_access(self, project_id) return res.remove_private_access(self, project_id)
# ====== VOLUMES ====== # ========== Volumes ==========
def get_volume(self, volume): def get_volume(self, volume):
"""Get a single volume """Get a single volume
@ -367,7 +382,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
volume = self._get_resource(_volume.Volume, volume) volume = self._get_resource(_volume.Volume, volume)
volume.force_delete(self) volume.force_delete(self)
# ====== VOLUME ACTIONS ====== # ========== Volume actions ==========
def extend_volume(self, volume, size): def extend_volume(self, volume, size):
"""Extend a volume """Extend a volume
@ -548,7 +564,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
volume = self._get_resource(_volume.Volume, volume) volume = self._get_resource(_volume.Volume, volume)
volume.complete_migration(self, new_volume, error) volume.complete_migration(self, new_volume, error)
# ====== BACKEND POOLS ====== # ========== Backend pools ==========
def backend_pools(self, **query): def backend_pools(self, **query):
"""Returns a generator of cinder Back-end storage pools """Returns a generator of cinder Back-end storage pools
@ -559,7 +576,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
""" """
return self._list(_stats.Pools, **query) return self._list(_stats.Pools, **query)
# ====== BACKUPS ====== # ========== Backups ==========
def backups(self, details=True, **query): def backups(self, details=True, **query):
"""Retrieve a generator of backups """Retrieve a generator of backups
@ -654,7 +672,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
backup = self._get_resource(_backup.Backup, backup) backup = self._get_resource(_backup.Backup, backup)
backup.force_delete(self) backup.force_delete(self)
# ====== BACKUP ACTIONS ====== # ========== Backup actions ==========
def restore_backup(self, backup, volume_id, name): def restore_backup(self, backup, volume_id, name):
"""Restore a Backup to volume """Restore a Backup to volume
@ -681,7 +700,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
backup = self._get_resource(_backup.Backup, backup) backup = self._get_resource(_backup.Backup, backup)
backup.reset(self, status) backup.reset(self, status)
# ====== LIMITS ====== # ========== Limits ==========
def get_limits(self, project=None): def get_limits(self, project=None):
"""Retrieves limits """Retrieves limits
@ -698,7 +718,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
params['project_id'] = resource.Resource._get_id(project) params['project_id'] = resource.Resource._get_id(project)
return self._get(_limits.Limits, requires_id=False, **params) return self._get(_limits.Limits, requires_id=False, **params)
# ====== CAPABILITIES ====== # ========== Capabilities ==========
def get_capabilities(self, host): def get_capabilities(self, host):
"""Get a backend's capabilites """Get a backend's capabilites
@ -711,7 +732,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
""" """
return self._get(_capabilities.Capabilities, host) return self._get(_capabilities.Capabilities, host)
# ====== QUOTA CLASS SETS ====== # ========== Quota class sets ==========
def get_quota_class_set(self, quota_class_set='default'): def get_quota_class_set(self, quota_class_set='default'):
"""Get a single quota class set """Get a single quota class set
@ -748,7 +770,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
_quota_class_set.QuotaClassSet, quota_class_set, **attrs _quota_class_set.QuotaClassSet, quota_class_set, **attrs
) )
# ====== QUOTA SETS ====== # ========== Quota sets ==========
def get_quota_set(self, project, usage=False, **query): def get_quota_set(self, project, usage=False, **query):
"""Show QuotaSet information for the project """Show QuotaSet information for the project
@ -841,7 +864,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
attrs['project_id'] = project.id attrs['project_id'] = project.id
return self._update(_quota_set.QuotaSet, None, **attrs) return self._update(_quota_set.QuotaSet, None, **attrs)
# ====== VOLUME METADATA ====== # ========== Volume metadata ==========
def get_volume_metadata(self, volume): def get_volume_metadata(self, volume):
"""Return a dictionary of metadata for a volume """Return a dictionary of metadata for a volume
@ -888,7 +912,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
else: else:
volume.delete_metadata(self) volume.delete_metadata(self)
# ====== SNAPSHOT METADATA ====== # ========== Snapshot metadata ==========
def get_snapshot_metadata(self, snapshot): def get_snapshot_metadata(self, snapshot):
"""Return a dictionary of metadata for a snapshot """Return a dictionary of metadata for a snapshot
@ -937,79 +962,68 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
else: else:
snapshot.delete_metadata(self) snapshot.delete_metadata(self)
# ====== EXTENSIONS ====== # ========== Utilities ==========
def extensions(self):
"""Return a generator of extensions
:returns: A generator of extension
:rtype: :class:`~openstack.block_storage.v2.extension.Extension`
"""
return self._list(_extension.Extension)
# ====== UTILS ======
def wait_for_status( def wait_for_status(
self, self,
res, res: resource.ResourceT,
status='available', status: str = 'available',
failures=None, failures: ty.Optional[list[str]] = None,
interval=2, interval: ty.Union[int, float, None] = 2,
wait=120, wait: ty.Optional[int] = None,
callback=None, attribute: str = 'status',
): callback: ty.Optional[ty.Callable[[int], None]] = None,
"""Wait for a resource to be in a particular status. ) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param res: The resource to wait on to reach the specified status. :param session: The session to use for making this request.
The resource must have a ``status`` attribute. :param resource: The resource to wait on to reach the status. The
:type resource: A :class:`~openstack.resource.Resource` object. resource must have a status attribute specified via ``attribute``.
:param status: Desired status. :param status: Desired status of the resource.
:param failures: Statuses that would be interpreted as failures. :param failures: Statuses that would indicate the transition
:type failures: :py:class:`list` failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait before to consecutive :param interval: Number of seconds to wait between checks.
checks. Default to 2. :param wait: Maximum number of seconds to wait for transition.
:param wait: Maximum number of seconds to wait before the change. Set to ``None`` to wait forever.
Default to 120. :param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress. value, progress. This is API specific but is generally a percentage
value from 0-100.
:returns: The resource is returned on success. :return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition :raises: :class:`~openstack.exceptions.ResourceTimeout` if the
to the desired status failed to occur in specified seconds. transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource :raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
has transited to one of the failure statuses. transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a :raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute. ``status`` attribute
""" """
failures = ['error'] if failures is None else failures if failures is None:
failures = ['error']
return resource.wait_for_status( return resource.wait_for_status(
self, self, res, status, failures, interval, wait, attribute, callback
res,
status,
failures,
interval,
wait,
callback=callback,
) )
def wait_for_delete(self, res, interval=2, wait=120, callback=None): def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted. """Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted. :param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive :param interval: Number of seconds to wait before to consecutive
checks. Default to 2. checks.
:param wait: Maximum number of seconds to wait before the change. :param wait: Maximum number of seconds to wait before the change.
Default to 120.
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress. value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success. :returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition :raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds. to delete failed to occur in the specified seconds.
""" """
return resource.wait_for_delete( return resource.wait_for_delete(self, res, interval, wait, callback)
self,
res,
interval,
wait,
callback=callback,
)

View File

@ -2192,69 +2192,67 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
# ====== UTILS ====== # ====== UTILS ======
def wait_for_status( def wait_for_status(
self, self,
res, res: resource.ResourceT,
status='available', status: str = 'available',
failures=None, failures: ty.Optional[list[str]] = None,
interval=2, interval: ty.Union[int, float, None] = 2,
wait=120, wait: ty.Optional[int] = None,
callback=None, attribute: str = 'status',
): callback: ty.Optional[ty.Callable[[int], None]] = None,
"""Wait for a resource to be in a particular status. ) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param res: The resource to wait on to reach the specified status. :param session: The session to use for making this request.
The resource must have a ``status`` attribute. :param resource: The resource to wait on to reach the status. The
:type resource: A :class:`~openstack.resource.Resource` object. resource must have a status attribute specified via ``attribute``.
:param str status: Desired status. :param status: Desired status of the resource.
:param list failures: Statuses that would be interpreted as failures. :param failures: Statuses that would indicate the transition
:param interval: Number of seconds to wait before to consecutive failed such as 'ERROR'. Defaults to ['ERROR'].
checks. Default to 2. :param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait before the change. :param wait: Maximum number of seconds to wait for transition.
Default to 120. Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress. value, progress. This is API specific but is generally a percentage
value from 0-100.
:returns: The resource is returned on success. :return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition :raises: :class:`~openstack.exceptions.ResourceTimeout` if the
to the desired status failed to occur in specified seconds. transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource :raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
has transited to one of the failure statuses. transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a :raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute. ``status`` attribute
""" """
failures = ['error'] if failures is None else failures if failures is None:
failures = ['error']
return resource.wait_for_status( return resource.wait_for_status(
self, self, res, status, failures, interval, wait, attribute, callback
res,
status,
failures,
interval,
wait,
callback=callback,
) )
def wait_for_delete(self, res, interval=2, wait=120, callback=None): def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted. """Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted. :param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object. :param interval: Number of seconds to wait before to consecutive
:param int interval: Number of seconds to wait before two consecutive checks.
checks. Default to 2. :param wait: Maximum number of seconds to wait before the change.
:param int wait: Maximum number of seconds to wait before the change.
Default to 120.
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress. value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success. :returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition :raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds. to delete failed to occur in the specified seconds.
""" """
return resource.wait_for_delete( return resource.wait_for_delete(self, res, interval, wait, callback)
self,
res,
interval,
wait,
callback=callback,
)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
return {'block_storage': {'before': []}} return {'block_storage': {'before': []}}

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.clustering.v1 import action as _action from openstack.clustering.v1 import action as _action
from openstack.clustering.v1 import build_info from openstack.clustering.v1 import build_info
from openstack.clustering.v1 import cluster as _cluster from openstack.clustering.v1 import cluster as _cluster
@ -1046,49 +1048,6 @@ class Proxy(proxy.Proxy):
""" """
return self._list(_event.Event, **query) return self._list(_event.Event, **query)
def wait_for_status(
self, res, status, failures=None, interval=2, wait=120
):
"""Wait for a resource to be in a particular status.
:param res: The resource to wait on to reach the specified status.
The resource must have a ``status`` attribute.
:type resource: A :class:`~openstack.resource.Resource` object.
:param status: Desired status.
:param failures: Statuses that would be interpreted as failures.
:type failures: :py:class:`list`
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to the desired status failed to occur in specified seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
has transited to one of the failure statuses.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute.
"""
failures = [] if failures is None else failures
return resource.wait_for_status(
self, res, status, failures, interval, wait
)
def wait_for_delete(self, res, interval=2, wait=120):
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait)
def services(self, **query): def services(self, **query):
"""Get a generator of services. """Get a generator of services.
@ -1111,3 +1070,66 @@ class Proxy(proxy.Proxy):
""" """
obj = self._get_resource(_profile_type.ProfileType, profile_type) obj = self._get_resource(_profile_type.ProfileType, profile_type)
return obj.type_ops(self) return obj.type_ops(self)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
import warnings import warnings
from openstack.block_storage.v3 import volume as _volume from openstack.block_storage.v3 import volume as _volume
@ -2630,13 +2631,13 @@ class Proxy(proxy.Proxy):
def wait_for_server( def wait_for_server(
self, self,
server, server: _server.Server,
status='ACTIVE', status: str = 'ACTIVE',
failures=None, failures: ty.Optional[list[str]] = None,
interval=2, interval: ty.Union[int, float, None] = 2,
wait=120, wait: ty.Optional[int] = 120,
callback=None, callback: ty.Optional[ty.Callable[[int], None]] = None,
): ) -> _server.Server:
"""Wait for a server to be in a particular status. """Wait for a server to be in a particular status.
:param server: The :class:`~openstack.compute.v2.server.Server` to wait :param server: The :class:`~openstack.compute.v2.server.Server` to wait
@ -2651,7 +2652,6 @@ class Proxy(proxy.Proxy):
:type interval: int :type interval: int
:param wait: Maximum number of seconds to wait before the change. :param wait: Maximum number of seconds to wait before the change.
Default to 120. Default to 120.
:type wait: int
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100. value, progress, which is a percentage value from 0-100.
:type callback: callable :type callback: callable
@ -2675,15 +2675,58 @@ class Proxy(proxy.Proxy):
callback=callback, callback=callback,
) )
def wait_for_delete(self, res, interval=2, wait=120, callback=None): def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted. """Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted. :param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive :param interval: Number of seconds to wait before to consecutive
checks. Default to 2. checks.
:param wait: Maximum number of seconds to wait before the change. :param wait: Maximum number of seconds to wait before the change.
Default to 120.
:param callback: A callback function. This will be called with a single :param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100. value, progress, which is a percentage value from 0-100.

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.container_infrastructure_management.v1 import ( from openstack.container_infrastructure_management.v1 import (
cluster as _cluster, cluster as _cluster,
) )
@ -23,6 +25,7 @@ from openstack.container_infrastructure_management.v1 import (
service as _service, service as _service,
) )
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
@ -32,6 +35,8 @@ class Proxy(proxy.Proxy):
"service": _service.Service, "service": _service.Service,
} }
# ========== Clusters ==========
def create_cluster(self, **attrs): def create_cluster(self, **attrs):
"""Create a new cluster from attributes """Create a new cluster from attributes
@ -51,9 +56,9 @@ class Proxy(proxy.Proxy):
:class:`~openstack.container_infrastructure_management.v1.cluster.Cluster` :class:`~openstack.container_infrastructure_management.v1.cluster.Cluster`
instance. instance.
:param bool ignore_missing: When set to ``False`` :param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.NotFoundException` will be raised when :class:`~openstack.exceptions.NotFoundException` will be raised
the cluster does not exist. When set to ``True``, no exception will when the cluster does not exist. When set to ``True``, no exception
be set when attempting to delete a nonexistent cluster. will be set when attempting to delete a nonexistent cluster.
:returns: ``None`` :returns: ``None``
""" """
self._delete(_cluster.Cluster, cluster, ignore_missing=ignore_missing) self._delete(_cluster.Cluster, cluster, ignore_missing=ignore_missing)
@ -119,6 +124,7 @@ class Proxy(proxy.Proxy):
return self._update(_cluster.Cluster, cluster, **attrs) return self._update(_cluster.Cluster, cluster, **attrs)
# ============== Cluster Templates ============== # ============== Cluster Templates ==============
def create_cluster_template(self, **attrs): def create_cluster_template(self, **attrs):
"""Create a new cluster_template from attributes """Create a new cluster_template from attributes
@ -139,8 +145,8 @@ class Proxy(proxy.Proxy):
:class:`~openstack.container_infrastructure_management.v1.cluster_template.ClusterTemplate` :class:`~openstack.container_infrastructure_management.v1.cluster_template.ClusterTemplate`
instance. instance.
:param bool ignore_missing: When set to ``False`` :param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.NotFoundException` will be raised when :class:`~openstack.exceptions.NotFoundException` will be raised
the cluster_template does not exist. When set to ``True``, no when the cluster_template does not exist. When set to ``True``, no
exception will be set when attempting to delete a nonexistent exception will be set when attempting to delete a nonexistent
cluster_template. cluster_template.
:returns: ``None`` :returns: ``None``
@ -215,6 +221,7 @@ class Proxy(proxy.Proxy):
) )
# ============== Cluster Certificates ============== # ============== Cluster Certificates ==============
def create_cluster_certificate(self, **attrs): def create_cluster_certificate(self, **attrs):
"""Create a new cluster_certificate from CSR """Create a new cluster_certificate from CSR
@ -243,6 +250,7 @@ class Proxy(proxy.Proxy):
return self._get(_cluster_cert.ClusterCertificate, cluster_certificate) return self._get(_cluster_cert.ClusterCertificate, cluster_certificate)
# ============== Services ============== # ============== Services ==============
def services(self): def services(self):
"""Return a generator of services """Return a generator of services
@ -251,3 +259,66 @@ class Proxy(proxy.Proxy):
:class:`~openstack.container_infrastructure_management.v1.service.Service` :class:`~openstack.container_infrastructure_management.v1.service.Service`
""" """
return self._list(_service.Service) return self._list(_service.Service)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,11 +10,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.database.v1 import database as _database from openstack.database.v1 import database as _database
from openstack.database.v1 import flavor as _flavor from openstack.database.v1 import flavor as _flavor
from openstack.database.v1 import instance as _instance from openstack.database.v1 import instance as _instance
from openstack.database.v1 import user as _user from openstack.database.v1 import user as _user
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
@ -332,3 +335,66 @@ class Proxy(proxy.Proxy):
""" """
instance = self._get_resource(_instance.Instance, instance) instance = self._get_resource(_instance.Instance, instance)
return self._get(_user.User, user) return self._get(_user.User, user)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.dns.v2 import floating_ip as _fip from openstack.dns.v2 import floating_ip as _fip
from openstack.dns.v2 import limit as _limit from openstack.dns.v2 import limit as _limit
from openstack.dns.v2 import recordset as _rs from openstack.dns.v2 import recordset as _rs
@ -21,6 +23,7 @@ from openstack.dns.v2 import zone_import as _zone_import
from openstack.dns.v2 import zone_share as _zone_share from openstack.dns.v2 import zone_share as _zone_share
from openstack.dns.v2 import zone_transfer as _zone_transfer from openstack.dns.v2 import zone_transfer as _zone_transfer
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
@ -691,6 +694,68 @@ class Proxy(proxy.Proxy):
""" """
return self._get(_svc_status.ServiceStatus, service) return self._get(_svc_status.ServiceStatus, service)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
# DNS may depend on floating ip # DNS may depend on floating ip
return {'dns': {'before': ['network']}} return {'dns': {'before': ['network']}}

View File

@ -10,11 +10,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.identity.v2 import extension as _extension from openstack.identity.v2 import extension as _extension
from openstack.identity.v2 import role as _role from openstack.identity.v2 import role as _role
from openstack.identity.v2 import tenant as _tenant from openstack.identity.v2 import tenant as _tenant
from openstack.identity.v2 import user as _user from openstack.identity.v2 import user as _user
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
@ -272,3 +275,66 @@ class Proxy(proxy.Proxy):
:rtype: :class:`~openstack.identity.v2.user.User` :rtype: :class:`~openstack.identity.v2.user.User`
""" """
return self._update(_user.User, user, **attrs) return self._update(_user.User, user, **attrs)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
import openstack.exceptions as exception import openstack.exceptions as exception
from openstack.identity.v3 import ( from openstack.identity.v3 import (
application_credential as _application_credential, application_credential as _application_credential,
@ -2372,3 +2374,66 @@ class Proxy(proxy.Proxy):
return self._update( return self._update(
_service_provider.ServiceProvider, service_provider, **attrs _service_provider.ServiceProvider, service_provider, **attrs
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -11,11 +11,13 @@
# under the License. # under the License.
import os import os
import typing as ty
import warnings import warnings
from openstack import exceptions as exc from openstack import exceptions as exc
from openstack.image.v1 import image as _image from openstack.image.v1 import image as _image
from openstack import proxy from openstack import proxy
from openstack import resource
from openstack import utils from openstack import utils
from openstack import warnings as os_warnings from openstack import warnings as os_warnings
@ -473,3 +475,66 @@ class Proxy(proxy.Proxy):
img_props[k] = v img_props[k] = v
return self._update_image_properties(image, meta, img_props) return self._update_image_properties(image, meta, img_props)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -12,6 +12,7 @@
import os import os
import time import time
import typing as ty
import warnings import warnings
from openstack import exceptions from openstack import exceptions
@ -1891,21 +1892,68 @@ class Proxy(proxy.Proxy):
""" """
return self._get(_si.Import, requires_id=False) return self._get(_si.Import, requires_id=False)
# ====== UTILS ====== # ========== Utilities ==========
def wait_for_delete(self, res, interval=2, wait=120):
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted. """Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted. :param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive :param interval: Number of seconds to wait before to consecutive
checks. Default to 2. checks.
:param wait: Maximum number of seconds to wait before the change. :param wait: Maximum number of seconds to wait before the change.
Default to 120. :param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success. :returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition :raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds. to delete failed to occur in the specified seconds.
""" """
return resource.wait_for_delete(self, res, interval, wait) return resource.wait_for_delete(self, res, interval, wait, callback)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
return {'image': {'before': ['identity']}} return {'image': {'before': ['identity']}}

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import typing as ty
from openstack import exceptions from openstack import exceptions
from openstack.instance_ha.v1 import host as _host from openstack.instance_ha.v1 import host as _host
from openstack.instance_ha.v1 import notification as _notification from openstack.instance_ha.v1 import notification as _notification
@ -258,3 +260,66 @@ class Proxy(proxy.Proxy):
vmove_id, vmove_id,
notification_id=notification_id, notification_id=notification_id,
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,10 +10,13 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.key_manager.v1 import container as _container from openstack.key_manager.v1 import container as _container
from openstack.key_manager.v1 import order as _order from openstack.key_manager.v1 import order as _order
from openstack.key_manager.v1 import secret as _secret from openstack.key_manager.v1 import secret as _secret
from openstack import proxy from openstack import proxy
from openstack import resource
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
@ -266,3 +269,66 @@ class Proxy(proxy.Proxy):
:rtype: :class:`~openstack.key_manager.v1.secret.Secret` :rtype: :class:`~openstack.key_manager.v1.secret.Secret`
""" """
return self._update(_secret.Secret, secret, **attrs) return self._update(_secret.Secret, secret, **attrs)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.load_balancer.v2 import amphora as _amphora from openstack.load_balancer.v2 import amphora as _amphora
from openstack.load_balancer.v2 import availability_zone as _availability_zone from openstack.load_balancer.v2 import availability_zone as _availability_zone
from openstack.load_balancer.v2 import ( from openstack.load_balancer.v2 import (
@ -1280,3 +1282,66 @@ class Proxy(proxy.Proxy):
return self._update( return self._update(
_availability_zone.AvailabilityZone, availability_zone, **attrs _availability_zone.AvailabilityZone, availability_zone, **attrs
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.message.v2 import claim as _claim from openstack.message.v2 import claim as _claim
from openstack.message.v2 import message as _message from openstack.message.v2 import message as _message
from openstack.message.v2 import queue as _queue from openstack.message.v2 import queue as _queue
@ -302,3 +304,66 @@ class Proxy(proxy.Proxy):
queue_name=queue_name, queue_name=queue_name,
ignore_missing=ignore_missing, ignore_missing=ignore_missing,
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -7075,6 +7075,69 @@ class Proxy(proxy.Proxy):
""" """
return self._list(_sfc_sservice_graph.SfcServiceGraph, **query) return self._list(_sfc_sservice_graph.SfcServiceGraph, **query)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
return {'network': {'before': ['identity']}} return {'network': {'before': ['identity']}}

View File

@ -29,6 +29,7 @@ from openstack.object_store.v1 import container as _container
from openstack.object_store.v1 import info as _info from openstack.object_store.v1 import info as _info
from openstack.object_store.v1 import obj as _obj from openstack.object_store.v1 import obj as _obj
from openstack import proxy from openstack import proxy
from openstack import resource
from openstack import utils from openstack import utils
DEFAULT_OBJECT_SEGMENT_SIZE = 1073741824 # 1GB DEFAULT_OBJECT_SEGMENT_SIZE = 1073741824 # 1GB
@ -1116,6 +1117,69 @@ class Proxy(proxy.Proxy):
deleted = True deleted = True
return deleted return deleted
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)
# ========== Project Cleanup ========== # ========== Project Cleanup ==========
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
return {'object_store': {'before': []}} return {'object_store': {'before': []}}

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack import exceptions from openstack import exceptions
from openstack.orchestration.util import template_utils from openstack.orchestration.util import template_utils
from openstack.orchestration.v1 import resource as _resource from openstack.orchestration.v1 import resource as _resource
@ -25,9 +27,8 @@ from openstack import proxy
from openstack import resource from openstack import resource
# TODO(rladntjr4): Some of these methods support lookup by ID, while # TODO(rladntjr4): Some of these methods support lookup by ID, while others
# others support lookup by ID or name. We should choose one and use # support lookup by ID or name. We should choose one and use it consistently.
# it consistently.
class Proxy(proxy.Proxy): class Proxy(proxy.Proxy):
_resource_registry = { _resource_registry = {
"resource": _resource.Resource, "resource": _resource.Resource,
@ -514,49 +515,6 @@ class Proxy(proxy.Proxy):
ignore_errors=ignore_errors, ignore_errors=ignore_errors,
) )
def wait_for_status(
self, res, status='ACTIVE', failures=None, interval=2, wait=120
):
"""Wait for a resource to be in a particular status.
:param res: The resource to wait on to reach the specified status.
The resource must have a ``status`` attribute.
:type resource: A :class:`~openstack.resource.Resource` object.
:param status: Desired status.
:param failures: Statuses that would be interpreted as failures.
:type failures: :py:class:`list`
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to the desired status failed to occur in specified seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
has transited to one of the failure statuses.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute.
"""
failures = [] if failures is None else failures
return resource.wait_for_status(
self, res, status, failures, interval, wait
)
def wait_for_delete(self, res, interval=2, wait=120):
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait)
def get_template_contents( def get_template_contents(
self, self,
template_file=None, template_file=None,
@ -576,6 +534,106 @@ class Proxy(proxy.Proxy):
f"Error in processing template files: {str(e)}" f"Error in processing template files: {str(e)}"
) )
# ========== Stack events ==========
def stack_events(self, stack, resource_name=None, **attr):
"""Get a stack events
:param stack: The value can be the ID of a stack or an instance of
:class:`~openstack.orchestration.v1.stack.Stack`
:param resource_name: The name of resource. If the resource_name is not
None, the base_path changes.
:returns: A generator of stack_events objects
:rtype: :class:`~openstack.orchestration.v1.stack_event.StackEvent`
"""
if isinstance(stack, _stack.Stack):
obj = stack
else:
obj = self._get(_stack.Stack, stack)
if resource_name:
base_path = '/stacks/%(stack_name)s/%(stack_id)s/resources/%(resource_name)s/events'
return self._list(
_stack_event.StackEvent,
stack_name=obj.name,
stack_id=obj.id,
resource_name=resource_name,
base_path=base_path,
**attr,
)
return self._list(
_stack_event.StackEvent,
stack_name=obj.name,
stack_id=obj.id,
**attr,
)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)
def _get_cleanup_dependencies(self): def _get_cleanup_dependencies(self):
return { return {
'orchestration': {'before': ['compute', 'network', 'identity']} 'orchestration': {'before': ['compute', 'network', 'identity']}
@ -609,38 +667,3 @@ class Proxy(proxy.Proxy):
for stack in stacks: for stack in stacks:
self.wait_for_delete(stack) self.wait_for_delete(stack)
def stack_events(self, stack, resource_name=None, **attr):
"""Get a stack events
:param stack: The value can be the ID of a stack or an instance of
:class:`~openstack.orchestration.v1.stack.Stack`
:param resource_name: The name of resource. If the resource_name is not None,
the base_path changes.
:returns: A generator of stack_events objects
:rtype: :class:`~openstack.orchestration.v1.stack_event.StackEvent`
"""
if isinstance(stack, _stack.Stack):
obj = stack
else:
obj = self._get(_stack.Stack, stack)
if resource_name:
base_path = '/stacks/%(stack_name)s/%(stack_id)s/resources/%(resource_name)s/events'
return self._list(
_stack_event.StackEvent,
stack_name=obj.name,
stack_id=obj.id,
resource_name=resource_name,
base_path=base_path,
**attr,
)
return self._list(
_stack_event.StackEvent,
stack_name=obj.name,
stack_id=obj.id,
**attr,
)

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack.placement.v1 import resource_class as _resource_class from openstack.placement.v1 import resource_class as _resource_class
from openstack.placement.v1 import resource_provider as _resource_provider from openstack.placement.v1 import resource_provider as _resource_provider
from openstack.placement.v1 import ( from openstack.placement.v1 import (
@ -460,3 +462,66 @@ class Proxy(proxy.Proxy):
:returns: A generator of trait objects :returns: A generator of trait objects
""" """
return self._list(_trait.Trait, **query) return self._list(_trait.Trait, **query)
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -2391,7 +2391,7 @@ def wait_for_status(
session: adapter.Adapter, session: adapter.Adapter,
resource: ResourceT, resource: ResourceT,
status: str, status: str,
failures: list[str], failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2, interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None, wait: ty.Optional[int] = None,
attribute: str = 'status', attribute: str = 'status',

View File

@ -9,6 +9,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack import exceptions from openstack import exceptions
from openstack import proxy from openstack import proxy
from openstack import resource from openstack import resource
@ -357,47 +360,6 @@ class Proxy(proxy.Proxy):
ignore_missing=ignore_missing, ignore_missing=ignore_missing,
) )
def wait_for_status(
self,
res,
status='active',
failures=None,
interval=2,
wait=120,
status_attr_name='status',
):
"""Wait for a resource to be in a particular status.
:param res: The resource to wait on to reach the specified status.
The resource must have a ``status`` attribute.
:type resource: A :class:`~openstack.resource.Resource` object.
:param status: Desired status.
:param failures: Statuses that would be interpreted as failures.
:type failures: :py:class:`list`
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:param status_attr_name: name of the attribute to reach the desired
status.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to the desired status failed to occur in specified seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
has transited to one of the failure statuses.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute.
"""
failures = [] if failures is None else failures
return resource.wait_for_status(
self,
res,
status,
failures,
interval,
wait,
attribute=status_attr_name,
)
def storage_pools(self, details=True, **query): def storage_pools(self, details=True, **query):
"""Lists all back-end storage pools with details """Lists all back-end storage pools with details
@ -619,21 +581,6 @@ class Proxy(proxy.Proxy):
ignore_missing=ignore_missing, ignore_missing=ignore_missing,
) )
def wait_for_delete(self, res, interval=2, wait=120):
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:type resource: A :class:`~openstack.resource.Resource` object.
:param interval: Number of seconds to wait before to consecutive
checks. Default to 2.
:param wait: Maximum number of seconds to wait before the change.
Default to 120.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait)
def share_snapshot_instances(self, details=True, **query): def share_snapshot_instances(self, details=True, **query):
"""Lists all share snapshot instances with details. """Lists all share snapshot instances with details.
@ -1237,3 +1184,66 @@ class Proxy(proxy.Proxy):
return self._update( return self._update(
_quota_class_set.QuotaClassSet, quota_class_name, **attrs _quota_class_set.QuotaClassSet, quota_class_name, **attrs
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)

View File

@ -127,8 +127,16 @@ class TestVolume(TestVolumeProxy):
self.verify_wait_for_status( self.verify_wait_for_status(
self.proxy.wait_for_status, self.proxy.wait_for_status,
method_args=[value], method_args=[value],
expected_args=[self.proxy, value, 'available', ['error'], 2, 120], expected_args=[
expected_kwargs={'callback': None}, self.proxy,
value,
'available',
['error'],
2,
None,
'status',
None,
],
) )

View File

@ -126,8 +126,16 @@ class TestVolume(TestVolumeProxy):
self.verify_wait_for_status( self.verify_wait_for_status(
self.proxy.wait_for_status, self.proxy.wait_for_status,
method_args=[value], method_args=[value],
expected_args=[self.proxy, value, 'available', ['error'], 2, 120], expected_args=[
expected_kwargs={'callback': None}, self.proxy,
value,
'available',
['error'],
2,
None,
'status',
None,
],
) )

View File

@ -410,7 +410,7 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.proxy.wait_for_status(mock_resource, 'ACTIVE') self.proxy.wait_for_status(mock_resource, 'ACTIVE')
mock_wait.assert_called_once_with( mock_wait.assert_called_once_with(
self.proxy, mock_resource, 'ACTIVE', [], 2, 120 self.proxy, mock_resource, 'ACTIVE', None, 2, None, 'status', None
) )
@mock.patch("openstack.resource.wait_for_status") @mock.patch("openstack.resource.wait_for_status")
@ -421,7 +421,14 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.proxy.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2) self.proxy.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2)
mock_wait.assert_called_once_with( mock_wait.assert_called_once_with(
self.proxy, mock_resource, 'ACTIVE', ['ERROR'], 1, 2 self.proxy,
mock_resource,
'ACTIVE',
['ERROR'],
1,
2,
'status',
None,
) )
@mock.patch("openstack.resource.wait_for_delete") @mock.patch("openstack.resource.wait_for_delete")
@ -431,7 +438,9 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.proxy.wait_for_delete(mock_resource) self.proxy.wait_for_delete(mock_resource)
mock_wait.assert_called_once_with(self.proxy, mock_resource, 2, 120) mock_wait.assert_called_once_with(
self.proxy, mock_resource, 2, 120, None
)
@mock.patch("openstack.resource.wait_for_delete") @mock.patch("openstack.resource.wait_for_delete")
def test_wait_for_delete_params(self, mock_wait): def test_wait_for_delete_params(self, mock_wait):
@ -440,7 +449,9 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
self.proxy.wait_for_delete(mock_resource, 1, 2) self.proxy.wait_for_delete(mock_resource, 1, 2)
mock_wait.assert_called_once_with(self.proxy, mock_resource, 1, 2) mock_wait.assert_called_once_with(
self.proxy, mock_resource, 1, 2, None
)
def test_get_cluster_metadata(self): def test_get_cluster_metadata(self):
self._verify( self._verify(

View File

@ -131,7 +131,7 @@ class TestSharedFileSystemShare(TestSharedFileSystemProxy):
self.proxy.wait_for_status(mock_resource, 'ACTIVE') self.proxy.wait_for_status(mock_resource, 'ACTIVE')
mock_wait.assert_called_once_with( mock_wait.assert_called_once_with(
self.proxy, mock_resource, 'ACTIVE', [], 2, 120, attribute='status' self.proxy, mock_resource, 'ACTIVE', None, 2, None, 'status', None
) )
@ -308,7 +308,9 @@ class TestShareSnapshotResource(test_proxy_base.TestProxyBase):
self.proxy.wait_for_delete(mock_resource) self.proxy.wait_for_delete(mock_resource)
mock_wait.assert_called_once_with(self.proxy, mock_resource, 2, 120) mock_wait.assert_called_once_with(
self.proxy, mock_resource, 2, 120, None
)
class TestShareSnapshotInstanceResource(test_proxy_base.TestProxyBase): class TestShareSnapshotInstanceResource(test_proxy_base.TestProxyBase):

View File

@ -10,7 +10,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import typing as ty
from openstack import proxy from openstack import proxy
from openstack import resource
from openstack.workflow.v2 import cron_trigger as _cron_trigger from openstack.workflow.v2 import cron_trigger as _cron_trigger
from openstack.workflow.v2 import execution as _execution from openstack.workflow.v2 import execution as _execution
from openstack.workflow.v2 import workflow as _workflow from openstack.workflow.v2 import workflow as _workflow
@ -291,3 +294,66 @@ class Proxy(proxy.Proxy):
all_projects=all_projects, all_projects=all_projects,
**query, **query,
) )
# ========== Utilities ==========
def wait_for_status(
self,
res: resource.ResourceT,
status: str,
failures: ty.Optional[list[str]] = None,
interval: ty.Union[int, float, None] = 2,
wait: ty.Optional[int] = None,
attribute: str = 'status',
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for the resource to be in a particular status.
:param session: The session to use for making this request.
:param resource: The resource to wait on to reach the status. The
resource must have a status attribute specified via ``attribute``.
:param status: Desired status of the resource.
:param failures: Statuses that would indicate the transition
failed such as 'ERROR'. Defaults to ['ERROR'].
:param interval: Number of seconds to wait between checks.
:param wait: Maximum number of seconds to wait for transition.
Set to ``None`` to wait forever.
:param attribute: Name of the resource attribute that contains the
status.
:param callback: A callback function. This will be called with a single
value, progress. This is API specific but is generally a percentage
value from 0-100.
:return: The updated resource.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if the
transition to status failed to occur in ``wait`` seconds.
:raises: :class:`~openstack.exceptions.ResourceFailure` if the resource
transitioned to one of the states in ``failures``.
:raises: :class:`~AttributeError` if the resource does not have a
``status`` attribute
"""
return resource.wait_for_status(
self, res, status, failures, interval, wait, attribute, callback
)
def wait_for_delete(
self,
res: resource.ResourceT,
interval: int = 2,
wait: int = 120,
callback: ty.Optional[ty.Callable[[int], None]] = None,
) -> resource.ResourceT:
"""Wait for a resource to be deleted.
:param res: The resource to wait on to be deleted.
:param interval: Number of seconds to wait before to consecutive
checks.
:param wait: Maximum number of seconds to wait before the change.
:param callback: A callback function. This will be called with a single
value, progress, which is a percentage value from 0-100.
:returns: The resource is returned on success.
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait, callback)