Exemplo n.º 1
0
 private static void copyDir(String dirName) throws Exception {
   System.out.println("Copying The Virtual Machine To Host..........");
   dirName = localPath + "/" + dirName;
   String[] listOfFiles = getDirFiles(dirName);
   for (int i = 0; i < listOfFiles.length; i++) {
     String remoteFilePath = "/" + vmName + "/" + listOfFiles[i];
     String localFilePath = dirName + "/" + listOfFiles[i];
     if (localFilePath.indexOf("vdisk") != -1) {
       String dataStoreName = dirName.substring(dirName.lastIndexOf("#") + 1);
       remoteFilePath = "/" + vmName + "/" + dataStoreName + "/" + listOfFiles[i];
       if (localFilePath.indexOf("flat") == -1) {
         vdiskName.add(dataStoreName + "/" + listOfFiles[i]);
       }
     } else {
       remoteFilePath = "/" + vmName + "/" + listOfFiles[i];
     }
     putVMFiles(remoteFilePath, localFilePath);
   }
   System.out.println("Copying The Virtual Machine To Host..........Done");
 }
Exemplo n.º 2
0
  /** @throws Exception */
  private static void displayStats() throws Exception {
    String[][] statsList = getCounters();
    ManagedObjectReference hostmor = getHostByHostName(hostname);
    if (hostmor == null) {
      System.out.println("Host Not Found");
      return;
    }

    Object property;
    ArrayList props = (ArrayList) getDynamicProperty(perfManager, "perfCounter");

    if (props != null && props.size() > 0) {
      property = props.get(0);
    } else {
      property = null;
    }

    // ArrayOfPerfCounterInfo arrayCounter = (ArrayOfPerfCounterInfo) property;
    ArrayList counterInfoList = new ArrayList();
    counterInfoList.add(property);

    List<PerfMetricId> midVector = new ArrayList<PerfMetricId>();
    List<String> statNames = new ArrayList<String>();
    for (int i = 0; i < statsList.length; i++) {
      PerfCounterInfo counterInfo =
          getCounterInfo(counterInfoList, statsList[i][0], statsList[i][1]);
      if (counterInfo == null) {
        System.out.println(
            "Warning: Unable to find stat " + statsList[i][0] + " " + statsList[i][1]);
        continue;
      }
      String counterName = counterInfo.getNameInfo().getLabel();
      statNames.add(counterName);

      PerfMetricId pmid = new PerfMetricId();
      pmid.setCounterId(counterInfo.getKey());
      pmid.setInstance("");
      midVector.add(pmid);
    }
    List<PerfMetricId> midList = new ArrayList<PerfMetricId>(midVector);
    Collections.copy(midList, midVector);

    PerfQuerySpec spec = new PerfQuerySpec();
    spec.setEntity(hostmor);

    GregorianCalendar startTime = new GregorianCalendar();
    startTime.add(Calendar.SECOND, -60);

    XMLGregorianCalendar starttimexmlgc =
        DatatypeFactory.newInstance().newXMLGregorianCalendar(startTime);

    // spec.setStartTime(starttimexmlgc);
    spec.getMetricId().addAll(midList);
    spec.setIntervalId(new Integer(20));
    querySpec = spec;

    final List<String> statNames2 = statNames;
    javax.swing.SwingUtilities.invokeLater(
        new Runnable() {

          public void run() {
            createAndShowGUI("VM Name", statNames2);
          }
        });

    Timer timer = new Timer(true);
    timer.schedule(
        new TimerTask() {

          public void run() {
            refreshStats();
          }
        },
        1000,
        21000);
  }