[one-users] Moving away from vmware, here are my modifications

Pasi Kärkkäinen pasik at iki.fi
Thu Feb 25 04:47:00 PST 2010


On Thu, Feb 18, 2010 at 05:59:34PM +0000, Tiago Batista wrote:
> Well, I am moving away from vmware as no license is available for me.
> 
> While setting things up, I made a few modifications that may be of use
> and are attached. Sorry that this is a single patch, but I pulled this
> from my running setup just to make sure that I sent some working code
> this time.
> 
> I believe that this patch brings the vmware drivers functionality close
> to the xen and kvm ones.
> 
> What the patch does:
> 
> 1 - No more usernames and passwords on the command line for im and vmm
> drivers. This is a big problem when one is installed on a shared
> computer. As an example, an excerpt form oned.conf
> 
> VM_MAD = [
>       name       = "vmm_vmware",
>       executable = "one_vmm_vmware",
>       arguments  = "--authfile /home/tsbatista/.vmware_auth",
>       type       = "xml" ]
> 
> The format for the authfile is simple, one line with username:password
> pair.
> 
> 2 - Contextualization iso attachment, and other cdroms. This may actualy
> make this driver a lot more useful as context is very important on a
> IaaS plattform.
> 
> 3 - CPU and VCPU. these parameters of the VM template file can now be
> used just as in Xen. VCPU is the number of virtual cpus available to the
> running VM, CPU is now a decimal value that can be used to manipulate
> the amount of CPU shares that a VM can use.
> 
> I have used as much as I could, but some testing is still required:
> CDROM: I just experimented one context iso and one cdrom iso, I never
> tried to attach a third cdrom and I do not know what will be the result
> of attaching a third cdrom.
> Contextualization: The driver does attach the cdrom with the context
> data, however I made no further tests on this one.
> CPU/VCPU: I tested with as much as 2 VCPU and 0.6 CPU, this worked fine,
> however I may be missing something here...
> Password: I never tested a failure scenario where the file is not
> available of not in the correct format, some more error checking may be
> required here!
> 
> Feel free to test these modifications and include them on the next
> release if you like the functionality.
> 
> Please do not ask me to perform any further testing on this as I no
> longer have access to a VMWare host.
> 
> As a side note, vmware is sooo much easier to manage than xen!
> 

You might want to compare to XCP (Xen Cloud Platform), and not just 
to the normal hypervisor-only Xen.

XCP has much easier to use and much more powerful API in it for management.

-- Pasi

> Tiago

> diff -ur one-org/one-1.4/src/im_mad/vmware/OneImVmware.java one-1.4/src/im_mad/vmware/OneImVmware.java
> --- one-org/one-1.4/src/im_mad/vmware/OneImVmware.java	2009-10-22 17:12:05.000000000 +0100
> +++ one-1.4/src/im_mad/vmware/OneImVmware.java	2010-02-12 18:38:34.000000000 +0000
> @@ -63,7 +63,29 @@
>      OneImVmware(String[] args,boolean _debug) 
>      {
>          debug = _debug;
> -        arguments = args;
> +        arguments = new String[4];
> +
> +	for (int i = 0; i < args.length; i++) {
> +            if (args[i].compareToIgnoreCase("--authfile") == 0) {
> +                try {
> +                    File authFile = new File(args[i+1]);
> +                    Scanner scanner = new Scanner(authFile);
> +                    if ( scanner.hasNextLine() ){
> +                        String[] authData = scanner.nextLine().split(":");
> +			arguments[0] = "--username";
> +                        arguments[1] = authData[0];
> +                        arguments[2] = "--password";
> +                        arguments[3] = authData[1];
> +                    }
> +                    scanner.close();
> +                }
> +                catch(Exception e) {
> +                    //no point in going on without authentication information!
> +                    e.printStackTrace();
> +                    System.exit(-1);
> +                }
> +            }
> +        }
>      
>          // Get out and err descriptors
>          stdout = System.out;
> diff -ur one-org/one-1.4/src/vmm_mad/vmware/DeployVM.java one-1.4/src/vmm_mad/vmware/DeployVM.java
> --- one-org/one-1.4/src/vmm_mad/vmware/DeployVM.java	2009-09-17 14:47:59.000000000 +0100
> +++ one-1.4/src/vmm_mad/vmware/DeployVM.java	2010-02-12 17:27:56.000000000 +0000
> @@ -22,7 +22,6 @@
>  
>  import java.util.*;
>  import java.io.*;
> -
>  import java.lang.*;
>  
>  import java.rmi.RemoteException;
> @@ -42,11 +41,12 @@
>      static  AppUtil cb = null;
>      private static  VimPortType service;  
>      
> -    private String  datacenterName  = "";
> -    private String  datastoreName   = "";
> -    private String  vmName          = "";
> -    private String  vmDiskName      = "";
> -    private String  vid             = "";
> +    private String    datacenterName  = "";
> +    private String    datastoreName   = "";
> +    private String    vmName          = "";
> +    private String    vmDiskName      = "";
> +    private String    vid             = "";
> +    private ManagedObjectReference datastore       = null;
>  
>  
>      ParseXML        pXML;
> @@ -107,6 +107,7 @@
>                        = (com.vmware.vim.DatastoreInfo)
>                           cb.getServiceUtil().getDynamicProperty(datastores[j],"info");
>  
> +                   datastore = (ManagedObjectReference)datastores[j];
>                     host      = hostMor;
>                     hostFound = true;
>                     i = hostList.size()+1;
> @@ -209,7 +210,16 @@
>           
>           vmConfigSpec.setMemoryMB((long)Integer.parseInt(pXML.getMemory()));
>  
> -         vmConfigSpec.setNumCPUs(Integer.parseInt(pXML.getCPU()));
> +         vmConfigSpec.setNumCPUs(Integer.parseInt(pXML.getVCPU()));
> +         
> +         Double cpuShares = 1000.0 * Double.parseDouble(pXML.getCPU());
> +//         String cShares = new Integer(cpuShares.intValue()).toString();
> +         ResourceAllocationInfo raInfo = new ResourceAllocationInfo();
> +         SharesInfo sharesInfo = new SharesInfo();
> +         sharesInfo.setLevel(SharesLevel.custom);          
> +         sharesInfo.setShares(cpuShares.intValue());
> +         raInfo.setShares(sharesInfo);
> +         vmConfigSpec.setCpuAllocation(raInfo);
>  
>           // DISKs
>           // TODO finish disk support
> @@ -220,18 +230,9 @@
>           configureNetwork();
>           
>         
> -         // TODO CD for contextualization  
> -          
> +         //CDrom and contextualization  
> +          cdDeviceConfig();
>         
> -         /* if(deviceType.equalsIgnoreCase("cd")) {
> -            System.out.println("Reconfiguring The Virtual Machine For CD Update "  
> -                              + cb.get_option("vmname"));                          
> -            VirtualDeviceConfigSpec cdSpec = getCDDeviceConfigSpec();
> -            if(cdSpec != null) {
> -               VirtualDeviceConfigSpec [] cdSpecArray = {cdSpec};                     
> -               vmConfigSpec.setDeviceChange(cdSpecArray);
> -            }*/ 
> -
>           ManagedObjectReference tmor 
>              = cb.getConnection().getService().reconfigVM_Task(
>                  virtualMachine, vmConfigSpec);
> @@ -247,8 +248,116 @@
>   
>        }
>        
> +      private void cdDeviceConfig() throws Exception {
> +
> +           ArrayList<VirtualDeviceConfigSpec> specList = new ArrayList<VirtualDeviceConfigSpec>();
> +           VirtualDevice [] test = vmConfigInfo.getHardware().getDevice();
>        
> -     
> +           //remove all existing cdroms
> +           for ( int i=0; i < test.length; i++ ) {
> +               VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec();
> +               VirtualCdrom cdRemove = null;
> +               cdSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);            
> +               try
> +                {
> +                    cdRemove = (VirtualCdrom)test[i];
> +                }
> +                catch(Exception e)
> +                {
> +                    continue;
> +                }
> +                cdSpec.setDevice(cdRemove);
> +                specList.add(cdSpec);
> +           }
> +      
> +
> +           // add new ones configured by OpenNebula using DISK and CONTEXT
> +           if ( pXML.hasContext() ) {
> +               VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec();
> +               cdSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
> +               VirtualCdrom cdrom =  new VirtualCdrom();
> +
> +               VirtualCdromIsoBackingInfo cdDeviceBacking
> +                   = new  VirtualCdromIsoBackingInfo();
> +               cdDeviceBacking.setDatastore(datastore);
> +               cdDeviceBacking.setFileName("[" + getDataStoreName() + "]one-"+getID()+"/context.iso");
> +
> +               VirtualDevice vd = getIDEController();
> +               cdrom.setBacking(cdDeviceBacking);
> +               cdrom.setControllerKey(vd.getKey());
> +               cdrom.setUnitNumber(vd.getUnitNumber());
> +               cdrom.setKey(-1);
> +
> +               cdSpec.setDevice(cdrom);
> +               specList.add(cdSpec);
> +          }
> +          String [] cdromList = pXML.getCdrom();
> +          for ( int i=0; i < cdromList.length; i++ ) {
> +               VirtualDeviceConfigSpec cdSpec = new VirtualDeviceConfigSpec();
> +               cdSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
> +               VirtualCdrom cdrom =  new VirtualCdrom();
> +
> +               VirtualCdromIsoBackingInfo cdDeviceBacking
> +                   = new  VirtualCdromIsoBackingInfo();
> +               cdDeviceBacking.setDatastore(datastore);
> +               // the device must be on the datastore and NOT be cloned!
> +               String cdPath = cdromList[i].replace(System.getenv("DATASTORE_PATH"),"[" + getDataStoreName() + "]/");
> +               cdDeviceBacking.setFileName(cdPath);
> +
> +               VirtualDevice vd = getIDEController();
> +               cdrom.setBacking(cdDeviceBacking);
> +               cdrom.setControllerKey(vd.getKey());
> +               cdrom.setUnitNumber(vd.getUnitNumber());
> +               cdrom.setKey(-1);
> +
> +               cdSpec.setDevice(cdrom);
> +               specList.add(cdSpec);
> +          }
> +          VirtualDeviceConfigSpec[] specArray;
> +          specArray = (VirtualDeviceConfigSpec[])specList.toArray(
> +              new VirtualDeviceConfigSpec[specList.size()]);
> +          vmConfigSpec.setDeviceChange(specArray);
> +      }
> +
> +      private VirtualDevice getIDEController() throws Exception {
> +           VirtualDevice ideCtlr = null;
> +           VirtualDevice [] defaultDevices = getDefaultDevices();
> +           for (int di = 0; di < defaultDevices.length; di++) {
> +                if (defaultDevices[di] instanceof VirtualIDEController) {
> +                    ideCtlr = defaultDevices[di];
> +                    break;
> +               }
> +           }
> +           return ideCtlr;
> +      }
> +
> +      private VirtualDevice[] getDefaultDevices() throws Exception {
> +           VirtualMachineRuntimeInfo vmRuntimeInfo
> +              = (VirtualMachineRuntimeInfo)cb.getServiceUtil().getDynamicProperty(
> +                    virtualMachine,"runtime");
> +           ManagedObjectReference envBrowser
> +              = (ManagedObjectReference)cb.getServiceUtil().getDynamicProperty(
> +                   virtualMachine,"environmentBrowser");
> +           ManagedObjectReference hmor = vmRuntimeInfo.getHost();
> +
> +           VirtualMachineConfigOption cfgOpt
> +              = cb.getConnection().getService().queryConfigOption(envBrowser, null, hmor);
> +           VirtualDevice[] defaultDevs = null;
> +
> +           if (cfgOpt == null) {
> +               throw new Exception("No VirtualHardwareInfo found in ComputeResource");
> +           }
> +           else {
> +              defaultDevs = cfgOpt.getDefaultDevice();
> +              if (defaultDevs == null) {
> +                  throw new Exception("No Datastore found in ComputeResource");
> +              }
> +           }
> +           return defaultDevs;
> +      }
> +
> +
> + 
>       void configureNetwork()
>       {
>           String[][] nics                  = pXML.getNet();
> @@ -256,7 +365,7 @@
>  
>           if(nics==null) 
>           {
> -	      return;
> +             return;
>           }
>   
>           if(nics.length==1 && nics[0].equals(""))
> @@ -379,7 +488,6 @@
>      
>      DeployVM(String[] arguments, String _hostName, String _vmName, String _vid, String _datastore, String _datacenter) throws Exception
>      {  
> -
>          args = new String[arguments.length+2];
>          
>          for(int i=0;i<arguments.length;i++)
> diff -ur one-org/one-1.4/src/vmm_mad/vmware/OneVmmVmware.java one-1.4/src/vmm_mad/vmware/OneVmmVmware.java
> --- one-org/one-1.4/src/vmm_mad/vmware/OneVmmVmware.java	2009-10-22 17:12:05.000000000 +0100
> +++ one-1.4/src/vmm_mad/vmware/OneVmmVmware.java	2010-02-12 15:33:54.000000000 +0000
> @@ -61,7 +61,29 @@
>      OneVmmVmware(String[] args, boolean _debug) 
>      {
>          debug     = _debug;
> -        arguments = args;
> +        arguments = new String[4];
> +
> +	for (int i = 0; i < args.length; i++) {
> +            if (args[i].compareToIgnoreCase("--authfile") == 0) {
> +                try {
> +                    File authFile = new File(args[i+1]);
> +                    Scanner scanner = new Scanner(authFile);
> +                    if ( scanner.hasNextLine() ){
> +                        String[] authData = scanner.nextLine().split(":");
> +			arguments[0] = "--username";
> +                        arguments[1] = authData[0];
> +                        arguments[2] = "--password";
> +                        arguments[3] = authData[1];
> +                    }
> +                    scanner.close();
> +                }
> +                catch(Exception e) {
> +                    //no point in going on without authentication information!
> +                    e.printStackTrace();
> +                    System.exit(-1);
> +                }
> +            }
> +        }
>          
>          // Get out and err descriptors
>          stdout    = System.out;
> diff -ur one-org/one-1.4/src/vmm_mad/vmware/ParseXML.java one-1.4/src/vmm_mad/vmware/ParseXML.java
> --- one-org/one-1.4/src/vmm_mad/vmware/ParseXML.java	2009-07-10 15:19:17.000000000 +0100
> +++ one-1.4/src/vmm_mad/vmware/ParseXML.java	2010-02-12 16:47:42.000000000 +0000
> @@ -1,3 +1,4 @@
> +import java.util.ArrayList;
>  import java.io.File;
>  import org.w3c.dom.Document;
>  import org.w3c.dom.*;
> @@ -15,10 +16,13 @@
>  {
>      private String      name = "";
>      private String      cpu  = "";
> -    private String[]    disk = {""};
> +    private String      vcpu  = "";
> +    private String[]    disk;
> +    private String[]    cdrom;
>      private String      memory = "";
>      private String[][]  macs;
>      private String      vmID = "";
> +    private boolean     ctx = false;
>      
>      /**
>       * Parses the XML file and fills the values
> @@ -68,6 +72,16 @@
>              }
>              cpu     = ((Node)cpuNL.item(0)).getFirstChild().getNodeValue().trim();
>              
> +            // CPU
> +            NodeList vcpuNL = vm.getElementsByTagName("VCPU");
> +            if(cpuNL.getLength()!=1)
> +            {
> +                //throw new Exception("Number of VCPU tags different of 1: [" + cpuNL.getLength() + "]");
> +                vcpu     = "1";
> +            } else {
> +                vcpu     = ((Node)vcpuNL.item(0)).getFirstChild().getNodeValue().trim();
> +            }
> +
>              // Memory
>              NodeList memoryNL = vm.getElementsByTagName("MEMORY"); 
>              if(memoryNL.getLength()!=1)
> @@ -76,20 +90,32 @@
>              }
>              memory   = ((Node)memoryNL.item(0)).getFirstChild().getNodeValue().trim();
>              
> -            // DISK
> +            // DISK and CDROM
>              NodeList diskNL = vm.getElementsByTagName("DISK");
> -            
> +            ArrayList<String> disks = new ArrayList<String>();
> +            ArrayList<String> cdroms = new ArrayList<String>();
> +
>              if(diskNL.getLength()!=0)
>              {
> -                disk = new String[diskNL.getLength()];
> +                //disk = new String[diskNL.getLength()];
>                  
>                  for(int i=0; i<diskNL.getLength(); i++)
>                  {
>                      NodeList sourceNode = ((Element)diskNL.item(i)).getElementsByTagName("SOURCE");
> -                    
> -                    disk[i] = ((Node)sourceNode.item(0)).getFirstChild().getNodeValue().trim();
> +                    NodeList typeNode = ((Element)diskNL.item(i)).getElementsByTagName("TYPE");
> +                    if ( typeNode.getLength() == 0 ) {
> +                         disks.add(((Node)sourceNode.item(0)).getFirstChild().getNodeValue().trim());
> +                    } else if ( ((Node)typeNode.item(0)).getFirstChild().getNodeValue().trim().compareToIgnoreCase("cdrom") == 0 ) {
> +                         cdroms.add(((Node)sourceNode.item(0)).getFirstChild().getNodeValue().trim());
> +                    }
>                  }
> +                disk = (String[])disks.toArray(new String[disks.size()]);
> +                cdrom = (String[])cdroms.toArray(new String[cdroms.size()]);
>              }
> +
> +            // Contextualization
> +            NodeList ctxNL = vm.getElementsByTagName("CONTEXT");
> +            ctx = (ctxNL.getLength() > 0);
>              
>              // Network
>              
> @@ -126,6 +152,15 @@
>      {
>          return cpu;
>      }
> +
> +    /**
> +     * Returns vcpu value
> +     * @return vcpu number of cpus to be used by the VM
> +     **/    
> +    String getVCPU()
> +    {
> +        return vcpu;
> +    }
>      
>      /**
>       * Returns disk value
> @@ -135,7 +170,15 @@
>      {
>          return disk;
>      }
> -    
> +   
> +    /**
> +     * Returns cdrom value
> +     * @return string array with the full local path of cdrom iso
> +     **/
> +    String[] getCdrom()
> +    {
> +        return cdrom;
> +    }
>      /**
>       * Returns memory value
>       * @return memory amount of memory in Mb to be used by this VM
> @@ -171,4 +214,14 @@
>      {
>          return vmID;
>      }
> +
> +    /**
> +     * Checks if the machine has context
> +     * @return true if the machine  has a context iso
> +     **/
> +    boolean hasContext()
> +    {
> +        return ctx;
> +    }
> +
>  }

> _______________________________________________
> Users mailing list
> Users at lists.opennebula.org
> http://lists.opennebula.org/listinfo.cgi/users-opennebula.org



More information about the Users mailing list