Skip to content

Commit 830044d

Browse files
committed
make bind address managementserver scoped
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent fac62ad commit 830044d

4 files changed

Lines changed: 37 additions & 12 deletions

File tree

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ public void startIfEnabled() throws Exception {
7777
StringUtils.isNotEmpty(keystorePassword) &&
7878
StringUtils.isNotEmpty(keyManagerPassword) &&
7979
Files.exists(Paths.get(keystorePath));
80-
final String bind = VeeamControlService.BindAddress.value();
80+
long managementServerHostId = veeamControlService.getCurrentManagementServerHostId();
81+
final String bindAddress = VeeamControlService.BindAddress.valueIn(managementServerHostId);
82+
final String bindHost = StringUtils.trimToNull(bindAddress);
8183
final int port = VeeamControlService.Port.value();
84+
final String bindDisplay = bindHost == null ?
85+
String.format("all interfaces, port: %d", port) :
86+
String.format("host: %s, port: %d", bindHost, port);
8287
String ctxPath = VeeamControlService.ContextPath.value();
83-
LOGGER.info("Veeam Control server - bind: {}, port: {}, context: {} with {} handlers", bind, port, ctxPath,
88+
LOGGER.info("Veeam Control server - {}, context: {} with {} handlers",
89+
bindDisplay,
90+
ctxPath,
8491
routeHandlers != null ? routeHandlers.size() : 0);
8592

8693

@@ -102,20 +109,20 @@ public void startIfEnabled() throws Exception {
102109
new SslConnectionFactory(sslContextFactory, "http/1.1"),
103110
new HttpConnectionFactory(https)
104111
);
105-
httpsConnector.setHost(bind);
112+
httpsConnector.setHost(bindHost);
106113
httpsConnector.setPort(port);
107114
server.addConnector(httpsConnector);
108115

109-
LOGGER.info("Veeam Control API server HTTPS enabled on {}:{}", bind, port);
116+
LOGGER.info("Veeam Control API server HTTPS enabled on {}", bindDisplay);
110117
} else {
111118
final HttpConfiguration http = new HttpConfiguration();
112119
final ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http));
113-
httpConnector.setHost(bind);
120+
httpConnector.setHost(bindHost);
114121
httpConnector.setPort(port);
115122
server.addConnector(httpConnector);
116123

117124
LOGGER.warn("Veeam Control API server HTTPS is NOT configured (missing keystore path/passwords). " +
118-
"Starting HTTP on {}:{} instead.", bind, port);
125+
"Starting HTTP on {} instead.", bindDisplay);
119126
}
120127

121128
final ServletContextHandler ctx =
@@ -140,7 +147,7 @@ public void startIfEnabled() throws Exception {
140147

141148
server.start();
142149

143-
LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bind, port, ctxPath);
150+
LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bindDisplay, port, ctxPath);
144151
}
145152

146153
@NotNull

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public interface VeeamControlService extends PluggableService, Configurable {
3131
ConfigKey<Boolean> Enabled = new ConfigKey<>("Advanced", Boolean.class, "integration.veeam.control.enabled",
3232
"false", "Enable the Veeam Integration REST API server", false);
3333
ConfigKey<String> BindAddress = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.bind.address",
34-
"127.0.0.1", "Bind address for Veeam Integration REST API server", false);
34+
"", "Bind address for Veeam Integration REST API server", false,
35+
ConfigKey.Scope.ManagementServer);
3536
ConfigKey<Integer> Port = new ConfigKey<>("Advanced", Integer.class, "integration.veeam.control.port",
3637
"8090", "Port for Veeam Integration REST API server", false);
3738
ConfigKey<String> ContextPath = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.context.path",
@@ -56,6 +57,7 @@ public interface VeeamControlService extends PluggableService, Configurable {
5657
"", "Comma-separated list of CIDR blocks representing clients allowed to access the API. " +
5758
"If empty, all clients will be allowed. Example: '192.168.1.1/24,192.168.2.100/32", true);
5859

60+
long getCurrentManagementServerHostId();
5961

6062
List<String> getAllowedClientCidrs();
6163

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@
2121
import java.util.List;
2222
import java.util.stream.Collectors;
2323

24+
import javax.inject.Inject;
25+
2426
import org.apache.cloudstack.framework.config.ConfigKey;
2527
import org.apache.cloudstack.utils.cache.SingleCache;
28+
import org.apache.cloudstack.utils.identity.ManagementServerNode;
2629
import org.apache.cloudstack.veeam.utils.DataUtil;
2730
import org.apache.commons.lang3.StringUtils;
2831

32+
import com.cloud.cluster.ManagementServerHostVO;
33+
import com.cloud.cluster.dao.ManagementServerHostDao;
2934
import com.cloud.utils.component.ManagerBase;
3035
import com.cloud.utils.net.NetUtils;
3136

3237
public class VeeamControlServiceImpl extends ManagerBase implements VeeamControlService {
3338

39+
@Inject
40+
ManagementServerHostDao managementServerHostDao;
41+
3442
private List<RouteHandler> routeHandlers;
3543
private VeeamControlServer veeamControlServer;
3644
private SingleCache<List<String>> allowedClientCidrsCache;
@@ -63,6 +71,13 @@ public void setRouteHandlers(final List<RouteHandler> routeHandlers) {
6371
this.routeHandlers = routeHandlers;
6472
}
6573

74+
@Override
75+
public long getCurrentManagementServerHostId() {
76+
ManagementServerHostVO hostVO =
77+
managementServerHostDao.findByMsid(ManagementServerNode.getManagementServerId());
78+
return hostVO.getId();
79+
}
80+
6681
@Override
6782
public List<String> getAllowedClientCidrs() {
6883
return allowedClientCidrsCache.get();

plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.cloudstack.veeam.api;
1919

2020
import java.io.IOException;
21-
import java.nio.charset.StandardCharsets;
2221
import java.util.ArrayList;
2322
import java.util.List;
2423

@@ -40,7 +39,7 @@
4039
import org.apache.cloudstack.veeam.api.dto.Version;
4140
import org.apache.cloudstack.veeam.utils.Negotiation;
4241

43-
import com.cloud.utils.UuidUtils;
42+
import com.cloud.user.AccountService;
4443
import com.cloud.utils.component.ManagerBase;
4544

4645
public class ApiRouteHandler extends ManagerBase implements RouteHandler {
@@ -49,6 +48,9 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler {
4948
@Inject
5049
ServerAdapter serverAdapter;
5150

51+
@Inject
52+
AccountService accountService;
53+
5254
@Override
5355
public boolean canHandle(String method, String path) {
5456
return getSanitizedPath(path).startsWith("/api");
@@ -97,8 +99,7 @@ protected Api createApiObject(String basePath) {
9799

98100
/* ---------------- Product info ---------------- */
99101
ProductInfo productInfo = new ProductInfo();
100-
productInfo.setInstanceId(UuidUtils.nameUUIDFromBytes(
101-
VeeamControlService.BindAddress.value().getBytes(StandardCharsets.UTF_8)).toString());
102+
productInfo.setInstanceId(accountService.getSystemAccount().getUuid());
102103
productInfo.name = VeeamControlService.PLUGIN_NAME;
103104

104105
productInfo.version = Version.fromPackageAndCSVersion(true);

0 commit comments

Comments
 (0)