Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 21 | Revision 44 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php
        //$Id$
        class vServer
        {
                protected $status;
                protected $name;
                protected $hn_id;
                protected $dist;
                protected $dist_id;
                protected $v_id;
                function __construct($v_id=NULL, $hn_id=1)
                {
                        global $db;
                        if(is_numeric($v_id))
                        {
                                $sql="SELECT * FROM vservers, distributions WHERE v_id=$v_id AND hn_id=$hn_id AND dist_id=v_dist";
                                $res=$db->query($sql);
                                if(!PEAR::isError($res))
                                {
                                        $row=$res->fetchRow();
                                        $this->v_id=$v_id;
                                        $this->dist=$row["dist_name"];
                                        $this->dist_id=$row["dist_id"];
                                        $this->name=$row["v_name"];
                                        $this->hn_id=$hn_id;
                                        $this->status=$this->getStatus();
                                }
                                else
                                {
                                        echo $res->getUserInfo();
                                        return false;
                                }
                        }
                        else
                        {
                                $this->v_id=0;
                                $this->dist_id=1;
                                $this->dist="gentoo";
                                $this->hn_id=1;
                                $this->name="";
                                $this->status["status"]="";
                                $this->status["code"]="0";
                        }
                }
                
                function getStatus()
                {
                        if(!$this->status)
                        {

                                unset($out);
                                if($this->v_id!=0)
                                {
                                        $id=$this->v_id;
                                        $cmd="ssh root@mainframe vzctl status $id";
                                        exec($cmd,$out,$ret);
                                        if(!$ret)
                                        {
                                                $out_v["status"]=$out[0];
                                        }
                                        else
                                        {
                                                $out_v["status"]="unknown";
                                        }
                                        $out_v["code"]=$ret;
                                }
                                else
                                {
                                        $out_v["status"]="Hardware node is running";
                                        $out_v["code"]=0;
                                }
                                if(eregi("running",$out_v["status"]))
                                {
                                        $out_v["started"]=true;
                                }
                                else
                                {
                                        $out_v["started"]=false;
                                }
                                if(!$out_v["code"]&&$out_v["started"])
                                {
                                        $class="success_upd";
                                }
                                else
                                {
                                        $class="error_upd";
                                }
                                $out_v["status"]="<div class=\"$class\">".$out_v["status"]."</div>";
                                $this->status=$out_v;

                        }
                        return $this->status;
                }
                
                static function getvServers($hn_id=1)
                {
                        global $db;
                        $sql="SELECT * FROM vservers WHERE hn_id=$hn_id";
                        $res=$db->query($sql);
                        return $res;    
                }
                
                function control($cmd="")
                {
                        $cmds=array("start","stop","restart");
                        if($cmd==""||!in_array($cmd, $cmds))
                        {
                                return false;
                        }
                        unset($out);
                        if($this->v_id!=0)
                        {
                                $id=$this->v_id;
                                $cmd="ssh root@mainframe vzctl $cmd $id";
                                exec($cmd,$out,$ret);
                                if(!$ret)
                                {
                                        $out_v["status"]=implode("<br>",$out);
                                        $out_v["error"]=false;
                                }
                                else
                                {
                                        $out_v["status"]="unknown";
                                        $out_v["error"]=true;
                                }
                                $out_v["code"]=$ret;
                        }
                        else
                        {
                                $out_v=false;
                        }
                        return $out_v;
                }
        }
?>