package org.zstack.appliancevm;

import org.springframework.beans.factory.annotation.Autowired;
import org.zstack.core.cloudbus.CloudBus;
import org.zstack.core.cloudbus.CloudBusCallBack;
import org.zstack.core.errorcode.ErrorFacade;
import org.zstack.header.core.Completion;
import org.zstack.header.host.HostConstant;
import org.zstack.header.message.MessageReply;
import org.zstack.header.message.NeedReplyMessage;
import org.zstack.header.vm.VmInstanceSpec;
import org.zstack.header.vm.VmInstanceType;
import org.zstack.header.vm.VmNicInventory;
import org.zstack.kvm.*;
import org.zstack.utils.CollectionUtils;
import org.zstack.utils.Utils;
import org.zstack.utils.function.Function;
import org.zstack.utils.logging.CLogger;
import org.zstack.utils.path.PathUtil;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 */
public class ApplianceVmKvmBackend implements KVMStartVmAddonExtensionPoint {
    private static final CLogger logger = Utils.getLogger(ApplianceVmKvmBackend.class);

    @Autowired
    private CloudBus bus;

    @Override
    public VmInstanceType getVmTypeForAddonExtension() {
        return ApplianceVmFactory.type;
    }

    @Override
    public void addAddon(KVMHostInventory host, VmInstanceSpec spec, KVMAgentCommands.StartVmCmd cmd) {
        if (!spec.getVmInventory().getType().equals(ApplianceVmConstant.APPLIANCE_VM_TYPE)) {
            return;
        }

        KVMAddons.Channel chan = new KVMAddons.Channel();
        chan.setSocketPath(makeChannelSocketPath(spec.getVmInventory().getUuid()));
        chan.setTargetName(String.format("applianceVm.vport"));
        cmd.getAddons().put(chan.NAME, chan);
        logger.debug(String.format("make kvm channel device[path:%s, target:%s]", chan.getSocketPath(), chan.getTargetName()));
    }

    public String makeChannelSocketPath(String apvmuuid) {
        return PathUtil.join(ApplianceVmConstant.KVM_CHANNEL_AGENT_PATH, String.format("applianceVm.%s", apvmuuid));
    }
}

@@ -41,609 +41,249 @@
 org.
-springframework.beans.factory.annotation.Autowired;%0Aimport org.zstack.core.cloudbus.CloudBus;%0Aimport org.zstack.core.cloudbus.CloudBusCallBack;%0Aimport org.zstack.core.errorcode.ErrorFacade;%0Aimport org.zstack.header.core.Completion;%0Aimport org.zstack.header.host.HostConstant;%0Aimport org.zstack.header.message.MessageReply;%0Aimport org.zstack.header.message.NeedReplyMessage;%0Aimport org.zstack.header.vm.VmInstanceSpec;%0Aimport org.zstack.header.vm.VmInstanceType;%0Aimport org.zstack.header.vm.VmNicInventory;%0Aimport org.zstack.kvm.*;%0Aimport org.zstack.utils.CollectionUtils;%0Aimport org.zstack.utils.Utils
+zstack.header.vm.VmInstanceSpec;%0Aimport org.zstack.header.vm.VmInstanceType;%0Aimport org.zstack.kvm.KVMAddons;%0Aimport org.zstack.kvm.KVMAgentCommands;%0Aimport org.zstack.kvm.KVMHostInventory;%0Aimport org.zstack.kvm.KVMStartVmAddonExtensionPoint
 ;%0Aim
@@ -308,25 +308,13 @@
 ils.
-function.Function
+Utils
 ;%0Aim
@@ -396,99 +396,8 @@
 l;%0A%0A
-import java.util.Collection;%0Aimport java.util.List;%0Aimport java.util.concurrent.TimeUnit;%0A%0A
 /**%0A
@@ -571,50 +571,8 @@
 );%0A%0A
-    @Autowired%0A    private CloudBus bus;%0A%0A
     
@@ -986,16 +986,53 @@
 nnel();%0A
+        cmd.setEmulateHyperV(false);%0A
         
@@ -1134,30 +1134,16 @@
 getName(
-String.format(
 %22applian
@@ -1154,17 +1154,16 @@
 .vport%22)
-)
 ;%0A      
@@ -1184,20 +1184,33 @@
 s().put(
-chan
+KVMAddons.Channel
 .NAME, c

Disable EmulateHyperV for ApplianceVM