Examples of ServiceInstance


Examples of com.vmware.vim25.mo.ServiceInstance

public class CacheFrameworkSample
{
  public static void main(String[] args) throws Exception
  {
    ServiceInstance si = new ServiceInstance(new URL("http://10.20.143.205/sdk"), "root", "password", true);
    Folder rootFolder = si.getRootFolder();
    ManagedEntity[] vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");
    ManagedEntity[] hosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");
 
    CacheInstance vicf = new CacheInstance(si);
    vicf.watch(vms, new String[] {"name", "runtime.powerState", "summary"});
    vicf.watch(hosts, new String[] {"name", "summary"});
    vicf.start();

    //check if the caching is ready to use; otherwise wait
    while(!vicf.isReady())
    {
      Thread.sleep(1000);
    }
   
    Thread[] vrs = new VimReader[2];

    for(int i=0; i<vrs.length; i++)
    {
      vrs[i] = new VimReader("Thread " + i, vicf, vms, hosts);
      vrs[i].start();
    }
   
    for(int i=0; i<vrs.length; i++)
    {
      vrs[i].join();
    }
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

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

    ServiceInstance si = new ServiceInstance(
            new URL(args[0]), args[1], args[2], true);
    HostLocalAccountManager hlam = si.getAccountManager();
    if(hlam==null)
    {
      System.out.println("This sample works ONLY with ESX. "
          + "Please try it again.");
    }

    //create a new POSIX account
    HostPosixAccountSpec has = new HostPosixAccountSpec();
    has.setId("vimaster");
    has.setDescription("The POSIX account for VI Master");
    has.setPassword("password");
    has.setShellAccess(true);
    hlam.createUser(has);

    //create a new group called masters
    HostAccountSpec grpSpec = new HostAccountSpec();
    grpSpec.setId("masters");
    // DON'T CALL the following two lines! NOT supported.
    // grpSpec.setDescription("The Group for VI Masters");
    // grpSpec.setPassword("grppass");
    hlam.createGroup(grpSpec);

    //assign the new user to the new group
    hlam.assignUserToGroup("vimaster", "masters");
   
    //let's check their existence
    UserDirectory ud = si.getUserDirectory();
    UserSearchResult[] usrs = ud.retrieveUserGroups(
          null, // only local machine is searched
          "master", // search string 
          null, null,
          false, //not exact match for the search
          true, // include users
          true // include groups
          );
    // print out the results
    for(int i=0; usrs!=null && i < usrs.length; i++)
    {
      System.out.println("\n===============================");
      System.out.println("Full name: " + usrs[i].getFullName());
      System.out.println("IsGroup:" + usrs[i].isGroup());
      System.out.println("Principal: " + usrs[i].getPrincipal());
    }
   
    //delete the new user and group
    //Note: you have to delete the user before delete the group
    hlam.removeUser("vimaster");
    hlam.removeGroup("masters");
   
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java ListAllUsers <url> "
        + "<username> <password>");
      return;
    }
   
    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    UserDirectory ud = si.getUserDirectory();
   
    //print out the domain names
    String[] domains = ud.getDomainList();
    System.out.println("domains:" + domains);
    for(int i=0; domains!=null && i<domains.length; i++)
    {
      System.out.println("Domain:" + domains[i]);
    }
   
    UserSearchResult[] usrs = ud.retrieveUserGroups(
          null, // only local machine is searched
          "", // blank means matching all 
          "users", null, // all the groups
          false, //not exact match for the search
          true, // include users
          false // include groups
          );
   
    // print out the results
    for(int i=0; usrs!=null && i < usrs.length; i++)
    {
      System.out.println("===============================");
      System.out.println("Full name: " + usrs[i].getFullName());
      System.out.println("IsGroup:" + usrs[i].isGroup());
      System.out.println("Principal: " + usrs[i].getPrincipal());
    }

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

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java ListAuthorization <url> "
        + "<username> <password>");
      return;
    }
   
    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    AuthorizationManager am = si.getAuthorizationManager();
    AuthorizationDescription ad = am.getDescription();
   
    System.out.println("Descriptions of all privileges:");
    printDescriptions(ad.getPrivilege());

    System.out.println("Descriptions of all privilege groups:");
    printDescriptions( ad.getPrivilegeGroup());

    System.out.println("List of all privileges with details:");
    printPrivileges(am.getPrivilegeList());
   
    System.out.println("List of all the roles with details:");
    printRoles(am.getRoleList());
   
    si.getServerConnection().logout();
  }
View Full Code Here

Examples of com.vmware.vim25.mo.ServiceInstance

      System.out.println("Usage: java CreateRole <url>"
        + " <username> <password>");
      return;
    }
   
    ServiceInstance si = new ServiceInstance(
        new URL(args[0]), args[1], args[2], true);

    AuthorizationManager am = si.getAuthorizationManager();
   
    int roleId = am.addAuthorizationRole("master1",
        new String[] { "System.View", "System.Read",
        "System.Anonymous", "Global.LogEvent" } );
   
    //even if you just want to rename the role, you
    // still need to provide full list of privileges
    am.updateAuthorizationRole(roleId, "master",
        new String[] { "System.View", "System.Read",
        "System.Anonymous", "Global.LogEvent",
        "Global.Diagnostics", "Folder.Create"} );
   
    System.out.println("The new role ID: " + roleId);
   
    Permission perm = new Permission();
    perm.setGroup(false); // false for user, true for group
    perm.setPrincipal("vimaster"); // the vimaster must exist
    perm.setPropagate(true); // propagate down the hierarchy
    perm.setRoleId(roleId);
   
    am.setEntityPermissions( si.getRootFolder(),
        new Permission[] {perm} );
   
    Permission[] ps = am.retrieveEntityPermissions(
        si.getRootFolder(), false);
   
    System.out.println("print the permissions on root:");
    printPermissions(ps);
   
    si.getServerConnection().logout();
  }
View Full Code Here

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

Examples of com.vmware.vim25.mo.ServiceInstance

      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

Examples of com.vmware.vim25.mo.ServiceInstance

    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

Examples of com.vmware.vim25.mo.ServiceInstance

    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

Examples of com.vmware.vim25.mo.ServiceInstance

    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
TOP
Copyright © 2018 www.massapi.com. 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.