Package be.jedi.jvspherecontrol.exceptions

Examples of be.jedi.jvspherecontrol.exceptions.InvalidCLIArgumentSyntaxException


    vsphereUrl=cmdLine.getOptionValue("url");
   
    try {
      URI uri= new URI (vsphereUrl);
      if (!((uri.getScheme().equals("http")) || (uri.getScheme().equals("https")))) {
        throw new InvalidCLIArgumentSyntaxException("url has an invalid Scheme syntax: "+uri.getScheme());       
      }

    } catch (URISyntaxException e) {
      throw new InvalidCLIArgumentSyntaxException("url has an invalid URL syntax: "+e.getMessage());
    }
   
    if (!vsphereUrl.endsWith("/sdk")) {
      throw new InvalidCLIArgumentSyntaxException("url needs to include the sdk part: f.i https://servername/sdk");
     
    }
   
    vsphereUsername=cmdLine.getOptionValue("user");
    vspherePassword=cmdLine.getOptionValue("password");
View Full Code Here


   
    //Omapi Host
    omapiHost=cmdLine.getOptionValue("omapihost");
    if (omapiHost!=null) {
      if (omapiHost.length()<2) {
        throw new InvalidCLIArgumentSyntaxException("omapihost must be at least two characters");       
      } else {
        //nothing to do here
      }
    } else {
      if (vmOmapiRegister) {
      throw new MissingCLIArgumentException("omapihost is required when omapiregister is enabled")
      }
    }

    //Omapi Port : default 9991
    String omapiPortString=cmdLine.getOptionValue("omapiport");
    if (omapiPortString!=null) {
      try {
        this.omapiPort=Integer.parseInt(omapiPortString);
      } catch (NumberFormatException ex) {
        throw new InvalidCLIArgumentSyntaxException("omapiport must be an integer");
      }
    } else {
      JVsphereControl.logger.debug("no omapiport is given, using default value of "+omapiPort+" for omapiport");
   
       
View Full Code Here

    super.validateArgs();
   
    //Name of the Virtual Machine
    vmName=cmdLine.getOptionValue("name");
    if (vmName.length()<=1) {
      throw new InvalidCLIArgumentSyntaxException("name must be at least two characters");
    }
 
    //Number of CPU's for the new VM
    String vmCpusString=cmdLine.getOptionValue("cpus");
    if (vmCpusString!=null) {
      try {
        this.vmCpus=Integer.parseInt(vmCpusString);
      } catch (NumberFormatException ex) {
        throw new InvalidCLIArgumentSyntaxException("cpus must be an integer");
      }
    } else {
      JVsphereControl.logger.debug("no cpus is given, using default value of "+vmCpus+" for cpus");
    }
   
    //Memorysize of the new VM
    String vmMemoryString=cmdLine.getOptionValue("memory");
    if (vmMemoryString!=null) {
      try {
        this.vmMemory=Integer.parseInt(vmMemoryString);
      } catch (NumberFormatException ex) {
        throw new InvalidCLIArgumentSyntaxException("memory must be an integer");
      }
    } else {
      JVsphereControl.logger.debug("no memory is given, using default value of "+vmMemory+" for memory");
    }
   
   
    ///Option GuesOsId - http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-VM.html
    //we need to check this against a list!
    String osTypes[]={"asianux3Guest", "asianux4_64Guest", "asianux4Guest", "darwin64Guest", "darwinGuest", "debian4_64Guest",
                           "debian4Guest", "debian5_64Guest", "debian5Guest", "dosGuest", "freebsd64Guest", "freebsdGuest",
                           "mandrivaGuest", "netware4Guest", "netware5Guest", "netware6Guest", "nld9Guest", "oesGuest", "openServer5Guest",
                           "openServer6Guest", "os2Guest", "other24xLinux64Guest", "other24xLinuxGuest", "other26xLinux64Guest", "other26xLinuxGuest",
                           "other26xLinuxGuest", "otherGuest", "otherGuest64", "otherLinux64Guest", "otherLinuxGuest", "redhatGuest", "rhel2Guest",
                           "rhel3_64Guest", "rhel3Guest", "rhel4_64Guest", "rhel4Guest", "rhel5_64Guest", "rhel5Guest", "rhel6_64Guest", "rhel6Guest",
                           "sjdsGuest", "sles10_64Guest", "sles10Guest", "sles11_64Guest", "sles11Guest", "sles64Guest", "slesGuest", "solaris10_64Guest",
                           "solaris10Guest", "solaris6Guest", "solaris7Guest", "solaris8Guest", "solaris9Guest", "suse64Guest", "suseGuest", "turboLinux64Guest",
                           "turboLinuxGuest", "ubuntu64Guest", "ubuntuGuest", "unixWare7Guest", "win2000AdvServGuest", "win2000ProGuest", "win2000ServGuest", "win31Guest",
                           "win95Guest", "win98Guest", "windows7_64Guest", "windows7Guest", "windows7Server64Guest", "winLonghorn64Guest", "winLonghornGuest", "winMeGuest",
                           "winNetBusinessGuest", "winNetDatacenter64Guest", "winNetDatacenterGuest", "winNetDatacenterGuest", "winNetDatacenterGuest", "winNetDatacenterGuest",
                           "winNetEnterprise64Guest", "winNetEnterpriseGuest", "winNetStandard64Guest", "winNetEnterpriseGuest", "winNetStandard64Guest", "winNetStandardGuest",
                           "winNetWebGuest", "winNTGuest", "winVista64Guest", "winVistaGuest", "winXPHomeGuest", "winXPPro64Guest", "winXPProGuest"};
   
    vmOsType=cmdLine.getOptionValue("ostype");
    boolean knownOs=false;
    for (int o=0 ; o< osTypes.length; o++) {
      if (vmOsType.toLowerCase().equals(osTypes[o].toLowerCase())) {
        knownOs=true;
        break;
      }
    }

    if (!knownOs) {
      String osTypeString="";
      for (int o=0 ; o< osTypes.length; o++) {
        osTypeString=osTypeString+osTypes[o]+",";
      }     
      throw new InvalidCLIArgumentSyntaxException(" ostype must be one of the following: "+osTypeString);
    }

    //Overwrite the VM or not
    String vmOverwriteString=cmdLine.getOptionValue("overwrite");
    if (vmOverwriteString!=null) {
      vmOverwrite=Boolean.parseBoolean(vmOverwriteString)
    }

    //Register the machine in Omapi
    String vmOmapiRegisterString=cmdLine.getOptionValue("omapiregister");
    if (vmOmapiRegisterString!=null) {
      vmOmapiRegister=Boolean.parseBoolean(vmOmapiRegisterString)
    }
   
    //Omapi Host
    omapiHost=cmdLine.getOptionValue("omapihost");
    if (omapiHost!=null) {
      if (omapiHost.length()<2) {
        throw new InvalidCLIArgumentSyntaxException("omapihost must be at least two characters");       
      } else {
        //nothing to do here
      }
    } else {
      if (vmOmapiRegister) {
      throw new MissingCLIArgumentException("omapihost is required when omapiregister is enabled")
      }
    }

    //Omapi Port : default 9991
    String omapiPortString=cmdLine.getOptionValue("omapiport");
    if (omapiPortString!=null) {
      try {
        this.omapiPort=Integer.parseInt(omapiPortString);
      } catch (NumberFormatException ex) {
        throw new InvalidCLIArgumentSyntaxException("omapiport must be an integer");
      }
    } else {
      JVsphereControl.logger.debug("no omapiport is given, using default value of "+omapiPort+" for omapiport");
   
       
    omapiKeyName=cmdLine.getOptionValue("omapikeyname");
    omapiKeyValue=cmdLine.getOptionValue("omapikeyvalue");
   
    if (vmOmapiRegister) {
      if (omapiKeyName==null) {
        throw new MissingCLIArgumentException("omapikeyname is required when omapiregister is enabled");       
      }
      if (omapiKeyValue==null) {
        throw new MissingCLIArgumentException("omapikeyvalue is required when omapiregister is enabled");       
      }
    }
   
    //Omapi Overwrite
    String omapiOverWriteString=cmdLine.getOptionValue("omapioverwrite");
    if (omapiOverWriteString!=null) {
      omapiOverWrite=Boolean.parseBoolean(omapiOverWriteString)
    }   
   

    //We need to check this against the available datacenter and datastores
    vsphereDataCenterName=cmdLine.getOptionValue("datacenter");
    vsphereDataStoreName=cmdLine.getOptionValue("datastore");
    vsphereClusterName=cmdLine.getOptionValue("cluster");
   
   
    /*****  Disks *****/ 
    //Size of the disk to be created
    int lastDisk=0;
    for (int i=1; i< 20; i++) {
      if (cmdLine.getOptionValues("disksize"+i)==null) {
        break;
      } else {
        lastDisk++;
      }
    }

   
    //Todo: set defaults if parameter is not specified:
    vmDisks=new VmDisk[lastDisk];
    for (int i=0; i< vmDisks.length; i++) {

      String disk_modes_values[]={ "persistent","independent_persistent","independent_nonpersistent"}

      String diskSize=cmdLine.getOptionValue("disksize"+(i+1));
      String diskMode=cmdLine.getOptionValue("diskmode"+(i+1));
      String diskDatastore=cmdLine.getOptionValue("diskdatastore"+(i+1));
   
      boolean vmDiskModeMatch=false;
      for (int j=0; j< disk_modes_values.length; j++) {
        if (disk_modes_values[j].equals(diskMode)) {
          vmDiskModeMatch=true;
        }
      }
      if (!vmDiskModeMatch) {
        throw new InvalidCLIArgumentSyntaxException("diskmode must be persistent,independent_persistent,idependent_nonpersistent");
      }
     
      VmDisk vmDisk=new VmDisk();
     
      vmDisk.setSize(Long.parseLong(diskSize));
View Full Code Here

    //We check for the list option to be part of the list we know
    String firstArg=this.getArgs()[0];
   
    if (!Arrays.asList(listItems).contains(firstArg)) {
      throw new InvalidCLIArgumentSyntaxException("the options specified to the list command is not valid");
    } else {
      listItem=firstArg;
    }
   
  }
View Full Code Here

      //prepare a command
      try {
        AbstractCommand command=getCommandByString(commandString);
        if (command==null)  {
          //Not a valid command
          InvalidCLIArgumentSyntaxException ex=new InvalidCLIArgumentSyntaxException("Unknown command:"+commandString);
          throw ex;
        }
        command.init(commandArguments);
        command.validateArgs();

      } catch (InvalidCLIArgumentSyntaxException e) {
        logger.error(e.toString());
        InvalidCLIArgumentSyntaxException ex=new InvalidCLIArgumentSyntaxException("Syntax error in argument:"+e.getLocalizedMessage());
        throw ex;       
      }
    } else {
      logger.error("We need at least one arg");
      MissingCLIArgumentException ex=new MissingCLIArgumentException("We need at least one argument");
View Full Code Here

TOP

Related Classes of be.jedi.jvspherecontrol.exceptions.InvalidCLIArgumentSyntaxException

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.