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:
parent
561e8cb8cd
commit
6395008300
@ -10,14 +10,19 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.accelerator.v2 import accelerator_request as _arq
|
||||
from openstack.accelerator.v2 import deployable as _deployable
|
||||
from openstack.accelerator.v2 import device as _device
|
||||
from openstack.accelerator.v2 import device_profile as _device_profile
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
# ========== Deployables ==========
|
||||
|
||||
def deployables(self, **query):
|
||||
"""Retrieve a generator of deployables.
|
||||
|
||||
@ -48,6 +53,8 @@ class Proxy(proxy.Proxy):
|
||||
self, patch
|
||||
)
|
||||
|
||||
# ========== Devices ==========
|
||||
|
||||
def devices(self, **query):
|
||||
"""Retrieve a generator of devices.
|
||||
|
||||
@ -81,6 +88,8 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._get(_device.Device, uuid)
|
||||
|
||||
# ========== Device profiles ==========
|
||||
|
||||
def device_profiles(self, **query):
|
||||
"""Retrieve a generator of device profiles.
|
||||
|
||||
@ -129,6 +138,8 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._get(_device_profile.DeviceProfile, uuid)
|
||||
|
||||
# ========== Accelerator requests ==========
|
||||
|
||||
def accelerator_requests(self, **query):
|
||||
"""Retrieve a generator of accelerator requests.
|
||||
|
||||
@ -192,3 +203,66 @@ class Proxy(proxy.Proxy):
|
||||
return self._get_resource(_arq.AcceleratorRequest, uuid).patch(
|
||||
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)
|
||||
|
@ -27,6 +27,7 @@ from openstack.baremetal.v1 import volume_connector as _volumeconnector
|
||||
from openstack.baremetal.v1 import volume_target as _volumetarget
|
||||
from openstack import exceptions
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
from openstack import utils
|
||||
|
||||
|
||||
@ -69,6 +70,8 @@ class Proxy(proxy.Proxy):
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
# ========== Chassis ==========
|
||||
|
||||
def chassis(self, details=False, **query):
|
||||
"""Retrieve a generator of chassis.
|
||||
|
||||
@ -186,6 +189,8 @@ class Proxy(proxy.Proxy):
|
||||
_chassis.Chassis, chassis, ignore_missing=ignore_missing
|
||||
)
|
||||
|
||||
# ========== Drivers ==========
|
||||
|
||||
def drivers(self, details=False, **query):
|
||||
"""Retrieve a generator of drivers.
|
||||
|
||||
@ -248,6 +253,8 @@ class Proxy(proxy.Proxy):
|
||||
self, verb, method, body
|
||||
)
|
||||
|
||||
# ========== Nodes ==========
|
||||
|
||||
def nodes(self, details=False, **query):
|
||||
"""Retrieve a generator of nodes.
|
||||
|
||||
@ -718,6 +725,114 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
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):
|
||||
"""Retrieve a generator of ports.
|
||||
|
||||
@ -843,6 +958,8 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._delete(_port.Port, port, ignore_missing=ignore_missing)
|
||||
|
||||
# ========== Port groups ==========
|
||||
|
||||
def port_groups(self, details=False, **query):
|
||||
"""Retrieve a generator of port groups.
|
||||
|
||||
@ -970,6 +1087,8 @@ class Proxy(proxy.Proxy):
|
||||
_portgroup.PortGroup, port_group, ignore_missing=ignore_missing
|
||||
)
|
||||
|
||||
# ========== VIFs ==========
|
||||
|
||||
def attach_vif_to_node(
|
||||
self,
|
||||
node: ty.Union[_node.Node, str],
|
||||
@ -1049,6 +1168,8 @@ class Proxy(proxy.Proxy):
|
||||
res = self._get_resource(_node.Node, node)
|
||||
return res.list_vifs(self)
|
||||
|
||||
# ========== Allocations ==========
|
||||
|
||||
def allocations(self, **query):
|
||||
"""Retrieve a generator of allocations.
|
||||
|
||||
@ -1175,109 +1296,7 @@ class Proxy(proxy.Proxy):
|
||||
res = self._get_resource(_allocation.Allocation, allocation)
|
||||
return res.wait(self, timeout=timeout, ignore_error=ignore_error)
|
||||
|
||||
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)
|
||||
# ========== Volume connectors ==========
|
||||
|
||||
def volume_connectors(self, details=False, **query):
|
||||
"""Retrieve a generator of volume_connector.
|
||||
@ -1426,6 +1445,8 @@ class Proxy(proxy.Proxy):
|
||||
ignore_missing=ignore_missing,
|
||||
)
|
||||
|
||||
# ========== Volume targets ==========
|
||||
|
||||
def volume_targets(self, details=False, **query):
|
||||
"""Retrieve a generator of volume_target.
|
||||
|
||||
@ -1568,6 +1589,8 @@ class Proxy(proxy.Proxy):
|
||||
ignore_missing=ignore_missing,
|
||||
)
|
||||
|
||||
# ========== Deploy templates ==========
|
||||
|
||||
def deploy_templates(self, details=False, **query):
|
||||
"""Retrieve a generator of deploy_templates.
|
||||
|
||||
@ -1678,6 +1701,8 @@ class Proxy(proxy.Proxy):
|
||||
_deploytemplates.DeployTemplate, deploy_template
|
||||
).patch(self, patch)
|
||||
|
||||
# ========== Conductors ==========
|
||||
|
||||
def conductors(self, details=False, **query):
|
||||
"""Retrieve a generator of conductors.
|
||||
|
||||
@ -1705,3 +1730,66 @@ class Proxy(proxy.Proxy):
|
||||
return self._get_with_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)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack import _log
|
||||
from openstack.baremetal.v1 import node as _node
|
||||
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 proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
_logger = _log.setup_logging('openstack')
|
||||
@ -29,6 +32,8 @@ class Proxy(proxy.Proxy):
|
||||
"introspection_rule": _introspection_rule.IntrospectionRule,
|
||||
}
|
||||
|
||||
# ========== Introspections ==========
|
||||
|
||||
def introspections(self, **query):
|
||||
"""Retrieve a generator of introspection records.
|
||||
|
||||
@ -155,6 +160,8 @@ class Proxy(proxy.Proxy):
|
||||
res = self._get_resource(_introspect.Introspection, introspection)
|
||||
return res.wait(self, timeout=timeout, ignore_error=ignore_error)
|
||||
|
||||
# ========== Introspection ruless ==========
|
||||
|
||||
def create_introspection_rule(self, **attrs):
|
||||
"""Create a new introspection rules from attributes.
|
||||
|
||||
@ -227,3 +234,66 @@ class Proxy(proxy.Proxy):
|
||||
objects
|
||||
"""
|
||||
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)
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
import warnings
|
||||
|
||||
from openstack.block_storage import _base_proxy
|
||||
@ -29,7 +30,18 @@ from openstack import warnings as os_warnings
|
||||
|
||||
|
||||
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):
|
||||
"""Get a single snapshot
|
||||
|
||||
@ -142,7 +154,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
_snapshot.Snapshot, snapshot, ignore_missing=ignore_missing
|
||||
)
|
||||
|
||||
# ====== SNAPSHOT ACTIONS ======
|
||||
# ========== Snapshot actions ==========
|
||||
|
||||
def reset_snapshot(self, snapshot, status):
|
||||
"""Reset status of the snapshot
|
||||
|
||||
@ -155,7 +168,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
snapshot = self._get_resource(_snapshot.Snapshot, snapshot)
|
||||
snapshot.reset(self, status)
|
||||
|
||||
# ====== TYPES ======
|
||||
# ========== Types ==========
|
||||
|
||||
def get_type(self, type):
|
||||
"""Get a single type
|
||||
|
||||
@ -260,7 +274,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
res = self._get_resource(_type.Type, type)
|
||||
return res.remove_private_access(self, project_id)
|
||||
|
||||
# ====== VOLUMES ======
|
||||
# ========== Volumes ==========
|
||||
|
||||
def get_volume(self, volume):
|
||||
"""Get a single volume
|
||||
|
||||
@ -367,7 +382,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
volume = self._get_resource(_volume.Volume, volume)
|
||||
volume.force_delete(self)
|
||||
|
||||
# ====== VOLUME ACTIONS ======
|
||||
# ========== Volume actions ==========
|
||||
|
||||
def extend_volume(self, volume, size):
|
||||
"""Extend a volume
|
||||
|
||||
@ -548,7 +564,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
volume = self._get_resource(_volume.Volume, volume)
|
||||
volume.complete_migration(self, new_volume, error)
|
||||
|
||||
# ====== BACKEND POOLS ======
|
||||
# ========== Backend pools ==========
|
||||
|
||||
def backend_pools(self, **query):
|
||||
"""Returns a generator of cinder Back-end storage pools
|
||||
|
||||
@ -559,7 +576,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
"""
|
||||
return self._list(_stats.Pools, **query)
|
||||
|
||||
# ====== BACKUPS ======
|
||||
# ========== Backups ==========
|
||||
|
||||
def backups(self, details=True, **query):
|
||||
"""Retrieve a generator of backups
|
||||
|
||||
@ -654,7 +672,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
backup = self._get_resource(_backup.Backup, backup)
|
||||
backup.force_delete(self)
|
||||
|
||||
# ====== BACKUP ACTIONS ======
|
||||
# ========== Backup actions ==========
|
||||
|
||||
def restore_backup(self, backup, volume_id, name):
|
||||
"""Restore a Backup to volume
|
||||
|
||||
@ -681,7 +700,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
backup = self._get_resource(_backup.Backup, backup)
|
||||
backup.reset(self, status)
|
||||
|
||||
# ====== LIMITS ======
|
||||
# ========== Limits ==========
|
||||
|
||||
def get_limits(self, project=None):
|
||||
"""Retrieves limits
|
||||
|
||||
@ -698,7 +718,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
params['project_id'] = resource.Resource._get_id(project)
|
||||
return self._get(_limits.Limits, requires_id=False, **params)
|
||||
|
||||
# ====== CAPABILITIES ======
|
||||
# ========== Capabilities ==========
|
||||
|
||||
def get_capabilities(self, host):
|
||||
"""Get a backend's capabilites
|
||||
|
||||
@ -711,7 +732,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
"""
|
||||
return self._get(_capabilities.Capabilities, host)
|
||||
|
||||
# ====== QUOTA CLASS SETS ======
|
||||
# ========== Quota class sets ==========
|
||||
|
||||
def get_quota_class_set(self, quota_class_set='default'):
|
||||
"""Get a single quota class set
|
||||
|
||||
@ -748,7 +770,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
_quota_class_set.QuotaClassSet, quota_class_set, **attrs
|
||||
)
|
||||
|
||||
# ====== QUOTA SETS ======
|
||||
# ========== Quota sets ==========
|
||||
|
||||
def get_quota_set(self, project, usage=False, **query):
|
||||
"""Show QuotaSet information for the project
|
||||
|
||||
@ -841,7 +864,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
attrs['project_id'] = project.id
|
||||
return self._update(_quota_set.QuotaSet, None, **attrs)
|
||||
|
||||
# ====== VOLUME METADATA ======
|
||||
# ========== Volume metadata ==========
|
||||
|
||||
def get_volume_metadata(self, volume):
|
||||
"""Return a dictionary of metadata for a volume
|
||||
|
||||
@ -888,7 +912,8 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
else:
|
||||
volume.delete_metadata(self)
|
||||
|
||||
# ====== SNAPSHOT METADATA ======
|
||||
# ========== Snapshot metadata ==========
|
||||
|
||||
def get_snapshot_metadata(self, snapshot):
|
||||
"""Return a dictionary of metadata for a snapshot
|
||||
|
||||
@ -937,79 +962,68 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
else:
|
||||
snapshot.delete_metadata(self)
|
||||
|
||||
# ====== EXTENSIONS ======
|
||||
def extensions(self):
|
||||
"""Return a generator of extensions
|
||||
# ========== Utilities ==========
|
||||
|
||||
:returns: A generator of extension
|
||||
:rtype: :class:`~openstack.block_storage.v2.extension.Extension`
|
||||
"""
|
||||
return self._list(_extension.Extension)
|
||||
|
||||
# ====== UTILS ======
|
||||
def wait_for_status(
|
||||
self,
|
||||
res,
|
||||
status='available',
|
||||
failures=None,
|
||||
interval=2,
|
||||
wait=120,
|
||||
callback=None,
|
||||
):
|
||||
"""Wait for a resource to be in a particular status.
|
||||
res: resource.ResourceT,
|
||||
status: str = 'available',
|
||||
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 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 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.
|
||||
value, progress. This is API specific but is generally a percentage
|
||||
value from 0-100.
|
||||
|
||||
:returns: The resource is returned on success.
|
||||
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
|
||||
to the desired status failed to occur in specified seconds.
|
||||
: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
|
||||
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
|
||||
``status`` attribute.
|
||||
``status`` attribute
|
||||
"""
|
||||
failures = ['error'] if failures is None else failures
|
||||
if failures is None:
|
||||
failures = ['error']
|
||||
|
||||
return resource.wait_for_status(
|
||||
self,
|
||||
res,
|
||||
status,
|
||||
failures,
|
||||
interval,
|
||||
wait,
|
||||
callback=callback,
|
||||
self, res, status, failures, interval, wait, attribute, 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.
|
||||
|
||||
: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.
|
||||
checks.
|
||||
: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.
|
||||
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=callback,
|
||||
)
|
||||
return resource.wait_for_delete(self, res, interval, wait, callback)
|
||||
|
@ -2192,69 +2192,67 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
# ====== UTILS ======
|
||||
def wait_for_status(
|
||||
self,
|
||||
res,
|
||||
status='available',
|
||||
failures=None,
|
||||
interval=2,
|
||||
wait=120,
|
||||
callback=None,
|
||||
):
|
||||
"""Wait for a resource to be in a particular status.
|
||||
res: resource.ResourceT,
|
||||
status: str = 'available',
|
||||
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 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 str status: Desired status.
|
||||
:param list failures: Statuses that would be interpreted as failures.
|
||||
: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 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.
|
||||
value, progress. This is API specific but is generally a percentage
|
||||
value from 0-100.
|
||||
|
||||
:returns: The resource is returned on success.
|
||||
:raises: :class:`~openstack.exceptions.ResourceTimeout` if transition
|
||||
to the desired status failed to occur in specified seconds.
|
||||
: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
|
||||
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
|
||||
``status`` attribute.
|
||||
``status`` attribute
|
||||
"""
|
||||
failures = ['error'] if failures is None else failures
|
||||
if failures is None:
|
||||
failures = ['error']
|
||||
|
||||
return resource.wait_for_status(
|
||||
self,
|
||||
res,
|
||||
status,
|
||||
failures,
|
||||
interval,
|
||||
wait,
|
||||
callback=callback,
|
||||
self, res, status, failures, interval, wait, attribute, 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.
|
||||
|
||||
:param res: The resource to wait on to be deleted.
|
||||
:type resource: A :class:`~openstack.resource.Resource` object.
|
||||
:param int interval: Number of seconds to wait before two consecutive
|
||||
checks. Default to 2.
|
||||
:param int wait: Maximum number of seconds to wait before the change.
|
||||
Default to 120.
|
||||
: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.
|
||||
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=callback,
|
||||
)
|
||||
return resource.wait_for_delete(self, res, interval, wait, callback)
|
||||
|
||||
def _get_cleanup_dependencies(self):
|
||||
return {'block_storage': {'before': []}}
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.clustering.v1 import action as _action
|
||||
from openstack.clustering.v1 import build_info
|
||||
from openstack.clustering.v1 import cluster as _cluster
|
||||
@ -1046,49 +1048,6 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
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):
|
||||
"""Get a generator of services.
|
||||
|
||||
@ -1111,3 +1070,66 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
obj = self._get_resource(_profile_type.ProfileType, profile_type)
|
||||
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)
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
import warnings
|
||||
|
||||
from openstack.block_storage.v3 import volume as _volume
|
||||
@ -2630,13 +2631,13 @@ class Proxy(proxy.Proxy):
|
||||
|
||||
def wait_for_server(
|
||||
self,
|
||||
server,
|
||||
status='ACTIVE',
|
||||
failures=None,
|
||||
interval=2,
|
||||
wait=120,
|
||||
callback=None,
|
||||
):
|
||||
server: _server.Server,
|
||||
status: str = 'ACTIVE',
|
||||
failures: ty.Optional[list[str]] = None,
|
||||
interval: ty.Union[int, float, None] = 2,
|
||||
wait: ty.Optional[int] = 120,
|
||||
callback: ty.Optional[ty.Callable[[int], None]] = None,
|
||||
) -> _server.Server:
|
||||
"""Wait for a server to be in a particular status.
|
||||
|
||||
:param server: The :class:`~openstack.compute.v2.server.Server` to wait
|
||||
@ -2651,7 +2652,6 @@ class Proxy(proxy.Proxy):
|
||||
:type interval: int
|
||||
:param wait: Maximum number of seconds to wait before the change.
|
||||
Default to 120.
|
||||
:type wait: int
|
||||
:param callback: A callback function. This will be called with a single
|
||||
value, progress, which is a percentage value from 0-100.
|
||||
:type callback: callable
|
||||
@ -2675,15 +2675,58 @@ class Proxy(proxy.Proxy):
|
||||
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.
|
||||
|
||||
: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.
|
||||
checks.
|
||||
: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.
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.container_infrastructure_management.v1 import (
|
||||
cluster as _cluster,
|
||||
)
|
||||
@ -23,6 +25,7 @@ from openstack.container_infrastructure_management.v1 import (
|
||||
service as _service,
|
||||
)
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
@ -32,6 +35,8 @@ class Proxy(proxy.Proxy):
|
||||
"service": _service.Service,
|
||||
}
|
||||
|
||||
# ========== Clusters ==========
|
||||
|
||||
def create_cluster(self, **attrs):
|
||||
"""Create a new cluster from attributes
|
||||
|
||||
@ -51,9 +56,9 @@ class Proxy(proxy.Proxy):
|
||||
:class:`~openstack.container_infrastructure_management.v1.cluster.Cluster`
|
||||
instance.
|
||||
:param bool ignore_missing: When set to ``False``
|
||||
:class:`~openstack.exceptions.NotFoundException` will be raised when
|
||||
the cluster does not exist. When set to ``True``, no exception will
|
||||
be set when attempting to delete a nonexistent cluster.
|
||||
:class:`~openstack.exceptions.NotFoundException` will be raised
|
||||
when the cluster does not exist. When set to ``True``, no exception
|
||||
will be set when attempting to delete a nonexistent cluster.
|
||||
:returns: ``None``
|
||||
"""
|
||||
self._delete(_cluster.Cluster, cluster, ignore_missing=ignore_missing)
|
||||
@ -119,6 +124,7 @@ class Proxy(proxy.Proxy):
|
||||
return self._update(_cluster.Cluster, cluster, **attrs)
|
||||
|
||||
# ============== Cluster Templates ==============
|
||||
|
||||
def create_cluster_template(self, **attrs):
|
||||
"""Create a new cluster_template from attributes
|
||||
|
||||
@ -139,8 +145,8 @@ class Proxy(proxy.Proxy):
|
||||
:class:`~openstack.container_infrastructure_management.v1.cluster_template.ClusterTemplate`
|
||||
instance.
|
||||
:param bool ignore_missing: When set to ``False``
|
||||
:class:`~openstack.exceptions.NotFoundException` will be raised when
|
||||
the cluster_template does not exist. When set to ``True``, no
|
||||
:class:`~openstack.exceptions.NotFoundException` will be raised
|
||||
when the cluster_template does not exist. When set to ``True``, no
|
||||
exception will be set when attempting to delete a nonexistent
|
||||
cluster_template.
|
||||
:returns: ``None``
|
||||
@ -215,6 +221,7 @@ class Proxy(proxy.Proxy):
|
||||
)
|
||||
|
||||
# ============== Cluster Certificates ==============
|
||||
|
||||
def create_cluster_certificate(self, **attrs):
|
||||
"""Create a new cluster_certificate from CSR
|
||||
|
||||
@ -243,6 +250,7 @@ class Proxy(proxy.Proxy):
|
||||
return self._get(_cluster_cert.ClusterCertificate, cluster_certificate)
|
||||
|
||||
# ============== Services ==============
|
||||
|
||||
def services(self):
|
||||
"""Return a generator of services
|
||||
|
||||
@ -251,3 +259,66 @@ class Proxy(proxy.Proxy):
|
||||
:class:`~openstack.container_infrastructure_management.v1.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)
|
||||
|
@ -10,11 +10,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.database.v1 import database as _database
|
||||
from openstack.database.v1 import flavor as _flavor
|
||||
from openstack.database.v1 import instance as _instance
|
||||
from openstack.database.v1 import user as _user
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
@ -332,3 +335,66 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
instance = self._get_resource(_instance.Instance, instance)
|
||||
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)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.dns.v2 import floating_ip as _fip
|
||||
from openstack.dns.v2 import limit as _limit
|
||||
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_transfer as _zone_transfer
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
@ -691,6 +694,68 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
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):
|
||||
# DNS may depend on floating ip
|
||||
return {'dns': {'before': ['network']}}
|
||||
|
@ -10,11 +10,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.identity.v2 import extension as _extension
|
||||
from openstack.identity.v2 import role as _role
|
||||
from openstack.identity.v2 import tenant as _tenant
|
||||
from openstack.identity.v2 import user as _user
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
@ -272,3 +275,66 @@ class Proxy(proxy.Proxy):
|
||||
:rtype: :class:`~openstack.identity.v2.user.User`
|
||||
"""
|
||||
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)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
import openstack.exceptions as exception
|
||||
from openstack.identity.v3 import (
|
||||
application_credential as _application_credential,
|
||||
@ -2372,3 +2374,66 @@ class Proxy(proxy.Proxy):
|
||||
return self._update(
|
||||
_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)
|
||||
|
@ -11,11 +11,13 @@
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import typing as ty
|
||||
import warnings
|
||||
|
||||
from openstack import exceptions as exc
|
||||
from openstack.image.v1 import image as _image
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
from openstack import utils
|
||||
from openstack import warnings as os_warnings
|
||||
|
||||
@ -473,3 +475,66 @@ class Proxy(proxy.Proxy):
|
||||
img_props[k] = v
|
||||
|
||||
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)
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
import os
|
||||
import time
|
||||
import typing as ty
|
||||
import warnings
|
||||
|
||||
from openstack import exceptions
|
||||
@ -1891,21 +1892,68 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
return self._get(_si.Import, requires_id=False)
|
||||
|
||||
# ====== UTILS ======
|
||||
def wait_for_delete(self, res, interval=2, wait=120):
|
||||
# ========== 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.
|
||||
:type resource: A :class:`~openstack.resource.Resource` object.
|
||||
: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.
|
||||
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.
|
||||
: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)
|
||||
return resource.wait_for_delete(self, res, interval, wait, callback)
|
||||
|
||||
def _get_cleanup_dependencies(self):
|
||||
return {'image': {'before': ['identity']}}
|
||||
|
@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack import exceptions
|
||||
from openstack.instance_ha.v1 import host as _host
|
||||
from openstack.instance_ha.v1 import notification as _notification
|
||||
@ -258,3 +260,66 @@ class Proxy(proxy.Proxy):
|
||||
vmove_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)
|
||||
|
@ -10,10 +10,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.key_manager.v1 import container as _container
|
||||
from openstack.key_manager.v1 import order as _order
|
||||
from openstack.key_manager.v1 import secret as _secret
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class Proxy(proxy.Proxy):
|
||||
@ -266,3 +269,66 @@ class Proxy(proxy.Proxy):
|
||||
:rtype: :class:`~openstack.key_manager.v1.secret.Secret`
|
||||
"""
|
||||
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)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
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 (
|
||||
@ -1280,3 +1282,66 @@ class Proxy(proxy.Proxy):
|
||||
return self._update(
|
||||
_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)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack.message.v2 import claim as _claim
|
||||
from openstack.message.v2 import message as _message
|
||||
from openstack.message.v2 import queue as _queue
|
||||
@ -302,3 +304,66 @@ class Proxy(proxy.Proxy):
|
||||
queue_name=queue_name,
|
||||
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)
|
||||
|
@ -7075,6 +7075,69 @@ class Proxy(proxy.Proxy):
|
||||
"""
|
||||
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):
|
||||
return {'network': {'before': ['identity']}}
|
||||
|
||||
|
@ -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 obj as _obj
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
from openstack import utils
|
||||
|
||||
DEFAULT_OBJECT_SEGMENT_SIZE = 1073741824 # 1GB
|
||||
@ -1116,6 +1117,69 @@ class Proxy(proxy.Proxy):
|
||||
deleted = True
|
||||
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 ==========
|
||||
def _get_cleanup_dependencies(self):
|
||||
return {'object_store': {'before': []}}
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack import exceptions
|
||||
from openstack.orchestration.util import template_utils
|
||||
from openstack.orchestration.v1 import resource as _resource
|
||||
@ -25,9 +27,8 @@ from openstack import proxy
|
||||
from openstack import resource
|
||||
|
||||
|
||||
# TODO(rladntjr4): Some of these methods support lookup by ID, while
|
||||
# others support lookup by ID or name. We should choose one and use
|
||||
# it consistently.
|
||||
# TODO(rladntjr4): Some of these methods support lookup by ID, while others
|
||||
# support lookup by ID or name. We should choose one and use it consistently.
|
||||
class Proxy(proxy.Proxy):
|
||||
_resource_registry = {
|
||||
"resource": _resource.Resource,
|
||||
@ -514,49 +515,6 @@ class Proxy(proxy.Proxy):
|
||||
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(
|
||||
self,
|
||||
template_file=None,
|
||||
@ -576,6 +534,106 @@ class Proxy(proxy.Proxy):
|
||||
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):
|
||||
return {
|
||||
'orchestration': {'before': ['compute', 'network', 'identity']}
|
||||
@ -609,38 +667,3 @@ class Proxy(proxy.Proxy):
|
||||
|
||||
for stack in stacks:
|
||||
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,
|
||||
)
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
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 (
|
||||
@ -460,3 +462,66 @@ class Proxy(proxy.Proxy):
|
||||
:returns: A generator of trait objects
|
||||
"""
|
||||
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)
|
||||
|
@ -2391,7 +2391,7 @@ def wait_for_status(
|
||||
session: adapter.Adapter,
|
||||
resource: ResourceT,
|
||||
status: str,
|
||||
failures: list[str],
|
||||
failures: ty.Optional[list[str]] = None,
|
||||
interval: ty.Union[int, float, None] = 2,
|
||||
wait: ty.Optional[int] = None,
|
||||
attribute: str = 'status',
|
||||
|
@ -9,6 +9,9 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack import exceptions
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
@ -357,47 +360,6 @@ class Proxy(proxy.Proxy):
|
||||
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):
|
||||
"""Lists all back-end storage pools with details
|
||||
|
||||
@ -619,21 +581,6 @@ class Proxy(proxy.Proxy):
|
||||
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):
|
||||
"""Lists all share snapshot instances with details.
|
||||
|
||||
@ -1237,3 +1184,66 @@ class Proxy(proxy.Proxy):
|
||||
return self._update(
|
||||
_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)
|
||||
|
@ -127,8 +127,16 @@ class TestVolume(TestVolumeProxy):
|
||||
self.verify_wait_for_status(
|
||||
self.proxy.wait_for_status,
|
||||
method_args=[value],
|
||||
expected_args=[self.proxy, value, 'available', ['error'], 2, 120],
|
||||
expected_kwargs={'callback': None},
|
||||
expected_args=[
|
||||
self.proxy,
|
||||
value,
|
||||
'available',
|
||||
['error'],
|
||||
2,
|
||||
None,
|
||||
'status',
|
||||
None,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
@ -126,8 +126,16 @@ class TestVolume(TestVolumeProxy):
|
||||
self.verify_wait_for_status(
|
||||
self.proxy.wait_for_status,
|
||||
method_args=[value],
|
||||
expected_args=[self.proxy, value, 'available', ['error'], 2, 120],
|
||||
expected_kwargs={'callback': None},
|
||||
expected_args=[
|
||||
self.proxy,
|
||||
value,
|
||||
'available',
|
||||
['error'],
|
||||
2,
|
||||
None,
|
||||
'status',
|
||||
None,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
@ -410,7 +410,7 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
|
||||
self.proxy.wait_for_status(mock_resource, 'ACTIVE')
|
||||
|
||||
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")
|
||||
@ -421,7 +421,14 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
|
||||
self.proxy.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2)
|
||||
|
||||
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")
|
||||
@ -431,7 +438,9 @@ class TestClusterProxy(test_proxy_base.TestProxyBase):
|
||||
|
||||
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")
|
||||
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)
|
||||
|
||||
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):
|
||||
self._verify(
|
||||
|
@ -131,7 +131,7 @@ class TestSharedFileSystemShare(TestSharedFileSystemProxy):
|
||||
self.proxy.wait_for_status(mock_resource, 'ACTIVE')
|
||||
|
||||
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)
|
||||
|
||||
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):
|
||||
|
@ -10,7 +10,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import typing as ty
|
||||
|
||||
from openstack import proxy
|
||||
from openstack import resource
|
||||
from openstack.workflow.v2 import cron_trigger as _cron_trigger
|
||||
from openstack.workflow.v2 import execution as _execution
|
||||
from openstack.workflow.v2 import workflow as _workflow
|
||||
@ -291,3 +294,66 @@ class Proxy(proxy.Proxy):
|
||||
all_projects=all_projects,
|
||||
**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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user