private bool ensureISCSIInterfaceIsSetUp(hypervisor hyp, string srcAddress, cancellableDateTime deadline) { executionResult res; // First, add our portgroup res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcli", "network vswitch standard portgroup add -p vlan11_iscsi -v vSwitch1")); if (res.resultCode != 0) { return(false); } // And then give the portgroup an address. res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable( "esxcfg-vmknic", "--add --ip " + srcAddress + " --netmask 255.255.0.0 vlan11_iscsi", deadline: deadline)); if (res.resultCode != 0) { return(false); } // Finally, tag it for management traffic. For this, we'll need to get the adaptor name for this portgroup. res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-vmknic", "--list", deadline: deadline)); if (res.resultCode != 0) { return(false); } string[] lines = res.stdout.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string adaptorName = null; foreach (var line in lines) { string[] fields = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (fields[1] == "vlan11_iscsi") { adaptorName = fields[0]; break; } } if (adaptorName == null) { return(false); } res = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable( "esxcli", "network ip interface tag add -i " + adaptorName + " -t Management", deadline: deadline)); if (res.resultCode != 0) { return(false); } return(true); }
private void _SetBIOS(biosThreadState state) { // SCP some needed files to it. copyDeploymentFilesToBlade(state.blade, state.biosxml, state.connectDeadline); // And execute the command to deploy the BIOS via SSH. using (hypervisor hyp = _hostManager.makeHypervisorForBlade_LTSP(state.blade)) { executionResult res = hyp.startExecutable("bash", "~/applyBIOS.sh"); if (res.resultCode != 0) { string msg = string.Format("Executing applyBIOS.sh on {0} resulted in error code {1}", state.nodeIP, res.resultCode); msg += "stdout: " + res.stdout; msg += "stderr: " + res.stderr; _hostManager.addLogEvent(msg); state.result = new result(resultCode.genericFail, msg); } else { _hostManager.addLogEvent(string.Format("Deployed BIOS successfully to {0}", state.nodeIP)); using (var tmp = new tempLockElevation(state.blade, bladeLockType.lockNone, bladeLockType.lockBIOS)) { _hostManager.markLastKnownBIOS(state.blade, state.biosxml); } state.result = new result(resultCode.success); } // All done, now we can power off and return. hyp.powerOff(state.connectDeadline); } state.isFinished = true; }
public override void mountDataStore(hypervisor hyp, string srcAddress, string dataStoreName, string serverName, string mountPath, cancellableDateTime deadline) { while (ensureISCSIInterfaceIsSetUp(hyp, srcAddress, deadline) == false) { deadline.doCancellableSleep(TimeSpan.FromSeconds(5)); } string expectedLine = String.Format("{0} is {1} from {2} mounted available", dataStoreName, mountPath, serverName); string[] nfsMounts = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-l")).stdout.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); string foundMount = nfsMounts.SingleOrDefault(x => x.Contains(expectedLine)); while (foundMount == null) { hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-d " + dataStoreName, deadline: deadline)); hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-a --host " + serverName + " --share " + mountPath + " " + dataStoreName, deadline: deadline)); hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-rescan", "--all", deadline: deadline)); nfsMounts = hypervisor.doWithRetryOnSomeExceptions(() => hyp.startExecutable("esxcfg-nas", "-l", deadline: deadline)).stdout.Split(new[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); foundMount = nfsMounts.SingleOrDefault(x => x.Contains(expectedLine)); deadline.throwIfTimedOutOrCancelled("While trying to mount NFS"); } }
protected override void waitForESXiBootToComplete(hypervisor hyp, cancellableDateTime deadline) { while (true) { executionResult res = hypervisor.doWithRetryOnSomeExceptions( () => hyp.startExecutable("/etc/init.d/vpxa", "status"), deadline, TimeSpan.FromSeconds(1)); if (res.resultCode != 0) { deadline.doCancellableSleep(TimeSpan.FromSeconds(4)); continue; } if (res.stdout.Contains("vpxa is running")) { return; } } }
private void _GetBIOS(biosThreadState state) { copyDeploymentFilesToBlade(state.blade, null, state.connectDeadline); using (hypervisor hyp = _hostManager.makeHypervisorForBlade_LTSP(state.blade)) { executionResult res = hyp.startExecutable("bash", "~/getBIOS.sh"); if (res.resultCode != 0) { string msg = string.Format("Executing getBIOS.sh on {0} resulted in error code {1}", state.nodeIP, res.resultCode); msg += "stdout: " + res.stdout; msg += "stderr: " + res.stderr; _hostManager.addLogEvent(msg); state.result = new result(resultCode.genericFail, msg); } else { string msg = string.Format("Deployed BIOS successfully to {0}", state.nodeIP); _hostManager.addLogEvent(msg); state.result = new result(resultCode.success, msg); } // Retrieve the output state.biosxml = hyp.getFileFromGuest("currentbios.xml", state.connectDeadline); // All done, now we can power off and return. hyp.powerOff(state.connectDeadline); } using (var tmp = new tempLockElevation(state.blade, bladeLockType.lockNone, bladeLockType.lockBIOS)) { _hostManager.markLastKnownBIOS(state.blade, state.biosxml); } state.isFinished = true; }
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); } } } }