2.6.5. 제거 방법 사용
이러한 서비스 메서드는 기존 오브젝트를 제거합니다. 일반적으로는 단일 오브젝트를 관리하는 서비스 방식이므로 매개 변수를 사용하지 않습니다. 따라서 이 서비스는 제거할 오브젝트를 이미 알고 있습니다.
이 예제에서는 식별자가 123
인 가상 머신을 제거합니다.
# Find the virtual machine by name: vm = vms_service.list(search='name=123')[0] # Find the service that manages the virtual machine using the ID: vm_service = vms_service.vm_service(vm.id) # Remove the virtual machine: vm_service.remove()
일부 서비스의 remove
메서드는 제거 방법 또는 항목을 제어하는 추가 매개 변수를 지원합니다. 예를 들어 detach_only
부울 매개 변수를 사용하여 디스크를 유지하면서 가상 머신을 제거할 수 있습니다.
# Remove the virtual machine while preserving the disks: vm_service.remove(detach_only=True)
Remove 메서드는 개체가 성공적으로 제거되면 None
을 반환합니다.The remove
method returns None if the object is removed successfully. 삭제된 개체를 반환하지 않습니다. 어떤 이유로든 오브젝트를 제거할 수 없는 경우 SDK는 실패 세부 정보가 포함된 ovirtsdk4.Error
예외를 발생시킵니다.