itsayushpandey commented on code in PR #7712:
URL: https://github.com/apache/cloudstack/pull/7712#discussion_r1260172315


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java:
##########
@@ -0,0 +1,185 @@
+// 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 com.cloud.agent.api.GetUnmanagedInstancesAnswer;
+import com.cloud.agent.api.GetUnmanagedInstancesCommand;
+import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
+import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
+import com.cloud.hypervisor.kvm.resource.LibvirtVMDef;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import org.apache.cloudstack.vm.UnmanagedInstanceTO;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+import org.libvirt.Connect;
+import org.libvirt.Domain;
+import org.libvirt.LibvirtException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+@ResourceWrapper(handles= GetUnmanagedInstancesCommand.class)
+public final class LibvirtGetUnmanagedInstancesCommandWrapper extends 
CommandWrapper<GetUnmanagedInstancesCommand, GetUnmanagedInstancesAnswer, 
LibvirtComputingResource> {
+    private static final Logger s_logger = 
Logger.getLogger(LibvirtPrepareUnmanageVMInstanceCommandWrapper.class);
+
+    @Override
+    public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand 
command, LibvirtComputingResource libvirtComputingResource) {
+        s_logger.info("Need to implement business logic");
+
+        HashMap<String, UnmanagedInstanceTO> unmanagedInstances = new 
HashMap<>();
+        try {
+            final LibvirtUtilitiesHelper libvirtUtilitiesHelper = 
libvirtComputingResource.getLibvirtUtilitiesHelper();
+            final Connect conn = libvirtUtilitiesHelper.getConnection();
+            final List<Domain> domains = getDomains(command, 
libvirtComputingResource, conn);
+
+            for (Domain domain : domains) {
+                UnmanagedInstanceTO instance = 
getUnmanagedInstance(libvirtComputingResource, domain, conn);
+                unmanagedInstances.put(instance.getName(), instance);
+                domain.free();
+            }
+        } catch (Exception e) {
+            s_logger.error("GetUnmanagedInstancesCommand failed due to " + 
e.getMessage());
+            throw new CloudRuntimeException("GetUnmanagedInstancesCommand 
failed due to " + e.getMessage());
+        }
+
+        return new GetUnmanagedInstancesAnswer(command, "True", 
unmanagedInstances);
+    }
+
+    private List<Domain> getDomains(GetUnmanagedInstancesCommand command,
+                                    LibvirtComputingResource 
libvirtComputingResource,
+                                    Connect conn) throws LibvirtException, 
CloudRuntimeException {
+        final List<Domain> domains = new ArrayList<>();
+        final String vmNameCmd = command.getInstanceName();
+        if (StringUtils.isNotBlank(vmNameCmd)) {

Review Comment:
   I think, the vm name is not send as blank when this wrapper is excuted as 
part of importvirtualmachine api.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to