Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for delete for bandwidth #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions otcextensions/sdk/vpc/v1/_proxy.py
Original file line number Diff line number Diff line change
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
46 changes: 45 additions & 1 deletion otcextensions/sdk/vpc/v1/bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down