diff options
Diffstat (limited to 'openstackclient/volume')
| -rw-r--r-- | openstackclient/volume/v1/volume.py | 37 | ||||
| -rw-r--r-- | openstackclient/volume/v2/volume.py | 37 |
2 files changed, 66 insertions, 8 deletions
diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py index dfbb0c54..198b890f 100644 --- a/openstackclient/volume/v1/volume.py +++ b/openstackclient/volume/v1/volume.py @@ -224,15 +224,44 @@ class CreateVolume(command.ShowOne): if parsed_args.bootable or parsed_args.non_bootable: try: - volume_client.volumes.set_bootable( - volume.id, parsed_args.bootable) + if utils.wait_for_status( + volume_client.volumes.get, + volume.id, + success_status=['available'], + error_status=['error'], + sleep_time=1 + ): + volume_client.volumes.set_bootable( + volume.id, + parsed_args.bootable + ) + else: + msg = _( + "Volume status is not available for setting boot " + "state" + ) + raise exceptions.CommandError(msg) except Exception as e: LOG.error(_("Failed to set volume bootable property: %s"), e) if parsed_args.read_only or parsed_args.read_write: try: - volume_client.volumes.update_readonly_flag( + if utils.wait_for_status( + volume_client.volumes.get, volume.id, - parsed_args.read_only) + success_status=['available'], + error_status=['error'], + sleep_time=1 + ): + volume_client.volumes.update_readonly_flag( + volume.id, + parsed_args.read_only + ) + else: + msg = _( + "Volume status is not available for setting it" + "read only." + ) + raise exceptions.CommandError(msg) except Exception as e: LOG.error(_("Failed to set volume read-only access " "mode flag: %s"), e) diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py index 7905e097..a5e5a670 100644 --- a/openstackclient/volume/v2/volume.py +++ b/openstackclient/volume/v2/volume.py @@ -257,15 +257,44 @@ class CreateVolume(command.ShowOne): if parsed_args.bootable or parsed_args.non_bootable: try: - volume_client.volumes.set_bootable( - volume.id, parsed_args.bootable) + if utils.wait_for_status( + volume_client.volumes.get, + volume.id, + success_status=['available'], + error_status=['error'], + sleep_time=1 + ): + volume_client.volumes.set_bootable( + volume.id, + parsed_args.bootable + ) + else: + msg = _( + "Volume status is not available for setting boot " + "state" + ) + raise exceptions.CommandError(msg) except Exception as e: LOG.error(_("Failed to set volume bootable property: %s"), e) if parsed_args.read_only or parsed_args.read_write: try: - volume_client.volumes.update_readonly_flag( + if utils.wait_for_status( + volume_client.volumes.get, volume.id, - parsed_args.read_only) + success_status=['available'], + error_status=['error'], + sleep_time=1 + ): + volume_client.volumes.update_readonly_flag( + volume.id, + parsed_args.read_only + ) + else: + msg = _( + "Volume status is not available for setting it" + "read only." + ) + raise exceptions.CommandError(msg) except Exception as e: LOG.error(_("Failed to set volume read-only access " "mode flag: %s"), e) |
