-
Notifications
You must be signed in to change notification settings - Fork 1.2k
NAS B&R Plugin enhancements #9666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 26 commits
64db486
d5a259d
e2cb774
6dfb0ea
b1ccf9d
343e7dc
f2f81c8
be9eba3
585126b
d024a96
5c23f4b
0760ef5
bf19dea
5430080
5bfed06
c087de4
3ae3601
d6181d5
59464be
862211c
7caa908
482c2c9
75e5c0c
f6f0ba6
9a6e0e3
5e39348
9714aae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,7 @@ | |
| restoreCommand.setBackupPath(backup.getExternalId()); | ||
| restoreCommand.setBackupRepoType(backupRepository.getType()); | ||
| restoreCommand.setBackupRepoAddress(backupRepository.getAddress()); | ||
| restoreCommand.setMountOptions(backupRepository.getMountOptions()); | ||
|
Check warning on line 224 in plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java
|
||
| restoreCommand.setVmName(vm.getName()); | ||
| restoreCommand.setVolumePaths(getVolumePaths(volumes)); | ||
| restoreCommand.setVmExists(vm.getRemoved() == null); | ||
|
|
@@ -289,6 +290,7 @@ | |
| restoreCommand.setVmName(vmNameAndState.first()); | ||
| restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", dataStore.getLocalPath(), volumeUUID))); | ||
| restoreCommand.setDiskType(volume.getVolumeType().name().toLowerCase(Locale.ROOT)); | ||
| restoreCommand.setMountOptions(backupRepository.getMountOptions()); | ||
|
Check warning on line 293 in plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java
|
||
| restoreCommand.setVmExists(null); | ||
| restoreCommand.setVmState(vmNameAndState.second()); | ||
| restoreCommand.setRestoreVolumeUUID(volumeUuid); | ||
|
|
@@ -373,8 +375,12 @@ | |
| Long vmBackupSize = 0L; | ||
| Long vmBackupProtectedSize = 0L; | ||
| for (final Backup backup: backupDao.listByVmId(null, vm.getId())) { | ||
| vmBackupSize += backup.getSize(); | ||
| vmBackupProtectedSize += backup.getProtectedSize(); | ||
| if (Objects.nonNull(backup.getSize())) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can these be null?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure - but just added a defensive check |
||
| vmBackupSize += backup.getSize(); | ||
|
Check warning on line 379 in plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java
|
||
| } | ||
| if (Objects.nonNull(backup.getProtectedSize())) { | ||
| vmBackupProtectedSize += backup.getProtectedSize(); | ||
|
Check warning on line 382 in plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java
|
||
| } | ||
| } | ||
| Backup.Metric vmBackupMetric = new Backup.Metric(vmBackupSize,vmBackupProtectedSize); | ||
| LOG.debug("Metrics for VM {} is [backup size: {}, data size: {}].", vm, vmBackupMetric.getBackupSize(), vmBackupMetric.getDataSize()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.naming.ConfigurationException; | ||
|
|
@@ -1467,6 +1468,10 @@ | |
| } | ||
|
|
||
| List<KubernetesClusterVmMapVO> vmMapList = kubernetesClusterVmMapDao.listByClusterId(kubernetesClusterId); | ||
| List<VMInstanceVO> vms = vmMapList.stream().map(vmMap -> vmInstanceDao.findById(vmMap.getVmId())).collect(Collectors.toList()); | ||
|
Check warning on line 1471 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
|
||
| if (checkIfVmsAssociatedWithBackupOffering(vms)) { | ||
| throw new CloudRuntimeException("Unable to delete Kubernetes cluster, as node(s) are associated to a backup offering"); | ||
|
Check warning on line 1473 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
|
||
| } | ||
|
Comment on lines
+1472
to
+1474
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not throw the exception from the new method? |
||
| for (KubernetesClusterVmMapVO vmMap : vmMapList) { | ||
| try { | ||
| userVmService.destroyVm(vmMap.getVmId(), expunge); | ||
|
|
@@ -1489,6 +1494,15 @@ | |
| } | ||
| } | ||
|
|
||
| public static boolean checkIfVmsAssociatedWithBackupOffering(List<VMInstanceVO> vms) { | ||
|
Check warning on line 1497 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
|
||
| for(VMInstanceVO vm : vms) { | ||
| if (Objects.nonNull(vm.getBackupOfferingId())) { | ||
| return true; | ||
|
Check warning on line 1500 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
|
||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
Check warning on line 1504 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
|
||
|
|
||
| @Override | ||
| public ListResponse<KubernetesClusterResponse> listKubernetesClusters(ListKubernetesClustersCmd cmd) { | ||
| if (!KubernetesServiceEnabled.value()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,58 @@ NAS_ADDRESS="" | |
| MOUNT_OPTS="" | ||
| BACKUP_DIR="" | ||
| DISK_PATHS="" | ||
| logFile="/var/log/cloudstack/agent/agent.log" | ||
|
|
||
| log() { | ||
| [[ "$verb" -eq 1 ]] && builtin echo "$@" | ||
| if [[ "$1" == "-ne" || "$1" == "-e" || "$1" == "-n" ]]; then | ||
| builtin echo -e "$(date '+%Y-%m-%d %H-%M-%S>')" "${@: 2}" >> "$logFile" | ||
| else | ||
| builtin echo "$(date '+%Y-%m-%d %H-%M-%S>')" "$@" >> "$logFile" | ||
| fi | ||
| } | ||
|
|
||
| vercomp() { | ||
| local IFS=. | ||
| local i ver1=($1) ver2=($3) | ||
|
|
||
| # Compare each segment of the version numbers | ||
| for ((i=0; i<${#ver1[@]}; i++)); do | ||
| if [[ -z ${ver2[i]} ]]; then | ||
| ver2[i]=0 | ||
| fi | ||
|
|
||
| if ((10#${ver1[i]} > 10#${ver2[i]})); then | ||
| return 0 # Version 1 is greater | ||
| elif ((10#${ver1[i]} < 10#${ver2[i]})); then | ||
| return 2 # Version 2 is greater | ||
| fi | ||
| done | ||
| return 0 # Versions are equal | ||
| } | ||
|
|
||
| sanity_checks() { | ||
| hvVersion=$(virsh version | grep hypervisor | awk '{print $(NF)}') | ||
| libvVersion=$(virsh version | grep libvirt | awk '{print $(NF)}' | tail -n 1) | ||
| apiVersion=$(virsh version | grep API | awk '{print $(NF)}') | ||
|
|
||
| # Compare qemu version (hvVersion >= 4.2.0) | ||
| vercomp "$hvVersion" ">=" "4.2.0" | ||
| hvStatus=$? | ||
|
|
||
| # Compare libvirt version (libvVersion >= 7.2.0) | ||
| vercomp "$libvVersion" ">=" "7.2.0" | ||
| libvStatus=$? | ||
|
|
||
| if [[ $hvStatus -eq 0 && $libvStatus -eq 0 ]]; then | ||
| log -ne "Success... [ QEMU: $hvVersion Libvirt: $libvVersion apiVersion: $apiVersion ]" | ||
| else | ||
| echo "Failure... Your QEMU version $hvVersion or libvirt version $libvVersion is unsupported. Consider upgrading to the required minimum version of QEMU: 4.2.0 and Libvirt: 7.2.0" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log -ne "Environment Sanity Checks successfully passed" | ||
| } | ||
|
|
||
| ### Operation methods ### | ||
|
|
||
|
|
@@ -79,7 +131,7 @@ backup_stopped_vm() { | |
| name="root" | ||
| for disk in $DISK_PATHS; do | ||
| volUuid="${disk##*/}" | ||
| qemu-img convert -O qcow2 $disk $dest/$name.$volUuid.qcow2 | ||
| qemu-img convert -O qcow2 $disk $dest/$name.$volUuid.qcow2 | tee -a "$logFile" | ||
| name="datadisk" | ||
| done | ||
| sync | ||
|
|
@@ -99,7 +151,16 @@ delete_backup() { | |
| mount_operation() { | ||
| mount_point=$(mktemp -d -t csbackup.XXXXX) | ||
| dest="$mount_point/${BACKUP_DIR}" | ||
| mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS}) | ||
| if [ ${NAS_TYPE} == "cifs" ]; then | ||
| MOUNT_OPTS="${MOUNT_OPTS},nobrl" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nobrl is added in mountBackupDirectory. Is it required here as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had faced the following issue while backing up the VM: As per https://unix.stackexchange.com/questions/622194/how-to-use-qemu-kvm-virtual-machine-disk-image-on-smb-cifs-network-share-permis adding nobrl solved it - so I used that fix. |
||
| fi | ||
| mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS}) | tee -a "$logFile" | ||
| if [ $? -eq 0 ]; then | ||
| log -ne "Successfully mounted ${NAS_TYPE} store" | ||
| else | ||
| echo "Failed to mount ${NAS_TYPE} store" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| function usage { | ||
|
|
@@ -157,6 +218,9 @@ while [[ $# -gt 0 ]]; do | |
| esac | ||
| done | ||
|
|
||
| # Perform Initial sanity checks | ||
| sanity_checks | ||
|
|
||
| if [ "$OP" = "backup" ]; then | ||
| STATE=$(virsh -c qemu:///system list | grep $VM | awk '{print $3}') | ||
| if [ "$STATE" = "running" ]; then | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.