diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ListHostUsbDevicesResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ListHostUsbDevicesResponse.java index f096852e1e44..e28346bdffb3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ListHostUsbDevicesResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ListHostUsbDevicesResponse.java @@ -1,79 +1,79 @@ -// //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 org.apache.cloudstack.api.response; - -// import com.cloud.host.Host; -// import com.cloud.serializer.Param; -// import com.google.gson.annotations.SerializedName; -// import java.util.List; -// import java.util.Map; -// import org.apache.cloudstack.api.ApiConstants; -// import org.apache.cloudstack.api.BaseResponse; -// import org.apache.cloudstack.api.EntityReference; - - -// @EntityReference(value = Host.class) -// public class ListHostUsbDevicesResponse extends BaseResponse { - -// @SerializedName(ApiConstants.HOSTDEVICES_NAME) -// @Param(description = "Allocated IP address") -// private List hostDevicesName; - -// @SerializedName(ApiConstants.HOSTDEVICES_TEXT) -// @Param(description = "the ID of the pod the IP address belongs to") -// private List hostDevicesText; - -// @SerializedName("vmallocations") -// @Param(description = "Map of device to VM allocations") -// private Map vmAllocations; - -// public ListHostUsbDevicesResponse(List hostDevicesName, List hostDevicesText) { -// this.hostDevicesName = hostDevicesName; -// this.hostDevicesText = hostDevicesText; -// } - -// public ListHostUsbDevicesResponse() { -// super(); -// this.setObjectName("listhostusbdevices"); -// } - -// public List getHostDevicesNames() { -// return hostDevicesName; -// } - -// public List getHostDevicesTexts() { -// return hostDevicesText; -// } - -// public void setHostDevicesNames(List hostDevicesName) { -// this.hostDevicesName = hostDevicesName; -// } - -// public void setHostDevicesTexts(List hostDevicesText) { -// this.hostDevicesText = hostDevicesText; -// } - -// public void setVmAllocations(Map vmAllocations) { -// this.vmAllocations = vmAllocations; -// } - -// public Map getVmAllocations() { -// return this.vmAllocations; -// } - -// } +//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 org.apache.cloudstack.api.response; + +import com.cloud.host.Host; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import java.util.List; +import java.util.Map; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; + + +@EntityReference(value = Host.class) +public class ListHostUsbDevicesResponse extends BaseResponse { + + @SerializedName(ApiConstants.HOSTDEVICES_NAME) + @Param(description = "Allocated IP address") + private List hostDevicesName; + + @SerializedName(ApiConstants.HOSTDEVICES_TEXT) + @Param(description = "the ID of the pod the IP address belongs to") + private List hostDevicesText; + + @SerializedName("vmallocations") + @Param(description = "Map of device to VM allocations") + private Map vmAllocations; + + public ListHostUsbDevicesResponse(List hostDevicesName, List hostDevicesText) { + this.hostDevicesName = hostDevicesName; + this.hostDevicesText = hostDevicesText; + } + + public ListHostUsbDevicesResponse() { + super(); + this.setObjectName("listhostusbdevices"); + } + + public List getHostDevicesNames() { + return hostDevicesName; + } + + public List getHostDevicesTexts() { + return hostDevicesText; + } + + public void setHostDevicesNames(List hostDevicesName) { + this.hostDevicesName = hostDevicesName; + } + + public void setHostDevicesTexts(List hostDevicesText) { + this.hostDevicesText = hostDevicesText; + } + + public void setVmAllocations(Map vmAllocations) { + this.vmAllocations = vmAllocations; + } + + public Map getVmAllocations() { + return this.vmAllocations; + } + +} diff --git a/core/src/main/java/com/cloud/resource/ServerResourceBase.java b/core/src/main/java/com/cloud/resource/ServerResourceBase.java index f2085449e486..033f0edc3e50 100644 --- a/core/src/main/java/com/cloud/resource/ServerResourceBase.java +++ b/core/src/main/java/com/cloud/resource/ServerResourceBase.java @@ -45,8 +45,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.Logger; -// import org.json.JSONArray; -// import org.json.JSONObject; import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; @@ -57,9 +55,6 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import com.cloud.agent.api.ListHostDeviceAnswer; -// import com.cloud.agent.api.ListHostLunDeviceAnswer; -// import com.cloud.agent.api.ListHostUsbDeviceAnswer; -// import com.cloud.agent.api.ListHostLunDeviceCommand; public abstract class ServerResourceBase implements ServerResource { protected Logger logger = LogManager.getLogger(getClass()); @@ -518,45 +513,4 @@ public boolean start() { public boolean stop() { return true; } - - // protected Answer updateHostUsbDevices(Command command, String vmName, String xmlConfig, boolean isAttach) { - // try { - // // 임시 XML 파일 생성 - // String tempXmlPath = "/tmp/usb_device_" + System.currentTimeMillis() + ".xml"; - // try (PrintWriter writer = new PrintWriter(tempXmlPath)) { - // writer.write(xmlConfig); - // } - // logger.info("Generated temporary XML file: {}", tempXmlPath); - // // virsh 명령어 실행 - // Script virshCmd = new Script("virsh"); - // if (isAttach) { - // virshCmd.add("attach-device", vmName, tempXmlPath); - // } else { - // virshCmd.add("detach-device", vmName, tempXmlPath); - // } - - // String result = virshCmd.execute(); - - // // 임시 파일 삭제 - // File tempFile = new File(tempXmlPath); - // if (tempFile.exists() && !tempFile.delete()) { - // logger.warn("Failed to delete temporary file: {}", tempXmlPath); - // } - - // if (result != null) { - // String action = isAttach ? "attach" : "detach"; - // logger.error("Failed to {} USB device: {}", action, result); - // return new Answer(command, false, "Failed to " + action + " USB device: " + result); - // } - - // String action = isAttach ? "attached to" : "detached from"; - // logger.info("Successfully {} USB device {} VM {}", action, tempXmlPath, vmName); - // return new Answer(command, true, null); - - // } catch (Exception e) { - // String action = isAttach ? "attaching" : "detaching"; - // logger.error("Error {} USB device: {}", action, e.getMessage(), e); - // return new Answer(command, false, "Error " + action + " USB device: " + e.getMessage()); - // } - // } } \ No newline at end of file diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index 2a9790f57fd9..d6a12da4f263 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -180,10 +180,7 @@ import org.apache.cloudstack.api.command.admin.outofbandmanagement.IssueOutOfBandManagementPowerActionCmd; import org.apache.cloudstack.api.command.admin.outofbandmanagement.LicenseCheckCmd; import org.apache.cloudstack.api.command.admin.outofbandmanagement.ListHostDevicesCmd; -// import org.apache.cloudstack.api.command.admin.outofbandmanagement.ListHostLunDevicesCmd; -// import org.apache.cloudstack.api.command.admin.outofbandmanagement.ListHostUsbDevicesCmd; import org.apache.cloudstack.api.command.admin.outofbandmanagement.UpdateHostDevicesCmd; -// import org.apache.cloudstack.api.command.admin.outofbandmanagement.UpdateHostLunDevicesCmd; // import org.apac import org.apache.cloudstack.api.command.admin.pod.CreatePodCmd; import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd; @@ -683,15 +680,9 @@ import com.cloud.agent.api.GetVncPortCommand; import com.cloud.agent.api.ListHostDeviceAnswer; import com.cloud.agent.api.ListHostDeviceCommand; -// import com.cloud.agent.api.ListHostLunDeviceAnswer; -// import com.cloud.agent.api.ListHostLunDeviceCommand; -// import com.cloud.agent.api.ListHostUsbDeviceAnswer; -// import com.cloud.agent.api.ListHostUsbDeviceCommand; import com.cloud.agent.api.PatchSystemVmAnswer; import com.cloud.agent.api.PatchSystemVmCommand; -// import com.cloud.agent.api.PatchSystemVmCommand; -// import com.cloud.agent.api.UpdateHostUsbDeviceAnswer; -// import com.cloud.agent.api.UpdateHostUsbDeviceCommand; +import com.cloud.agent.api.PatchSystemVmCommand; import com.cloud.agent.api.proxy.AllowConsoleAccessCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.manager.Commands; @@ -2197,161 +2188,6 @@ public Pair, Integer> searchForPods(final ListPodsByCmd cmd) return new Pair<>(result.first(), result.second()); } - - // @Override - // public ListResponse listHostUsbDevices(ListHostUsbDevicesCmd cmd) { - // Long id = cmd.getId(); - // HostVO hostVO = _hostDao.findById(id); - // if (hostVO == null) { - // throw new CloudRuntimeException("Host not found with ID: " + id); - // } - - // ListHostUsbDeviceCommand usbCmd = new ListHostUsbDeviceCommand(id); - // Answer answer; - // try { - // answer = _agentMgr.send(hostVO.getId(), usbCmd); - // } catch (Exception e) { - // String errorMsg = "Error sending ListHostUsbDeviceCommand: " + e.getMessage(); - // logger.error(errorMsg, e); - // throw new CloudRuntimeException(errorMsg, e); - // } - - // if (answer == null) { - // throw new CloudRuntimeException("Answer is null"); - // } - // if (!answer.getResult()) { - // String errorDetails = (answer.getDetails() != null) ? answer.getDetails() - // : "No additional details available"; - // String errorMsg = "Answer result is false. Details: " + errorDetails; - // logger.error(errorMsg); - // throw new CloudRuntimeException(errorMsg); - // } - // if (!(answer instanceof ListHostUsbDeviceAnswer)) { - // throw new CloudRuntimeException("Answer is not an instance of listHostUsbDeviceAnswer"); - // } - - // ListHostUsbDeviceAnswer usbAnswer = (ListHostUsbDeviceAnswer) answer; - // if (!usbAnswer.isSuccessMessage()) { - // throw new IllegalArgumentException("Failed to list VM USB objects."); - // } - - // List responses = new ArrayList<>(); - // ListResponse listResponse = new ListResponse<>(); - - // List hostDevicesTexts = usbAnswer.getHostDevicesTexts(); - - // List hostDevicesNames = new ArrayList<>(); - // List pciDescriptions = new ArrayList<>(); - - // for (String hostDevicesText : hostDevicesTexts) { - // String[] parts = hostDevicesText.split(": ", 2); - // if (parts.length == 2) { - // hostDevicesNames.add(parts[0].trim()); - // pciDescriptions.add(parts[1].trim()); - // } else { - // logger.warn("Unexpected PCI info format: " + hostDevicesText); - // } - // } - - // ListHostUsbDevicesResponse response = new ListHostUsbDevicesResponse(); - // response.setHostDevicesNames(hostDevicesNames); - // response.setHostDevicesTexts(pciDescriptions); - - // // VM 할당 정보 확인 및 업데이트 - // Map vmAllocations = new HashMap<>(); - // for (String deviceName : hostDevicesNames) { - // // 현재 할당 상태 확인 - // String currentAllocation = getDeviceAllocation(id, deviceName); - - // if (currentAllocation != null) { - // // 이미 할당된 경우에만 맵에 추가 - // vmAllocations.put(deviceName, currentAllocation); - // } - // } - // response.setVmAllocations(vmAllocations); - - // responses.add(response); - // listResponse.setResponses(responses); - // return listResponse; - // } - - // @Override - // public ListResponse listHostLunDevices(ListHostLunDevicesCmd cmd) { - // Long id = cmd.getId(); - // HostVO hostVO = _hostDao.findById(id); - // if (hostVO == null) { - // throw new CloudRuntimeException("Host not found with ID: " + id); - // } - - // ListHostLunDeviceCommand lunCmd = new ListHostLunDeviceCommand(id); - // Answer answer; - // try { - // answer = _agentMgr.send(hostVO.getId(), lunCmd); - // } catch (Exception e) { - // String errorMsg = "Error sending ListHostLunDeviceCommand: " + e.getMessage(); - // logger.error(errorMsg, e); - // throw new CloudRuntimeException(errorMsg, e); - // } - - // validateAnswer(answer); - // ListHostLunDeviceAnswer lunAnswer = (ListHostLunDeviceAnswer) answer; - - // ListResponse listResponse = new ListResponse<>(); - // List responses = new ArrayList<>(); - - // ListHostLunDevicesResponse response = createResponse(lunAnswer, id); - // responses.add(response); - - // listResponse.setResponses(responses); - // return listResponse; - // } - - // private void validateAnswer(Answer answer) { - // if (answer == null) { - // throw new CloudRuntimeException("Answer is null"); - // } - // if (!answer.getResult()) { - // String errorDetails = answer.getDetails() != null ? answer.getDetails() - // : "No additional details available"; - // throw new CloudRuntimeException("Answer result is false. Details: " + errorDetails); - // } - // if (!(answer instanceof ListHostLunDeviceAnswer)) { - // throw new CloudRuntimeException("Answer is not an instance of ListHostLunDeviceAnswer"); - // } - // } - - // private ListHostLunDevicesResponse createResponse(ListHostLunDeviceAnswer lunAnswer, Long hostId) { - // ListHostLunDevicesResponse response = new ListHostLunDevicesResponse(); - - // List deviceNames = new ArrayList<>(); - // List deviceDescriptions = new ArrayList<>(); - // List hasPartitions = lunAnswer.getHasPartitions(); - - // for (int i = 0; i < lunAnswer.getHostDevicesTexts().size(); i++) { - // String deviceText = lunAnswer.getHostDevicesTexts().get(i); - // String deviceName = lunAnswer.getHostDevicesNames().get(i); - // boolean hasPartition = hasPartitions.get(i); - - // deviceNames.add(deviceName); - // deviceDescriptions.add(deviceText); - // response.addPartitionInfo(deviceName, hasPartition); - // } - - // response.setHostDevicesNames(deviceNames); - // response.setHostDevicesTexts(deviceDescriptions); - - // Map vmAllocations = new HashMap<>(); - // for (String deviceName : deviceNames) { - // String allocation = getDeviceAllocation(hostId, deviceName); - // if (allocation != null) { - // vmAllocations.put(deviceName, allocation); - // } - // } - // response.setVmAllocations(vmAllocations); - - // return response; - // } - @Override public ListResponse listHostDevices(ListHostDevicesCmd cmd) { Long id = cmd.getId(); @@ -2547,277 +2383,6 @@ public String getDeviceAllocation(Long hostId, String deviceName) { return vmAllocationDetail != null ? vmAllocationDetail.getValue() : null; } - // VM에 디바이스가 할당될 때 호출되는 메서드 - // @Override - // public ListResponse updateHostUsbDevices(UpdateHostUsbDevicesCmd cmd) { - // Long hostId = cmd.getHostId(); - // String hostDeviceName = cmd.getHostDeviceName(); - // Long vmId = cmd.getVirtualMachineId(); - // String xmlConfig = cmd.getXmlConfig(); - - // // 호스트 존재 여부 확인 - // HostVO hostVO = _hostDao.findById(hostId); - // if (hostVO == null) { - // throw new CloudRuntimeException("Host not found with ID: " + hostId); - // } - - // // VM 존재 여부 확인 (vmId가 null이 아닌 경우) - // VMInstanceVO vmInstance = null; - // if (vmId != null) { - // vmInstance = _vmInstanceDao.findById(vmId); - // if (vmInstance == null) { - // throw new CloudRuntimeException("VM not found with ID: " + vmId); - // } - // } - - // logger.info("Updating host device allocation - hostId: {}, hostDeviceName: {}, virtualMachineId: {}", - // hostId, hostDeviceName, vmId); - - // try { - // DetailVO currentAllocation = _hostDetailsDao.findDetail(hostId, hostDeviceName); - // String vmInternalName = null; - // boolean isAttach = (vmId != null); - - // if (!isAttach) { - // // 디바이스 할당 해제 - // String currentVmId = cmd.getCurrentVmId(); - // if (currentAllocation != null && currentVmId != null) { - // // 현재 할당된 VM이 요청된 VM과 일치하는지 확인 - // if (!currentVmId.equals(currentAllocation.getValue())) { - // throw new CloudRuntimeException("Device is allocated to a different VM"); - // } - // VMInstanceVO vm = _vmInstanceDao.findById(Long.parseLong(currentVmId)); - // if (vm != null) { - // vmInternalName = vm.getInstanceName(); - // } - // } - // } else { - // // 새로운 할당 - // if (currentAllocation != null) { - // throw new CloudRuntimeException("Device is already allocated to VM: " + currentAllocation.getValue()); - // } - // vmInternalName = vmInstance.getInstanceName(); - // } - - // if (vmInternalName == null) { - // throw new CloudRuntimeException("Unable to get VM instance name"); - // } - - // // 호스트에 명령 전송 - // UpdateHostUsbDeviceCommand usbCmd = new UpdateHostUsbDeviceCommand(vmInternalName, xmlConfig, isAttach); - // Answer answer; - // try { - // answer = _agentMgr.send(hostVO.getId(), usbCmd); - // } catch (Exception e) { - // String errorMsg = "Error sending UpdateHostUsbDeviceCommand: " + e.getMessage(); - // logger.error(errorMsg, e); - // throw new CloudRuntimeException(errorMsg, e); - // } - - // if (answer == null) { - // throw new CloudRuntimeException("Answer is null"); - // } - // if (!answer.getResult()) { - // String errorDetails = (answer.getDetails() != null) ? - // answer.getDetails() : "No additional details available"; - // throw new CloudRuntimeException("Failed to update USB device. Details: " + errorDetails); - // } - // if (!(answer instanceof UpdateHostUsbDeviceAnswer)) { - // throw new CloudRuntimeException("Answer is not an instance of UpdateHostUsbDeviceAnswer"); - // } - - // UpdateHostUsbDeviceAnswer usbAnswer = (UpdateHostUsbDeviceAnswer) answer; - // if (!usbAnswer.isSuccessMessage()) { - // throw new CloudRuntimeException("Failed to update USB device for VM: " + usbAnswer.getVmName()); - // } - - // // DB 업데이트 - // if (!isAttach) { - // // 할당 해제 - // if (currentAllocation != null) { - // _hostDetailsDao.remove(currentAllocation.getId()); - // } - // } else { - // // 새로운 할당 - // DetailVO detail = new DetailVO(hostId, hostDeviceName, vmId.toString()); - // _hostDetailsDao.persist(detail); - // } - - // // 응답 생성 - // ListResponse response = new ListResponse<>(); - // List responses = new ArrayList<>(); - // UpdateHostUsbDevicesResponse deviceResponse = new UpdateHostUsbDevicesResponse(); - - // DetailVO allocation = _hostDetailsDao.findDetail(hostId, hostDeviceName); - // deviceResponse.setHostDeviceName(hostDeviceName); - // deviceResponse.setVirtualMachineId(allocation != null ? allocation.getValue() : null); - // deviceResponse.setAllocated(allocation != null); - - // responses.add(deviceResponse); - // response.setResponses(responses); - - // return response; - - // } catch (Exception e) { - // logger.error("Error during USB device allocation/deallocation - hostDeviceName: {}, error: {}", - // hostDeviceName, e.getMessage(), e); - // throw new CloudRuntimeException("Failed to update USB device allocation: " + e.getMessage(), e); - // } - // } - // VM에 디바이스가 할당될 때 호출되는 메서드 - // @Override - // public ListResponse updateHostLunDevices(UpdateHostLunDevicesCmd cmd) { - // Long hostId = cmd.getHostId(); - // String hostDeviceName = cmd.getHostDeviceName(); - // Long vmId = cmd.getVirtualMachineId(); - // String xmlConfig = cmd.getXmlConfig(); - - // // 호스트 존재 여부 확인 - // HostVO hostVO = _hostDao.findById(hostId); - // if (hostVO == null) { - // throw new CloudRuntimeException("Host not found with ID: " + hostId); - // } - - // // VM 존재 여부 확인 (vmId가 null이 아닌 경우) - // VMInstanceVO vmInstance = null; - // if (vmId != null) { - // vmInstance = _vmInstanceDao.findById(vmId); - // if (vmInstance == null) { - // throw new CloudRuntimeException("VM not found with ID: " + vmId); - // } - // } - - // logger.info("Updating host device allocation - hostId: {}, hostDeviceName: {}, virtualMachineId: {}", - // hostId, hostDeviceName, vmId); - - // try { - // DetailVO currentAllocation = _hostDetailsDao.findDetail(hostId, hostDeviceName); - - // if (vmId == null) { - // // 디바이스 할당 해제 - // if (currentAllocation != null) { - // Set allocatedVmIds = new HashSet<>(Arrays.asList(currentAllocation.getValue().split(","))); - // String currentVmId = cmd.getCurrentVmId(); - - // if (currentVmId != null && allocatedVmIds.contains(currentVmId)) { - // VMInstanceVO vm = _vmInstanceDao.findById(Long.parseLong(currentVmId)); - // if (vm != null) { - // String vmInternalName = vm.getInstanceName(); - - // // LUN 디바이스 분리 로직 - // String tempXmlPath = "/tmp/lun_device_" + hostDeviceName.replace("/", "_") + "_" + - // currentVmId + "_" + System.currentTimeMillis() + ".xml"; - // try { - // try (PrintWriter writer = new PrintWriter(tempXmlPath)) { - // writer.write(xmlConfig); - // } - - // Script detachCmd = new Script("/usr/bin/virsh"); - // detachCmd.add("detach-device", vmInternalName, tempXmlPath); - // String result = detachCmd.execute(); - - // File tempFile = new File(tempXmlPath); - // if (tempFile.exists() && !tempFile.delete()) { - // logger.warn("Failed to delete temporary file: {}", tempXmlPath); - // } - - // if (result != null) { - // throw new CloudRuntimeException("Failed to detach LUN device: " + result); - // } - // logger.info("Successfully detached LUN device from VM {}", vmInternalName); - // } catch (Exception e) { - // logger.error("Error detaching LUN device: " + e.getMessage(), e); - // throw new CloudRuntimeException("Failed to detach LUN device: " + e.getMessage()); - // } - // } - - // // VM ID 제거 후 업데이트 - // allocatedVmIds.remove(currentVmId); - // if (allocatedVmIds.isEmpty()) { - // _hostDetailsDao.remove(currentAllocation.getId()); - // } else { - // Map details = new HashMap<>(); - // details.put(hostDeviceName, String.join(",", allocatedVmIds)); - // _hostDetailsDao.persist(hostId, details); - // } - // } - // } - // } else { - // // 새로운 할당 - // if (vmInstance == null) { - // throw new CloudRuntimeException("VM instance cannot be null for device allocation"); - // } - - // Set allocatedVmIds = new HashSet<>(); - // if (currentAllocation != null) { - // allocatedVmIds.addAll(Arrays.asList(currentAllocation.getValue().split(","))); - // } - - // if (allocatedVmIds.contains(vmId.toString())) { - // throw new CloudRuntimeException("VM " + vmInstance.getInstanceName() + " is already allocated to this device"); - // } - - // String vmInternalName = vmInstance.getInstanceName(); - // if (vmInternalName == null) { - // throw new CloudRuntimeException("Unable to get VM instance name"); - // } - - // // LUN 디바이스 연결 로직 - // String tempXmlPath = "/tmp/lun_device_" + hostDeviceName.replace("/", "_") + "_" + - // vmId + "_" + System.currentTimeMillis() + ".xml"; - // try { - // try (PrintWriter writer = new PrintWriter(tempXmlPath)) { - // writer.write(xmlConfig); - // } - - // Script attachCmd = new Script("/usr/bin/virsh"); - // attachCmd.add("attach-device", vmInternalName, tempXmlPath); - // String result = attachCmd.execute(); - - // File tempFile = new File(tempXmlPath); - // if (tempFile.exists() && !tempFile.delete()) { - // logger.warn("Failed to delete temporary file: {}", tempXmlPath); - // } - - // if (result != null) { - // throw new CloudRuntimeException("Failed to attach LUN device: " + result); - // } - // logger.info("Successfully attached LUN device to VM {}", vmInternalName); - // } catch (Exception e) { - // logger.error("Error attaching LUN device: " + e.getMessage(), e); - // throw new CloudRuntimeException("Failed to attach LUN device: " + e.getMessage()); - // } - - // // 새로운 VM ID 추가 - // allocatedVmIds.add(vmId.toString()); - - // // DB에 할당 정보 저장 - // Map details = new HashMap<>(); - // details.put(hostDeviceName, String.join(",", allocatedVmIds)); - // _hostDetailsDao.persist(hostId, details); - // } - - // // 응답 생성 - // ListResponse response = new ListResponse<>(); - // List responses = new ArrayList<>(); - // UpdateHostLunDevicesResponse deviceResponse = new UpdateHostLunDevicesResponse(); - - // DetailVO allocation = _hostDetailsDao.findDetail(hostId, hostDeviceName); - // deviceResponse.setHostDeviceName(hostDeviceName); - // deviceResponse.setVirtualMachineId(allocation != null ? allocation.getValue() : null); - // deviceResponse.setAllocated(allocation != null && allocation.getValue() != null); - - // responses.add(deviceResponse); - // response.setResponses(responses); - - // return response; - // } catch (Exception e) { - // logger.error("Error during LUN device allocation/deallocation - hostDeviceName: {}, error: {}", - // hostDeviceName, e.getMessage(), e); - // throw new CloudRuntimeException("Failed to update LUN device allocation: " + e.getMessage(), e); - // } - // } - @Override public Pair, Integer> searchForVlans(final ListVlanIpRangesCmd cmd) { // If an account name and domain ID are specified, look up the account