VMWare の pyvmomi を使用して、ESXi の仮想マシンを管理しています
私は使用しています:
pyvmomi-6.0.0とpython 2.7.5で VM のクローンを作成
によって管理されるVMWare ESXi 6.0.0 Update 1
vCenter サーバー 6
pyvmomi を使用して、vm オブジェクトを正常に取得し、データセンター、データストア、vm などを反復処理できます...しかし、それらを複製できません。
root として ESXi に接続しています
常に次のエラーが発生します: (vms のクローンを作成し、ESXi にフォルダーを作成しようとしました)
./test.py
Source VM : TEST_A
Pool cible : Pool_2
Traceback (most recent call last):
File "./vmomiTest.py", line 111, in <module>
sys.exit(main())
File "./vmomiTest.py", line 106, in main
tasks.wait_for_tasks(esxi, [task])
File "/home/user/dev/tools/tasks.py", line 53, in wait_for_tasks
raise task.info.error
pyVmomi.VmomiSupport.NotSupported: (vmodl.fault.NotSupported) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
msg = 'The operation is not supported on the object.',
faultCause = <unset>,
faultMessage = (vmodl.LocalizableMessage) []
}
esxi で /var/log/hostd.log ファイルを読み取ると、次のようになります。
2016-09-13T10:15:17.775Z 情報 hostd[51F85B70] [Originator@6876 sub=Vimsvc.TaskManager opID=467be296 user=root] 作成されたタスク: haTask-2-vim.VirtualMachine.clone-416315
2016-09-13T10:15:17.779Z 情報 hostd[51F03B70] [Originator@6876 sub=Default opID=467be296 user=root] AdapterServer が例外をキャッチ: vmodl.fault.NotSupported
2016-09-13T10:15:17.779Z 情報 hostd[51F03B70] [Originator@6876 sub=Vimsvc.TaskManager opID=467be296 user=root] タスク完了: haTask-2-vim.VirtualMachine.clone-416315 ステータス エラー
私が一致しない他の前提条件はありますか? 誰にも手がかりはありますか?
次の test.py サンプル コードを使用します。
def get_obj_case_insensitive(content, vimtype, name, folder=None):
obj = None
if not folder:
folder = content.rootFolder
container = content.viewManager.CreateContainerView(folder, vimtype, True)
for item in container.view:
if item.name.lower() == name.lower():
obj = item
break
return obj
def get_obj(content, vimtype, name, folder=None):
obj = None
if not folder:
folder = content.rootFolder
container = content.viewManager.CreateContainerView(folder, vimtype, True)
for item in container.view:
if item.name == name:
obj = item
break
return obj
def main():
esxi = connect.SmartConnect(user=esxi_user,
pwd=esxi_password,
host=esxi_addr,
port=443)
atexit.register(connect.Disconnect, esxi)
content = esxi.RetrieveContent()
source_vm = get_obj(content, [vim.VirtualMachine], source_vm_name)
if source_vm == None:
print "Source VM %s doesn't exist, couldn't create VM" % source_vm_name
return None
print "Source VM Found : %s" % source_vm.config.name
wanted_pool = get_obj_case_insensitive(content, [vim.ResourcePool], wanted_pool_name)
if wanted_pool == None:
print "Resource Pool couldn't be found: Pool=%s" % wanted_pool_name
return None
else:
print "Pool Found : %s " % wanted_pool.name
new_location = vim.vm.RelocateSpec()
new_location.diskMoveType = 'createNewChildDiskBacking'
new_location.datastore = content.rootFolder.childEntity[0].datastore[0]
new_location.pool = wanted_pool
ESXI.ensure_snapshot_exists(source_vm)
clone_spec = vim.vm.CloneSpec(template=False, location=new_location, snapshot=source_vm.snapshot.rootSnapshotList[0].snapshot)
task = source_vm.Clone(name=dest_vm_name, folder=source_vm.parent, spec=clone_spec)
tasks.wait_for_tasks(esxi, [task])
print "Cloning %s into %s was successfull" % (source_vm.config.name, dest_vm_name)
if __name__ == '__main__':
sys.exit(main())