如何使用 VSphere java API 创建虚拟机?
我想编写一些java代码来创建VM,安装iso(或者如果无法安装iso则复制现有的vm设置)并分配磁盘空间,为创建的VM创建登录名。
我查看了 http 中的 Vsphere API 示例://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim25/mo/samples/,有已安装的电源开关虚拟机。我不知道如何使用 API 创建一个。我有两个问题:
- 使用API创建VM的步骤是什么?
- 应使用哪些 API 或对象以编程方式创建 VM?
感谢您的帮助。
I want to write some java code to create a VM, install iso (or copy the existing vm set up if install iso is not possible) and assign disk space, create login for the created VM.
I looked at Vsphere API examples in http://vijava.svn.sourceforge.net/viewvc/vijava/trunk/src/com/vmware/vim25/mo/samples/, it has power on/off of installed VM. I could not figure out how to create one with the API. I have two questions:
- What are the steps to create VM using API?
- What API or objects should be used to create VM programatically?
Appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道我迟到了大约一年,但是当您下载 SDK 时,您将获得如何创建 VMdisk 的示例。了解代码,然后您就可以按照自己的方式进行操作:)
SDK.zip 文件的链接
http://communities.vmware.com/community/vmtn/developer/forums/java_toolkit
以及 SDk 内部的 VMDisk 文件:
\SDK\vsphere-ws\java\JAXWS\samples\com\vmware\vm
I know i am about a year late, but when you download the SDK, you will have a sample how to create a VMdisk. Understand the code and then you can just do it your way :)
The link to the SDK.zip file
http://communities.vmware.com/community/vmtn/developer/forums/java_toolkit
and inside the SDk, the VMDisk file:
\SDK\vsphere-ws\java\JAXWS\samples\com\vmware\vm
您需要保留 VMware Web Services SDK 文档 很方便 - 不幸的是,它们最近更改了格式,因此我不确定能为您提供多好的深层链接。我使用的具体方法是 CreateVM_Task(您必须向下滚动才能在文件夹对象上找到它)。或者,如果您使用资源池,CreateChildVM_Task 可能更适用(再次向下滚动以查找 它)。
还有 有关创建虚拟机的文档包含一些不完整的示例代码。
至于在层次结构中的哪个位置创建虚拟机,这取决于您。每个主机或集群都有一个 vmfolder 属性,您可以使用它来创建 VM,或者任何其他文件夹都可以使用。祝你好运!
You'll want to keep the VMware Web Services SDK documentation handy - unfortunately they changed formats recently so I'm not sure how good of deep links I can get for you. The specific method I've used is CreateVM_Task (you'll have to scroll down to find it on the Folder object). Alternatively, if you're using a resource pool, CreateChildVM_Task may be more applicable (again, scroll down to find it).
There is also a section of documentation on creating VMs that has some incomplete example code.
As far as where in the hierarchy to create the VM, that's up to you. Each host or cluster will have a vmfolder property that you can use to create VMs, or any other folder may work. Good luck!