Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 20 | Revision 24 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
13 lars 1
<?php
2
	//$Id$
3
	class vServer
4
	{
5
	 	protected $status;
6
	 	protected $name;
7
	 	protected $hn_id;
8
	 	protected $dist;
9
	 	protected $dist_id;
10
	 	protected $v_id;
21 lars 11
	 	function __construct($v_id=0, $hn_id=1)
13 lars 12
	 	{
13
	 	 	global $db;
21 lars 14
			if($v_id)
13 lars 15
			{
16
				$sql="SELECT * FROM vservers, distributions WHERE v_id=$v_id AND hn_id=$hn_id AND dist_id=v_dist";
17
				$res=$db->query($sql);
18
				if(!PEAR::isError($res))
19
				{
20
					$row=$res->fetchRow();
21
					$this->v_id=$v_id;
22
					$this->dist=$row["dist_name"];
23
					$this->dist_id=$row["dist_id"];
24
					$this->name=$row["v_name"];
25
					$this->hn_id=$hn_id;
26
					$this->status=$this->getStatus();
27
				}
28
				else
29
				{
30
					echo $res->getUserInfo();
31
					return false;
32
				}
33
			}
34
			else
35
			{
36
				$this->v_id=0;
37
				$this->dist_id=1;
38
				$this->dist="gentoo";
39
				$this->hn_id=1;
40
				$this->name="";
41
				$this->status="running";
42
			}
43
		}
44
 
45
		function getStatus()
46
		{
47
			if(!$this->status)
48
			{
49
 
50
				unset($out);
51
				if($this->v_id!=0)
52
				{
53
					$id=$this->v_id;
54
					$cmd="ssh root@mainframe vzctl status $id";
55
					exec($cmd,$out,$ret);
56
					if(!$ret)
57
					{
15 lars 58
						$out_v["status"]=$out[0];
13 lars 59
					}
60
					else
61
					{
62
						$out_v["status"]="unknown";
63
					}
64
					$out_v["code"]=$ret;
65
				}
66
				else
67
				{
68
					$out_v["status"]="Hardware node is running";
69
					$out_v["code"]=0;
70
				}
71
				if(eregi("running",$out_v["status"]))
72
				{
73
					$out_v["started"]=true;
74
				}
75
				else
76
				{
77
					$out_v["started"]=false;
78
				}
79
				if(!$out_v["code"]&&$out_v["started"])
80
				{
81
					$class="success_upd";
82
				}
83
				else
84
				{
20 lars 85
					$class="error_upd";
13 lars 86
				}
87
				$out_v["status"]="<div class=\"$class\">".$out_v["status"]."</div>";
88
				$this->status=$out_v;
89
 
90
			}
91
			return $this->status;
92
		}
93
 
18 lars 94
		static function getvServers($hn_id=1)
13 lars 95
		{
96
			global $db;
18 lars 97
			$sql="SELECT * FROM vservers WHERE hn_id=$hn_id";
13 lars 98
			$res=$db->query($sql);
99
			return $res;
100
		}
15 lars 101
 
102
		function control($cmd="")
103
		{
104
			$cmds=array("start","stop","restart");
105
			if($cmd==""||!in_array($cmd, $cmds))
106
			{
107
				return false;
108
			}
109
			unset($out);
110
			if($this->v_id!=0)
111
			{
112
				$id=$this->v_id;
113
				$cmd="ssh root@mainframe vzctl $cmd $id";
114
				exec($cmd,$out,$ret);
115
				if(!$ret)
116
				{
117
					$out_v["status"]=implode("<br>",$out);
16 lars 118
					$out_v["error"]=false;
15 lars 119
				}
120
				else
121
				{
122
					$out_v["status"]="unknown";
16 lars 123
					$out_v["error"]=true;
15 lars 124
				}
125
				$out_v["code"]=$ret;
126
			}
127
			else
128
			{
129
				$out_v=false;
130
			}
131
			return $out_v;
132
		}
13 lars 133
	}
134
?>