Java 类com.vmware.vim25.mo.FileManager 实例源码

项目:primecloud-controller    文件:VmwareProcessClient.java   
public void deleteDisk(String datastoreName, String fileName) {
    // Datacenter
    ManagedEntity datacenter = vmwareClient.getRootEntity();

    // Datastore
    Datastore datastore = vmwareClient.search(Datastore.class, datastoreName);
    if (datastore == null) {
        // データストアが見つからない場合
        throw new AutoException("EPROCESS-000505", datastoreName);
    }

    // ディスクの削除
    FileManager fileManager = vmwareClient.getServiceInstance().getFileManager();
    if (fileManager == null) {
        // fileManagerが利用できない場合
        throw new AutoException("EPROCESS-000533");
    }

    try {
        // ディスク削除
        fileManager.deleteDatastoreFile_Task(fileName, (Datacenter) datacenter);
        // ディスク削除後にごみができ、再度アタッチするとエラーになるので削除
        String flatname;
        flatname = fileName.substring(0, fileName.length() - 5) + "-flat.vmdk";
        fileManager.deleteDatastoreFile_Task(flatname, (Datacenter) datacenter);
    } catch (RemoteException e) {
        throw new AutoException("EPROCESS-000522", e, fileName);
    }

    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100455", fileName));
    }
}
项目:vijava    文件:CopyFile.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java CopyFile " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  Datacenter dc = (Datacenter)new InventoryNavigator(
      si.getRootFolder()).searchManagedEntity(
          "Datacenter", "ha-datacenter");
  FileManager fileMgr = si.getFileManager();
  if(fileMgr==null)
  {
    System.out.println("FileManager not available.");
    si.getServerConnection().logout();
    return;
  }

  String basePath = "[storage1 (2)] Nostalgia011";
  String dirPath = basePath + "/" + "testDir";
  // create parent directories if needed - true
  fileMgr.makeDirectory(dirPath, dc, true);

  String srcPath = basePath + "/Nostalgia011.vmdk";
  String dstPath = dirPath + "/copy of Nostalgia011.vmdk";
  Task cTask = fileMgr.copyDatastoreFile_Task(srcPath, dc, 
      dstPath, dc, true);

  if(cTask.waitForMe()==Task.SUCCESS)
  {
    System.out.println("File copied successfully!");
  }
  else
  {
    System.out.println("File copy failed!");
    return;
  }
  Thread.sleep(30*1000);

  fileMgr.deleteDatastoreFile_Task(dstPath, dc);
  fileMgr.deleteDatastoreFile_Task(dirPath, dc);
  si.getServerConnection().logout();
}