String vmName = cmd.getVmName();
try {
Connection conn = this.hypervisorResource.getConnection();
VBD isoVBD = null;
// Find the VM
VM vm = this.hypervisorResource.getVM(conn, vmName);
// Find the ISO VDI
VDI isoVDI = this.hypervisorResource.getIsoVDIByURL(conn, vmName, isoURL);
// Find the VM's CD-ROM VBD
Set<VBD> vbds = vm.getVBDs(conn);
for (VBD vbd : vbds) {
String userDevice = vbd.getUserdevice(conn);
Types.VbdType type = vbd.getType(conn);
if (userDevice.equals("3") && type == Types.VbdType.CD) {
isoVBD = vbd;
break;
}
}
if (isoVBD == null) {
throw new CloudRuntimeException("Unable to find CD-ROM VBD for VM: " + vmName);
} else {
// If an ISO is already inserted, eject it
if (isoVBD.getEmpty(conn) == false) {
isoVBD.eject(conn);
}
// Insert the new ISO
isoVBD.insert(conn, isoVDI);
}
return new AttachAnswer(disk);
} catch (XenAPIException e) {