Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
64db486d5a259de2cb7746dfb0eab1ccf9d343e7dcf2f81c8be9eba3585126bd024a965c23f4b0760ef5bf19dea54300805bfed06c087de43ae3601d6181d559464be862211c7caa908482c2c975e5c0cf6f0ba69a6e0e35e393489714aaeFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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 @@ public boolean deleteKubernetesCluster(DeleteKubernetesClusterCmd cmd) throws Cl | ||
| } | ||
| List<KubernetesClusterVmMapVO> vmMapList = kubernetesClusterVmMapDao.listByClusterId(kubernetesClusterId); | ||
| List<VMInstanceVO> vms = vmMapList.stream().map(vmMap -> vmInstanceDao.findById(vmMap.getVmId())).collect(Collectors.toList()); | ||
| if (checkIfVmsAssociatedWithBackupOffering(vms)) { | ||
| throw new CloudRuntimeException("Unable to delete Kubernetes cluster, as node(s) are associated to a backup offering"); | ||
| } | ||
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 Boolean doInTransaction(TransactionStatus status) { | ||
| } | ||
| } | ||
| public static boolean checkIfVmsAssociatedWithBackupOffering(List<VMInstanceVO> vms) { | ||
| for(VMInstanceVO vm : vms) { | ||
| if (Objects.nonNull(vm.getBackupOfferingId())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| @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" | ||
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. nobrl is added in mountBackupDirectory. Is it required here as well? ContributorAuthor 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can these be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure - but just added a defensive check