public Map < String , String > createVM ( HttpInputs httpInputs , VmInputs vmInputs ) throws Exception { ConnectionResources connectionResources = new ConnectionResources ( httpInputs , vmInputs ) ; try { VmUtils utils = new VmUtils ( ) ; ManagedObjectReference vmFolderMor = utils . getMorFolder ( vmInputs . getFolderName ( ) , connectionResources ) ; ManagedObjectReference resourcePoolMor = utils . getMorResourcePool ( vmInputs . getResourcePool ( ) , connectionResources ) ; ManagedObjectReference hostMor = utils . getMorHost ( vmInputs . getHostname ( ) , connectionResources , null ) ; VirtualMachineConfigSpec vmConfigSpec = new VmConfigSpecs ( ) . getVmConfigSpec ( vmInputs , connectionResources ) ; ManagedObjectReference task = connectionResources . getVimPortType ( ) . createVMTask ( vmFolderMor , vmConfigSpec , resourcePoolMor , hostMor ) ; return new ResponseHelper ( connectionResources , task ) . getResultsMap ( "Success: Created [" + vmInputs . getVirtualMachineName ( ) + "] VM. The taskId is: " + task . getValue ( ) , "Failure: Could not create [" + vmInputs . getVirtualMachineName ( ) + "] VM" ) ; } catch ( Exception ex ) { return ResponseUtils . getResultsMap ( ex . toString ( ) , Outputs . RETURN_CODE_FAILURE ) ; } finally { if ( httpInputs . isCloseSession ( ) ) { connectionResources . getConnection ( ) . disconnect ( ) ; clearConnectionFromContext ( httpInputs . getGlobalSessionObject ( ) ) ; } } }
Method used to connect to specified data center and create a virtual machine using the inputs provided .