|
16 | 16 | // under the License. |
17 | 17 | package com.cloud.hypervisor.vmware.manager; |
18 | 18 |
|
| 19 | +import java.io.File; |
| 20 | +import java.io.FileInputStream; |
| 21 | +import java.io.IOException; |
| 22 | +import java.net.URI; |
| 23 | +import java.net.URISyntaxException; |
| 24 | +import java.net.URL; |
| 25 | +import java.rmi.RemoteException; |
| 26 | +import java.time.Duration; |
| 27 | +import java.time.Instant; |
| 28 | +import java.util.ArrayList; |
| 29 | +import java.util.Collections; |
| 30 | +import java.util.HashMap; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | +import java.util.Random; |
| 34 | +import java.util.UUID; |
| 35 | +import java.util.concurrent.Executors; |
| 36 | +import java.util.concurrent.RejectedExecutionException; |
| 37 | +import java.util.concurrent.ScheduledExecutorService; |
| 38 | +import java.util.concurrent.TimeUnit; |
| 39 | +import java.util.stream.Collectors; |
| 40 | + |
| 41 | +import javax.inject.Inject; |
| 42 | +import javax.naming.ConfigurationException; |
| 43 | + |
| 44 | +import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd; |
| 45 | +import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd; |
| 46 | +import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd; |
| 47 | +import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd; |
| 48 | +import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd; |
| 49 | +import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd; |
| 50 | +import org.apache.cloudstack.api.command.admin.zone.UpdateVmwareDcCmd; |
| 51 | +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
| 52 | +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
| 53 | +import org.apache.cloudstack.framework.config.ConfigKey; |
| 54 | +import org.apache.cloudstack.framework.config.Configurable; |
| 55 | +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
| 56 | +import org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl; |
| 57 | +import org.apache.cloudstack.management.ManagementServerHost; |
| 58 | +import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand; |
| 59 | +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
| 60 | +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
| 61 | +import org.apache.cloudstack.utils.identity.ManagementServerNode; |
| 62 | +import org.apache.commons.codec.digest.DigestUtils; |
| 63 | +import org.apache.commons.lang3.StringUtils; |
| 64 | +import org.apache.log4j.Logger; |
| 65 | + |
19 | 66 | import com.amazonaws.util.CollectionUtils; |
20 | 67 | import com.cloud.agent.AgentManager; |
21 | 68 | import com.cloud.agent.Listener; |
|
118 | 165 | import com.vmware.pbm.PbmProfile; |
119 | 166 | import com.vmware.vim25.AboutInfo; |
120 | 167 | import com.vmware.vim25.ManagedObjectReference; |
121 | | -import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd; |
122 | | -import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd; |
123 | | -import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd; |
124 | | -import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd; |
125 | | -import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd; |
126 | | -import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd; |
127 | | -import org.apache.cloudstack.api.command.admin.zone.UpdateVmwareDcCmd; |
128 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
129 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
130 | | -import org.apache.cloudstack.framework.config.ConfigKey; |
131 | | -import org.apache.cloudstack.framework.config.Configurable; |
132 | | -import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
133 | | -import org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl; |
134 | | -import org.apache.cloudstack.management.ManagementServerHost; |
135 | | -import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand; |
136 | | -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
137 | | -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
138 | | -import org.apache.cloudstack.utils.identity.ManagementServerNode; |
139 | | -import org.apache.log4j.Logger; |
140 | | - |
141 | | -import javax.inject.Inject; |
142 | | -import javax.naming.ConfigurationException; |
143 | | -import java.io.File; |
144 | | -import java.io.IOException; |
145 | | -import java.net.URI; |
146 | | -import java.net.URISyntaxException; |
147 | | -import java.net.URL; |
148 | | -import java.rmi.RemoteException; |
149 | | -import java.time.Duration; |
150 | | -import java.time.Instant; |
151 | | -import java.util.ArrayList; |
152 | | -import java.util.Collections; |
153 | | -import java.util.HashMap; |
154 | | -import java.util.List; |
155 | | -import java.util.Map; |
156 | | -import java.util.Random; |
157 | | -import java.util.UUID; |
158 | | -import java.util.concurrent.Executors; |
159 | | -import java.util.concurrent.RejectedExecutionException; |
160 | | -import java.util.concurrent.ScheduledExecutorService; |
161 | | -import java.util.concurrent.TimeUnit; |
162 | | -import java.util.stream.Collectors; |
163 | 168 |
|
164 | 169 | public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService, Configurable { |
165 | 170 | private static final Logger s_logger = Logger.getLogger(VmwareManagerImpl.class); |
@@ -263,6 +268,24 @@ public VmwareManagerImpl() { |
263 | 268 | _storageMgr = new VmwareStorageManagerImpl(this); |
264 | 269 | } |
265 | 270 |
|
| 271 | + private boolean isSystemVmIsoCopyNeeded(File srcIso, File destIso) { |
| 272 | + if (!destIso.exists()) { |
| 273 | + return true; |
| 274 | + } |
| 275 | + boolean copyNeeded = false; |
| 276 | + try { |
| 277 | + String srcIsoMd5 = DigestUtils.md5Hex(new FileInputStream(srcIso)); |
| 278 | + String destIsoMd5 = DigestUtils.md5Hex(new FileInputStream(destIso)); |
| 279 | + copyNeeded = !StringUtils.equals(srcIsoMd5, destIsoMd5); |
| 280 | + if (copyNeeded) { |
| 281 | + s_logger.debug(String.format("MD5 checksum: %s for source ISO: %s is different from MD5 checksum: %s from destination ISO: %s", srcIsoMd5, srcIso.getAbsolutePath(), destIsoMd5, destIso.getAbsolutePath())); |
| 282 | + } |
| 283 | + } catch (IOException e) { |
| 284 | + s_logger.debug(String.format("Unable to compare MD5 checksum for systemvm.iso at source: %s and destination: %s", srcIso.getAbsolutePath(), destIso.getAbsolutePath()), e); |
| 285 | + } |
| 286 | + return copyNeeded; |
| 287 | + } |
| 288 | + |
266 | 289 | @Override |
267 | 290 | public String getConfigComponentName() { |
268 | 291 | return VmwareManagerImpl.class.getSimpleName(); |
@@ -673,7 +696,7 @@ public void prepareSecondaryStorageStore(String storageUrl, Long storeId) { |
673 | 696 |
|
674 | 697 | File srcIso = getSystemVMPatchIsoFile(); |
675 | 698 | File destIso = new File(mountPoint + "/systemvm/" + getSystemVMIsoFileNameOnDatastore()); |
676 | | - if (!destIso.exists()) { |
| 699 | + if (isSystemVmIsoCopyNeeded(srcIso, destIso)) { |
677 | 700 | s_logger.info("Inject SSH key pairs before copying systemvm.iso into secondary storage"); |
678 | 701 | _configServer.updateKeyPairs(); |
679 | 702 |
|
|
0 commit comments