diff --git a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java index a70babe9b27..48a27802dd3 100644 --- a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java +++ b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServer.java @@ -77,10 +77,17 @@ public class VeeamControlServer { StringUtils.isNotEmpty(keystorePassword) && StringUtils.isNotEmpty(keyManagerPassword) && Files.exists(Paths.get(keystorePath)); - final String bind = VeeamControlService.BindAddress.value(); + long managementServerHostId = veeamControlService.getCurrentManagementServerHostId(); + final String bindAddress = VeeamControlService.BindAddress.valueIn(managementServerHostId); + final String bindHost = StringUtils.trimToNull(bindAddress); final int port = VeeamControlService.Port.value(); + final String bindDisplay = bindHost == null ? + String.format("all interfaces, port: %d", port) : + String.format("host: %s, port: %d", bindHost, port); String ctxPath = VeeamControlService.ContextPath.value(); - LOGGER.info("Veeam Control server - bind: {}, port: {}, context: {} with {} handlers", bind, port, ctxPath, + LOGGER.info("Veeam Control server - {}, context: {} with {} handlers", + bindDisplay, + ctxPath, routeHandlers != null ? routeHandlers.size() : 0); @@ -102,20 +109,20 @@ public class VeeamControlServer { new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https) ); - httpsConnector.setHost(bind); + httpsConnector.setHost(bindHost); httpsConnector.setPort(port); server.addConnector(httpsConnector); - LOGGER.info("Veeam Control API server HTTPS enabled on {}:{}", bind, port); + LOGGER.info("Veeam Control API server HTTPS enabled on {}", bindDisplay); } else { final HttpConfiguration http = new HttpConfiguration(); final ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http)); - httpConnector.setHost(bind); + httpConnector.setHost(bindHost); httpConnector.setPort(port); server.addConnector(httpConnector); LOGGER.warn("Veeam Control API server HTTPS is NOT configured (missing keystore path/passwords). " + - "Starting HTTP on {}:{} instead.", bind, port); + "Starting HTTP on {} instead.", bindDisplay); } final ServletContextHandler ctx = @@ -140,7 +147,7 @@ public class VeeamControlServer { server.start(); - LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bind, port, ctxPath); + LOGGER.info("Started Veeam Control API server on {}:{} with context {}", bindDisplay, port, ctxPath); } @NotNull diff --git a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java index 159d7eead06..ae7c00ad94d 100644 --- a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java +++ b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlService.java @@ -31,7 +31,8 @@ public interface VeeamControlService extends PluggableService, Configurable { ConfigKey Enabled = new ConfigKey<>("Advanced", Boolean.class, "integration.veeam.control.enabled", "false", "Enable the Veeam Integration REST API server", false); ConfigKey BindAddress = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.bind.address", - "127.0.0.1", "Bind address for Veeam Integration REST API server", false); + "", "Bind address for Veeam Integration REST API server", false, + ConfigKey.Scope.ManagementServer); ConfigKey Port = new ConfigKey<>("Advanced", Integer.class, "integration.veeam.control.port", "8090", "Port for Veeam Integration REST API server", false); ConfigKey ContextPath = new ConfigKey<>("Advanced", String.class, "integration.veeam.control.context.path", @@ -56,6 +57,7 @@ public interface VeeamControlService extends PluggableService, Configurable { "", "Comma-separated list of CIDR blocks representing clients allowed to access the API. " + "If empty, all clients will be allowed. Example: '192.168.1.1/24,192.168.2.100/32", true); + long getCurrentManagementServerHostId(); List getAllowedClientCidrs(); diff --git a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java index a00d6bd5b83..b52a113648b 100644 --- a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java +++ b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/VeeamControlServiceImpl.java @@ -21,16 +21,24 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import javax.inject.Inject; + import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.utils.cache.SingleCache; +import org.apache.cloudstack.utils.identity.ManagementServerNode; import org.apache.cloudstack.veeam.utils.DataUtil; import org.apache.commons.lang3.StringUtils; +import com.cloud.cluster.ManagementServerHostVO; +import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.net.NetUtils; public class VeeamControlServiceImpl extends ManagerBase implements VeeamControlService { + @Inject + ManagementServerHostDao managementServerHostDao; + private List routeHandlers; private VeeamControlServer veeamControlServer; private SingleCache> allowedClientCidrsCache; @@ -63,6 +71,13 @@ public class VeeamControlServiceImpl extends ManagerBase implements VeeamControl this.routeHandlers = routeHandlers; } + @Override + public long getCurrentManagementServerHostId() { + ManagementServerHostVO hostVO = + managementServerHostDao.findByMsid(ManagementServerNode.getManagementServerId()); + return hostVO.getId(); + } + @Override public List getAllowedClientCidrs() { return allowedClientCidrsCache.get(); diff --git a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java index be71164d672..f8b82d7f25f 100644 --- a/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java +++ b/plugins/integrations/veeam-control-service/src/main/java/org/apache/cloudstack/veeam/api/ApiRouteHandler.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.veeam.api; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -40,7 +39,7 @@ import org.apache.cloudstack.veeam.api.dto.SummaryCount; import org.apache.cloudstack.veeam.api.dto.Version; import org.apache.cloudstack.veeam.utils.Negotiation; -import com.cloud.utils.UuidUtils; +import com.cloud.user.AccountService; import com.cloud.utils.component.ManagerBase; public class ApiRouteHandler extends ManagerBase implements RouteHandler { @@ -49,6 +48,9 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler { @Inject ServerAdapter serverAdapter; + @Inject + AccountService accountService; + @Override public boolean canHandle(String method, String path) { return getSanitizedPath(path).startsWith("/api"); @@ -97,8 +99,7 @@ public class ApiRouteHandler extends ManagerBase implements RouteHandler { /* ---------------- Product info ---------------- */ ProductInfo productInfo = new ProductInfo(); - productInfo.setInstanceId(UuidUtils.nameUUIDFromBytes( - VeeamControlService.BindAddress.value().getBytes(StandardCharsets.UTF_8)).toString()); + productInfo.setInstanceId(accountService.getSystemAccount().getUuid()); productInfo.name = VeeamControlService.PLUGIN_NAME; productInfo.version = Version.fromPackageAndCSVersion(true);