def delete_vm(self, name):
        vm = self.client.find_entity_view("VirtualMachine", filter={"name":name})
        if not vm:
            raise Exception("Cannot find VM with name (%s)" % (name))

        vmdestroy = vm.Destroy_Task()
        for i in range(300):
            if not (vmdestroy.info.state in ["queued", "running"]):
                break
            sleep(1)
            vmdestroy.update_view_data(properties=["info"])

        if vmdestroy.info.state != "success":
            # TODO: Return the reason - this is part of the rather complex Task object
            raise Exception("Failed to delete VM (%s) in timeout period" % (name))
dataset/ETHPy150Open redhat-imaging/imagefactory/imagefactory_plugins/vSphere/VSphereHelper.py/VSphereHelper.delete_vm/original