diff --git a/otcextensions/sdk/vpc/v1/_proxy.py b/otcextensions/sdk/vpc/v1/_proxy.py index cbb310a49..e740dc5a1 100644 --- a/otcextensions/sdk/vpc/v1/_proxy.py +++ b/otcextensions/sdk/vpc/v1/_proxy.py @@ -145,6 +145,30 @@ def delete_bandwidth(self, bandwidth, ignore_missing=True): ignore_missing=ignore_missing, project_id=project_id, base_path=base_path) + def wait_for_delete_bandwidth(self, bandwidth, interval=2, wait=60): + """Wait for the bandwidth to be deleted. + + :param bandwidth: + The :class:`~otcextensions.sdk.vpc.v1.bandwidth.Bandwidth` + or group ID to wait on to be deleted. + :param int interval: + Number of seconds to wait before to consecutive checks. + Default to 2. + :param int wait: + Maximum number of seconds to wait for the delete. + Default to 60. + :return: Method returns self on success. + :raises: :class:`~openstack.exceptions.ResourceTimeout` transition + to status failed to occur in wait seconds. + """ + project_id = self.get_project_id() + version = 'v2.0' + base_path = _bandwidth.Bandwidth.base_path % {'version': version, + 'project_id': project_id} + bandwidth = self._get_resource(_bandwidth.Bandwidth, bandwidth) + return _bandwidth.wait_for_delete(self, bandwidth, interval, + wait, base_path) + # ======== Peering ======== def create_peering(self, **attrs): """Create a new vpc peering from attributes diff --git a/otcextensions/sdk/vpc/v1/bandwidth.py b/otcextensions/sdk/vpc/v1/bandwidth.py index c98580fb6..6e0473eed 100644 --- a/otcextensions/sdk/vpc/v1/bandwidth.py +++ b/otcextensions/sdk/vpc/v1/bandwidth.py @@ -9,10 +9,52 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from openstack import exceptions from openstack import resource from openstack import utils +def wait_for_delete(session, resource, interval, wait, base_path, + callback=None): + """Wait for the bandwidth to be deleted. + + :param session: The session to use for making this request. + :type session: :class:`~keystoneauth1.adapter.Adapter` + :param resource: The resource to wait on to be deleted. + :type resource: :class:`~openstack.resource.Resource` + :param interval: Number of seconds to wait between checks. + :param wait: Maximum number of seconds to wait for the delete. + :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: Method returns self on success. + :raises: :class:`~openstack.exceptions.ResourceTimeout` transition + to status failed to occur in wait seconds. + """ + orig_resource = resource + for count in utils.iterate_timeout( + timeout=wait, + message="Timeout waiting for {res}:{id} to delete".format( + res=resource.__class__.__name__, id=resource.id + ), + wait=interval, + ): + try: + resource = resource.fetch(session, base_path=base_path, + skip_cache=True) + if not resource: + return orig_resource + if resource.status.lower() == 'deleted': + return resource + except exceptions.NotFoundException: + return orig_resource + + if callback: + progress = getattr(resource, 'progress', None) or 0 + callback(progress) + + class PublicIPInfo(resource.Resource): #: Properties #: Specifies the ID of the EIP that uses the bandwidth. @@ -37,12 +79,14 @@ class Bandwidth(resource.Resource): allow_delete = True allow_list = True - _query_mapping = resource.QueryParameters() + _query_mapping = resource.QueryParameters('id') # Properties #: Specifies the bandwidth name. #: *Type: dict* name = resource.Body('name', type=str) + #: *Type: dict* + id = resource.Body('id', type=str) #: Specifies the bandwidth size. #: *Type: dict* size = resource.Body('size', type=int)