Skip to content

Commit

Permalink
wait for delete for bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
Polina-Gubina committed Jul 26, 2023
1 parent 82430c3 commit 44f064c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
26 changes: 25 additions & 1 deletion otcextensions/sdk/vpc/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from openstack import exceptions
from openstack import proxy
from openstack import proxy, resource

Check warning on line 13 in otcextensions/sdk/vpc/v1/_proxy.py

View check run for this annotation

otc-zuul / eco/check

otcextensions/sdk/vpc/v1/_proxy.py#L13

pep8: F401 'openstack.resource' imported but unused

Check warning on line 13 in otcextensions/sdk/vpc/v1/_proxy.py

View check run for this annotation

otc-zuul / eco/check

otcextensions/sdk/vpc/v1/_proxy.py#L13

pep8: H301: one import per line

from otcextensions.sdk.vpc.v1 import bandwidth as _bandwidth
from otcextensions.sdk.vpc.v1 import peering as _peering
Expand Down Expand Up @@ -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
Expand Down
47 changes: 45 additions & 2 deletions otcextensions/sdk/vpc/v1/bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,51 @@
# 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 resource
from openstack import exceptions, resource

Check warning on line 12 in otcextensions/sdk/vpc/v1/bandwidth.py

View check run for this annotation

otc-zuul / eco/check

otcextensions/sdk/vpc/v1/bandwidth.py#L12

pep8: H301: one import per line
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.
Expand All @@ -37,12 +78,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)
Expand Down

0 comments on commit 44f064c

Please sign in to comment.