Examples of VsphereServer


Examples of be.jedi.jvspherecontrol.vsphere.VsphereServer

      return description;
    }

  public void execute(){
   
    VsphereServer vsphereServer=new VsphereServer(vsphereUrl, vsphereUsername,vspherePassword);
    try {
      vsphereServer.connect();
           

      ArrayList<String> datacenters=vsphereServer.listDataCenters();
      ArrayList<String> datastores=vsphereServer.listDataStores();
      ArrayList<String> networks=vsphereServer.listNetworks();
      ArrayList<String> clusters=vsphereServer.listClusters();

      //Check cluster
      if (!clusters.contains(vsphereClusterName)) {
        System.err.println("cluster "+vsphereClusterName+" does not exist");
        System.exit(-1);       
      }   
   
      //Check datastore
      if (!datastores.contains(vsphereDataStoreName)) {
        System.err.println("datastore "+vsphereDataStoreName+" does not exist");
        System.exit(-1);       
      }

      //Check datacenter
      if (!datacenters.contains(vsphereDataCenterName)) {
        System.err.println("datacenter "+vsphereDataCenterName+" does not exist");
        System.exit(-1);       
      }

      //Check networks to be used
      for (int i=0; i< vmNics.length; i++) {
        if (! networks.contains(vmNics[i].getNetwork())) {
          System.err.println("network "+vmNics[i].getNetwork()+" does not exist");
          System.exit(-1);
        }
      }

      //verify cdrom
     
      //Find if vm by name vmname already exists
      VirtualMachine existingVm=vsphereServer.findVmByName(vmName);

      if (existingVm!=null) {
        System.out.println("Machine exists with name:"+existingVm.getName());
        //vsphereServer.showVmDetail(existingVm);

        //Where was this used for?
        //      VirtualMachineCapability vmc = existingVm.getCapability();
        //      VirtualMachineSummary summary = (VirtualMachineSummary) (existingVm.getSummary());

        if(vmOverwrite) {
          if (vsphereServer.isVmPoweredOn(existingVm))
          {
            vsphereServer.powerOffVm(existingVm);       
          }

          vsphereServer.destroyVm(existingVm);       

        } else {
          System.out.println("use --overwrite true to overwrite");
          System.exit(1);
        }
      }

      VirtualMachine newVm=vsphereServer.createVm(vmName,vmMemory,
          vmCpus,vmOsType,vmDisks,
          vmNics,vsphereDataCenterName,vsphereDataStoreName,vsphereClusterName);

      if (vmCdromIsoPath!=null) {
        vsphereServer.setCdromVm(newVm,vmCdromIsoPath,vmCdromDataStoreName);
       
      }

      if (vmVncActivate) {
        vsphereServer.vncActivateVm(newVm,vmVncPort,vmVncPassword);
      }

      String pxeInterface="";     
      //Determine the PXE interface
      for (int i=0; i< vmNics.length; i++) {
        if (vmNics[i].isPxe()) {
          System.out.println("enabling pxe on interface"+vmNics[i].getName());
          pxeInterface="Network Adapter "+(i+1);
          vsphereServer.setVmPxebootInterface(newVm,pxeInterface);
        }
      }   

      //Enough config, let's prepare the server for it's first boot
      vsphereServer.setEnterBiosVm(newVm,true);

      if (newVm!=null) {
        vsphereServer.powerOnVm(newVm);
      }

      //it is now in bios waiting , so we can power it off
      if (newVm!=null) {
        vsphereServer.powerOffVm(newVm);
      }

      //flip the enterbios flag
      vsphereServer.setEnterBiosVm(newVm,false);
     
      if (vmBootOrder!=null) {
        //allow:net
        vsphereServer.setBootOrderVm(newVm, vmBootOrder);       
      }

      //if (vmPxeInterface!=null) {
      //  vsphereServer.setVmPxebootInterface(newVm,vmPxeInterface);
      //}

      //vsphereServer.listNicsVm(newVm);
      if (vmOmapiRegister) {
        System.out.println("registering nic:"+vmPxeInterface);

        OmapiServer omapiServer=new OmapiServer(omapiHost,omapiPort,omapiKeyName, omapiKeyValue);
        String macAddress=vsphereServer.getMacAddress(pxeInterface,newVm);
        omapiServer.updateDHCP(vmName, macAddress,omapiOverWrite);
        System.out.println(macAddress);
      }
     
      if (registermac) {
        String command = String.format(registermacCommand, vsphereServer.getMacAddress(pxeInterface,newVm));
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec(command);
        process.waitFor();
      }

      vsphereServer.powerOnVm(newVm);   
    } catch (RemoteException ex) { 
      System.err.println("eror logging in the vsphere, username, password?");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

Examples of be.jedi.jvspherecontrol.vsphere.VsphereServer

  }
 
 
  public void execute(){
   
    VsphereServer vsphereServer=new VsphereServer(vsphereUrl, vsphereUsername,vspherePassword);
    try {
      vsphereServer.connect();
           
      //Find if vm by name vmname already exists
      VirtualMachine existingVm=vsphereServer.findVmByName(vmName);

      if (existingVm!=null) {
        vsphereServer.vncActivateVm(existingVm,vncPort,vncPassword);
      } else {
        System.out.println("VM "+vmName+" not found");
      }

     
View Full Code Here

Examples of be.jedi.jvspherecontrol.vsphere.VsphereServer


  public void execute() {

    try {
      VsphereServer vsphereServer=new VsphereServer(vsphereUrl, vsphereUsername,vspherePassword);
      vsphereServer.connect();

      //Find if vm by name vmname already exists
      VirtualMachine existingVm=vsphereServer.findVmByName(vmName);

      if (existingVm!=null) {
        vsphereServer.powerOnVm(existingVm);   
      }


    } catch (Exception e) {
      // TODO Auto-generated catch block
View Full Code Here

Examples of be.jedi.jvspherecontrol.vsphere.VsphereServer

  }
 
 
  public void execute(){
   
    VsphereServer vsphereServer=new VsphereServer(vsphereUrl, vsphereUsername,vspherePassword);
    try {
      vsphereServer.connect();
           
      //Find if vm by name vmname already exists
      VirtualMachine existingVm=vsphereServer.findVmByName(vmName);

      if (existingVm!=null) {
        vsphereServer.vncDeActivateVm(existingVm);
      } else {
        System.out.println("VM "+vmName+" not found");
      }

View Full Code Here

Examples of be.jedi.jvspherecontrol.vsphere.VsphereServer

   
  }

  public void execute() {

    VsphereServer vsphereServer=new VsphereServer(vsphereUrl, vsphereUsername,vspherePassword);
    try {

      vsphereServer.connect();

      if ((listItem.equals("hosts")) || (listItem.equals("all"))) {
        for (String host : vsphereServer.listHosts()) {
          System.out.println("Host found: "+host);
        }
      }

      if ((listItem.equals("datacenters")) || (listItem.equals("all"))) {
        for (String datacenter :vsphereServer.listDataCenters() ) {
          System.out.println("Datacenter found: "+datacenter);         
       
      }

      if ((listItem.equals("clusters")) || (listItem.equals("all"))) {
        for (String cluster :vsphereServer.listClusters() ) {
          System.out.println("Cluster found: "+cluster);         
       
      }
     
      if ((listItem.equals("datastores")) || (listItem.equals("all"))) {
        for (String datastore :vsphereServer.listDataStores() ) {
          System.out.println("Datastore found: "+datastore);         
        }
      }

      if ((listItem.equals("networks")) || (listItem.equals("all"))) {

        for (String network :vsphereServer.listNetworks() ) {
          System.out.println("Network found: "+network);         
        }
      }
     
      if ((listItem.equals("users")) || (listItem.equals("all"))) {

        for (String user :vsphereServer.listUsers() ) {
          System.out.println("User found: "+user);         
       
      }

      if ((listItem.equals("vms")) || (listItem.equals("all"))) {
      for (String vm :vsphereServer.listVms() ) {
        System.out.println("Vm found: "+vm);         
      }
      }
     
      if ((listItem.equals("resourcepools")) || (listItem.equals("all"))) {
        for (String resourcepool :vsphereServer.listResourcePools() ) {
          System.out.println("Resourcepool found: "+resourcepool);         
       
      }

    } catch (RemoteException e) {
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.