Package com.vmware.vim25.mo

Examples of com.vmware.vim25.mo.ServiceInstance


            String username = args[1];
            String password = args[2];

            System.out.println("Connecting to " + urlStr + " as " + username);

            si = new ServiceInstance(new URL(urlStr), username, password, true);

            System.out.println("info---" + si.getAboutInfo().getFullName());

            VMEventsMonitor eventMonitor = new VMEventsMonitor();
View Full Code Here


      System.out.println(
      "java ImportLocalOvfVApp https://10.20.140.47/sdk Administrator password 10.17.204.115 E:/Downloads/Nostalgia.ovf NewVM");
      return;
    }
   
    ServiceInstance si = new ServiceInstance(new URL(args[0]), args[1], args[2], true);

    String ovfLocal = args[4];
    String hostip = args[3];
    String newVmName = args[5];
   
    HostSystem host = (HostSystem) si.getSearchIndex().findByIp(null, hostip, false);
     
    System.out.println("Host Name : " + host.getName());
    System.out.println("Network : " + host.getNetworks()[0].getName());
    System.out.println("Datastore : " + host.getDatastores()[0].getName());

    Folder vmFolder = (Folder) host.getVms()[0].getParent();

    OvfCreateImportSpecParams importSpecParams = new OvfCreateImportSpecParams();
    importSpecParams.setHostSystem(host.getMOR());
    importSpecParams.setLocale("US");
    importSpecParams.setEntityName(newVmName);
    importSpecParams.setDeploymentOption("");
    OvfNetworkMapping networkMapping = new OvfNetworkMapping();
    networkMapping.setName("Network 1");
    networkMapping.setNetwork(host.getNetworks()[0].getMOR()); // network);
    importSpecParams.setNetworkMapping(new OvfNetworkMapping[] { networkMapping });
    importSpecParams.setPropertyMapping(null);

    String ovfDescriptor = readOvfContent(ovfLocal);
    if (ovfDescriptor == null)
    {
      si.getServerConnection().logout();
      return;
    }
   
    System.out.println("ovfDesc:" + ovfDescriptor);
     
    ResourcePool rp = ((ComputeResource)host.getParent()).getResourcePool();

    OvfCreateImportSpecResult ovfImportResult = si.getOvfManager().createImportSpec(
        ovfDescriptor, rp, host.getDatastores()[0], importSpecParams);

    if(ovfImportResult==null)
    {
      si.getServerConnection().logout();
      return;
    }
   
    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

    String userName = props.getProperty("userName");
    String password = props.getProperty("password");
    String operation = props.getProperty("operation");
    String keyStr = props.getProperty("keyStr");

    ServiceInstance si = new ServiceInstance(
        url, userName, password, true);
    ExtensionManager extMgr = si.getExtensionManager();

    if("register".equalsIgnoreCase(operation))
    {
      if(extMgr.findExtension(keyStr)!=null)
      {
        System.out.println("Plugin key: " + keyStr +
            " is used. Please try with a new key.");
      }
      else
      {
        Extension ext = createExtensionObject(props);
        extMgr.registerExtension(ext);
        System.out.println("Plugin: " + keyStr +
            " has been successfully registered.");
      }
    }
    else if ("update".equalsIgnoreCase(operation))
    {
      if(extMgr.findExtension(keyStr)!=null)
      {
        Extension ext = createExtensionObject(props);
        extMgr.updateExtension(ext);
        System.out.println("Plugin: " + keyStr +
            " has been successfully updated.");
      }
      else
      {
        System.out.println("The plugin doesn't exist. " +
            "Please register it before updating it.");
      }
    }
    else if("listall".equalsIgnoreCase(operation))
    {
      printAllExtensions(extMgr.getExtensionList());
    }
    else if("unregister".equalsIgnoreCase(operation))
    {
      if(extMgr.findExtension(keyStr)!=null)
      {
        extMgr.unregisterExtension(keyStr);
        System.out.println("Plugin: " + keyStr +
            " has been successfully un-registered.");
      }
      else
      {
        System.out.println("Plugin: " + keyStr +
          " does NOT exist. No need to unregister it.");
      }

    }
    else if("find".equalsIgnoreCase(operation))
    {
      if(extMgr.findExtension(keyStr)!=null)
      {
        System.out.println("Plugin: " + keyStr +
            " is registered.");
      }
      else
      {
        System.out.println("Plugin: " + keyStr +
            " can NOT be found.");
      }
    }
    else
    {
      System.out.println("Operation is not valide. " +
          "Please try again.");
    }

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

    String username = args[1];
    String password = args[2];
    String mode = args[3];
    String drs_obj_id = "domain-c5";
   
    ServiceInstance si = new ServiceInstance(url, username, password, true);
   
    ManagedObjectReference mref_drs = new ManagedObjectReference();
    mref_drs.set_value(drs_obj_id);
    mref_drs.setType("ClusterComputeResource");
   
    ClusterComputeResource ccr = (ClusterComputeResource )MorUtil.createExactManagedEntity(si.getServerConnection(), mref_drs);
   
    ClusterConfigSpec ccs = new ClusterConfigSpec();
    ClusterDrsConfigInfo cdci = new ClusterDrsConfigInfo();
    if("manual".equals(mode))
      cdci.setDefaultVmBehavior(DrsBehavior.manual);
    else
      cdci.setDefaultVmBehavior(DrsBehavior.fullyAutomated);
    cdci.setVmotionRate(new Integer(5));
    ccs.setDrsConfig(cdci);
   
    ccr.reconfigureCluster_Task(ccs, true);
   
    si.getServerConnection().logout();
    System.out.println("End of changing DRS config to " + args[3]);
  }
View Full Code Here

    System.out.println("morStr:" + morStr);
    System.out.println("serviceUrl"
        + request.getParameter(SERVICE_URL) );
    System.out.println("session:" + sessionStr);

    ServiceInstance si = new ServiceInstance(new URL(
        request.getParameter(SERVICE_URL)),sessionStr, true);

    ManagedEntity me = MorUtil.createExactManagedEntity(
        si.getServerConnection(), mor);

    String name = me.getName();
    out.println("name:" + name);
    out.println(DateFormat.getDateTimeInstance().format(
        new Date()));
View Full Code Here

    String password = args[2];
    String vm1_oid = "vm-26"; // The reference ID for VM 1
    String vm2_oid = "vm-28"; // The reference ID for VM 2
   
    // initialize the system, set up web services
    ServiceInstance si = new ServiceInstance(url, username, password, true);
   
    // create a new VirtualMachineConfigSpec for VM1
    VirtualMachineConfigSpec vmcs1 = new VirtualMachineConfigSpec();
    ResourceAllocationInfo rai1 = new ResourceAllocationInfo();
    SharesInfo si1 = new SharesInfo();
    si1.setLevel(SharesLevel.custom);
    si1.setShares(1333);
    rai1.setShares(si1);
    vmcs1.setCpuAllocation(rai1);

    // do the same for VM2
    VirtualMachineConfigSpec vmcs2 = new VirtualMachineConfigSpec();
    ResourceAllocationInfo rai2 = new ResourceAllocationInfo();
    SharesInfo si2 = new SharesInfo();
    si2.setLevel(SharesLevel.high);
    rai2.setShares(si2);
    vmcs2.setCpuAllocation(rai2);
   
    ManagedObjectReference vm1_mor = createMOR("VirtualMachine", vm1_oid);
    ManagedObjectReference vm2_mor = createMOR("VirtualMachine", vm2_oid);
    VirtualMachine vm1 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm1_mor);
    VirtualMachine vm2 = (VirtualMachine) MorUtil.createExactManagedEntity(si.getServerConnection(), vm2_mor);
   
    // make a web service call to set the configuration.
    vm1.reconfigVM_Task(vmcs1);
    vm2.reconfigVM_Task(vmcs2);     

    // log out from web service
    si.getServerConnection().logout();
    System.out.println("Done with setting VM CPU shares.");
  }
View Full Code Here

      System.out.println("Usage: java AddNIC <url> "
          + "<username> <password>");
      return;
    }

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

    String hostname = "dev.acme.com";
    String portGroupName = "ViMaster PortGroup";
    String switchName = "ViMaster Switch";

    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);

    HostNetworkSystem hns = host.getHostNetworkSystem();

    // add a virtual switch
    HostVirtualSwitchSpec spec = new HostVirtualSwitchSpec();
    spec.setNumPorts(8);
    hns.addVirtualSwitch(switchName, spec);
   
    // add a port group
    HostPortGroupSpec hpgs = new HostPortGroupSpec();
    hpgs.setName(portGroupName);
    hpgs.setVlanId(0); // not associated with a VLAN
    hpgs.setVswitchName(switchName);
    hpgs.setPolicy(new HostNetworkPolicy());
    hns.addPortGroup(hpgs);
   
    // add a virtual NIC to VMKernel
    HostVirtualNicSpec hvns = new HostVirtualNicSpec();
    hvns.setMac("00:50:56:7d:5e:0b");
    HostIpConfig hic = new HostIpConfig();
    hic.setDhcp(false);
    hic.setIpAddress("10.20.143.204");
    hic.setSubnetMask("255.255.252.0");
    hvns.setIp(hic);
    String result = hns.addVirtualNic("VMKernel", hvns);
    System.out.println(result);
   
    si.getServerConnection().logout();
  }
View Full Code Here

      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();
  }
View Full Code Here

      System.out.println("Usage: java CreateScheduledTasks "
      + "<url> <username> <password> <vmname>");
    return;
    }
   
    ServiceInstance si = new ServiceInstance(
                new URL(args[0]), args[1], args[2], true);
    Folder rootFolder = si.getRootFolder();
   
    InventoryNavigator inv = new InventoryNavigator(rootFolder);
    String vmname = args[3];
    VirtualMachine vm = (VirtualMachine)inv.searchManagedEntity(
            "VirtualMachine", vmname);
  if(vm==null)
  {
    System.out.println("Cannot find the VM " + vmname
      + "\nExisting...");
    si.getServerConnection().logout();
    return;
  }

    ScheduledTaskManager stm = si.getScheduledTaskManager();
    if(stm!=null)
    {
      //to save space, we just check one name here
      if(taskNameExists(stm, "ViMaster_OneTime"))
      {
        si.getServerConnection().logout();
        return;
      }
     
      // Note: the time should be fetched from server,
      // just to make sure it's synchronized.
      ScheduledTaskSpec oneSpec = createOneTimeSchedulerSpec(
          "ViMaster_OneTime", si.currentTime());
     
      ScheduledTaskSpec weekSpec = createWeeklySchedulerSpec(
          "ViMaster_Weekly");

      ScheduledTask st = stm.createScheduledTask(vm, oneSpec);
      ScheduledTask st1 = stm.createScheduledTask(vm, weekSpec);
    // sleep two minutes before deleting
    // the one time scheduled task.
      // An one time scheduled task has not to be deleted after
      // it's run. It can be run any time again by calling the
      // runScheduledTask() method.
      Thread.sleep(2*60*1000);
      st.removeScheduledTask();
    }
    else
    {
      System.out.println("SchduledTaskManager is not "
        + "available on this target.");
    }
   
  si.getServerConnection().logout();
   }
View Full Code Here

      System.out.println("Usage: java TurnOnFirewallPolicy " +
          "<url> <username> <password> <hostname>");
      return;
    }

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

    String hostname = args[3];
    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(
        rootFolder).searchManagedEntity("HostSystem", hostname);

    if(host==null)
    {
      System.out.println("Cannot find the host:" + hostname);
      si.getServerConnection().logout();
      return;
    }
   
    HostFirewallSystem hss = host.getHostFirewallSystem();
   
View Full Code Here

TOP

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

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.