Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1401817
  • 博文数量: 269
  • 博客积分: 3602
  • 博客等级: 中校
  • 技术积分: 4535
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-17 21:13
文章分类

全部博文(269)

文章存档

2014年(8)

2013年(139)

2012年(122)

分类: 系统运维

2013-10-08 11:37:35

最近有人问这个问题VI的Java API论坛已经回答了由社区

There should be a “Destroy_Task()”-Method for each Managed Object, so also Virtual Machines…. Cheers, Joerg

As  J?rg Lew has correctly pointed out the solution, I would like to elaborate a bit more here.

If you are using VI Java API, the method name is destroy_Task(). The code is as simple as:

VirtualMachine vm = null;
//get object assigned to vm
vm.destroy_Task()

To run the code, the user must have “VirtualMachine.Inventory.Delete” privilege on the virtual machine object. For other types of objects, the required privileges are different even though the method called is exactly the same. For the data center, for example, it’s “Datacenter.Delete.” You can check out the full table in the API reference.

Using destroy_Task() method can be a dangerous because it deletes everything of a VM, which cannot be reversed. If you call the method by mistake, then you’re screwed.

To play safe, you have another method to call: unregisterVM() method defined in VirtualMachine. When it’s called, the virtual machine disappears from the inventory tree, but all the files are still there. If you regret what you just called, you can add the virtual machine any time by calling the registerVM_Task() defined in Folder managed object.

The downside of this approach is you haven’t really released the disk space. If you have many of such virtual machines, you may find your data store out of space easily. To deal with it, you can run a script that scan for unregistered VM and remove them once in a while.

In the end, I have a fun question for you: what happens if you call destroy_Task() on a HostSystem? Will it destroy your ESX or ESXi?

阅读(4149) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~