Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.HttpNfcLease


     */
    private HostSystem getAvailableHost(String hostName)
        throws Exception
    {

        HostSystem host = null;

        if (hostName != null) {
            List<HostSystem> hosts = getAllHostList();
            for (HostSystem h: hosts) {
                if (hostName.equals(h.getName())) {
                    host = h; break;
                }
            }
        }

        if (hostName != null && host == null) {
            logger_.warning
                (String.format("Host %s not found.", hostName));
            hostName = null;
        }
       
        if (hostName == null) {
            host = getDefaultHost();
            logger_.info(String.format
                         ("Use default host %s.", host.getName()));
        }

        if (host == null) {
            throw new Exception("host is null.");
        }
View Full Code Here


                                   rp.getName(),
                                   host.getName(),
                                   datastore.getName()));
       
        OvfCreateImportSpecResult ovfImportResult = null;
        HttpNfcLease httpNfcLease = null;       

        /* create import spec */
        ovfImportResult =
            conn_.getServiceInstance().getOvfManager().createImportSpec
            (ovfDescriptor, rp, datastore, importSpecParams);

        /* import execution */
        try {
            httpNfcLease =
                rp.importVApp(ovfImportResult.getImportSpec(), vmFolder, host);
        } catch (Exception e) {
            logger_.warning("importVapp failed.");
            throw e;
        }

        String morefOfNewVm = null;
       
        /* wait nfc lease */
        HttpNfcLeaseState hls;
    while (true) {
      hls = httpNfcLease.getState();
      if (hls == HttpNfcLeaseState.ready ||
                hls == HttpNfcLeaseState.error) { break; }
    }
        if (hls == HttpNfcLeaseState.ready) {

            morefOfNewVm = httpNfcLease.getInfo().getEntity().getVal();

            logger_.info
                (String.format
                 ("Moref of the created vm: %s\n", morefOfNewVm));
           
            httpNfcLease.httpNfcLeaseComplete();
            /*
              We do not upload disk files, because the specified ovf
              must not contain disk information.
            */
        } else {
View Full Code Here

    }
   
    long totalBytes = addTotalBytes(ovfImportResult);
    System.out.println("Total bytes: " + totalBytes);

    HttpNfcLease httpNfcLease = null;

    httpNfcLease = rp.importVApp(ovfImportResult.getImportSpec(), vmFolder, host);
     
    // Wait until the HttpNfcLeaseState is ready
    HttpNfcLeaseState hls;
    for(;;)
    {
      hls = httpNfcLease.getState();
      if(hls == HttpNfcLeaseState.ready || hls == HttpNfcLeaseState.error)
      {
        break;
      }
    }
   
    if (hls.equals(HttpNfcLeaseState.ready))
    {
      System.out.println("HttpNfcLeaseState: ready ");
      HttpNfcLeaseInfo httpNfcLeaseInfo = (HttpNfcLeaseInfo) httpNfcLease.getInfo();
      printHttpNfcLeaseInfo(httpNfcLeaseInfo);

      leaseUpdater = new LeaseProgressUpdater(httpNfcLease, 5000);
      leaseUpdater.start();

      HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
     
      long bytesAlreadyWritten = 0;
      for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls)
      {
        String deviceKey = deviceUrl.getImportKey();
        for (OvfFileItem ovfFileItem : ovfImportResult.getFileItem())
        {
          if (deviceKey.equals(ovfFileItem.getDeviceId()))
          {
            System.out.println("Import key==OvfFileItem device id: " + deviceKey);
            String absoluteFile = new File(ovfLocal).getParent() + File.separator + ovfFileItem.getPath();
            String urlToPost = deviceUrl.getUrl().replace("*", hostip);
            uploadVmdkFile(ovfFileItem.isCreate(), absoluteFile, urlToPost, bytesAlreadyWritten, totalBytes);
            bytesAlreadyWritten += ovfFileItem.getSize();
            System.out.println("Completed uploading the VMDK file:" + absoluteFile);
          }
        }
      }

      leaseUpdater.interrupt();
      httpNfcLease.httpNfcLeaseProgress(100);
      httpNfcLease.httpNfcLeaseComplete();
    }
    si.getServerConnection().logout();
  }
View Full Code Here

      System.out.println("Network : " + host.getNetworks()[0].getName());
      System.out.println("Datastore : " + host.getDatastores()[0].getName());

      InventoryNavigator iv = new InventoryNavigator(si.getRootFolder());
     
      HttpNfcLease hnLease = null;
     
      ManagedEntity me = null;
      if (entityType.equals("VirtualApp"))
      {
        me = iv.searchManagedEntity("VirtualApp", vAppOrVmName);
        hnLease = ((VirtualApp)me).exportVApp();
      }
      else
      {
        me = iv.searchManagedEntity("VirtualMachine", vAppOrVmName);
        hnLease = ((VirtualMachine)me).exportVm();
      }
       
      // Wait until the HttpNfcLeaseState is ready
      HttpNfcLeaseState hls;
      for(;;)
      {
        hls = hnLease.getState();
        if(hls == HttpNfcLeaseState.ready)
        {
          break;
        }
        if(hls == HttpNfcLeaseState.error)
        {
          si.getServerConnection().logout();
          return;
        }
      }
     
      System.out.println("HttpNfcLeaseState: ready ");
      HttpNfcLeaseInfo httpNfcLeaseInfo = hnLease.getInfo();
      httpNfcLeaseInfo.setLeaseTimeout(300*1000*1000);
      printHttpNfcLeaseInfo(httpNfcLeaseInfo);

      //Note: the diskCapacityInByte could be many time bigger than
      //the total size of VMDK files downloaded.
      //As a result, the progress calculated could be much less than reality.
      long diskCapacityInByte = (httpNfcLeaseInfo.getTotalDiskCapacityInKB()) * 1024;

      leaseProgUpdater = new LeaseProgressUpdater(hnLease, 5000);
      leaseProgUpdater.start();

      long alredyWrittenBytes = 0;
      HttpNfcLeaseDeviceUrl[] deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
      if (deviceUrls != null)
      {
        OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
        System.out.println("Downloading Files:");
        for (int i = 0; i < deviceUrls.length; i++)
        {
          String deviceId = deviceUrls[i].getKey();
          String deviceUrlStr = deviceUrls[i].getUrl();
          String diskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
          String diskUrlStr = deviceUrlStr.replace("*", hostip);
          String diskLocalPath = targetDir + diskFileName;
          System.out.println("File Name: " + diskFileName);
          System.out.println("VMDK URL: " + diskUrlStr);
          String cookie = si.getServerConnection().getVimService().getWsc().getCookie();
          long lengthOfDiskFile = writeVMDKFile(diskLocalPath, diskUrlStr, cookie, alredyWrittenBytes, diskCapacityInByte);
          alredyWrittenBytes += lengthOfDiskFile;
          OvfFile ovfFile = new OvfFile();
          ovfFile.setPath(diskFileName);
          ovfFile.setDeviceId(deviceId);
          ovfFile.setSize(lengthOfDiskFile);
          ovfFiles[i] = ovfFile;
        }
       
        OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
        ovfDescParams.setOvfFiles(ovfFiles);
        OvfCreateDescriptorResult ovfCreateDescriptorResult =
          si.getOvfManager().createDescriptor(me, ovfDescParams);

        String ovfPath = targetDir + vAppOrVmName + ".ovf";
        FileWriter out = new FileWriter(ovfPath);
        out.write(ovfCreateDescriptorResult.getOvfDescriptor());
        out.close();
        System.out.println("OVF Desriptor Written to file: " + ovfPath);
      }
     
      System.out.println("Completed Downloading the files");
      leaseProgUpdater.interrupt();
      hnLease.httpNfcLeaseProgress(100);
      hnLease.httpNfcLeaseComplete();

      si.getServerConnection().logout();
    }
View Full Code Here

     */
    protected ManagedEntity searchManagedEntity(String type, String name)
    {
        ManagedEntity ret = null;
        try {
            ret = new InventoryNavigator
                (rootFolder_).searchManagedEntity(type, name);
        } catch (Exception e) { /* InvalidProperty, RuntimeFault, RemoteException */
            logger_.warning(Utility.toString(e));
            return null;
        }
View Full Code Here

    {
        List<ManagedEntity> ret = new LinkedList<ManagedEntity>();
       
        ManagedEntity[] mes;
        try {
            mes = new InventoryNavigator(rootFolder_).searchManagedEntities(type);
        } catch (Exception e) { /* InvalidProperty, RuntimeFault, RemoteException */
            return ret;
        }
        assert(mes != null);

View Full Code Here

    {
        List<ManagedEntity> ret = new LinkedList<ManagedEntity>();
       
        ManagedEntity[] mes;
        try {
            mes = new InventoryNavigator(rootFolder_).searchManagedEntities
                (new String[][] { {type, name}, }, true);
           
        } catch (Exception e) { /* InvalidProperty, RuntimeFault, RemoteException */
            return ret;
        }
View Full Code Here

     * @param name Name of the entity.
     * @return Found managed entity in success or null in failure.
     */
    protected ManagedEntity searchManagedEntity(String type, String name)
    {
        ManagedEntity ret = null;
        try {
            ret = new InventoryNavigator
                (rootFolder_).searchManagedEntity(type, name);
        } catch (Exception e) { /* InvalidProperty, RuntimeFault, RemoteException */
            logger_.warning(Utility.toString(e));
View Full Code Here

        ManagedObjectReference mor =
            generateMoref("VirtualMachine", morefStr);
        if (mor == null) { return null; }

        ManagedEntity vm =
            MorUtil.createExactManagedEntity(si_.getServerConnection(), mor);

        if (vm instanceof VirtualMachine) {
            return (VirtualMachine) vm; /* may be null */
        } else {
View Full Code Here

     */
    public VirtualMachineManager searchVmWithName(String vmName)
        throws Exception
    {
        if (conn_.isConnected() == false) { conn_.connect(); }
        ManagedEntity vm = conn_.searchManagedEntity("VirtualMachine", vmName);
        if (vm == null) { throw new Exception(); }
        return new VirtualMachineManager(conn_, (VirtualMachine)vm);
    }
View Full Code Here

TOP

Related Classes of com.vmware.vim25.mo.HttpNfcLease

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.