private void insertAEISO(string vmRef, string aeFileName) { HTTPHelper.progressInfo = "获取AE ISO库"; HTTPHelper.progressPercent += 1; SROper srOper = new SROper(); string aeIsoRepoUuid = srOper.getAeISORepoUuid(); XenRef <VBD> cdVBDRef = null; VM vm = VM.get_record(ConnectManager.session, vmRef); List <XenRef <VBD> > vbdRefs = vm.VBDs; foreach (XenRef <VBD> vbdRef in vbdRefs) { VBD vbd = VBD.get_record(ConnectManager.session, vbdRef); if (vbd_type.CD.Equals(vbd.type)) { cdVBDRef = vbdRef; try { VBD.eject(ConnectManager.session, vbdRef); } catch (Exception ex) { log.InfoFormat("设置VBD eject, error=[{0}]", ex.Message); } break; } } if (cdVBDRef == null) { string[] userdevices = VM.get_allowed_VBD_devices(ConnectManager.session, vmRef); if (userdevices != null && userdevices.Length > 0) { VBD vbd = new VBD(); vbd.VM = new XenRef <VM>(vmRef); vbd.type = vbd_type.CD; vbd.mode = vbd_mode.RO; vbd.userdevice = userdevices[0]; vbd.empty = true; cdVBDRef = VBD.create(ConnectManager.session, vbd); log.InfoFormat("WinCenter VM没有虚拟光驱,新建一个VBD成功"); } else { log.InfoFormat("可供使用的VBD标识符列表数为0,不能创建VBD"); } } XenRef <VDI> vdiRef = srOper.getVdiRef(aeIsoRepoUuid, aeFileName); VBD cdVBD = VBD.get_record(ConnectManager.session, cdVBDRef); bool isInsert = VBD.get_allowed_operations(ConnectManager.session, cdVBDRef).Contains(vbd_operations.insert); if (isInsert) { log.InfoFormat("加载AE ISO文件"); VBD.insert(ConnectManager.session, cdVBDRef, vdiRef); HTTPHelper.progressInfo = "加载AE ISO文件"; HTTPHelper.progressPercent += 1; } else { XenRef <VDI> cdVDIRef = cdVBD.VDI; string name = VDI.get_name_label(ConnectManager.session, cdVDIRef); log.InfoFormat("WinCenter VM已插入镜像[{0}],不能插入AE镜像", name); } }