Github user ustcweizhou commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/977#discussion_r43734962
  
    --- Diff: 
plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java
 ---
    @@ -0,0 +1,108 @@
    +//
    +// 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.cloudstack.storage.to.PrimaryDataStoreTO;
    +import org.apache.cloudstack.storage.to.VolumeObjectTO;
    +import org.apache.log4j.Logger;
    +import org.libvirt.Connect;
    +import org.libvirt.Domain;
    +import org.libvirt.DomainSnapshot;
    +import org.libvirt.LibvirtException;
    +
    +import com.cloud.agent.api.Answer;
    +import com.cloud.agent.api.DeleteVMSnapshotAnswer;
    +import com.cloud.agent.api.DeleteVMSnapshotCommand;
    +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
    +import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
    +import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
    +import com.cloud.resource.CommandWrapper;
    +import com.cloud.resource.ResourceWrapper;
    +import com.cloud.storage.Volume;
    +import com.cloud.utils.script.Script;
    +
    +@ResourceWrapper(handles =  DeleteVMSnapshotCommand.class)
    +public final class LibvirtDeleteVMSnapshotCommandWrapper extends 
CommandWrapper<DeleteVMSnapshotCommand, Answer, LibvirtComputingResource> {
    +
    +    private static final Logger s_logger = 
Logger.getLogger(LibvirtDeleteVMSnapshotCommandWrapper.class);
    +
    +    @Override
    +    public Answer execute(final DeleteVMSnapshotCommand cmd, final 
LibvirtComputingResource libvirtComputingResource) {
    +        String vmName = cmd.getVmName();
    +
    +        final KVMStoragePoolManager storagePoolMgr = 
libvirtComputingResource.getStoragePoolMgr();
    +        Domain dm = null;
    +        try {
    +            final LibvirtUtilitiesHelper libvirtUtilitiesHelper = 
libvirtComputingResource.getLibvirtUtilitiesHelper();
    +            Connect conn = libvirtUtilitiesHelper.getConnection();
    +            dm = libvirtComputingResource.getDomain(conn, vmName);
    +
    +            DomainSnapshot snapshot = null;
    +            try {
    +                snapshot = 
dm.snapshotLookupByName(cmd.getTarget().getSnapshotName());
    +            } catch (LibvirtException e) {
    +                s_logger.warn("Cannot find vmSnapshot with name: " + 
cmd.getTarget().getSnapshotName());
    +                return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
    +            }
    +
    +            snapshot.delete(0); // only remove this snapshot, not children
    +
    +            return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs());
    +        } catch (LibvirtException e) {
    +            String msg = " Delete VM snapshot failed due to " + 
e.toString();
    --- End diff --
    
    This is because I wanted to display different error/warning message when 
exceptions are thown on snapshotLookupByName and snapshot.delete(0).
    It looks not necessary. I will modify it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to