|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 4 | + <title>CBSD Project</title> |
| 5 | + <link type="text/css" href="./css/all.css" rel="stylesheet" /> |
| 6 | + <style> |
| 7 | + body { |
| 8 | + font-size:14px; |
| 9 | + } |
| 10 | + </style> |
| 11 | +</head> |
| 12 | +<body> |
| 13 | +<a href="javascript:location.reload(true)">[ Refresh Page ]</a> | <a href="bcreate.php">[ New VM ]</a> |
| 14 | +<script> |
| 15 | +</script> |
| 16 | + |
| 17 | + |
| 18 | +<?php |
| 19 | +function show_bhyvevm($nodelist="local") |
| 20 | +{ |
| 21 | + global $workdir; |
| 22 | + |
| 23 | + $pieces = explode(" ", $nodelist); |
| 24 | + |
| 25 | + ?> |
| 26 | + |
| 27 | + <table class="images"> |
| 28 | + <thead> |
| 29 | + <tr> |
| 30 | + <th>node</th> |
| 31 | + <th>vm</th> |
| 32 | + <th>vm_ram</th> |
| 33 | + <th>vm_cpus</th> |
| 34 | + <th>vm_os_type</th> |
| 35 | + <th>status</th> |
| 36 | + <th>action</th> |
| 37 | + <th>remove</th> |
| 38 | + </tr> |
| 39 | + </thead> |
| 40 | + <tbody> |
| 41 | + <?php |
| 42 | + |
| 43 | + foreach ($pieces as $nodename) { |
| 44 | + if (!$nodename) { |
| 45 | + $nodename=$nodelist; |
| 46 | + } |
| 47 | + $db = new SQLite3("$workdir/var/db/$nodename.sqlite"); $db->busyTimeout(5000); |
| 48 | + $sql = "SELECT jname,vm_ram,vm_cpus,vm_os_type FROM bhyve;"; |
| 49 | + $result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC); |
| 50 | + $row = array(); |
| 51 | + $i = 0; |
| 52 | + |
| 53 | + if ( $nodename != "local" ) { |
| 54 | + $nodeip=get_node_info($nodename,"ip"); |
| 55 | + $idle=check_locktime($nodeip); |
| 56 | + } else { |
| 57 | + $idle=1; |
| 58 | + } |
| 59 | + |
| 60 | + if ($idle == 0 ) { |
| 61 | + $hdr = '<tr style="background-color:#D6D2D0">'; |
| 62 | + } else { |
| 63 | + $hdr = '<tr>'; |
| 64 | + } |
| 65 | + |
| 66 | + while($res = $result->fetchArray(SQLITE3_ASSOC)){ |
| 67 | + if(!isset($res['jname'])) continue; |
| 68 | + $jname = $res['jname']; |
| 69 | + $vm_ram = $res['vm_ram'] / 1024 / 1024 ; |
| 70 | + $vm_cpus = $res['vm_cpus']; |
| 71 | + $vm_os_type = $res['vm_os_type']; |
| 72 | + $status=check_vmonline($jname); |
| 73 | + $i++; |
| 74 | + |
| 75 | + if ( $idle != 0 ) { |
| 76 | + switch ($status) { |
| 77 | + case 0: |
| 78 | + //off |
| 79 | + $statuscolor="#EDECEA"; |
| 80 | + $action="<form action=\"bstart.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"$jname\"/> <input type=\"submit\" name=\"start\" value=\"Start\"></form>"; |
| 81 | + break; |
| 82 | + case 1: |
| 83 | + //running |
| 84 | + $statuscolor="#51FF5F"; |
| 85 | + $action="<form action=\"bstop.php\" method=\"post\"><input type=\"hidden\" name=\"jname\" value=\"$jname\"/> <input type=\"submit\" name=\"stop\" value=\"Stop\"></form>"; |
| 86 | + break; |
| 87 | + default: |
| 88 | + $action="maintenance"; |
| 89 | + break; |
| 90 | + } |
| 91 | + } else { |
| 92 | + $statuscolor="#D6D2D0"; |
| 93 | + $action="offline"; |
| 94 | + } |
| 95 | + |
| 96 | + if ( $idle != 0 ) { |
| 97 | + $status_td="<td><a href=\"bstatus.php?jname=$jname\">$jname</a></td>"; |
| 98 | + $remove_td="<td><a href=\"bremove.php?jname=$jname\">Remove</a></td>"; |
| 99 | + } else { |
| 100 | + $status_td="<td>$jname</td>"; |
| 101 | + $remove_td="<td>Remove</td>"; |
| 102 | + } |
| 103 | + |
| 104 | + $str = <<<EOF |
| 105 | + ${hdr} |
| 106 | + <td><strong>$nodename</strong></td> |
| 107 | + ${status_td} |
| 108 | + <td>$vm_ram</td><td>$vm_cpus</td> |
| 109 | + <td>$vm_os_type</td> |
| 110 | + <td style="background-color:$statuscolor">$status</td> |
| 111 | + <td>$action</td> |
| 112 | + ${remove_td} |
| 113 | + </tr> |
| 114 | +EOF; |
| 115 | + echo $str; |
| 116 | + } |
| 117 | + } |
| 118 | + echo "</tbody></table>"; |
| 119 | +} |
| 120 | + |
| 121 | +// MAIN |
| 122 | +require('cbsd.php'); |
| 123 | +require('nodes.inc.php'); |
| 124 | + |
| 125 | +$db = new SQLite3("$workdir/var/db/nodes.sqlite"); $db->busyTimeout(5000); |
| 126 | +$sql = "SELECT nodename FROM nodelist"; |
| 127 | +$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC); |
| 128 | +$row = array(); |
| 129 | +$i = 0; |
| 130 | + |
| 131 | +$nodelist="local"; |
| 132 | + |
| 133 | +while($res = $result->fetchArray(SQLITE3_ASSOC)){ |
| 134 | + if(!isset($res['nodename'])) continue; |
| 135 | + $nodelist=$nodelist." ".$res['nodename']; |
| 136 | +} |
| 137 | + |
| 138 | +show_bhyvevm($nodelist); |
0 commit comments