public disposingList <lockableBladeSpec> getAllBladeInfo(Func <bladeSpec, bool> filter, bladeLockType lockTypeRead, bladeLockType lockTypeWrite, bool permitAccessDuringBIOS = false, bool permitAccessDuringDeployment = false, int max = Int32.MaxValue) { disposingList <lockableBladeSpec> toRet = new disposingList <lockableBladeSpec>(); foreach (string bladeIP in getAllBladeIP()) { lockableBladeSpec blade = getBladeByIP(bladeIP, lockTypeRead, lockTypeWrite, true, true); // Filter out anything as requested if (!filter(blade.spec)) { blade.Dispose(); continue; } // Filter out anything we don't have access to right now, due to BIOS or VM deployments if ((!permitAccessDuringDeployment) && blade.spec.vmDeployState != VMDeployStatus.notBeingDeployed && blade.spec.vmDeployState != VMDeployStatus.failed && blade.spec.vmDeployState != VMDeployStatus.readyForDeployment) { blade.Dispose(); continue; } if ((!permitAccessDuringBIOS) && blade.spec.currentlyHavingBIOSDeployed) { blade.Dispose(); continue; } // Have we hit our maximum yet? if (toRet.Count == max) { blade.Dispose(); continue; } // Otherwise, okay. toRet.Add(blade); } return(toRet); }
// FIXME: code duplication public lockableBladeSpec getBladeByIP(string IP, bladeLockType readLock, bladeLockType writeLock, bool permitAccessDuringBIOS = false, bool permitAccessDuringDeployment = false) { bladeLockType origReadLock = readLock | writeLock; readLock = origReadLock; // We need to lock IP addressess, since we're searching by them. readLock = readLock | bladeLockType.lockIPAddresses; readLock = readLock | bladeLockType.lockvmDeployState; readLock = readLock | bladeLockType.lockBIOS; lockableBladeSpec toRet = null; try { toRet = new lockableBladeSpec(IP, readLock, writeLock); string sqlCommand = "select * from bladeOwnership " + "join bladeConfiguration on ownershipKey = bladeConfiguration.ownershipID " + "where bladeIP = $bladeIP"; using (SQLiteCommand cmd = new SQLiteCommand(sqlCommand, conn)) { cmd.Parameters.AddWithValue("$bladeIP", IP); using (SQLiteDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { bladeSpec newSpec = new bladeSpec(conn, reader, readLock, writeLock); toRet.setSpec(newSpec); if ((!permitAccessDuringDeployment) && newSpec.vmDeployState != VMDeployStatus.notBeingDeployed && newSpec.vmDeployState != VMDeployStatus.failed && newSpec.vmDeployState != VMDeployStatus.readyForDeployment) { throw new Exception("Attempt to access blade during VM deployment"); } if ((!permitAccessDuringBIOS) && newSpec.currentlyHavingBIOSDeployed) { throw new Exception("Attempt to access blade during BIOS deployment"); } if ((origReadLock & bladeLockType.lockvmDeployState) == 0 && (writeLock & bladeLockType.lockvmDeployState) == 0) { toRet.downgradeLocks(bladeLockType.lockvmDeployState, bladeLockType.lockNone); } if ((origReadLock & bladeLockType.lockBIOS) == 0 && (writeLock & bladeLockType.lockBIOS) == 0) { toRet.downgradeLocks(bladeLockType.lockBIOS, bladeLockType.lockNone); } leakCheckerInspector.monitorDisposable(toRet); return(toRet); } // No records returned. throw new bladeNotFoundException(); } } } catch (Exception) { if (toRet != null) { toRet.Dispose(); } throw; } }