protected Dictionary <uint, DiskInformation> _GetNewDisks(Dictionary <uint, DiskInformation> existingDisks, int expected) { Dictionary <uint, DiskInformation> dictionary = CUtils.Retry <Dictionary <uint, DiskInformation> >(10, this._ConnectDelay, (Func <Dictionary <uint, DiskInformation> >)(() => { this._Logger.Verbose("Rescanning hardware"); this._RescanHardwareWithRetry(); this._Logger.Verbose("Checking for new disks"); Dictionary <uint, DiskInformation> currentDiskInformation = this._GetCurrentDiskInformation(); ConnectVirtualDiskESXCommon.LogDiskInformation(currentDiskInformation, this._Logger); currentDiskInformation.ExceptWith <uint, DiskInformation>((IDictionary <uint, DiskInformation>)existingDisks); this._Logger.FormatVerbose("Check for new disks returns {0}, expecting {1}", (object)currentDiskInformation.Count, (object)expected); if (currentDiskInformation.Count < expected) { this._Logger.Verbose("Not enough disks"); throw new OculiServiceServiceException(0, "Not enough disks added"); } return(currentDiskInformation); })); if (dictionary.Count <= expected) { return(dictionary); } this._Logger.Verbose("Too many disks"); throw new OculiServiceServiceException(0, "Too many disks added"); }
private void _ConnectDrives() { this._Logger.Verbose("Connecting disks"); List <VmDiskInfo> list = ((IEnumerable <OculiServiceVolumePersistedState>) this._Context.JobInfoWrapper.VolumePersistedState).Select <OculiServiceVolumePersistedState, VmDiskInfo>((Func <OculiServiceVolumePersistedState, VmDiskInfo>)(volumeInfo => new VmDiskInfo(true, volumeInfo.VirtualDiskFilename, this._GetSCSIControllerKeyFromHelperBus(volumeInfo), volumeInfo.ApplianceSCSIUnitNumber, 0L, "persistent", (IVimDatastore)null, volumeInfo.PreexistingDiskPath))).ToList <VmDiskInfo>(); while (list.Count > 0) { VmDiskInfo[] diskBatch = this.TakeFirstControllerDisks(list); Dictionary <uint, DiskInformation> currentDiskInformation = this._GetCurrentDiskInformation(); ConnectVirtualDiskESXCommon.LogDiskInformation(currentDiskInformation, this._Logger); CUtils.Retry(this._ConnectAttempts, this._ConnectDelay, (CUtils.Workload)(() => this._AddVirtualDisksToHelper(diskBatch))); this._Logger.Verbose("VMWare has been asked to add these disks: " + string.Join(",", ((IEnumerable <VmDiskInfo>)diskBatch).Select <VmDiskInfo, string>((Func <VmDiskInfo, string>)(vmDiskInfo => vmDiskInfo.File)).ToArray <string>())); try { Dictionary <uint, DiskInformation> newDisks = this._GetNewDisks(currentDiskInformation, diskBatch.Length); int diskBatchSCSIBus = this._GetSCSIBusFromControllerKey(diskBatch); foreach (OculiServiceVolumePersistedState volume in ((IEnumerable <OculiServiceVolumePersistedState>) this._Context.JobInfoWrapper.VolumePersistedState).Where <OculiServiceVolumePersistedState>((Func <OculiServiceVolumePersistedState, bool>)(v => v.ApplianceSCSIBus == diskBatchSCSIBus))) { this._FillVolumeInfoFromNewDisk(newDisks, volume); } } catch (Exception ex) { this._ResetESXConnection(); this._RemoveAllDrives(); throw; } } }
private void _ConnectDrive(OculiServiceVolumePersistedState volumeInfo) { this._Logger.Verbose("Connecting disk."); int keyFromHelperBus = this._GetSCSIControllerKeyFromHelperBus(volumeInfo); VmDiskInfo[] vmDiskInfos = new VmDiskInfo[1] { new VmDiskInfo(true, volumeInfo.VirtualDiskFilename, keyFromHelperBus, volumeInfo.ApplianceSCSIUnitNumber, 0L, "persistent", (IVimDatastore)null, volumeInfo.PreexistingDiskPath) }; Dictionary <uint, DiskInformation> currentDiskInformation = this._GetCurrentDiskInformation(); ConnectVirtualDiskESXCommon.LogDiskInformation(currentDiskInformation, this._Logger); CUtils.Retry(this._ConnectAttempts, this._ConnectDelay, (CUtils.Workload)(() => this._AddVirtualDisksToHelper(vmDiskInfos))); this._Logger.Verbose("VMWare has been asked to add these disks: " + string.Join(",", ((IEnumerable <VmDiskInfo>)vmDiskInfos).Select <VmDiskInfo, string>((Func <VmDiskInfo, string>)(vmDiskInfo => vmDiskInfo.File)).ToArray <string>())); try { this._FillVolumeInfoFromNewDisk(this._GetNewDisks(currentDiskInformation, 1), volumeInfo); } catch (Exception ex) { this._ResetESXConnection(); this._RemoveVirtDiskFromAppliance(volumeInfo); throw; } }