Skip to content

Commit 3ac3af0

Browse files
Merge branch '4.20' into 4.20-routed-support-vxlan
2 parents bc0c3db + f2a6a2f commit 3ac3af0

File tree

44 files changed

+1153
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1153
-495
lines changed

.github/workflows/main-sonar-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
uses: actions/cache@v4
5555
with:
5656
path: ~/.m2/repository
57-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
57+
key: ${{ runner.os }}-m2-${{ hashFiles('pom.xml', '*/pom.xml', '*/*/pom.xml', '*/*/*/pom.xml') }}
5858
restore-keys: |
5959
${{ runner.os }}-m2
6060

.github/workflows/sonar-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
uses: actions/cache@v4
5757
with:
5858
path: ~/.m2/repository
59-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
59+
key: ${{ runner.os }}-m2-${{ hashFiles('pom.xml', '*/pom.xml', '*/*/pom.xml', '*/*/*/pom.xml') }}
6060
restore-keys: |
6161
${{ runner.os }}-m2
6262

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ public class ApiConstants {
448448
public static final String SENT = "sent";
449449
public static final String SENT_BYTES = "sentbytes";
450450
public static final String SERIAL = "serial";
451+
public static final String SERVICE_IP = "serviceip";
451452
public static final String SERVICE_OFFERING_ID = "serviceofferingid";
452453
public static final String SESSIONKEY = "sessionkey";
453454
public static final String SHOW_CAPACITIES = "showcapacities";

api/src/main/java/org/apache/cloudstack/api/response/ManagementServerResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public class ManagementServerResponse extends BaseResponse {
7474
@Param(description = "the running OS kernel version for this Management Server")
7575
private String kernelVersion;
7676

77+
@Deprecated
78+
@SerializedName(ApiConstants.SERVICE_IP)
79+
@Param(description = "the IP Address for this Management Server. This is deprecated, please use 'ipaddress' instead.")
80+
private String serviceIp;
81+
7782
@SerializedName(ApiConstants.IP_ADDRESS)
7883
@Param(description = "the IP Address for this Management Server")
7984
private String ipAddress;
@@ -122,6 +127,10 @@ public Date getLastBoot() {
122127
return lastBoot;
123128
}
124129

130+
public String getServiceIp() {
131+
return serviceIp;
132+
}
133+
125134
public String getIpAddress() {
126135
return ipAddress;
127136
}
@@ -170,6 +179,10 @@ public void setKernelVersion(String kernelVersion) {
170179
this.kernelVersion = kernelVersion;
171180
}
172181

182+
public void setServiceIp(String serviceIp) {
183+
this.serviceIp = serviceIp;
184+
}
185+
173186
public void setIpAddress(String ipAddress) {
174187
this.ipAddress = ipAddress;
175188
}

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public class UnmanagedInstanceResponse extends BaseResponse {
7979
@Param(description = "the operating system of the virtual machine")
8080
private String operatingSystem;
8181

82+
@SerializedName(ApiConstants.BOOT_MODE)
83+
@Param(description = "indicates the boot mode")
84+
private String bootMode;
85+
86+
@SerializedName(ApiConstants.BOOT_TYPE)
87+
@Param(description = "indicates the boot type")
88+
private String bootType;
89+
8290
@SerializedName(ApiConstants.DISK)
8391
@Param(description = "the list of disks associated with the virtual machine", responseObject = UnmanagedInstanceDiskResponse.class)
8492
private Set<UnmanagedInstanceDiskResponse> disks;
@@ -211,4 +219,20 @@ public void setNics(Set<NicResponse> nics) {
211219
public void addNic(NicResponse nic) {
212220
this.nics.add(nic);
213221
}
222+
223+
public String getBootMode() {
224+
return bootMode;
225+
}
226+
227+
public void setBootMode(String bootMode) {
228+
this.bootMode = bootMode;
229+
}
230+
231+
public String getBootType() {
232+
return bootType;
233+
}
234+
235+
public void setBootType(String bootType) {
236+
this.bootType = bootType;
237+
}
214238
}

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public enum PowerState {
6161

6262
private String vncPassword;
6363

64+
private String bootType;
65+
private String bootMode;
66+
6467
public String getName() {
6568
return name;
6669
}
@@ -196,6 +199,22 @@ public String toString() {
196199
this, "name", "internalCSName", "hostName", "clusterName"));
197200
}
198201

202+
public String getBootType() {
203+
return bootType;
204+
}
205+
206+
public void setBootType(String bootType) {
207+
this.bootType = bootType;
208+
}
209+
210+
public String getBootMode() {
211+
return bootMode;
212+
}
213+
214+
public void setBootMode(String bootMode) {
215+
this.bootMode = bootMode;
216+
}
217+
199218
public static class Disk {
200219
private String diskId;
201220

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
import org.apache.cloudstack.context.CallContext;
6262
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
6363
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
64+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
6465
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
66+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
67+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
68+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
6569
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
6670
import org.apache.cloudstack.framework.ca.Certificate;
6771
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -409,6 +413,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
409413
ResourceCleanupService resourceCleanupService;
410414
@Inject
411415
VmWorkJobDao vmWorkJobDao;
416+
@Inject
417+
DataStoreProviderManager dataStoreProviderManager;
412418

413419
private SingleCache<List<Long>> vmIdsInProgressCache;
414420

@@ -1224,6 +1230,13 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
12241230
planChangedByVolume = true;
12251231
}
12261232
}
1233+
DataStoreProvider storeProvider = dataStoreProviderManager.getDataStoreProvider(pool.getStorageProviderName());
1234+
if (storeProvider != null) {
1235+
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
1236+
if (storeDriver instanceof PrimaryDataStoreDriver) {
1237+
((PrimaryDataStoreDriver)storeDriver).detachVolumeFromAllStorageNodes(vol);
1238+
}
1239+
}
12271240
}
12281241
}
12291242

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.host.dao.HostDao;
2727
import com.cloud.hypervisor.Hypervisor;
2828
import com.cloud.storage.ScopeType;
29+
import com.cloud.storage.Storage;
2930
import com.cloud.storage.StoragePoolHostVO;
3031
import com.cloud.storage.Volume;
3132
import com.cloud.storage.VolumeVO;
@@ -280,6 +281,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
280281
restoredVolume.setPoolId(dataStore.getPoolId());
281282
restoredVolume.setPath(restoredVolume.getUuid());
282283
restoredVolume.setState(Volume.State.Copying);
284+
restoredVolume.setFormat(Storage.ImageFormat.QCOW2);
283285
restoredVolume.setSize(backedUpVolumeSize);
284286
restoredVolume.setDiskOfferingId(volume.getDiskOfferingId());
285287

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class LibvirtRestoreBackupCommandWrapper extends CommandWrapper<RestoreBa
4545
private static final String MOUNT_COMMAND = "sudo mount -t %s %s %s";
4646
private static final String UMOUNT_COMMAND = "sudo umount %s";
4747
private static final String FILE_PATH_PLACEHOLDER = "%s/%s";
48-
private static final String ATTACH_DISK_COMMAND = " virsh attach-disk %s %s %s --cache none";
48+
private static final String ATTACH_DISK_COMMAND = " virsh attach-disk %s %s %s --driver qemu --subdriver qcow2 --cache none";
4949
private static final String CURRRENT_DEVICE = "virsh domblklist --domain %s | tail -n 3 | head -n 1 | awk '{print $1}'";
5050
private static final String RSYNC_COMMAND = "rsync -az %s %s";
5151

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import javax.naming.ConfigurationException;
4444
import javax.persistence.EntityExistsException;
4545

46+
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
4647
import com.cloud.hypervisor.vmware.util.VmwareClient;
4748
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
4849
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
@@ -171,8 +172,11 @@
171172
import com.vmware.pbm.PbmProfile;
172173
import com.vmware.vim25.AboutInfo;
173174
import com.vmware.vim25.ManagedObjectReference;
175+
import org.apache.logging.log4j.LogManager;
176+
import org.apache.logging.log4j.Logger;
174177

175178
public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService, Configurable {
179+
protected static Logger static_logger = LogManager.getLogger(VmwareManagerImpl.class);
176180

177181
private static final long SECONDS_PER_MINUTE = 60;
178182
private static final int DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x = 256;
@@ -249,7 +253,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
249253
private boolean _fullCloneFlag;
250254
private boolean _instanceNameFlag;
251255
private String _serviceConsoleName;
252-
private String _managemetPortGroupName;
256+
private String _managementPortGroupName;
253257
private String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
254258
private String _recycleHungWorker = "false";
255259
private int _additionalPortRangeStart;
@@ -347,9 +351,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
347351
_serviceConsoleName = "Service Console";
348352
}
349353

350-
_managemetPortGroupName = _configDao.getValue(Config.VmwareManagementPortGroup.key());
351-
if (_managemetPortGroupName == null) {
352-
_managemetPortGroupName = "Management Network";
354+
_managementPortGroupName = _configDao.getValue(Config.VmwareManagementPortGroup.key());
355+
if (_managementPortGroupName == null) {
356+
_managementPortGroupName = "Management Network";
353357
}
354358

355359
_defaultSystemVmNicAdapterType = _configDao.getValue(Config.VmwareSystemVmNicDeviceType.key());
@@ -614,13 +618,13 @@ public String getServiceConsolePortGroupName() {
614618

615619
@Override
616620
public String getManagementPortGroupName() {
617-
return _managemetPortGroupName;
621+
return _managementPortGroupName;
618622
}
619623

620624
@Override
621625
public String getManagementPortGroupByHost(HostMO hostMo) throws Exception {
622626
if (hostMo.getHostType() == VmwareHostType.ESXi) {
623-
return _managemetPortGroupName;
627+
return _managementPortGroupName;
624628
}
625629
return _serviceConsoleName;
626630
}
@@ -630,7 +634,7 @@ public void setupResourceStartupParams(Map<String, Object> params) {
630634
params.put("vmware.create.full.clone", _fullCloneFlag);
631635
params.put("vm.instancename.flag", _instanceNameFlag);
632636
params.put("service.console.name", _serviceConsoleName);
633-
params.put("management.portgroup.name", _managemetPortGroupName);
637+
params.put("management.portgroup.name", _managementPortGroupName);
634638
params.put("vmware.root.disk.controller", _rootDiskController);
635639
params.put("vmware.data.disk.controller", _dataDiskController);
636640
params.put("vmware.recycle.hung.wokervm", _recycleHungWorker);
@@ -1585,14 +1589,26 @@ public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsph
15851589
return compatiblePools;
15861590
}
15871591

1588-
@Override
1589-
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
1592+
private static class VcenterData {
1593+
public final String vcenter;
1594+
public final String datacenterName;
1595+
public final String username;
1596+
public final String password;
1597+
1598+
public VcenterData(String vcenter, String datacenterName, String username, String password) {
1599+
this.vcenter = vcenter;
1600+
this.datacenterName = datacenterName;
1601+
this.username = username;
1602+
this.password = password;
1603+
}
1604+
}
1605+
1606+
private VcenterData getVcenterData(ListVmwareDcVmsCmd cmd) {
15901607
String vcenter = cmd.getVcenter();
15911608
String datacenterName = cmd.getDatacenterName();
15921609
String username = cmd.getUsername();
15931610
String password = cmd.getPassword();
15941611
Long existingVcenterId = cmd.getExistingVcenterId();
1595-
String keyword = cmd.getKeyword();
15961612

15971613
if ((existingVcenterId == null && StringUtils.isBlank(vcenter)) ||
15981614
(existingVcenterId != null && StringUtils.isNotBlank(vcenter))) {
@@ -1613,34 +1629,69 @@ public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
16131629
username = vmwareDc.getUser();
16141630
password = vmwareDc.getPassword();
16151631
}
1632+
VcenterData vmwaredc = new VcenterData(vcenter, datacenterName, username, password);
1633+
return vmwaredc;
1634+
}
1635+
1636+
private static VmwareContext getVmwareContext(String vcenter, String username, String password) throws Exception {
1637+
static_logger.debug(String.format("Connecting to the VMware vCenter %s", vcenter));
1638+
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
1639+
VmwareClient vimClient = new VmwareClient(vcenter);
1640+
vimClient.connect(serviceUrl, username, password);
1641+
return new VmwareContext(vimClient, vcenter);
1642+
}
1643+
1644+
@Override
1645+
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
1646+
VcenterData vmwareDC = getVcenterData(cmd);
1647+
String vcenter = vmwareDC.vcenter;
1648+
String username = vmwareDC.username;
1649+
String password = vmwareDC.password;
1650+
String datacenterName = vmwareDC.datacenterName;
1651+
String keyword = cmd.getKeyword();
1652+
String esxiHostName = cmd.getHostName();
1653+
String virtualMachineName = cmd.getInstanceName();
16161654

16171655
try {
16181656
logger.debug(String.format("Connecting to the VMware datacenter %s at vCenter %s to retrieve VMs",
16191657
datacenterName, vcenter));
1620-
String serviceUrl = String.format("https://%s/sdk/vimService", vcenter);
1621-
VmwareClient vimClient = new VmwareClient(vcenter);
1622-
vimClient.connect(serviceUrl, username, password);
1623-
VmwareContext context = new VmwareContext(vimClient, vcenter);
1624-
1625-
DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
1626-
ManagedObjectReference dcMor = dcMo.getMor();
1627-
if (dcMor == null) {
1628-
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s",
1629-
datacenterName, vcenter);
1630-
logger.error(msg);
1631-
throw new InvalidParameterValueException(msg);
1658+
VmwareContext context = getVmwareContext(vcenter, username, password);
1659+
DatacenterMO dcMo = getDatacenterMO(context, vcenter, datacenterName);
1660+
1661+
List<UnmanagedInstanceTO> instances;
1662+
if (StringUtils.isNotBlank(esxiHostName) && StringUtils.isNotBlank(virtualMachineName)) {
1663+
ManagedObjectReference hostMor = dcMo.findHost(esxiHostName);
1664+
if (hostMor == null) {
1665+
String errorMsg = String.format("Cannot find a host with name %s on vcenter %s", esxiHostName, vcenter);
1666+
logger.error(errorMsg);
1667+
throw new CloudRuntimeException(errorMsg);
1668+
}
1669+
HostMO hostMO = new HostMO(context, hostMor);
1670+
VirtualMachineMO vmMo = hostMO.findVmOnHyperHost(virtualMachineName);
1671+
instances = Collections.singletonList(VmwareHelper.getUnmanagedInstance(hostMO, vmMo));
1672+
} else {
1673+
instances = dcMo.getAllVmsOnDatacenter(keyword);
16321674
}
1633-
List<UnmanagedInstanceTO> instances = dcMo.getAllVmsOnDatacenter();
1634-
return StringUtils.isBlank(keyword) ? instances :
1635-
instances.stream().filter(x -> x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
1675+
return instances;
16361676
} catch (Exception e) {
1637-
String errorMsg = String.format("Error retrieving stopped VMs from the VMware VC %s datacenter %s: %s",
1677+
String errorMsg = String.format("Error retrieving VMs from the VMware VC %s datacenter %s: %s",
16381678
vcenter, datacenterName, e.getMessage());
16391679
logger.error(errorMsg, e);
16401680
throw new CloudRuntimeException(errorMsg);
16411681
}
16421682
}
16431683

1684+
private static DatacenterMO getDatacenterMO(VmwareContext context, String vcenter, String datacenterName) throws Exception {
1685+
DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
1686+
ManagedObjectReference dcMor = dcMo.getMor();
1687+
if (dcMor == null) {
1688+
String msg = String.format("Unable to find VMware datacenter %s in vCenter %s", datacenterName, vcenter);
1689+
static_logger.error(msg);
1690+
throw new InvalidParameterValueException(msg);
1691+
}
1692+
return dcMo;
1693+
}
1694+
16441695
@Override
16451696
public boolean hasNexusVSM(Long clusterId) {
16461697
ClusterVSMMapVO vsmMapVo = null;
@@ -1693,7 +1744,7 @@ private void startTemplateCleanJobSchedule() {
16931744
}
16941745

16951746
/**
1696-
* This task is to cleanup templates from primary storage that are otherwise not cleaned by the {@link com.cloud.storage.StorageManagerImpl.StorageGarbageCollector}.
1747+
* This task is to cleanup templates from primary storage that are otherwise not cleaned by the {code}StorageGarbageCollector{code} from {@link com.cloud.storage.StorageManagerImpl}.
16971748
* it is called at regular intervals when storage.template.cleanup.enabled == true
16981749
* It collect all templates that
16991750
* - are deleted from cloudstack

0 commit comments

Comments
 (0)