public hypervisorCollection <hypSpec_iLo> requestAsManyHypervisorsAsPossible(string snapshotName) { initialiseIfNeeded(); using (BladeDirectorServices director = new BladeDirectorServices(machinePools.bladeDirectorURL)) { int nodeCount = director.svc.getAllBladeIP().Length; hypervisorCollection <hypSpec_iLo> toRet = new hypervisorCollection <hypSpec_iLo>(); DateTime deadline = DateTime.Now + TimeSpan.FromMinutes(60); try { for (int i = 0; i < nodeCount; i++) { resultAndBladeName res = director.svc.RequestAnySingleNode(); resultAndBladeName progress = director.waitForSuccess(res, deadline - DateTime.Now); bladeSpec bladeConfig = director.svc.getBladeByIP_withoutLocking(progress.bladeName); resultAndWaitToken snapRes = director.svc.selectSnapshotForBladeOrVM(progress.bladeName, snapshotName); director.waitForSuccess(snapRes, TimeSpan.FromMinutes(3)); snapshotDetails snapshot = director.svc.getCurrentSnapshotDetails(progress.bladeName); userDesc cred = bladeConfig.credentials.First(); NASParams nas = director.svc.getNASParams(); hypSpec_iLo spec = new hypSpec_iLo( bladeConfig.bladeIP, cred.username, cred.password, bladeConfig.iLOIP, bladeConfig.iLoUsername, bladeConfig.iLoPassword, nas.IP, nas.username, nas.password, snapshot.friendlyName, snapshot.path, bladeConfig.kernelDebugPort, bladeConfig.kernelDebugKey ); ipUtils.ensurePortIsFree(bladeConfig.kernelDebugPort); bladeDirectedHypervisor_iLo newHyp = new bladeDirectedHypervisor_iLo(spec); newHyp.setDisposalCallback(onDestruction); if (!toRet.TryAdd(bladeConfig.bladeIP, newHyp)) { throw new Exception(); } } return(toRet); } catch (Exception) { toRet.Dispose(); throw; } } }
public void willProvisionBlade() { using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI)) { machinePools.bladeDirectorURL = svc.servicesURL; string hostip = "1.2.3.4"; //string debuggerHost = testUtils.getBestRouteTo(IPAddress.Parse("172.17.129.131")).ToString(); // We will be using this blade for our tests. bladeSpec spec = svc.svcDebug.createBladeSpecForXDLNode(31, "xdl.hacks.the.planet", bladeLockType.lockAll, bladeLockType.lockAll); spec.friendlyName = "newBlade"; svc.svcDebug.initWithBladesFromBladeSpec(new[] { spec }, false, NASFaultInjectionPolicy.retunSuccessful); resultAndBladeName res = svc.svcDebug._RequestAnySingleNode(hostip); testUtils.waitForSuccess(svc, res, TimeSpan.FromMinutes(15)); string bladeName = res.bladeName; resultAndWaitToken res2 = svc.svcDebug._selectSnapshotForBladeOrVM(hostip, bladeName, "discord"); testUtils.waitForSuccess(svc, res2, TimeSpan.FromMinutes(30)); // Okay, we have our blade allocated now. bladeSpec createdBlade = svc.svc.getBladeByIP_withoutLocking(bladeName); snapshotDetails snap = svc.svc.getCurrentSnapshotDetails(bladeName); NASParams nas = svc.svc.getNASParams(); using (hypervisor foo = utils.createHypForBlade(createdBlade, snap, nas)) { foo.powerOn(new cancellableDateTime(TimeSpan.FromMinutes(5))); // Check that debugging has been provisioned correctly executionResult bcdEditRes = foo.startExecutable("bcdedit", "/dbgsettings"); try { Assert.AreEqual(0, bcdEditRes.resultCode); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "key\\s*xdl.hacks.the.planet"), "bcdedit did not match regex for debug key"); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "debugtype\\s*NET"), "bcdedit did not match regex for debug type"); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "hostip\\s*1.2.3.4"), "bcdedit did not match regex for debug host"); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "port\\s*53101"), "bcdedit did not match regex for debug port"); } catch (AssertFailedException) { Debug.WriteLine("return code " + bcdEditRes.resultCode); Debug.WriteLine("stdout " + bcdEditRes.stdout); Debug.WriteLine("stderr " + bcdEditRes.stderr); } executionResult getNameRes = foo.startExecutable("echo %COMPUTERNAME%", ""); try { Assert.AreEqual(0, getNameRes.resultCode); Assert.AreSame(getNameRes.stdout.ToLower(), "newBlade".Trim().ToLower(), "machine name was incorrect"); } catch (AssertFailedException) { Debug.WriteLine("return code " + bcdEditRes.resultCode); Debug.WriteLine("stdout " + bcdEditRes.stdout); Debug.WriteLine("stderr " + bcdEditRes.stderr); } } } }
public void willProvisionVM() { using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI)) { machinePools.bladeDirectorURL = svc.servicesURL; string hostip = "1.2.3.4"; // We will be using this blade for our tests. bladeSpec spec = svc.svcDebug.createBladeSpecForXDLNode(31, "xdl.hacks.the.planet", bladeLockType.lockAll, bladeLockType.lockAll); svc.svcDebug.initWithBladesFromBladeSpec(new[] { spec }, false, NASFaultInjectionPolicy.retunSuccessful); string debuggerHost = ipUtils.getBestRouteTo(IPAddress.Parse(spec.bladeIP)).ToString(); VMSoftwareSpec sw = new VMSoftwareSpec() { debuggerHost = debuggerHost, debuggerKey = "a.b.c.d", debuggerPort = 60234 }; VMHardwareSpec hw = new VMHardwareSpec() { cpuCount = 1, memoryMB = 4096 }; resultAndBladeName res = svc.svcDebug._requestAnySingleVM(hostip, hw, sw); testUtils.waitForSuccess(svc, res, TimeSpan.FromMinutes(15)); string VMName = res.bladeName; // Okay, we have our new VM allocated now. vmSpec createdBlade = svc.svc.getVMByIP_withoutLocking(VMName); bladeSpec parentBlade = svc.svc.getBladeByIP_withoutLocking(createdBlade.parentBladeIP); snapshotDetails snap = svc.svc.getCurrentSnapshotDetails(VMName); NASParams nas = svc.svc.getNASParams(); using (hypervisor_vmware_FreeNAS hyp = utils.createHypForVM(createdBlade, parentBlade, snap, nas)) { hyp.powerOn(new cancellableDateTime(TimeSpan.FromMinutes(2))); // Check that debugging has been provisioned correctly executionResult bcdEditRes = hyp.startExecutable("bcdedit", "/dbgsettings"); try { Assert.AreEqual(0, bcdEditRes.resultCode); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "key\\s*a.b.c.d")); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "debugtype\\s*NET")); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "hostip\\s*" + hostip)); Assert.IsTrue(Regex.IsMatch(bcdEditRes.stdout, "port\\s*60234")); } catch (AssertFailedException) { Debug.WriteLine("bcdedit stdout " + bcdEditRes.stdout); Debug.WriteLine("bcdedit stderr " + bcdEditRes.stderr); throw; } executionResult wmicRes = hyp.startExecutable("wmic", "computersystem get totalPhysicalMemory,name,numberOfLogicalProcessors /format:value"); try { // We expect an response similar to: // // Name=ALIZANALYSIS // NumberOfLogicalProcessors=8 // TotalPhysicalMemory=17119825920 // Assert.AreEqual(0, wmicRes.resultCode); string[] lines = wmicRes.stdout.Split(new[] { '\n', 'r' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { if (line.Trim().Length == 0) { continue; } string[] parts = line.Split('='); string name = parts[0].ToLower().Trim(); string value = parts[1].ToLower().Trim(); switch (name) { case "name": Assert.AreEqual("VM_31_01", value, "Name is incorrect"); break; case "NumberOfLogicalProcessors": Assert.AreEqual("1", value, "CPU count is incorrect"); break; case "TotalPhysicalMemory": Assert.AreEqual((4096L * 1024L * 1024L).ToString(), value, "RAM size is incorrect"); break; default: break; } } } catch (AssertFailedException) { Debug.WriteLine("WMIC reported stdout '" + wmicRes.stdout + "'"); Debug.WriteLine("WMIC reported stderr '" + wmicRes.stderr + "'"); } } } }
public static hypervisor_iLo createHypForBlade(bladeSpec blade, snapshotDetails snap, NASParams nas) { userDesc usernameToUse = blade.credentials.First(); return(new hypervisor_iLo(new hypSpec_iLo( blade.bladeIP, usernameToUse.username, usernameToUse.password, blade.iLOIP, blade.iLoUsername, blade.iLoPassword, nas.IP, nas.username, nas.password, snap.friendlyName, snap.path, blade.kernelDebugPort, blade.kernelDebugKey))); }
public static hypervisor_vmware_FreeNAS createHypForVM(vmSpec vmSpec, bladeSpec vmServerSpec, snapshotDetails snapshotInfo, NASParams nas, clientExecutionMethod exec = clientExecutionMethod.smbWithWMI) { userDesc usernameToUse = vmSpec.credentials.First(); return(new hypervisor_vmware_FreeNAS( new hypSpec_vmware( vmSpec.friendlyName, vmServerSpec.bladeIP, vmServerSpec.ESXiUsername, vmServerSpec.ESXiPassword, usernameToUse.username, usernameToUse.password, snapshotInfo.friendlyName, snapshotInfo.path, vmSpec.kernelDebugPort, vmSpec.kernelDebugKey, vmSpec.VMIP ), nas.IP, nas.username, nas.password, exec)); }
public hypervisorCollection <hypSpec_vmware> requestVMs(VMSpec[] specs, bool allowPartialAllocation = false) { initialiseIfNeeded(); Stopwatch allocWatch = new Stopwatch(); using (BladeDirectorServices director = new BladeDirectorServices(machinePools.bladeDirectorURL)) { DateTime deadline = DateTime.Now + TimeSpan.FromMinutes(30); resultAndBladeName[] results = new resultAndBladeName[specs.Length]; for (int n = 0; n < specs.Length; n++) { results[n] = director.svc.RequestAnySingleVM(specs[n].hw, specs[n].sw); if (results[n].result.code == resultCode.bladeQueueFull) { if (allowPartialAllocation) { results[n] = null; break; } } if (results[n].result.code != resultCode.success && results[n].result.code != resultCode.pending) { throw new bladeAllocationException(results[n].result.code); } } hypervisorCollection <hypSpec_vmware> toRet = new hypervisorCollection <hypSpec_vmware>(); try { foreach (resultAndBladeName res in results) { if (res == null) { continue; } resultAndBladeName progress = director.waitForSuccessWithoutThrowing(res, deadline - DateTime.Now); if (progress == null) { throw new TimeoutException(); } if (progress.result.code == resultCode.bladeQueueFull) { if (allowPartialAllocation) { continue; } throw new Exception("Not enough blades available to accomodate new VMs"); } if (progress.result.code != resultCode.success) { if (allowPartialAllocation) { continue; } throw new Exception("Unexpected status while allocing: " + progress.result.code); } vmSpec vmSpec = director.svc.getVMByIP_withoutLocking(progress.bladeName); bladeSpec vmServerSpec = director.svc.getBladeByIP_withoutLocking(vmSpec.parentBladeIP); snapshotDetails snapshotInfo = director.svc.getCurrentSnapshotDetails(vmSpec.VMIP); NASParams nasParams = director.svc.getNASParams(); hypervisor_vmware_FreeNAS newVM = utils.createHypForVM(vmSpec, vmServerSpec, snapshotInfo, nasParams); ipUtils.ensurePortIsFree(vmSpec.kernelDebugPort); newVM.setDisposalCallback(onDestruction); if (!toRet.TryAdd(vmSpec.VMIP, newVM)) { throw new Exception(); } } } catch (Exception) { foreach (KeyValuePair <string, hypervisorWithSpec <hypSpec_vmware> > allocedBlades in toRet) { if (allocedBlades.Key != null) { try { director.svc.ReleaseBladeOrVM(allocedBlades.Key); } catch (Exception) { // ... } } } throw; } allocWatch.Stop(); Debug.WriteLine("Allocated all VMs, took " + allocWatch.Elapsed.ToString()); return(toRet); } }
public bladeDirectedHypervisor_iLo createSingleHypervisor(string snapshotName) { initialiseIfNeeded(); // We request a blade from the blade director, and use them for all our tests, blocking if none are available. using (BladeDirectorServices director = new BladeDirectorServices(machinePools.bladeDirectorURL)) { // Request a node. If all queues are full, then wait and retry until we get one. resultAndBladeName allocatedBladeResult; while (true) { allocatedBladeResult = director.svc.RequestAnySingleNode(); if (allocatedBladeResult.result.code == resultCode.success || allocatedBladeResult.result.code == resultCode.pending) { break; } if (allocatedBladeResult.result.code == resultCode.bladeQueueFull) { Debug.WriteLine("All blades are fully queued, waiting until one is spare"); Thread.Sleep(TimeSpan.FromSeconds(5)); continue; } throw new Exception("Blade director returned unexpected return status '" + allocatedBladeResult.result + "'"); } // Now, wait until our blade is available. try { bool isMine = director.svc.isBladeMine(allocatedBladeResult.bladeName); while (!isMine) { Debug.WriteLine("Blade " + allocatedBladeResult.bladeName + " not released yet, awaiting release.."); Thread.Sleep(TimeSpan.FromSeconds(5)); isMine = director.svc.isBladeMine(allocatedBladeResult.bladeName); } // Great, now we have ownership of the blade, so we can use it safely. //bladeSpec bladeConfig = director.svc.getConfigurationOfBlade(allocatedBladeResult.bladeName); resultAndWaitToken res = director.svc.selectSnapshotForBladeOrVM(allocatedBladeResult.bladeName, snapshotName); director.waitForSuccess(res, TimeSpan.FromMinutes(5)); bladeSpec bladeConfig = director.svc.getBladeByIP_withoutLocking(allocatedBladeResult.bladeName); snapshotDetails currentShot = director.svc.getCurrentSnapshotDetails(allocatedBladeResult.bladeName); userDesc cred = bladeConfig.credentials.First(); NASParams nas = director.svc.getNASParams(); hypSpec_iLo spec = new hypSpec_iLo( bladeConfig.bladeIP, cred.username, cred.password, bladeConfig.iLOIP, bladeConfig.iLoUsername, bladeConfig.iLoPassword, nas.IP, nas.username, nas.password, currentShot.friendlyName, currentShot.path, bladeConfig.kernelDebugPort, bladeConfig.kernelDebugKey ); ipUtils.ensurePortIsFree(bladeConfig.kernelDebugPort); bladeDirectedHypervisor_iLo toRet = new bladeDirectedHypervisor_iLo(spec); toRet.setDisposalCallback(onDestruction); return(toRet); } catch (Exception) { director.svc.ReleaseBladeOrVM(allocatedBladeResult.bladeName); throw; } } }