slavkap commented on a change in pull request #3724: URL: https://github.com/apache/cloudstack/pull/3724#discussion_r487055111
########## File path: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFreezeThawVMCommandWrapper.java ########## @@ -0,0 +1,92 @@ +// +// 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.hypervisor.kvm.resource.wrapper; + +import org.apache.log4j.Logger; +import org.libvirt.Connect; +import org.libvirt.Domain; +import org.libvirt.DomainInfo.DomainState; +import org.libvirt.LibvirtException; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.FreezeThawVMAnswer; +import com.cloud.agent.api.FreezeThawVMCommand; +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.script.Script; + +@ResourceWrapper(handles = FreezeThawVMCommand.class) +public class LibvirtFreezeThawVMCommandWrapper extends CommandWrapper<FreezeThawVMCommand, Answer, LibvirtComputingResource> { + + private static final Logger s_logger = Logger.getLogger(LibvirtFreezeThawVMCommandWrapper.class); + + @Override + public Answer execute(FreezeThawVMCommand command, LibvirtComputingResource serverResource) { + String vmName = command.getVmName(); + Domain domain = null; + + try { + final LibvirtUtilitiesHelper libvirtUtilitiesHelper = serverResource.getLibvirtUtilitiesHelper(); + Connect connect = libvirtUtilitiesHelper.getConnection(); + domain = serverResource.getDomain(connect, vmName); + if (domain == null) { + return new FreezeThawVMAnswer(command, false, String.format("Failed to %s due to %s was not found", + command.getOption().toUpperCase(), vmName)); + } + DomainState domainState = domain.getInfo().state ; + if (domainState != DomainState.VIR_DOMAIN_RUNNING) { + return new FreezeThawVMAnswer(command, false, + String.format("%s of VM failed due to vm %s is in %s state", command.getOption().toUpperCase(), + vmName, domainState)); + } + Script cmd = new Script("virsh", s_logger); Review comment: replaced with libvirt's Java API ########## File path: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java ########## @@ -947,25 +953,57 @@ public Answer backupSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(e.toString()); } } else { - final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), s_logger); - command.add("-b", snapshotDisk.getPath()); - command.add("-n", snapshotName); - command.add("-p", snapshotDestPath); - if (isCreatedFromVmSnapshot) { - descName = UUID.randomUUID().toString(); - } - command.add("-t", descName); - final String result = command.execute(); - if (result != null) { - s_logger.debug("Failed to backup snaptshot: " + result); - return new CopyCmdAnswer(result); - } - final File snapFile = new File(snapshotDestPath + "/" + descName); - if(snapFile.exists()){ - size = snapFile.length(); + if (isKVMEnabled) { + OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); + Script sc = new Script("virsh"); + sc.add(String.format("qemu-monitor-command %s '{ \"execute\" : \"query-block-jobs\" }'", vmName)); Review comment: here also is replaced the use of virsh with libvirt's Java API ########## File path: plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java ########## @@ -1456,22 +1496,65 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { final KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath()); if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && !primaryPool.isExternalSnapshot()) { final String vmUuid = vm.getUUIDString(); - final Object[] args = new Object[] {snapshotName, vmUuid}; - final String snapshot = SnapshotXML.format(args); + boolean isKVMEnabled = cmd.getContextParam("kvmsnapshot") != null ? Boolean.parseBoolean(cmd.getContextParam("kvmsnapshot")) : false; + s_logger.debug(String.format("Snapshots on KVM is enabled %s", isKVMEnabled)); + if (isKVMEnabled) { + long size = 0; + OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); + Script sc = new Script("virsh"); + sc.add(String.format("qemu-monitor-command %s '{ \"execute\" : \"query-block\" }'", vmName)); Review comment: replaced with libvirt's Java bindings ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
