|
33 | 33 | import org.zstack.core.db.SQLBatch; |
34 | 34 | import org.zstack.core.db.SimpleQuery; |
35 | 35 | import org.zstack.core.db.SimpleQuery.Op; |
| 36 | +import org.zstack.core.jsonlabel.JsonLabel; |
36 | 37 | import org.zstack.core.thread.*; |
37 | 38 | import org.zstack.core.timeout.ApiTimeoutManager; |
38 | 39 | import org.zstack.core.timeout.TimeHelper; |
@@ -195,6 +196,7 @@ public class KVMHost extends HostBase implements Host { |
195 | 196 | private String checkSnapshotPath; |
196 | 197 | private String mergeSnapshotPath; |
197 | 198 | private String hostFactPath; |
| 199 | + private String updateTlsCertPath; |
198 | 200 | private String hostCheckFilePath; |
199 | 201 | private String attachIsoPath; |
200 | 202 | private String detachIsoPath; |
@@ -328,6 +330,10 @@ public KVMHost(KVMHostVO self, KVMHostContext context) { |
328 | 330 | ub.path(KVMConstant.KVM_HOST_FACT_PATH); |
329 | 331 | hostFactPath = ub.build().toString(); |
330 | 332 |
|
| 333 | + ub = UriComponentsBuilder.fromHttpUrl(baseUrl); |
| 334 | + ub.path(KVMConstant.KVM_UPDATE_TLS_CERT_PATH); |
| 335 | + updateTlsCertPath = ub.build().toString(); |
| 336 | + |
331 | 337 | ub = UriComponentsBuilder.fromHttpUrl(baseUrl); |
332 | 338 | ub.path(KVMConstant.KVM_HOST_CHECK_FILE_PATH); |
333 | 339 | hostCheckFilePath = ub.build().toString(); |
@@ -6025,6 +6031,70 @@ public void fail(ErrorCode errorCode) { |
6025 | 6031 |
|
6026 | 6032 | flow(createCollectHostFactsFlow(info)); |
6027 | 6033 |
|
| 6034 | + flow(new NoRollbackFlow() { |
| 6035 | + String __name__ = "update-tls-certs-if-needed"; |
| 6036 | + |
| 6037 | + @Override |
| 6038 | + public boolean skip(Map data) { |
| 6039 | + return CoreGlobalProperty.UNIT_TEST_ON |
| 6040 | + || !KVMGlobalConfig.LIBVIRT_TLS_ENABLED.value(Boolean.class); |
| 6041 | + } |
| 6042 | + |
| 6043 | + @Override |
| 6044 | + public void run(FlowTrigger trigger, Map data) { |
| 6045 | + String managementIp = getSelf().getManagementIp(); |
| 6046 | + String extraIps = HostSystemTags.EXTRA_IPS.getTokenByResourceUuid( |
| 6047 | + self.getUuid(), HostSystemTags.EXTRA_IPS_TOKEN); |
| 6048 | + |
| 6049 | + List<String> allIps = new ArrayList<>(); |
| 6050 | + allIps.add(managementIp); |
| 6051 | + if (extraIps != null && !extraIps.isEmpty()) { |
| 6052 | + for (String ip : extraIps.split(",")) { |
| 6053 | + String trimmed = ip.trim(); |
| 6054 | + if (!trimmed.isEmpty() && !allIps.contains(trimmed)) { |
| 6055 | + allIps.add(trimmed); |
| 6056 | + } |
| 6057 | + } |
| 6058 | + } |
| 6059 | + |
| 6060 | + String certIps = String.join(",", allIps); |
| 6061 | + |
| 6062 | + String caCert = new JsonLabel().get("libvirtTLSCA", String.class); |
| 6063 | + String caKey = new JsonLabel().get("libvirtTLSPrivateKey", String.class); |
| 6064 | + if (caCert == null || caKey == null) { |
| 6065 | + logger.warn("TLS CA cert/key not found in database, skipping cert update"); |
| 6066 | + trigger.next(); |
| 6067 | + return; |
| 6068 | + } |
| 6069 | + |
| 6070 | + UpdateTlsCertCmd cmd = new UpdateTlsCertCmd(); |
| 6071 | + cmd.setCaCert(caCert); |
| 6072 | + cmd.setCaKey(caKey); |
| 6073 | + cmd.setCertIps(certIps); |
| 6074 | + |
| 6075 | + new Http<>(updateTlsCertPath, cmd, UpdateTlsCertResponse.class) |
| 6076 | + .call(new ReturnValueCompletion<UpdateTlsCertResponse>(trigger) { |
| 6077 | + @Override |
| 6078 | + public void success(UpdateTlsCertResponse ret) { |
| 6079 | + if (!ret.isSuccess()) { |
| 6080 | + logger.warn(String.format("Failed to update TLS certs on host[uuid:%s]: %s", |
| 6081 | + self.getUuid(), ret.getError())); |
| 6082 | + } |
| 6083 | + // cert update failure should not block reconnect |
| 6084 | + trigger.next(); |
| 6085 | + } |
| 6086 | + |
| 6087 | + @Override |
| 6088 | + public void fail(ErrorCode errorCode) { |
| 6089 | + logger.warn(String.format("Failed to update TLS certs on host[uuid:%s]: %s", |
| 6090 | + self.getUuid(), errorCode)); |
| 6091 | + // cert update failure should not block reconnect |
| 6092 | + trigger.next(); |
| 6093 | + } |
| 6094 | + }); |
| 6095 | + } |
| 6096 | + }); |
| 6097 | + |
6028 | 6098 | if (info.isNewAdded()) { |
6029 | 6099 | flow(new NoRollbackFlow() { |
6030 | 6100 | String __name__ = "check-qemu-libvirt-version"; |
|
0 commit comments