@@ -58,37 +58,38 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
5858 DataStoreTO conversionTemporaryLocation = cmd .getConversionTemporaryLocation ();
5959 long timeout = (long ) cmd .getWait () * 1000 ;
6060 String extraParams = cmd .getExtraParams ();
61+ String originalVMName = cmd .getOriginalVMName (); // For logging purposes, as the sourceInstance may have been cloned
6162
6263 if (cmd .getCheckConversionSupport () && !serverResource .hostSupportsInstanceConversion ()) {
6364 String msg = String .format ("Cannot convert the instance %s from VMware as the virt-v2v binary is not found. " +
6465 "Please install virt-v2v%s on the host before attempting the instance conversion." , sourceInstanceName , serverResource .isUbuntuOrDebianHost ()? ", nbdkit" : "" );
65- logger .info (String .format ("(%s) %s" , sourceInstanceName , msg ));
66+ logger .info (String .format ("(%s) %s" , originalVMName , msg ));
6667 return new Answer (cmd , false , msg );
6768 }
6869
6970 if (!areSourceAndDestinationHypervisorsSupported (sourceHypervisorType , destinationHypervisorType )) {
7071 String err = destinationHypervisorType != Hypervisor .HypervisorType .KVM ?
7172 String .format ("The destination hypervisor type is %s, KVM was expected, cannot handle it" , destinationHypervisorType ) :
7273 String .format ("The source hypervisor type %s is not supported for KVM conversion" , sourceHypervisorType );
73- logger .error (String .format ("(%s) %s" , sourceInstanceName , err ));
74+ logger .error (String .format ("(%s) %s" , originalVMName , err ));
7475 return new Answer (cmd , false , err );
7576 }
7677
7778 final KVMStoragePoolManager storagePoolMgr = serverResource .getStoragePoolMgr ();
7879 KVMStoragePool temporaryStoragePool = getTemporaryStoragePool (conversionTemporaryLocation , storagePoolMgr );
7980
8081 logger .info (String .format ("(%s) Attempting to convert the instance %s from %s to KVM" ,
81- sourceInstanceName , sourceInstanceName , sourceHypervisorType ));
82+ originalVMName , sourceInstanceName , sourceHypervisorType ));
8283 final String temporaryConvertPath = temporaryStoragePool .getLocalPath ();
8384
8485 String ovfTemplateDirOnConversionLocation ;
8586 String sourceOVFDirPath ;
8687 boolean ovfExported = false ;
8788 if (cmd .getExportOvfToConversionLocation ()) {
88- String exportInstanceOVAUrl = getExportInstanceOVAUrl (sourceInstance );
89+ String exportInstanceOVAUrl = getExportInstanceOVAUrl (sourceInstance , originalVMName );
8990 if (StringUtils .isBlank (exportInstanceOVAUrl )) {
9091 String err = String .format ("Couldn't export OVA for the VM %s, due to empty url" , sourceInstanceName );
91- logger .error (String .format ("(%s) %s" , sourceInstanceName , err ));
92+ logger .error (String .format ("(%s) %s" , originalVMName , err ));
9293 return new Answer (cmd , false , err );
9394 }
9495
@@ -99,10 +100,10 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
99100 ovfTemplateDirOnConversionLocation = UUID .randomUUID ().toString ();
100101 temporaryStoragePool .createFolder (ovfTemplateDirOnConversionLocation );
101102 sourceOVFDirPath = String .format ("%s/%s/" , temporaryConvertPath , ovfTemplateDirOnConversionLocation );
102- ovfExported = exportOVAFromVMOnVcenter (exportInstanceOVAUrl , sourceOVFDirPath , noOfThreads , sourceInstanceName , timeout );
103+ ovfExported = exportOVAFromVMOnVcenter (exportInstanceOVAUrl , sourceOVFDirPath , noOfThreads , originalVMName , timeout );
103104 if (!ovfExported ) {
104105 String err = String .format ("Export OVA for the VM %s failed" , sourceInstanceName );
105- logger .error (String .format ("(%s) %s" , sourceInstanceName , err ));
106+ logger .error (String .format ("(%s) %s" , originalVMName , err ));
106107 return new Answer (cmd , false , err );
107108 }
108109 sourceOVFDirPath = String .format ("%s%s/" , sourceOVFDirPath , sourceInstanceName );
@@ -112,39 +113,39 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve
112113 }
113114
114115 logger .info (String .format ("(%s) Attempting to convert the OVF %s of the instance %s from %s to KVM" ,
115- sourceInstanceName , ovfTemplateDirOnConversionLocation , sourceInstanceName , sourceHypervisorType ));
116+ originalVMName , ovfTemplateDirOnConversionLocation , sourceInstanceName , sourceHypervisorType ));
116117
117118 final String temporaryConvertUuid = UUID .randomUUID ().toString ();
118119 boolean verboseModeEnabled = serverResource .isConvertInstanceVerboseModeEnabled ();
119120
120121 boolean cleanupSecondaryStorage = false ;
121122 try {
122- boolean result = performInstanceConversion (sourceInstanceName , sourceOVFDirPath , temporaryConvertPath , temporaryConvertUuid ,
123+ boolean result = performInstanceConversion (originalVMName , sourceOVFDirPath , temporaryConvertPath , temporaryConvertUuid ,
123124 timeout , verboseModeEnabled , extraParams , serverResource );
124125 if (!result ) {
125126 String err = String .format (
126127 "The virt-v2v conversion for the OVF %s failed. Please check the agent logs " +
127128 "for the virt-v2v output. Please try on a different kvm host which " +
128129 "has a different virt-v2v version." ,
129130 ovfTemplateDirOnConversionLocation );
130- logger .error (String .format ("(%s) %s" , sourceInstanceName , err ));
131+ logger .error (String .format ("(%s) %s" , originalVMName , err ));
131132 return new Answer (cmd , false , err );
132133 }
133134 return new ConvertInstanceAnswer (cmd , temporaryConvertUuid );
134135 } catch (Exception e ) {
135136 String error = String .format ("Error converting instance %s from %s, due to: %s" ,
136137 sourceInstanceName , sourceHypervisorType , e .getMessage ());
137- logger .error (String .format ("(%s) %s" , sourceInstanceName , error ), e );
138+ logger .error (String .format ("(%s) %s" , originalVMName , error ), e );
138139 cleanupSecondaryStorage = true ;
139140 return new Answer (cmd , false , error );
140141 } finally {
141142 if (ovfExported && StringUtils .isNotBlank (ovfTemplateDirOnConversionLocation )) {
142143 String sourceOVFDir = String .format ("%s/%s" , temporaryConvertPath , ovfTemplateDirOnConversionLocation );
143- logger .debug ("({}) Cleaning up exported OVA at dir: {}" , sourceInstanceName , sourceOVFDir );
144+ logger .debug ("({}) Cleaning up exported OVA at dir: {}" , originalVMName , sourceOVFDir );
144145 FileUtil .deletePath (sourceOVFDir );
145146 }
146147 if (cleanupSecondaryStorage && conversionTemporaryLocation instanceof NfsTO ) {
147- logger .debug ("({}) Cleaning up secondary storage temporary location" , sourceInstanceName );
148+ logger .debug ("({}) Cleaning up secondary storage temporary location" , originalVMName );
148149 storagePoolMgr .deleteStoragePool (temporaryStoragePool .getType (), temporaryStoragePool .getUuid ());
149150 }
150151 }
@@ -166,15 +167,15 @@ protected boolean areSourceAndDestinationHypervisorsSupported(Hypervisor.Hypervi
166167 supportedInstanceConvertSourceHypervisors .contains (sourceHypervisorType );
167168 }
168169
169- private String getExportInstanceOVAUrl (RemoteInstanceTO sourceInstance ) {
170+ private String getExportInstanceOVAUrl (RemoteInstanceTO sourceInstance , String originalVMName ) {
170171 String url = null ;
171172 if (sourceInstance .getHypervisorType () == Hypervisor .HypervisorType .VMware ) {
172- url = getExportOVAUrlFromRemoteInstance (sourceInstance );
173+ url = getExportOVAUrlFromRemoteInstance (sourceInstance , originalVMName );
173174 }
174175 return url ;
175176 }
176177
177- private String getExportOVAUrlFromRemoteInstance (RemoteInstanceTO vmwareInstance ) {
178+ private String getExportOVAUrlFromRemoteInstance (RemoteInstanceTO vmwareInstance , String originalVMName ) {
178179 String vcenter = vmwareInstance .getVcenterHost ();
179180 String username = vmwareInstance .getVcenterUsername ();
180181 String password = vmwareInstance .getVcenterPassword ();
@@ -185,7 +186,7 @@ private String getExportOVAUrlFromRemoteInstance(RemoteInstanceTO vmwareInstance
185186 String encodedUsername = encodeUsername (username );
186187 String encodedPassword = encodeUsername (password );
187188 if (StringUtils .isNotBlank (path )) {
188- logger .info ("({}) VM path: {}" , vm , path );
189+ logger .info ("({}) VM path: {}" , originalVMName , path );
189190 return String .format ("vi://%s:%s@%s/%s/%s/%s" ,
190191 encodedUsername , encodedPassword , vcenter , datacenter , path , vm );
191192 }
@@ -204,7 +205,7 @@ protected void sanitizeDisksPath(List<LibvirtVMDef.DiskDef> disks) {
204205 private boolean exportOVAFromVMOnVcenter (String vmExportUrl ,
205206 String targetOvfDir ,
206207 int noOfThreads ,
207- String sourceInstanceName , long timeout ) {
208+ String originalVMName , long timeout ) {
208209 Script script = new Script ("ovftool" , timeout , logger );
209210 script .add ("--noSSLVerify" );
210211 if (noOfThreads > 1 ) {
@@ -213,14 +214,14 @@ private boolean exportOVAFromVMOnVcenter(String vmExportUrl,
213214 script .add (vmExportUrl );
214215 script .add (targetOvfDir );
215216
216- String logPrefix = String .format ("(%s) export ovf" , sourceInstanceName );
217+ String logPrefix = String .format ("(%s) export ovf" , originalVMName );
217218 OutputInterpreter .LineByLineOutputLogger outputLogger = new OutputInterpreter .LineByLineOutputLogger (logger , logPrefix );
218219 script .execute (outputLogger );
219220 int exitValue = script .getExitValue ();
220221 return exitValue == 0 ;
221222 }
222223
223- protected boolean performInstanceConversion (String sourceInstanceName , String sourceOVFDirPath ,
224+ protected boolean performInstanceConversion (String originalVMName , String sourceOVFDirPath ,
224225 String temporaryConvertFolder ,
225226 String temporaryConvertUuid ,
226227 long timeout , boolean verboseModeEnabled , String extraParams ,
@@ -240,7 +241,7 @@ protected boolean performInstanceConversion(String sourceInstanceName, String so
240241 script .add (extraParams );
241242 }
242243
243- String logPrefix = String .format ("(%s) virt-v2v ovf source: %s progress" , sourceInstanceName , sourceOVFDirPath );
244+ String logPrefix = String .format ("(%s) virt-v2v ovf source: %s progress" , originalVMName , sourceOVFDirPath );
244245 OutputInterpreter .LineByLineOutputLogger outputLogger = new OutputInterpreter .LineByLineOutputLogger (logger , logPrefix );
245246 script .execute (outputLogger , serverResource .getConvertInstanceEnv ());
246247 int exitValue = script .getExitValue ();
0 commit comments