public disposingList <lockableVMSpec> getAllVMInfo(Func <vmSpec, bool> filter, bladeLockType lockTypeRead, bladeLockType lockTypeWrite) { disposingList <lockableVMSpec> toRet = new disposingList <lockableVMSpec>(); foreach (string bladeIP in getAllVMIP()) { lockableVMSpec VM = getVMByIP(bladeIP, lockTypeRead, lockTypeWrite); if (filter(VM.spec)) { toRet.Add(VM); } else { VM.Dispose(); } } return(toRet); }
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); }
public disposingList <lockableVMSpec> getVMByVMServerIP(lockableBladeSpec blade, bladeLockType readLock, bladeLockType writeLock) { disposingList <lockableVMSpec> toRet = new disposingList <lockableVMSpec>(); if ((blade.getCurrentLocks().read & bladeLockType.lockVMCreation) == 0) { throw new Exception("lockVMCreation required on vmserver passed to getVMByVMServerIP"); } // We need to lock IP addressess on the VMs, since we lock by them. readLock = readLock | bladeLockType.lockIPAddresses; // Since we hold lockVMCreation, we can assume no new VMs will be added or removed to/from this blade. We assume that // VM IP addresses will never change, except during initialization, when they go from null - we just drop any with a // NULL IP address. Dictionary <string, lockableVMSpec> VMNames = new Dictionary <string, lockableVMSpec>(); string sqlCommand = "select VMIP from vmConfiguration " + "join bladeConfiguration on parentbladeID = bladeConfigKey " + "where bladeIP = $vmServerIP"; using (SQLiteCommand cmd = new SQLiteCommand(sqlCommand, conn)) { cmd.Parameters.AddWithValue("$vmServerIP", blade.spec.bladeIP); using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string VMName = reader[0].ToString(); if (!String.IsNullOrEmpty(VMName)) { VMNames.Add(VMName, new lockableVMSpec(VMName, readLock, writeLock)); } } } } try { // Now read each from the DB, now that we hold the lock for each. foreach (KeyValuePair <string, lockableVMSpec> kvp in VMNames) { string vmName = kvp.Key; lockableVMSpec vmSpec = kvp.Value; string sql_getVM = "select bladeOwnership.*, vmConfiguration.* from vmConfiguration " + " join bladeOwnership on bladeOwnership.ownershipKey = vmConfiguration.ownershipID " + " join bladeConfiguration on parentbladeID = bladeConfigKey " + " where VMIP = $vmIP"; using (SQLiteCommand cmd = new SQLiteCommand(sql_getVM, conn)) { cmd.Parameters.AddWithValue("$vmIP", vmName); using (SQLiteDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { throw new Exception("VM disappeared, even though we hold lockVMCreation on the parent!"); } vmSpec.setSpec(new vmSpec(conn, reader, readLock, writeLock)); toRet.Add(vmSpec); } } } } catch (Exception) { foreach (KeyValuePair <string, lockableVMSpec> kvp in VMNames) { kvp.Value.Dispose(); } throw; } return(toRet); }