protected override void Run() { // First, save changes to the VBD. string vbdServerRef = vbd.SaveChanges(Session, null, null); if (!VM.IsHVM() && vbd.empty) { // PV guest require no further action return; } // Then if we can plug the vbd in, do so... if (vbdServerRef != null && VBD.get_allowed_operations(Session, vbdServerRef).Contains(vbd_operations.plug)) { log.DebugFormat("Attempting to hot plug VBD {0}.", vbd.uuid); this.RelatedTask = XenAPI.VBD.async_plug(Session, vbdServerRef); PollToCompletion(); this.Description = Messages.ATTACHDISKWIZARD_ATTACHED; } else { VM vm = this.Connection.Resolve(vbd.VM); if (vm != null && vm.power_state != vm_power_state.Halted) { if (vbd.type == vbd_type.CD) { ShowUserInstruction?.Invoke(Messages.NEW_DVD_DRIVE_REBOOT); } else { ShowUserInstruction?.Invoke(Messages.NEWDISKWIZARD_MESSAGE); } } } }
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); } }