def do_detach(cs, args): """Clear attachment metadata.""" volume = shell_utils.find_volume(cs, args.volume) try: cs.volumes.detach(volume.id, args.instance_uuid) print("Request to detach volume %s has been accepted." % (volume.id)) except Exception as e: print("Request to detach volume %s failed: %s." % (volume.id, e))
def do_reset_state(cs, args): volume = shell_utils.find_volume(cs, args.volume) try: cs.volumes.reset_state(volume.id, args.state) print("Request to reset-state volume %s has been accepted." % (volume.id)) except Exception as e: print("Reset-state for volume %s failed: %s" % (volume.id, e))
def do_attach(cs, args): """Add sg-volume attachment metadata.""" mode = args.mode mode = 'rw' if mode is None else mode if mode not in ['rw', 'ro']: print("Attach mode must be rw or ro") return volume = shell_utils.find_volume(cs, args.volume) attach = cs.volumes.attach(volume.id, args.instance_uuid, mode) utils.print_dict(attach.to_dict())
def do_delete(cs, args): """Delete error or available sg volume.""" failure_count = 0 for item in args.volume: try: volume = shell_utils.find_volume(cs, item) cs.volumes.delete(volume.id) print("Request to delete volume %s has been accepted." % item) except Exception as e: failure_count += 1 print("Request to delete volume %s failed: %s." % (item, e)) if failure_count == len(args.volume): raise exceptions.CommandError("Unable to delete any of the specified " "volumes.")
def do_update(cs, args): kwargs = {} if args.name is not None: kwargs['name'] = args.name if args.description is not None: kwargs['description'] = args.description if not kwargs: msg = 'Must supply either name or description.' raise exceptions.ClientException(code=1, message=msg) volume = shell_utils.find_volume(cs, args.volume) volume = cs.volumes.update(volume.id, kwargs) utils.print_dict(volume.to_dict())
def do_backup_create(cs, args): """Create backup.""" type = args.type type = 'full' if type is None else type if type not in ['full', 'incremental']: print("Backup type must be full or incremental") return destination = args.destination destination = 'local' if destination is None else destination if destination not in ['local', 'remote']: print("Backup destination must be local or remote") return volume = shell_utils.find_volume(cs, args.volume) backup = cs.backups.create(volume_id=volume.id, name=args.name, description=args.description, type=type, destination=destination) utils.print_dict(backup.to_dict())
def do_snapshot_create(cs, args): """Create snapshot.""" volume = shell_utils.find_volume(cs, args.volume) snapshot = cs.snapshots.create(volume.id, args.name, args.description) utils.print_dict(snapshot.to_dict())
def do_replicate_force_failover(cs, args): """Force failover volume's replicate.""" volume = shell_utils.find_volume(cs, args.volume) volume = cs.replicates.failover(volume.id, force=True) utils.print_dict(volume.to_dict())
def do_disable_sg(cs, args): """Disable volume's SG.""" volume = shell_utils.find_volume(cs, args.volume) volume = cs.volumes.disable(volume.id) utils.print_dict(volume.to_dict())
def do_show(cs, args): """Get a volume.""" volume = shell_utils.find_volume(cs, args.volume) utils.print_dict(volume.to_dict())