+
+ BufferedReader bin = new BufferedReader( fin ) ;
+ String line = "" ;
+ FileWriter fout = null ;
+
+ try {
+ fout = new FileWriter( new File( working_directory + "/" + directory + "/" + vmx_name ) ) ;
+ } catch( IOException e ) {
+ System.err.println( "Unable to open the VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ // Keeping only some information
+ // -- this force VmWare to generate new identifiers and MAC address
+ while( line != null )
+ {
+ try {
+ line = bin.readLine() ;
+ if( line != null )
+ if( ! line.contains( "ethernet0.addressType" )
+ && ! line.contains( "uuid.location " )
+ && ! line.contains( "uuid.bios " )
+ && ! line.contains( "ethernet0.generatedAddress " )
+ && ! line.contains( "ethernet0.generatedAddressOffset " )
+ )
+ {
+ fout.write( line + "\n" ) ;
+ }
+ } catch( IOException e ) {}
+ }
+
+ try {
+ bin.close() ;
+ } catch (IOException e) {
+ System.err.println( "Unable to close the initial VMX file!" ) ;
+ e.printStackTrace() ;
+ }
+
+ // Adding the copy information
+ try
+ {
+ fout.write( "msg.autoAnswer = \"TRUE\"\n" ) ;
+ fout.write( "answer.msg.checkpoint.cpufeaturecheck.fail = \"_Yes\"\n" ) ;
+ fout.write( "checkpoint.vmState = \"\"\n" ) ;
+ fout.write( "answer.msg.uuid.altered = \"I _copied it\"\n" ) ;
+ } catch( IOException e ) {
+ System.err.println( "Unable to add infortion to VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ try {
+ fout.close() ;
+ } catch( IOException e ) {
+ System.err.println( "Unable to close the VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ System.out.println( "Successful rewrite of the VMX file." ) ;
+
+ // Removing the initial mark
+ System.out.print( "Removing the deployment mark ... " ) ;
+
+ command = new String[]{ "/bin/rm",
+ working_directory + "/" + directory + "/initial.hpcvm" } ;
+
+ try {
+ Process p = Runtime.getRuntime().exec( command ) ;
+ p.waitFor() ;
+
+ if( p.exitValue() == 0 )
+ {
+ System.out.println( "Successfully deletion of the deployment mark." ) ;
+ } else {
+ System.err.println( "Unsuccessful deletion of the deployment mark!" ) ;
+ printProcessError( p ) ;
+ return 1 ;
+ }
+ } catch( IOException e ) {
+ System.err.println( "Error during deletion of the deployment mark: " ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ deploy = false ;
+
+ // Writing the first start mark
+ try {
+ FileWriter fw = new FileWriter( new File( working_directory + "/" + directory + "/first.hpcvm" ) ) ;
+ fw.write( "first!\n" ) ;
+ fw.flush() ;
+ fw.close() ;
+ fw = null ;
+ return 0 ;
+ } catch( IOException e1 ) {
+ e1.printStackTrace() ;
+ System.err.println( "Unable to mark the first run of the VM!" ) ;
+ }
+ }
+
+
+ // First start of the VM
+
+ if( first )
+ {
+ System.out.print( "Saving the first start VMX file ... " ) ;
+
+ String[] command = new String[]{ "/bin/cp",
+ working_directory + "/" + directory + "/" + vmx_name,
+ working_directory + "/" + directory + "/" + vmx_name_first } ;
+
+ try {
+ Process p = Runtime.getRuntime().exec( command ) ;
+ p.waitFor() ;
+
+ if( p.exitValue() == 0 )
+ {
+ System.out.println( "Successfully saved the first start VMX file." ) ;
+ } else {
+ System.err.println( "Unsuccessful save of the first start VMX file!" ) ;
+ printProcessError( p ) ;
+ return 1 ;
+ }
+ } catch( IOException e ) {
+ System.err.println( "Error during first start VMX file save: " ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ System.out.print( "Rewritting WMX file ... " ) ;
+
+
+ FileReader fin = null ;
+ try {
+ fin = new FileReader( new File( working_directory + "/" + directory + "/" + vmx_name_first ) );
+ } catch( FileNotFoundException e ) {
+ System.err.println( "Unable to open the first start VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ BufferedReader bin = new BufferedReader( fin ) ;
+ String line = "" ;
+ FileWriter fout = null ;
+
+ try {
+ fout = new FileWriter( new File( working_directory + "/" + directory + "/" + vmx_name ) ) ;
+ } catch( IOException e ) {
+ System.err.println( "Unable to open the VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ // Keeping all information
+ // -- except copy information
+ while( line != null )
+ {
+ try {
+ line = bin.readLine() ;
+ if( line != null )
+ if( ! line.contains( "answer.msg.uuid.altered " ) )
+ {
+ fout.write( line + "\n" ) ;
+ }
+ } catch( IOException e ) {}
+ }
+
+ try {
+ bin.close() ;
+ } catch (IOException e) {
+ System.err.println( "Unable to close the first start VMX file!" ) ;
+ e.printStackTrace() ;
+ }
+
+ try {
+ fout.close() ;
+ } catch( IOException e ) {
+ System.err.println( "Unable to close the VMX file!" ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ System.out.println( "Successful rewrite of the VMX file." ) ;
+
+ // Removing the initial mark
+ System.out.print( "Removing the first start mark ... " ) ;
+
+ command = new String[]{ "/bin/rm",
+ working_directory + "/" + directory + "/first.hpcvm" } ;
+
+ try {
+ Process p = Runtime.getRuntime().exec( command ) ;
+ p.waitFor() ;
+
+ if( p.exitValue() == 0 )
+ {
+ System.out.println( "Successfully deletion of the first start mark." ) ;
+ } else {
+ System.err.println( "Unsuccessful deletion of the first start mark!" ) ;
+ printProcessError( p ) ;
+ return 1 ;
+ }
+ } catch( IOException e ) {
+ System.err.println( "Error during deletion of the first start mark: " ) ;
+ e.printStackTrace() ;
+ return 1 ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ return 1 ;
+ }
+
+ first = false ;
+
+ return 0 ;