public void canGetBladeSpec()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(WCFPath))
            {
                bladeSpec   spec1Expected = svc.svcDebug.createBladeSpec("blade1ip", "blade1iscsiIP", "blade1ILOIP", 111, false, VMDeployStatus.notBeingDeployed, null, "idk", "box1", bladeLockType.lockAll, bladeLockType.lockAll);
                bladeSpec   spec2Expected = svc.svcDebug.createBladeSpec("blade2ip", "blade2iscsiIP", "blade2ILOIP", 222, false, VMDeployStatus.notBeingDeployed, null, "idk", "box2", bladeLockType.lockAll, bladeLockType.lockAll);
                bladeSpec[] expected      = new[] { spec1Expected, spec2Expected };

                svc.svcDebug.initWithBladesFromBladeSpec(expected, false, NASFaultInjectionPolicy.retunSuccessful);

                bladeSpec   spec1Actual = svc.svc.getBladeByIP_withoutLocking("blade1ip");
                bladeSpec   spec2Actual = svc.svc.getBladeByIP_withoutLocking("blade2ip");
                bladeSpec[] actual      = new[] { spec1Actual, spec2Actual };

                for (int i = 0; i < 2; i++)
                {
                    Assert.AreEqual(expected[i].bladeIP, actual[i].bladeIP);
                    Assert.AreEqual(expected[i].ESXiPassword, actual[i].ESXiPassword);
                    Assert.AreEqual(expected[i].ESXiUsername, actual[i].ESXiUsername);
                    Assert.AreEqual(expected[i].currentlyBeingAVMServer, actual[i].currentlyBeingAVMServer);
                    Assert.AreEqual(expected[i].currentlyHavingBIOSDeployed, actual[i].currentlyHavingBIOSDeployed);
                    Assert.AreEqual(expected[i].iLOIP, actual[i].iLOIP);
                    Assert.AreEqual(expected[i].kernelDebugPort, actual[i].kernelDebugPort);
                    Assert.AreEqual(expected[i].iLoPassword, actual[i].iLoPassword);
                    Assert.AreEqual(expected[i].iLoUsername, actual[i].iLoUsername);
                    Assert.AreEqual(expected[i].iscsiIP, actual[i].iscsiIP);
                    Assert.AreEqual(expected[i].lastDeployedBIOS, actual[i].lastDeployedBIOS);
                    Assert.AreEqual(expected[i].ESXiPassword, actual[i].ESXiPassword);
                    Assert.AreEqual(expected[i].ESXiUsername, actual[i].ESXiUsername);
                    // thats enough for now
                }
            }
        }
示例#2
0
        public void willCancelBIOSWrite(TimeSpan delay)
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, basicBladeTests.WebURI))
            {
                machinePools.bladeDirectorURL = svc.servicesURL;

                string    hostIP = "1.1.1.1";
                bladeSpec spec   = svc.svcDebug.createBladeSpec("172.17.129.131", "192.168.129.131", "172.17.2.131", 1234, false, VMDeployStatus.notBeingDeployed, " ... ", "idk", "box", bladeLockType.lockAll, bladeLockType.lockAll);
                svc.svcDebug.initWithBladesFromBladeSpec(new[] { spec }, false, NASFaultInjectionPolicy.retunSuccessful);

                resultAndBladeName res = svc.svcDebug._RequestAnySingleNode(hostIP);
                Assert.AreEqual(resultCode.success, res.result.code);
                string ourBlade = ((resultAndBladeName)testUtils.waitForSuccess(svc, res, TimeSpan.FromSeconds(30))).bladeName;

                // Start a BIOS read
                resultAndWaitToken readRes = svc.svcDebug._rebootAndStartReadingBIOSConfiguration(hostIP, ourBlade);
                Assert.AreEqual(resultCode.pending, readRes.result.code);

                // Wait a while to see if we get somewhere where it is impossible to free without a hueg delay
                Thread.Sleep(delay);

                // Then free the blade. The BIOS operation should be cancelled before it soaks up all the ten minutes of time.
                resultAndWaitToken releaseRes = svc.svcDebug._ReleaseBladeOrVM(hostIP, ourBlade, false);
                testUtils.waitForSuccess(svc, releaseRes, TimeSpan.FromMinutes(1));

                // And it should be no longer getting.
                resultAndWaitToken bladeState = svc.svc.getProgress(readRes.waitToken);
                Assert.AreNotEqual(resultCode.pending, bladeState.result.code);

                // It no longer be allocated to us, since we released it earlier.
                GetBladeStatusResult ownershipRes = svc.svc.GetBladeStatus(ourBlade);
                Assert.AreEqual(GetBladeStatusResult.unused, ownershipRes);
            }
        }
示例#3
0
        public void willSetBIOS()
        {
            string testBiosXML = Properties.Resources.testBIOS;

            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.createBladeSpec("172.17.129.131", "192.168.129.131", "172.17.2.131", 1234, false, VMDeployStatus.notBeingDeployed, " ... ", "idk", "box", bladeLockType.lockAll, bladeLockType.lockAll);
                svc.svcDebug.initWithBladesFromBladeSpec(new[] { spec }, false, NASFaultInjectionPolicy.retunSuccessful);

                resultAndBladeName res = svc.svcDebug._RequestAnySingleNode(hostip);
                Assert.AreEqual(resultCode.success, res.result.code);

                // Write the new BIOS. This configuration has the 'boot state' of the numlock key set to 'off', so we can
                // read that back after writing to ensure that the BIOS write succeeds.
                var resultAndReadBack = writeBIOSAndReadBack(svc, hostip, res.bladeName, testBiosXML);
                Assert.IsTrue(resultAndReadBack.BIOSConfig.Contains("<Section name=\"NumLock\">Off</Section>"));
                // Now we can modify the BIOS slightly, to set the numlock boot state to 'on', and again write/readback, and see
                // if the change was carried out.
                testBiosXML       = testBiosXML.Replace("<Section name=\"NumLock\">Off</Section>", "<Section name=\"NumLock\">On</Section>");
                resultAndReadBack = writeBIOSAndReadBack(svc, hostip, res.bladeName, testBiosXML);
                Assert.IsTrue(resultAndReadBack.BIOSConfig.Contains("<Section name=\"NumLock\">On</Section>"));

                resultAndWaitToken relRes = svc.svcDebug._ReleaseBladeOrVM(hostip, res.bladeName, false);
                while (relRes.result.code == resultCode.pending)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(3));
                    relRes = svc.svc.getProgress(relRes.waitToken);
                }
                Assert.AreEqual(resultCode.success, relRes.result.code);
            }
        }
        public void willDeallocateOldVMsOnLogon()
        {
            using (bladeDirectorDebugServices svc = new bladeDirectorDebugServices(basicBladeTests.WCFPath, "172.17.129.131", true))
            {
                string hostIP = "1.1.1.1";
                testUtils.doLogin(svc, hostIP);

                // Allocate all the blades, then login again. The allocated blades should no longer be allocated.
                string ourVM = testUtils.doVMAllocationForTest(svc, hostIP);

                // Find the parent blade of the VM we got, and make sure it is now in use (by the blade director)
                vmSpec    VMSpec    = svc.svc.getVMByIP_withoutLocking(ourVM);
                bladeSpec bladeSpec = svc.svc.getBladeByIP_withoutLocking(VMSpec.parentBladeIP);

                GetBladeStatusResult bladeState = svc.svcDebug._GetBladeStatus(hostIP, bladeSpec.bladeIP);
                string bladeIP = bladeSpec.bladeIP;
                Assert.AreEqual(bladeState, GetBladeStatusResult.notYours);

                // Do a new login, which should cause our blades to be deallocated.
                testUtils.doLogin(svc, hostIP);

                // The VM should now not exist.
                Assert.AreEqual(null, svc.svc.getVMByIP_withoutLocking(ourVM));

                // Find the parent blade of the VM we got, and make sure it is now unused.
                GetBladeStatusResult bladeState2 = svc.svcDebug._GetBladeStatus(hostIP, bladeIP);
                Assert.AreEqual(bladeState2, GetBladeStatusResult.unused);
            }
        }
        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;
                }
            }
        }
示例#6
0
        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);
                    }
                }
            }
        }
示例#7
0
        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 + "'");
                    }
                }
            }
        }
示例#8
0
        private void doLoggedInData()
        {
            // Populate the main page data.
            lblServerURL.Text = getCurrentServerURL(this);
            lblClientIP.Text  = Request.UserHostAddress;
            TableRow headerRow = new TableRow();

            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = ""
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "State"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Blade IP"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Time since last keepalive"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Currently-selected snapshot"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Current owner"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Next owner"
            });
            headerRow.Cells.Add(new TableHeaderCell()
            {
                Text = "Links"
            });

            tblBladeStatus.Rows.Add(headerRow);

            using (BladeDirectorServices services = new BladeDirectorServices(getCurrentServerURL(this)))
            {
                lblServerBaseWebURL.Text = services.svc.getWebSvcURL();

                string[] allBladeIPs = services.svc.getAllBladeIP();

                foreach (string bladeIP in allBladeIPs)
                {
                    // Query the server for information about this blade

                    bladeSpec bladeInfo = services.svc.getBladeByIP_withoutLocking(bladeIP);

                    // Assemble the always-visible status row
                    TableRow newRow = new TableRow();

                    newRow.Cells.Add(makeTableCell(new ImageButton()
                    {
                        ImageUrl      = "images/collapsed.png",
                        AlternateText = "Details",
                        OnClientClick = "javascript:toggleDetail($(this), " + bladeInfo.bladeID + "); return false;"
                    }));
                    newRow.Cells.Add(new TableCell()
                    {
                        Text = bladeInfo.state.ToString()
                    });
                    newRow.Cells.Add(new TableCell()
                    {
                        Text = bladeInfo.bladeIP
                    });
                    if (bladeInfo.lastKeepAlive == DateTime.MinValue)
                    {
                        newRow.Cells.Add(new TableCell()
                        {
                            Text = "(none)"
                        });
                    }
                    else
                    {
                        string cssClass = "";
                        if (DateTime.Now - bladeInfo.lastKeepAlive > services.svc.getKeepAliveTimeout())
                        {
                            cssClass = "timedout";
                        }
                        TableCell cell = new TableCell
                        {
                            Text     = formatDateTimeForWeb((DateTime.Now - bladeInfo.lastKeepAlive)),
                            CssClass = cssClass
                        };
                        newRow.Cells.Add(cell);
                    }
                    newRow.Cells.Add(new TableCell()
                    {
                        Text = bladeInfo.currentSnapshot
                    });
                    newRow.Cells.Add(new TableCell()
                    {
                        Text = bladeInfo.currentOwner ?? "none"
                    });
                    newRow.Cells.Add(new TableCell()
                    {
                        Text = bladeInfo.nextOwner ?? "none"
                    });

                    string    iloURL = String.Format("iloConsole.aspx?bladeIP={0}", bladeInfo.bladeIP);
                    HyperLink link   = new HyperLink()
                    {
                        NavigateUrl = iloURL, Text = "iLo"
                    };
                    TableCell iloURLtableCell = new TableCell();
                    iloURLtableCell.Controls.Add(link);
                    newRow.Cells.Add(iloURLtableCell);

                    tblBladeStatus.Rows.Add(newRow);

                    // Then populate the invisible-until-expanded details row.
                    tblBladeStatus.Rows.Add(makeDetailRow(services, bladeInfo));
                }

                // Finally, populate any log events.
                logEntry[] logEvents = services.svc.getLogEvents(100);
                int        logID     = 0;
                foreach (logEntry logEvent in logEvents)
                {
                    // Make the expandable row, with a little bit of info
                    TableRow tumbRow = new TableRow();
                    tumbRow.Cells.Add(makeTableCell(new ImageButton()
                    {
                        ImageUrl      = "images/collapsed.png",
                        AlternateText = "Details",
                        OnClientClick = "javascript:toggleDetail($(this),  null); return false;"
                    }));

                    tumbRow.Cells.Add(new TableCell()
                    {
                        Text = logEvent.timestamp.ToString()
                    });
                    tumbRow.Cells.Add(new TableCell()
                    {
                        Text = logEvent.threadName ?? "(unknown)"
                    });
                    string thumbtext = logEvent.msg.Split('\n')[0];
                    if (thumbtext.Length > 50)
                    {
                        thumbtext = thumbtext.Substring(0, 50) + "...";
                    }
                    tumbRow.Cells.Add(new TableCell()
                    {
                        Text = thumbtext
                    });
                    tblLogTable.Rows.Add(tumbRow);

                    // and then the full detail row.
                    TableRow detailRow = new TableRow();
                    detailRow.Cells.Add(new TableCell()
                    {
                        Text = logEvent.msg, ColumnSpan = 4
                    });
                    detailRow.Style.Add("display", "none");
                    tblLogTable.Rows.Add(detailRow);

                    logID++;
                }
            }
        }
示例#9
0
        private TableRow makeDetailRow(BladeDirectorServices svc, bladeSpec bladeInfo)
        {
            Table detailTable = new Table();

            TableRow miscTR = new TableRow();

            miscTR.Cells.Add(makeTableCell(
                                 new Label()
            {
                Text = "Blade DB ID: "
            },
                                 new Label()
            {
                Text = bladeInfo.bladeID.ToString() + "<br/>", CssClass = "fixedSize"
            },
                                 new Label()
            {
                Text = "ISCSI IP: "
            },
                                 new Label()
            {
                Text = bladeInfo.iscsiIP.ToString() + "<br/>", CssClass = "fixedSize"
            },
                                 new Label()
            {
                Text = "Kernel debug port: "
            },
                                 new Label()
            {
                Text = bladeInfo.kernelDebugPort.ToString() + "<br/>", CssClass = "fixedSize"
            },
                                 new Label()
            {
                Text = "Is currently having BIOS config deployed: "
            },
                                 new Label()
            {
                Text = bladeInfo.currentlyHavingBIOSDeployed.ToString() + "<br/>", CssClass = "fixedSize"
            },
                                 new Label()
            {
                Text = "Is currently acting as VM server: "
            },
                                 new Label()
            {
                Text = bladeInfo.currentlyBeingAVMServer.ToString() + "<br/>", CssClass = "fixedSize"
            }
                                 ));
            detailTable.Rows.Add(miscTR);

            // And add rows for any VMs.
            vmSpec[] VMs = svc.svc.getVMByVMServerIP_nolocking(bladeInfo.bladeIP);
            if (VMs.Length > 0)
            {
                TableRow VMHeaderRow = new TableRow();
                VMHeaderRow.Cells.Add(new TableHeaderCell()
                {
                    Text = "VM name"
                });
                VMHeaderRow.Cells.Add(new TableHeaderCell()
                {
                    Text = "Time since last keepalive"
                });
                VMHeaderRow.Cells.Add(new TableHeaderCell()
                {
                    Text = "VM IP"
                });
                VMHeaderRow.Cells.Add(new TableHeaderCell()
                {
                    Text = "Current owner"
                });
                VMHeaderRow.Cells.Add(new TableHeaderCell()
                {
                    Text = "Kernel debug info"
                });
                detailTable.Rows.Add(VMHeaderRow);
            }
            foreach (vmSpec vmInfo in VMs)
            {
                TableRow thisVMRow = new TableRow();

                thisVMRow.Cells.Add(new TableCell()
                {
                    Text = vmInfo.friendlyName
                });
                thisVMRow.Cells.Add(new TableCell()
                {
                    Text = formatDateTimeForWeb((DateTime.Now - vmInfo.lastKeepAlive))
                });
                thisVMRow.Cells.Add(new TableCell()
                {
                    Text = vmInfo.VMIP
                });
                thisVMRow.Cells.Add(new TableCell()
                {
                    Text = vmInfo.currentOwner
                });
                string dbgStr = String.Format("Port {0} key \"{1}\"", vmInfo.kernelDebugPort, vmInfo.kernelDebugKey);
                thisVMRow.Cells.Add(new TableCell()
                {
                    Text = dbgStr
                });
                //thisVMRow.Cells.Add(new TableCell() { Text = vmInfo.currentSnapshot });
                detailTable.Rows.Add(thisVMRow);
            }

            TableHeaderRow toRet       = new TableHeaderRow();
            TableCell      paddingCell = new TableCell {
                CssClass = "invisible"
            };

            toRet.Cells.Add(paddingCell);
            TableCell tc = new TableCell();

            tc.ColumnSpan = 7;
            tc.Controls.Add(detailTable);
            toRet.Cells.Add(tc);
            toRet.Style.Add("display", "none");

            return(toRet);
        }
        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;
                }
            }
        }