mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch '4.20'
This commit is contained in:
commit
0dbd761fbb
1
.github/workflows/ui.yml
vendored
1
.github/workflows/ui.yml
vendored
@ -56,6 +56,7 @@ jobs:
|
||||
npm run test:unit
|
||||
|
||||
- uses: codecov/codecov-action@v4
|
||||
if: github.repository == 'apache/cloudstack'
|
||||
with:
|
||||
working-directory: ui
|
||||
files: ./coverage/lcov.info
|
||||
|
||||
@ -171,6 +171,13 @@ public interface VolumeApiService {
|
||||
* </table>
|
||||
*/
|
||||
boolean doesStoragePoolSupportDiskOffering(StoragePool destPool, DiskOffering diskOffering);
|
||||
|
||||
/**
|
||||
* Checks if the storage pool supports the required disk offering tags
|
||||
* destPool the storage pool to check the disk offering tags
|
||||
* diskOfferingTags the tags that should be supported
|
||||
* return whether the tags are supported in the storage pool
|
||||
*/
|
||||
boolean doesStoragePoolSupportDiskOfferingTags(StoragePool destPool, String diskOfferingTags);
|
||||
|
||||
Volume destroyVolume(long volumeId, Account caller, boolean expunge, boolean forceExpunge);
|
||||
|
||||
@ -16,8 +16,6 @@
|
||||
// under the License.
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
|
||||
|
||||
public class ConvertInstanceAnswer extends Answer {
|
||||
|
||||
private String temporaryConvertUuid;
|
||||
@ -25,16 +23,6 @@ public class ConvertInstanceAnswer extends Answer {
|
||||
public ConvertInstanceAnswer() {
|
||||
super();
|
||||
}
|
||||
private UnmanagedInstanceTO convertedInstance;
|
||||
|
||||
public ConvertInstanceAnswer(Command command, boolean success, String details) {
|
||||
super(command, success, details);
|
||||
}
|
||||
|
||||
public ConvertInstanceAnswer(Command command, UnmanagedInstanceTO convertedInstance) {
|
||||
super(command, true, "");
|
||||
this.convertedInstance = convertedInstance;
|
||||
}
|
||||
|
||||
public ConvertInstanceAnswer(Command command, String temporaryConvertUuid) {
|
||||
super(command, true, "");
|
||||
@ -44,8 +32,4 @@ public class ConvertInstanceAnswer extends Answer {
|
||||
public String getTemporaryConvertUuid() {
|
||||
return temporaryConvertUuid;
|
||||
}
|
||||
|
||||
public UnmanagedInstanceTO getConvertedInstance() {
|
||||
return convertedInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,13 +20,10 @@ import com.cloud.agent.api.to.DataStoreTO;
|
||||
import com.cloud.agent.api.to.RemoteInstanceTO;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConvertInstanceCommand extends Command {
|
||||
|
||||
private RemoteInstanceTO sourceInstance;
|
||||
private Hypervisor.HypervisorType destinationHypervisorType;
|
||||
private List<String> destinationStoragePools;
|
||||
private DataStoreTO conversionTemporaryLocation;
|
||||
private String templateDirOnConversionLocation;
|
||||
private boolean checkConversionSupport;
|
||||
@ -36,12 +33,10 @@ public class ConvertInstanceCommand extends Command {
|
||||
public ConvertInstanceCommand() {
|
||||
}
|
||||
|
||||
public ConvertInstanceCommand(RemoteInstanceTO sourceInstance, Hypervisor.HypervisorType destinationHypervisorType,
|
||||
List<String> destinationStoragePools, DataStoreTO conversionTemporaryLocation,
|
||||
public ConvertInstanceCommand(RemoteInstanceTO sourceInstance, Hypervisor.HypervisorType destinationHypervisorType, DataStoreTO conversionTemporaryLocation,
|
||||
String templateDirOnConversionLocation, boolean checkConversionSupport, boolean exportOvfToConversionLocation) {
|
||||
this.sourceInstance = sourceInstance;
|
||||
this.destinationHypervisorType = destinationHypervisorType;
|
||||
this.destinationStoragePools = destinationStoragePools;
|
||||
this.conversionTemporaryLocation = conversionTemporaryLocation;
|
||||
this.templateDirOnConversionLocation = templateDirOnConversionLocation;
|
||||
this.checkConversionSupport = checkConversionSupport;
|
||||
@ -56,10 +51,6 @@ public class ConvertInstanceCommand extends Command {
|
||||
return destinationHypervisorType;
|
||||
}
|
||||
|
||||
public List<String> getDestinationStoragePools() {
|
||||
return destinationStoragePools;
|
||||
}
|
||||
|
||||
public DataStoreTO getConversionTemporaryLocation() {
|
||||
return conversionTemporaryLocation;
|
||||
}
|
||||
|
||||
@ -39,9 +39,7 @@ import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
import org.apache.cloudstack.utils.security.SSLUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -55,6 +53,7 @@ import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
@ -120,10 +119,10 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl
|
||||
String password = "changeit";
|
||||
defaultKeystore.load(is, password.toCharArray());
|
||||
}
|
||||
TrustManager[] tm = HttpsMultiTrustManager.getTrustManagersFromKeyStores(customKeystore, defaultKeystore);
|
||||
SSLContext sslContext = SSLUtils.getSSLContext();
|
||||
sslContext.init(null, tm, null);
|
||||
return sslContext;
|
||||
return SSLContexts.custom()
|
||||
.loadTrustMaterial(customKeystore, null)
|
||||
.loadTrustMaterial(defaultKeystore, null)
|
||||
.build();
|
||||
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) {
|
||||
logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e);
|
||||
try {
|
||||
|
||||
@ -1,102 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.direct.download;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class HttpsMultiTrustManager implements X509TrustManager {
|
||||
|
||||
private final List<X509TrustManager> trustManagers;
|
||||
|
||||
public HttpsMultiTrustManager(KeyStore... keystores) {
|
||||
List<X509TrustManager> trustManagers = new ArrayList<>();
|
||||
trustManagers.add(getTrustManager(null));
|
||||
for (KeyStore keystore : keystores) {
|
||||
trustManagers.add(getTrustManager(keystore));
|
||||
}
|
||||
this.trustManagers = ImmutableList.copyOf(trustManagers);
|
||||
}
|
||||
|
||||
public static TrustManager[] getTrustManagersFromKeyStores(KeyStore... keyStore) {
|
||||
return new TrustManager[] { new HttpsMultiTrustManager(keyStore) };
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
for (X509TrustManager trustManager : trustManagers) {
|
||||
try {
|
||||
trustManager.checkClientTrusted(chain, authType);
|
||||
return;
|
||||
} catch (CertificateException ignored) {}
|
||||
}
|
||||
throw new CertificateException("None of the TrustManagers trust this certificate chain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
for (X509TrustManager trustManager : trustManagers) {
|
||||
try {
|
||||
trustManager.checkServerTrusted(chain, authType);
|
||||
return;
|
||||
} catch (CertificateException ignored) {}
|
||||
}
|
||||
throw new CertificateException("None of the TrustManagers trust this certificate chain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
ImmutableList.Builder<X509Certificate> certificates = ImmutableList.builder();
|
||||
for (X509TrustManager trustManager : trustManagers) {
|
||||
for (X509Certificate cert : trustManager.getAcceptedIssuers()) {
|
||||
certificates.add(cert);
|
||||
}
|
||||
}
|
||||
return Iterables.toArray(certificates.build(), X509Certificate.class);
|
||||
}
|
||||
|
||||
public X509TrustManager getTrustManager(KeyStore keystore) {
|
||||
return getTrustManager(TrustManagerFactory.getDefaultAlgorithm(), keystore);
|
||||
}
|
||||
|
||||
public X509TrustManager getTrustManager(String algorithm, KeyStore keystore) {
|
||||
TrustManagerFactory factory;
|
||||
try {
|
||||
factory = TrustManagerFactory.getInstance(algorithm);
|
||||
factory.init(keystore);
|
||||
return Iterables.getFirst(Iterables.filter(
|
||||
Arrays.asList(factory.getTrustManagers()), X509TrustManager.class), null);
|
||||
} catch (NoSuchAlgorithmException | KeyStoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -100,8 +100,6 @@ public class Upgrade42000to42010 extends DbUpgradeAbstractImpl implements DbUpgr
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "network_offering_details", "name");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "network_offering_details", "resource_id", "resource_type");
|
||||
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "cpu");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "speed");
|
||||
DbUpgradeUtils.addIndexIfNeeded(conn, "service_offering", "ram_size");
|
||||
|
||||
@ -18,22 +18,12 @@
|
||||
//
|
||||
package com.cloud.hypervisor.kvm.resource.wrapper;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
@ -44,17 +34,12 @@ import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.agent.api.to.RemoteInstanceTO;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
|
||||
import com.cloud.resource.CommandWrapper;
|
||||
import com.cloud.resource.ResourceWrapper;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.utils.FileUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@ -77,7 +62,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
String msg = String.format("Cannot convert the instance %s from VMware as the virt-v2v binary is not found. " +
|
||||
"Please install virt-v2v%s on the host before attempting the instance conversion.", sourceInstanceName, serverResource.isUbuntuHost()? ", nbdkit" : "");
|
||||
logger.info(msg);
|
||||
return new ConvertInstanceAnswer(cmd, false, msg);
|
||||
return new Answer(cmd, false, msg);
|
||||
}
|
||||
|
||||
if (!areSourceAndDestinationHypervisorsSupported(sourceHypervisorType, destinationHypervisorType)) {
|
||||
@ -85,7 +70,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
String.format("The destination hypervisor type is %s, KVM was expected, cannot handle it", destinationHypervisorType) :
|
||||
String.format("The source hypervisor type %s is not supported for KVM conversion", sourceHypervisorType);
|
||||
logger.error(err);
|
||||
return new ConvertInstanceAnswer(cmd, false, err);
|
||||
return new Answer(cmd, false, err);
|
||||
}
|
||||
|
||||
final KVMStoragePoolManager storagePoolMgr = serverResource.getStoragePoolMgr();
|
||||
@ -103,7 +88,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
if (StringUtils.isBlank(exportInstanceOVAUrl)) {
|
||||
String err = String.format("Couldn't export OVA for the VM %s, due to empty url", sourceInstanceName);
|
||||
logger.error(err);
|
||||
return new ConvertInstanceAnswer(cmd, false, err);
|
||||
return new Answer(cmd, false, err);
|
||||
}
|
||||
|
||||
int noOfThreads = cmd.getThreadsCountToExportOvf();
|
||||
@ -117,7 +102,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
if (!ovfExported) {
|
||||
String err = String.format("Export OVA for the VM %s failed", sourceInstanceName);
|
||||
logger.error(err);
|
||||
return new ConvertInstanceAnswer(cmd, false, err);
|
||||
return new Answer(cmd, false, err);
|
||||
}
|
||||
sourceOVFDirPath = String.format("%s%s/", sourceOVFDirPath, sourceInstanceName);
|
||||
} else {
|
||||
@ -140,7 +125,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
"has a different virt-v2v version.",
|
||||
ovfTemplateDirOnConversionLocation);
|
||||
logger.error(err);
|
||||
return new ConvertInstanceAnswer(cmd, false, err);
|
||||
return new Answer(cmd, false, err);
|
||||
}
|
||||
return new ConvertInstanceAnswer(cmd, temporaryConvertUuid);
|
||||
} catch (Exception e) {
|
||||
@ -148,7 +133,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
sourceInstanceName, sourceHypervisorType, e.getMessage());
|
||||
logger.error(error, e);
|
||||
cleanupSecondaryStorage = true;
|
||||
return new ConvertInstanceAnswer(cmd, false, error);
|
||||
return new Answer(cmd, false, error);
|
||||
} finally {
|
||||
if (ovfExported && StringUtils.isNotBlank(ovfTemplateDirOnConversionLocation)) {
|
||||
String sourceOVFDir = String.format("%s/%s", temporaryConvertPath, ovfTemplateDirOnConversionLocation);
|
||||
@ -205,55 +190,6 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
encodedUsername, encodedPassword, vcenter, datacenter, vm);
|
||||
}
|
||||
|
||||
protected List<KVMPhysicalDisk> getTemporaryDisksFromParsedXml(KVMStoragePool pool, LibvirtDomainXMLParser xmlParser, String convertedBasePath) {
|
||||
List<LibvirtVMDef.DiskDef> disksDefs = xmlParser.getDisks();
|
||||
disksDefs = disksDefs.stream().filter(x -> x.getDiskType() == LibvirtVMDef.DiskDef.DiskType.FILE &&
|
||||
x.getDeviceType() == LibvirtVMDef.DiskDef.DeviceType.DISK).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(disksDefs)) {
|
||||
String err = String.format("Cannot find any disk defined on the converted XML domain %s.xml", convertedBasePath);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
sanitizeDisksPath(disksDefs);
|
||||
return getPhysicalDisksFromDefPaths(disksDefs, pool);
|
||||
}
|
||||
|
||||
private List<KVMPhysicalDisk> getPhysicalDisksFromDefPaths(List<LibvirtVMDef.DiskDef> disksDefs, KVMStoragePool pool) {
|
||||
List<KVMPhysicalDisk> disks = new ArrayList<>();
|
||||
for (LibvirtVMDef.DiskDef diskDef : disksDefs) {
|
||||
KVMPhysicalDisk physicalDisk = pool.getPhysicalDisk(diskDef.getDiskPath());
|
||||
disks.add(physicalDisk);
|
||||
}
|
||||
return disks;
|
||||
}
|
||||
|
||||
protected List<KVMPhysicalDisk> getTemporaryDisksWithPrefixFromTemporaryPool(KVMStoragePool pool, String path, String prefix) {
|
||||
String msg = String.format("Could not parse correctly the converted XML domain, checking for disks on %s with prefix %s", path, prefix);
|
||||
logger.info(msg);
|
||||
pool.refresh();
|
||||
List<KVMPhysicalDisk> disksWithPrefix = pool.listPhysicalDisks()
|
||||
.stream()
|
||||
.filter(x -> x.getName().startsWith(prefix) && !x.getName().endsWith(".xml"))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(disksWithPrefix)) {
|
||||
msg = String.format("Could not find any converted disk with prefix %s on temporary location %s", prefix, path);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return disksWithPrefix;
|
||||
}
|
||||
|
||||
private void cleanupDisksAndDomainFromTemporaryLocation(List<KVMPhysicalDisk> disks,
|
||||
KVMStoragePool temporaryStoragePool,
|
||||
String temporaryConvertUuid) {
|
||||
for (KVMPhysicalDisk disk : disks) {
|
||||
logger.info(String.format("Cleaning up temporary disk %s after conversion from temporary location", disk.getName()));
|
||||
temporaryStoragePool.deletePhysicalDisk(disk.getName(), Storage.ImageFormat.QCOW2);
|
||||
}
|
||||
logger.info(String.format("Cleaning up temporary domain %s after conversion from temporary location", temporaryConvertUuid));
|
||||
FileUtil.deleteFiles(temporaryStoragePool.getLocalPath(), temporaryConvertUuid, ".xml");
|
||||
}
|
||||
|
||||
protected void sanitizeDisksPath(List<LibvirtVMDef.DiskDef> disks) {
|
||||
for (LibvirtVMDef.DiskDef disk : disks) {
|
||||
String[] diskPathParts = disk.getDiskPath().split("/");
|
||||
@ -262,114 +198,6 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
}
|
||||
}
|
||||
|
||||
protected List<KVMPhysicalDisk> moveTemporaryDisksToDestination(List<KVMPhysicalDisk> temporaryDisks,
|
||||
List<String> destinationStoragePools,
|
||||
KVMStoragePoolManager storagePoolMgr) {
|
||||
List<KVMPhysicalDisk> targetDisks = new ArrayList<>();
|
||||
if (temporaryDisks.size() != destinationStoragePools.size()) {
|
||||
String warn = String.format("Discrepancy between the converted instance disks (%s) " +
|
||||
"and the expected number of disks (%s)", temporaryDisks.size(), destinationStoragePools.size());
|
||||
logger.warn(warn);
|
||||
}
|
||||
for (int i = 0; i < temporaryDisks.size(); i++) {
|
||||
String poolPath = destinationStoragePools.get(i);
|
||||
KVMStoragePool destinationPool = storagePoolMgr.getStoragePool(Storage.StoragePoolType.NetworkFilesystem, poolPath);
|
||||
if (destinationPool == null) {
|
||||
String err = String.format("Could not find a storage pool by URI: %s", poolPath);
|
||||
logger.error(err);
|
||||
continue;
|
||||
}
|
||||
if (destinationPool.getType() != Storage.StoragePoolType.NetworkFilesystem) {
|
||||
String err = String.format("Storage pool by URI: %s is not an NFS storage", poolPath);
|
||||
logger.error(err);
|
||||
continue;
|
||||
}
|
||||
KVMPhysicalDisk sourceDisk = temporaryDisks.get(i);
|
||||
if (logger.isDebugEnabled()) {
|
||||
String msg = String.format("Trying to copy converted instance disk number %s from the temporary location %s" +
|
||||
" to destination storage pool %s", i, sourceDisk.getPool().getLocalPath(), destinationPool.getUuid());
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
String destinationName = UUID.randomUUID().toString();
|
||||
|
||||
KVMPhysicalDisk destinationDisk = storagePoolMgr.copyPhysicalDisk(sourceDisk, destinationName, destinationPool, 7200 * 1000);
|
||||
targetDisks.add(destinationDisk);
|
||||
}
|
||||
return targetDisks;
|
||||
}
|
||||
|
||||
private UnmanagedInstanceTO getConvertedUnmanagedInstance(String baseName,
|
||||
List<KVMPhysicalDisk> vmDisks,
|
||||
LibvirtDomainXMLParser xmlParser) {
|
||||
UnmanagedInstanceTO instanceTO = new UnmanagedInstanceTO();
|
||||
instanceTO.setName(baseName);
|
||||
instanceTO.setDisks(getUnmanagedInstanceDisks(vmDisks, xmlParser));
|
||||
instanceTO.setNics(getUnmanagedInstanceNics(xmlParser));
|
||||
return instanceTO;
|
||||
}
|
||||
|
||||
private List<UnmanagedInstanceTO.Nic> getUnmanagedInstanceNics(LibvirtDomainXMLParser xmlParser) {
|
||||
List<UnmanagedInstanceTO.Nic> nics = new ArrayList<>();
|
||||
if (xmlParser != null) {
|
||||
List<LibvirtVMDef.InterfaceDef> interfaces = xmlParser.getInterfaces();
|
||||
for (LibvirtVMDef.InterfaceDef interfaceDef : interfaces) {
|
||||
UnmanagedInstanceTO.Nic nic = new UnmanagedInstanceTO.Nic();
|
||||
nic.setMacAddress(interfaceDef.getMacAddress());
|
||||
nic.setNicId(interfaceDef.getBrName());
|
||||
nic.setAdapterType(interfaceDef.getModel().toString());
|
||||
nics.add(nic);
|
||||
}
|
||||
}
|
||||
return nics;
|
||||
}
|
||||
|
||||
protected List<UnmanagedInstanceTO.Disk> getUnmanagedInstanceDisks(List<KVMPhysicalDisk> vmDisks, LibvirtDomainXMLParser xmlParser) {
|
||||
List<UnmanagedInstanceTO.Disk> instanceDisks = new ArrayList<>();
|
||||
List<LibvirtVMDef.DiskDef> diskDefs = xmlParser != null ? xmlParser.getDisks() : null;
|
||||
for (int i = 0; i< vmDisks.size(); i++) {
|
||||
KVMPhysicalDisk physicalDisk = vmDisks.get(i);
|
||||
KVMStoragePool storagePool = physicalDisk.getPool();
|
||||
UnmanagedInstanceTO.Disk disk = new UnmanagedInstanceTO.Disk();
|
||||
disk.setPosition(i);
|
||||
Pair<String, String> storagePoolHostAndPath = getNfsStoragePoolHostAndPath(storagePool);
|
||||
disk.setDatastoreHost(storagePoolHostAndPath.first());
|
||||
disk.setDatastorePath(storagePoolHostAndPath.second());
|
||||
disk.setDatastoreName(storagePool.getUuid());
|
||||
disk.setDatastoreType(storagePool.getType().name());
|
||||
disk.setCapacity(physicalDisk.getVirtualSize());
|
||||
disk.setFileBaseName(physicalDisk.getName());
|
||||
if (CollectionUtils.isNotEmpty(diskDefs)) {
|
||||
LibvirtVMDef.DiskDef diskDef = diskDefs.get(i);
|
||||
disk.setController(diskDef.getBusType() != null ? diskDef.getBusType().toString() : LibvirtVMDef.DiskDef.DiskBus.VIRTIO.toString());
|
||||
} else {
|
||||
// If the job is finished but we cannot parse the XML, the guest VM can use the virtio driver
|
||||
disk.setController(LibvirtVMDef.DiskDef.DiskBus.VIRTIO.toString());
|
||||
}
|
||||
instanceDisks.add(disk);
|
||||
}
|
||||
return instanceDisks;
|
||||
}
|
||||
|
||||
protected Pair<String, String> getNfsStoragePoolHostAndPath(KVMStoragePool storagePool) {
|
||||
String sourceHostIp = null;
|
||||
String sourcePath = null;
|
||||
List<String[]> commands = new ArrayList<>();
|
||||
commands.add(new String[]{Script.getExecutableAbsolutePath("mount")});
|
||||
commands.add(new String[]{Script.getExecutableAbsolutePath("grep"), storagePool.getLocalPath()});
|
||||
String storagePoolMountPoint = Script.executePipedCommands(commands, 0).second();
|
||||
logger.debug(String.format("NFS Storage pool: %s - local path: %s, mount point: %s", storagePool.getUuid(), storagePool.getLocalPath(), storagePoolMountPoint));
|
||||
if (StringUtils.isNotEmpty(storagePoolMountPoint)) {
|
||||
String[] res = storagePoolMountPoint.strip().split(" ");
|
||||
res = res[0].split(":");
|
||||
if (res.length > 1) {
|
||||
sourceHostIp = res[0].strip();
|
||||
sourcePath = res[1].strip();
|
||||
}
|
||||
}
|
||||
return new Pair<>(sourceHostIp, sourcePath);
|
||||
}
|
||||
|
||||
private boolean exportOVAFromVMOnVcenter(String vmExportUrl,
|
||||
String targetOvfDir,
|
||||
int noOfThreads,
|
||||
@ -412,27 +240,6 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
||||
return exitValue == 0;
|
||||
}
|
||||
|
||||
protected LibvirtDomainXMLParser parseMigratedVMXmlDomain(String installPath) throws IOException {
|
||||
String xmlPath = String.format("%s.xml", installPath);
|
||||
if (!new File(xmlPath).exists()) {
|
||||
String err = String.format("Conversion failed. Unable to find the converted XML domain, expected %s", xmlPath);
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
InputStream is = new BufferedInputStream(new FileInputStream(xmlPath));
|
||||
String xml = IOUtils.toString(is, Charset.defaultCharset());
|
||||
final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
|
||||
try {
|
||||
parser.parseDomainXML(xml);
|
||||
return parser;
|
||||
} catch (RuntimeException e) {
|
||||
String err = String.format("Error parsing the converted instance XML domain at %s: %s", xmlPath, e.getMessage());
|
||||
logger.error(err, e);
|
||||
logger.debug(xml);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String encodeUsername(String username) {
|
||||
return URLEncoder.encode(username, Charset.defaultCharset());
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command
|
||||
private void importCertificate(String tempCerFilePath, String keyStoreFile, String certificateName, String privatePassword) {
|
||||
logger.debug("Importing certificate from temporary file to keystore");
|
||||
String keyToolPath = Script.getExecutableAbsolutePath("keytool");
|
||||
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "file", tempCerFilePath,
|
||||
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "-file", tempCerFilePath,
|
||||
"-keystore", keyStoreFile, "-alias", sanitizeBashCommandArgument(certificateName), "-storepass",
|
||||
privatePassword, "-noprompt");
|
||||
if (result != 0) {
|
||||
|
||||
@ -22,7 +22,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -40,13 +39,10 @@ import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.agent.api.to.RemoteInstanceTO;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
|
||||
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
|
||||
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ -118,72 +114,6 @@ public class LibvirtConvertInstanceCommandWrapperTest {
|
||||
Assert.assertEquals(relativePath, diskDef.getDiskPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveTemporaryDisksToDestination() {
|
||||
KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class);
|
||||
List<KVMPhysicalDisk> disks = List.of(sourceDisk);
|
||||
String destinationPoolUuid = UUID.randomUUID().toString();
|
||||
List<String> destinationPools = List.of(destinationPoolUuid);
|
||||
|
||||
KVMPhysicalDisk destDisk = Mockito.mock(KVMPhysicalDisk.class);
|
||||
Mockito.when(destDisk.getPath()).thenReturn("xyz");
|
||||
Mockito.when(storagePoolManager.getStoragePool(Storage.StoragePoolType.NetworkFilesystem, destinationPoolUuid))
|
||||
.thenReturn(destinationPool);
|
||||
Mockito.when(destinationPool.getType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
|
||||
Mockito.when(storagePoolManager.copyPhysicalDisk(Mockito.eq(sourceDisk), Mockito.anyString(), Mockito.eq(destinationPool), Mockito.anyInt()))
|
||||
.thenReturn(destDisk);
|
||||
|
||||
List<KVMPhysicalDisk> movedDisks = convertInstanceCommandWrapper.moveTemporaryDisksToDestination(disks, destinationPools, storagePoolManager);
|
||||
Assert.assertEquals(1, movedDisks.size());
|
||||
Assert.assertEquals("xyz", movedDisks.get(0).getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnmanagedInstanceDisks() {
|
||||
try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
|
||||
String relativePath = UUID.randomUUID().toString();
|
||||
LibvirtVMDef.DiskDef diskDef = new LibvirtVMDef.DiskDef();
|
||||
LibvirtVMDef.DiskDef.DiskBus bus = LibvirtVMDef.DiskDef.DiskBus.IDE;
|
||||
LibvirtVMDef.DiskDef.DiskFmtType type = LibvirtVMDef.DiskDef.DiskFmtType.QCOW2;
|
||||
diskDef.defFileBasedDisk(relativePath, relativePath, bus, type);
|
||||
|
||||
KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class);
|
||||
Mockito.when(sourceDisk.getName()).thenReturn(UUID.randomUUID().toString());
|
||||
Mockito.when(sourceDisk.getPool()).thenReturn(destinationPool);
|
||||
Mockito.when(destinationPool.getType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
|
||||
List<KVMPhysicalDisk> disks = List.of(sourceDisk);
|
||||
|
||||
LibvirtDomainXMLParser parser = Mockito.mock(LibvirtDomainXMLParser.class);
|
||||
Mockito.when(parser.getDisks()).thenReturn(List.of(diskDef));
|
||||
Mockito.doReturn(new Pair<String, String>(null, null)).when(convertInstanceCommandWrapper).getNfsStoragePoolHostAndPath(destinationPool);
|
||||
|
||||
Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong()))
|
||||
.thenReturn(new Pair<>(0, null));
|
||||
|
||||
List<UnmanagedInstanceTO.Disk> unmanagedInstanceDisks = convertInstanceCommandWrapper.getUnmanagedInstanceDisks(disks, parser);
|
||||
Assert.assertEquals(1, unmanagedInstanceDisks.size());
|
||||
UnmanagedInstanceTO.Disk disk = unmanagedInstanceDisks.get(0);
|
||||
Assert.assertEquals(LibvirtVMDef.DiskDef.DiskBus.IDE.toString(), disk.getController());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNfsStoragePoolHostAndPath() {
|
||||
try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
|
||||
String localMountPoint = "/mnt/xyz";
|
||||
String host = "192.168.1.2";
|
||||
String path = "/secondary";
|
||||
String mountOutput = String.format("%s:%s on %s type nfs (...)", host, path, localMountPoint);
|
||||
Mockito.when(temporaryPool.getLocalPath()).thenReturn(localMountPoint);
|
||||
Mockito.when(Script.executePipedCommands(Mockito.anyList(), Mockito.anyLong()))
|
||||
.thenReturn(new Pair<>(0, mountOutput));
|
||||
|
||||
Pair<String, String> pair = convertInstanceCommandWrapper.getNfsStoragePoolHostAndPath(temporaryPool);
|
||||
Assert.assertEquals(host, pair.first());
|
||||
Assert.assertEquals(path, pair.second());
|
||||
}
|
||||
}
|
||||
|
||||
private RemoteInstanceTO getRemoteInstanceTO(Hypervisor.HypervisorType hypervisorType) {
|
||||
RemoteInstanceTO remoteInstanceTO = Mockito.mock(RemoteInstanceTO.class);
|
||||
Mockito.when(remoteInstanceTO.getHypervisorType()).thenReturn(hypervisorType);
|
||||
|
||||
@ -165,6 +165,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
||||
|
||||
protected String kubernetesClusterNodeNamePrefix;
|
||||
|
||||
private static final int MAX_CLUSTER_PREFIX_LENGTH = 43;
|
||||
|
||||
protected KubernetesClusterResourceModifierActionWorker(final KubernetesCluster kubernetesCluster, final KubernetesClusterManagerImpl clusterManager) {
|
||||
super(kubernetesCluster, clusterManager);
|
||||
}
|
||||
@ -787,19 +789,35 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a valid name prefix for Kubernetes cluster nodes.
|
||||
*
|
||||
* <p>The prefix must comply with Kubernetes naming constraints:
|
||||
* <ul>
|
||||
* <li>Maximum 63 characters total</li>
|
||||
* <li>Only lowercase alphanumeric characters and hyphens</li>
|
||||
* <li>Must start with a letter</li>
|
||||
* <li>Must end with an alphanumeric character</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>The generated prefix is limited to 43 characters to accommodate the full node naming pattern:
|
||||
* <pre>{'prefix'}-{'control' | 'node'}-{'11-digit-hash'}</pre>
|
||||
*
|
||||
* @return A valid node name prefix, truncated if necessary
|
||||
* @see <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/names/">Kubernetes "Object Names and IDs" documentation</a>
|
||||
*/
|
||||
protected String getKubernetesClusterNodeNamePrefix() {
|
||||
String prefix = kubernetesCluster.getName();
|
||||
if (!NetUtils.verifyDomainNameLabel(prefix, true)) {
|
||||
prefix = prefix.replaceAll("[^a-zA-Z0-9-]", "");
|
||||
if (prefix.length() == 0) {
|
||||
String prefix = kubernetesCluster.getName().toLowerCase();
|
||||
|
||||
if (NetUtils.verifyDomainNameLabel(prefix, true)) {
|
||||
return StringUtils.truncate(prefix, MAX_CLUSTER_PREFIX_LENGTH);
|
||||
}
|
||||
|
||||
prefix = prefix.replaceAll("[^a-z0-9-]", "");
|
||||
if (prefix.isEmpty()) {
|
||||
prefix = kubernetesCluster.getUuid();
|
||||
}
|
||||
prefix = "k8s-" + prefix;
|
||||
}
|
||||
if (prefix.length() > 40) {
|
||||
prefix = prefix.substring(0, 40);
|
||||
}
|
||||
return prefix;
|
||||
return StringUtils.truncate("k8s-" + prefix, MAX_CLUSTER_PREFIX_LENGTH);
|
||||
}
|
||||
|
||||
protected String getEtcdNodeNameForCluster() {
|
||||
|
||||
@ -0,0 +1,138 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.kubernetes.cluster.actionworkers;
|
||||
|
||||
import com.cloud.kubernetes.cluster.KubernetesCluster;
|
||||
import com.cloud.kubernetes.cluster.KubernetesClusterManagerImpl;
|
||||
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
|
||||
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDetailsDao;
|
||||
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
|
||||
import com.cloud.kubernetes.version.dao.KubernetesSupportedVersionDao;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class KubernetesClusterResourceModifierActionWorkerTest {
|
||||
@Mock
|
||||
private KubernetesClusterDao kubernetesClusterDaoMock;
|
||||
|
||||
@Mock
|
||||
private KubernetesClusterDetailsDao kubernetesClusterDetailsDaoMock;
|
||||
|
||||
@Mock
|
||||
private KubernetesClusterVmMapDao kubernetesClusterVmMapDaoMock;
|
||||
|
||||
@Mock
|
||||
private KubernetesSupportedVersionDao kubernetesSupportedVersionDaoMock;
|
||||
|
||||
@Mock
|
||||
private KubernetesClusterManagerImpl kubernetesClusterManagerMock;
|
||||
|
||||
@Mock
|
||||
private KubernetesCluster kubernetesClusterMock;
|
||||
|
||||
private KubernetesClusterResourceModifierActionWorker kubernetesClusterResourceModifierActionWorker;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
kubernetesClusterManagerMock.kubernetesClusterDao = kubernetesClusterDaoMock;
|
||||
kubernetesClusterManagerMock.kubernetesSupportedVersionDao = kubernetesSupportedVersionDaoMock;
|
||||
kubernetesClusterManagerMock.kubernetesClusterDetailsDao = kubernetesClusterDetailsDaoMock;
|
||||
kubernetesClusterManagerMock.kubernetesClusterVmMapDao = kubernetesClusterVmMapDaoMock;
|
||||
|
||||
kubernetesClusterResourceModifierActionWorker = new KubernetesClusterResourceModifierActionWorker(kubernetesClusterMock, kubernetesClusterManagerMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestReturnOriginalPrefixWhenNamingAllRequirementsAreMet() {
|
||||
String originalPrefix = "k8s-cluster-01";
|
||||
String expectedPrefix = "k8s-cluster-01";
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldOnlyContainLowerCaseCharacters() {
|
||||
String originalPrefix = "k8s-CLUSTER-01";
|
||||
String expectedPrefix = "k8s-cluster-01";
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldBeTruncatedWhenRequired() {
|
||||
int maxPrefixLength = 43;
|
||||
|
||||
String originalPrefix = "c".repeat(maxPrefixLength + 1);
|
||||
String expectedPrefix = "c".repeat(maxPrefixLength);
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
String normalizedPrefix = kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix();
|
||||
Assert.assertEquals(expectedPrefix, normalizedPrefix);
|
||||
Assert.assertEquals(maxPrefixLength, normalizedPrefix.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldBeTruncatedWhenRequiredAndWhenOriginalPrefixIsInvalid() {
|
||||
int maxPrefixLength = 43;
|
||||
|
||||
String originalPrefix = "1!" + "c".repeat(maxPrefixLength);
|
||||
String expectedPrefix = "k8s-1" + "c".repeat(maxPrefixLength - 5);
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
String normalizedPrefix = kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix();
|
||||
Assert.assertEquals(expectedPrefix, normalizedPrefix);
|
||||
Assert.assertEquals(maxPrefixLength, normalizedPrefix.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldOnlyIncludeAlphanumericCharactersAndHyphen() {
|
||||
String originalPrefix = "Cluster!@#$%^&*()_+?.-01|<>";
|
||||
String expectedPrefix = "k8s-cluster-01";
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldContainClusterUuidWhenAllCharactersAreInvalid() {
|
||||
String clusterUuid = "2699b547-cb56-4a59-a2c6-331cfb21d2e4";
|
||||
String originalPrefix = "!@#$%^&*()_+?.|<>";
|
||||
String expectedPrefix = "k8s-" + clusterUuid;
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getUuid()).thenReturn(clusterUuid);
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getKubernetesClusterNodeNamePrefixTestNormalizedPrefixShouldNotStartWithADigit() {
|
||||
String originalPrefix = "1 cluster";
|
||||
String expectedPrefix = "k8s-1cluster";
|
||||
|
||||
Mockito.when(kubernetesClusterMock.getName()).thenReturn(originalPrefix);
|
||||
Assert.assertEquals(expectedPrefix, kubernetesClusterResourceModifierActionWorker.getKubernetesClusterNodeNamePrefix());
|
||||
}
|
||||
}
|
||||
@ -194,7 +194,8 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
|
||||
|
||||
if (!isAdmin && zoneIdList == null && !isRegionStore ) {
|
||||
// domain admin and user should also be able to register template on a region store
|
||||
throw new InvalidParameterValueException("Please specify a valid zone Id. Only admins can create templates in all zones.");
|
||||
throw new InvalidParameterValueException("Template registered for 'All zones' can only be owned a Root Admin account. " +
|
||||
"Please select specific zone(s).");
|
||||
}
|
||||
|
||||
// check for the url format only when url is not null. url can be null incase of form based upload
|
||||
|
||||
@ -1962,27 +1962,12 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
||||
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVM);
|
||||
List<String> destinationStoragePools = selectInstanceConversionStoragePools(convertStoragePools, sourceVMwareInstance.getDisks(), serviceOffering, dataDiskOfferingMap);
|
||||
ConvertInstanceCommand cmd = new ConvertInstanceCommand(remoteInstanceTO,
|
||||
Hypervisor.HypervisorType.KVM, destinationStoragePools, temporaryConvertLocation, ovfTemplateDirConvertLocation, false, false);
|
||||
Hypervisor.HypervisorType.KVM, temporaryConvertLocation, ovfTemplateDirConvertLocation, false, false);
|
||||
int timeoutSeconds = UnmanagedVMsManager.ConvertVmwareInstanceToKvmTimeout.value() * 60 * 60;
|
||||
cmd.setWait(timeoutSeconds);
|
||||
|
||||
Answer convertAnswer;
|
||||
try {
|
||||
convertAnswer = agentManager.send(convertHost.getId(), cmd);
|
||||
} catch (AgentUnavailableException | OperationTimedoutException e) {
|
||||
String err = String.format("Could not send the convert instance command to host %s due to: %s",
|
||||
convertHost, e.getMessage());
|
||||
logger.error(err, e);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
|
||||
if (!convertAnswer.getResult()) {
|
||||
String err = String.format("The convert process failed for instance %s from VMware to KVM on host %s: %s",
|
||||
sourceVM, convertHost, convertAnswer.getDetails());
|
||||
logger.error(err);
|
||||
throw new CloudRuntimeException(err);
|
||||
}
|
||||
return ((ConvertInstanceAnswer) convertAnswer).getConvertedInstance();
|
||||
return convertAndImportToKVM(cmd, convertHost, importHost, sourceVM,
|
||||
remoteInstanceTO, destinationStoragePools, temporaryConvertLocation);
|
||||
}
|
||||
|
||||
private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvertLocation(
|
||||
@ -1997,7 +1982,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
||||
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVMwareInstance.getName(), sourceVMwareInstance.getPath(), vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
|
||||
List<String> destinationStoragePools = selectInstanceConversionStoragePools(convertStoragePools, sourceVMwareInstance.getDisks(), serviceOffering, dataDiskOfferingMap);
|
||||
ConvertInstanceCommand cmd = new ConvertInstanceCommand(remoteInstanceTO,
|
||||
Hypervisor.HypervisorType.KVM, destinationStoragePools, temporaryConvertLocation, null, false, true);
|
||||
Hypervisor.HypervisorType.KVM, temporaryConvertLocation, null, false, true);
|
||||
int timeoutSeconds = UnmanagedVMsManager.ConvertVmwareInstanceToKvmTimeout.value() * 60 * 60;
|
||||
cmd.setWait(timeoutSeconds);
|
||||
int noOfThreads = UnmanagedVMsManager.ThreadsOnKVMHostToImportVMwareVMFiles.value();
|
||||
@ -2065,7 +2050,6 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
||||
List<StoragePoolVO> pools = new ArrayList<>();
|
||||
pools.addAll(primaryDataStoreDao.findClusterWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem));
|
||||
pools.addAll(primaryDataStoreDao.findZoneWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getDataCenterId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem));
|
||||
List<String> diskOfferingTags = new ArrayList<>();
|
||||
if (pools.isEmpty()) {
|
||||
String msg = String.format("Cannot find suitable storage pools in the cluster %s for the conversion", destinationCluster.getName());
|
||||
logger.error(msg);
|
||||
@ -2092,39 +2076,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
diskOfferingTags.add(diskOffering.getTags());
|
||||
}
|
||||
if (serviceOffering.getDiskOfferingId() != null) {
|
||||
DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId());
|
||||
if (diskOffering != null) {
|
||||
diskOfferingTags.add(diskOffering.getTags());
|
||||
}
|
||||
}
|
||||
|
||||
pools = getPoolsWithMatchingTags(pools, diskOfferingTags);
|
||||
if (pools.isEmpty()) {
|
||||
String msg = String.format("Cannot find suitable storage pools in cluster %s for the conversion", destinationCluster);
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
return pools;
|
||||
}
|
||||
|
||||
private List<StoragePoolVO> getPoolsWithMatchingTags(List<StoragePoolVO> pools, List<String> diskOfferingTags) {
|
||||
if (diskOfferingTags.isEmpty()) {
|
||||
return pools;
|
||||
}
|
||||
List<StoragePoolVO> poolsSupportingTags = new ArrayList<>(pools);
|
||||
for (String tags : diskOfferingTags) {
|
||||
boolean tagsMatched = false;
|
||||
for (StoragePoolVO pool : pools) {
|
||||
if (volumeApiService.doesStoragePoolSupportDiskOfferingTags(pool, tags)) {
|
||||
poolsSupportingTags.add(pool);
|
||||
tagsMatched = true;
|
||||
}
|
||||
}
|
||||
if (!tagsMatched) {
|
||||
String msg = String.format("Cannot find suitable storage pools for the conversion with disk offering tags %s", tags);
|
||||
if (getStoragePoolWithTags(pools, diskOffering.getTags()) == null) {
|
||||
String msg = String.format("Cannot find suitable storage pool for disk offering %s", diskOffering.getName());
|
||||
logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
}
|
||||
|
||||
@ -700,11 +700,9 @@ public class UnmanagedVMsManagerImplTest {
|
||||
}
|
||||
|
||||
when(volumeApiService.doesStoragePoolSupportDiskOffering(any(StoragePool.class), any(DiskOffering.class))).thenReturn(true);
|
||||
when(volumeApiService.doesStoragePoolSupportDiskOfferingTags(any(StoragePool.class), any())).thenReturn(true);
|
||||
|
||||
ConvertInstanceAnswer convertInstanceAnswer = mock(ConvertInstanceAnswer.class);
|
||||
ImportConvertedInstanceAnswer convertImportedInstanceAnswer = mock(ImportConvertedInstanceAnswer.class);
|
||||
when(convertInstanceAnswer.getConvertedInstance()).thenReturn(instance);
|
||||
when(convertInstanceAnswer.getResult()).thenReturn(vcenterParameter != VcenterParameter.CONVERT_FAILURE);
|
||||
Mockito.lenient().when(convertImportedInstanceAnswer.getConvertedInstance()).thenReturn(instance);
|
||||
Mockito.lenient().when(convertImportedInstanceAnswer.getResult()).thenReturn(vcenterParameter != VcenterParameter.CONVERT_FAILURE);
|
||||
|
||||
@ -1006,7 +1006,7 @@ export default {
|
||||
},
|
||||
fetchVolumes (searchKeyword) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getAPI('listvolumes', { listAll: true, isencrypted: searchKeyword }).then(json => {
|
||||
getAPI('listVolumes', { listAll: true, isencrypted: searchKeyword }).then(json => {
|
||||
const volumes = json.listvolumesresponse.volume
|
||||
resolve({
|
||||
type: 'isencrypted',
|
||||
|
||||
@ -853,7 +853,7 @@
|
||||
:deployButtonMenuOptions="deployMenuOptions"
|
||||
@handle-cancel="() => $router.back()"
|
||||
@handle-deploy="handleSubmit"
|
||||
@handle-deploy-menu="handleSubmitAndStay" />
|
||||
@handle-deploy-menu="(index, e) => handleSubmitAndStay(e)" />
|
||||
</div>
|
||||
</a-form>
|
||||
</a-card>
|
||||
@ -868,7 +868,7 @@
|
||||
:deployButtonMenuOptions="deployMenuOptions"
|
||||
@handle-cancel="() => $router.back()"
|
||||
@handle-deploy="handleSubmit"
|
||||
@handle-deploy-menu="handleSubmitAndStay" />
|
||||
@handle-deploy-menu="(index, e) => handleSubmitAndStay(e)" />
|
||||
</template>
|
||||
</info-card>
|
||||
</a-affix>
|
||||
|
||||
@ -810,7 +810,7 @@
|
||||
:deployButtonMenuOptions="deployMenuOptions"
|
||||
@handle-cancel="() => $router.back()"
|
||||
@handle-deploy="handleSubmit"
|
||||
@handle-deploy-menu="handleSubmitAndStay" />
|
||||
@handle-deploy-menu="(index, e) => handleSubmitAndStay(e)" />
|
||||
</div>
|
||||
</a-form>
|
||||
</a-card>
|
||||
@ -825,7 +825,7 @@
|
||||
:deployButtonMenuOptions="deployMenuOptions"
|
||||
@handle-cancel="() => $router.back()"
|
||||
@handle-deploy="handleSubmit"
|
||||
@handle-deploy-menu="handleSubmitAndStay" />
|
||||
@handle-deploy-menu="(index, e) => handleSubmitAndStay(e)" />
|
||||
</template>
|
||||
</info-card>
|
||||
</a-affix>
|
||||
|
||||
@ -86,7 +86,7 @@ export default {
|
||||
this.$emit('handle-deploy', e)
|
||||
},
|
||||
handleMenu (e) {
|
||||
this.$emit('handle-deploy-menu', e.key - 1)
|
||||
this.$emit('handle-deploy-menu', e.key - 1, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,8 +110,10 @@ export default {
|
||||
.button-container {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
.btn-stay-on-page {
|
||||
&.ant-dropdown-menu-dark {
|
||||
@ -120,9 +122,6 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
.ant-btn-group > .ant-btn:first-child:not(:last-child) {
|
||||
flex-grow: 1; /* Make each button grow equally */
|
||||
|
||||
@ -1058,13 +1058,23 @@ public class NetUtils {
|
||||
return Integer.toString(portRange[0]) + ":" + Integer.toString(portRange[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a domain name.
|
||||
*
|
||||
* <p>Domain names must satisfy the following constraints:
|
||||
* <ul>
|
||||
* <li>Length between 1 and 63 characters</li>
|
||||
* <li>Contain only ASCII letters 'a' through 'z' (case-insensitive)</li>
|
||||
* <li>Can include digits '0' through '9' and hyphens (-)</li>
|
||||
* <li>Must not start or end with a hyphen</li>
|
||||
* <li>If used as hostname, must not start with a digit</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hostName The domain name to validate
|
||||
* @param isHostName If true, verifies whether the domain name starts with a digit
|
||||
* @return true if the domain name is valid, false otherwise
|
||||
*/
|
||||
public static boolean verifyDomainNameLabel(final String hostName, final boolean isHostName) {
|
||||
// must be between 1 and 63 characters long and may contain only the ASCII letters 'a' through 'z' (in a
|
||||
// case-insensitive manner),
|
||||
// the digits '0' through '9', and the hyphen ('-').
|
||||
// Can not start with a hyphen and digit, and must not end with a hyphen
|
||||
// If it's a host name, don't allow to start with digit
|
||||
|
||||
if (hostName.length() > 63 || hostName.length() < 1) {
|
||||
LOGGER.warn("Domain name label must be between 1 and 63 characters long");
|
||||
return false;
|
||||
|
||||
@ -253,12 +253,29 @@ public class BaseMO {
|
||||
hostClusterPair = hostClusterNamesMap.get(hostMorValue);
|
||||
} else {
|
||||
HostMO hostMO = new HostMO(_context, hostMor);
|
||||
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
|
||||
hostClusterPair = new Pair<>(hostMO.getHostName(), clusterMO.getName());
|
||||
String hostName = hostMO.getHostName();
|
||||
String clusterName = getClusterNameFromHostIncludingStandaloneHosts(hostMO, hostName);
|
||||
hostClusterPair = new Pair<>(hostName, clusterName);
|
||||
hostClusterNamesMap.put(hostMorValue, hostClusterPair);
|
||||
}
|
||||
vm.setHostName(hostClusterPair.first());
|
||||
vm.setClusterName(hostClusterPair.second());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cluster name of the host on the vCenter
|
||||
* @return null in case the host is standalone (doesn't belong to a cluster), cluster name otherwise
|
||||
*/
|
||||
private String getClusterNameFromHostIncludingStandaloneHosts(HostMO hostMO, String hostName) {
|
||||
try {
|
||||
ClusterMO clusterMO = new ClusterMO(_context, hostMO.getHyperHostCluster());
|
||||
return clusterMO.getName();
|
||||
} catch (Exception e) {
|
||||
String msg = String.format("Cannot find a cluster for host %s, assuming standalone host, " +
|
||||
"setting its cluster name as empty", hostName);
|
||||
logger.info(msg);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user