q81622579 2015-11-05 12:21 采纳率: 0%
浏览 2519

使用vmware vsphere通过模板clone虚拟机器错误

使用vmware vsphere通过模板clone虚拟机器错误,报制定的参数错误。环境是集群,模板在其中一台主机上。
代码如下:
Map aa = getMOREFsInContainerByType(serviceContent.getRootFolder(),
"ResourcePool");
Set bb = aa.keySet();
String pool = null;
for( String poolName : bb)
{
pool = poolName;
break;
}

  ManagedObjectReference datacenterRef =
        vimPort.findByInventoryPath(serviceContent.getSearchIndex(),
                dataCenterName);

  if (datacenterRef == null) {
     System.out.printf("The specified datacenter [ %s ]is not found %n",
           dataCenterName);
     return;
  }
  // Find the virtual machine folder for this datacenter.
  ManagedObjectReference vmFolderRef =
        (ManagedObjectReference) getDynamicProperty(datacenterRef,
              "vmFolder");
  if (vmFolderRef == null) {
     System.out.println("The virtual machine is not found");
     return;
  }

// vimPort.markAsVirtualMachine(_this, pool, host);
ManagedObjectReference vmRef =
vimPort.findByInventoryPath(serviceContent.getSearchIndex(),
vmPathName);
//

if (vmRef == null) {
System.out.printf("The VMPath specified [ %s ] is not found %n",
vmPathName);
return;
}
ManagedObjectReference host =
getDecendentMoRef(null, "HostSystem","10.134.98.186");

  ManagedObjectReference hMOR = getHostByHostName("10.134.98.186");
  List<DynamicProperty> datastoresSource =
          getDynamicProarray(hMOR, "HostSystem", "datastore");
    ArrayOfManagedObjectReference dsSourceArr =
          ((ArrayOfManagedObjectReference) (datastoresSource.get(0)).getVal());
    List<ManagedObjectReference> dsTarget =
          dsSourceArr.getManagedObjectReference();
    ManagedObjectReference dsMOR = browseDSMOR(dsTarget);

// ManagedObjectReference dataStore =
// getDecendentMoRef(null, "DataStore","datastore (98186)");
ManagedObjectReference poolMOR =
getDecendentMoRef(null, "ResourcePool",pool);
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
VirtualMachineRelocateSpec relocSpec = new VirtualMachineRelocateSpec();
cloneSpec.setLocation(relocSpec);
cloneSpec.setPowerOn(true);
cloneSpec.setTemplate(false);
cloneSpec.getLocation().setPool(poolMOR);
cloneSpec.getLocation().setHost(host);
cloneSpec.getLocation().setDatastore(dsMOR);

  VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
  vmConfigSpec.setMemoryMB(new Long(memory));
  vmConfigSpec.setNumCPUs(Integer.valueOf(cpu));
  cloneSpec.setConfig(vmConfigSpec);

  System.out.printf("Cloning Virtual Machine [%s] to clone name [%s] %n",
        vmPathName.substring(vmPathName.lastIndexOf("/") + 1), cloneName);
  try {
     ManagedObjectReference cloneTask =
           vimPort.cloneVMTask(vmRef, vmFolderRef, cloneName, cloneSpec);

     if (getTaskResultAfterDone(cloneTask)) {
        System.out
              .printf(
                    "Successfully cloned Virtual Machine [%s] to clone name [%s] %n",
                    vmPathName.substring(vmPathName.lastIndexOf("/") + 1),
                    cloneName);
     } else {
        System.out.printf(
              "Failure Cloning Virtual Machine [%s] to clone name [%s] %n",
              vmPathName.substring(vmPathName.lastIndexOf("/") + 1),
              cloneName);
     }
  } catch (SOAPFaultException sfe) {
     printSoapFaultException(sfe);
  } catch (Exception e) {
     e.printStackTrace();
  }

求解

  • 写回答

1条回答 默认 最新

  • xubinen 2017-10-20 03:12
    关注
    1. Login to VSphere Client,

    2. go to Home

    3. go to VMs and Templates

    4. browse folder and find the virtual machine,

    5. the inventory path would be DataCenter/vm/folder structure inside DataCenter e.g. if the path in the inventory is DataCenter/folder1/folder2/machine, then it the inventory path would be DataCenter/vm/folder1/folder2/machine

    注意:正确的vmpath的路机应该是 datacentername/vm/foldername/vmname 其中的vm是系统隐含的目录,必须要写上,否则一直提示找不到目录。The VMPath specified [ datacentername/foldername/vm1 ] is not found

    参考:http://www.hivmr.com/db/xkap9ka8xspa11cfpksx83zspp1zf7kp

    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现