溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

php管理虛擬機(jī),通過(guò)代理連接

發(fā)布時(shí)間:2020-06-24 10:04:13 來(lái)源:網(wǎng)絡(luò) 閱讀:443 作者:巴啦 欄目:系統(tǒng)運(yùn)維

1、        進(jìn)入安裝目錄

Cd C:\Program Files\Oracle\VirtualBox

設(shè)置web認(rèn)證庫(kù)為null:

VboxManagesetproperty websrvauthlibrary null

然后開(kāi)啟服務(wù)

 vboxwebsrv --host 0.0.0.0

2、在瀏覽器輸入http://127.0.0.1:18083

在博客下方附件,提供vbox接口文件

寫(xiě)代碼實(shí)現(xiàn)時(shí),vbox_oper操作幫助類(lèi)

include_once('vboxServiceWrappers.php');
class Vbox_oper
{
   protected $serverIp;
   protected $serverPort = "18083";
   protected $proxy_uname;
   protected $proxy_password;
   protected $proxy_host;
   protected $proxy_port;
   protected $item;
   protected $connection;
   /*
    * 模塊名稱(chēng):得到連接
    * 參數(shù)說(shuō)明:
    * 作者:csl
   */
   public function getConn()
   {
       $url = "http://" . $this->serverIp . ":" . $this->serverPort . "/";
       //$this->connection = new SoapClient("vboxwebService.wsdl", array('location' => $url, 'connection_timeout' => 5,));
       $this->connection = new SoapClient("vboxwebService.wsdl", array('location' => $url,'connection_timeout'=>5,
           'proxy_host' => $this->proxy_host, 'proxy_port' => $this->proxy_port,
           'proxy_login' => $this->proxy_uname, 'proxy_password' => $this->proxy_password));
       return $this->connection;
   }
   /*
    * 模塊名稱(chēng):初始化代理信息
    * 參數(shù)說(shuō)明:
    * init_proxy 包含:ip,port,username,password
    * 作者:csl
    */
   public function init_proxy($proxy){
       if(!empty($proxy['ip']))
           $this->proxy_host = $proxy['ip'];
       if(!empty($proxy['port']))
           $this->proxy_port = (int)$proxy['port'];
       if(!empty($proxy['username']))
           $this->proxy_uname = $proxy['username'];
       if(!empty($proxy['password']))
           $this->proxy_password = $proxy['password'];
   }
   /*
    * 模塊名稱(chēng):初始化服務(wù)器信息
    * 參數(shù)說(shuō)明:
    * init_proxy 包含:server_ip,sbmc
    * 作者:csl
    */
   public function init_data($item, $proxy = array())
   {
       $this->serverPort = "18083";
       if(!empty($item['server_ip']))
           $this->serverIp = $item['server_ip'];
       if(!empty( $item['sbmc']))
           $this->name = $item['sbmc'];
       if (!empty($proxy)) {
           $this->init_proxy($proxy);
       }
   }
   /*
    * 模塊名稱(chēng):?jiǎn)?dòng)虛擬機(jī)
    * 參數(shù)說(shuō)明:
    * 作者:csl
    */
   public function start()
   {
       $this->getConn();
       $websessionManager = new IWebsessionManager($this->connection);
       $virtualbox = $websessionManager->logon("", "");
       $machine = $virtualbox->findMachine($this->name);
       $session = $websessionManager->getSessionObject($virtualbox->handle);
       $state = (string)$machine->state;
       if ($state != 'Running' && $state != 'Paused') {
           $progress = $machine->launchVMProcess($session->handle, "headless", "");
       }
   }
   /*
       * 模塊名稱(chēng):關(guān)閉虛擬機(jī)
       * 參數(shù)說(shuō)明:
       * 作者:csl
       */
   public function stop()
   {
       $this->getConn();
       $websessionManager = new IWebsessionManager($this->connection);
       $virtualbox = $websessionManager->logon("", "");
       $machine = $virtualbox->findMachine($this->name);
       $session = $websessionManager->getSessionObject($virtualbox->handle);
       $state = (string)$machine->state;
       if ($state == 'Running' || $state == 'Paused') {
           $lockType = new LockType($session, 'Shared');
           $machine->lockMachine($session, $lockType->NameMap[1]);
           $iconsole = $session->getConsole();
           $progress = $iconsole->powerDown();
       }
   }
   /*
       * 模塊名稱(chēng):重啟虛擬機(jī)
       * 參數(shù)說(shuō)明:
       * 作者:csl
       */
   public function restart()
   {
       $this->getConn();
       $websessionManager = new IWebsessionManager($this->connection);
       $virtualbox = $websessionManager->logon("", "");
       $machine = $virtualbox->findMachine($this->name);
       $session = $websessionManager->getSessionObject($virtualbox->handle);
       $state = (string)$machine->state;
       if ($state == 'Running' || $state == 'Paused') {
           $lockType = new LockType($session, 'Shared');
           $machine->lockMachine($session, $lockType->NameMap[1]);
           $iconsole = $session->getConsole();
           $progress = $iconsole->reset();
       } else if ($state == 'PoweredOff') {
           $progress = $machine->launchVMProcess($session->handle, "headless", "");
       }
   }
   /*
   * 模塊名稱(chēng):獲取vbox里面所有虛擬機(jī)
   * 參數(shù)說(shuō)明:
   * 作者:csl
   */
   public function get_machines(){
       $this->getConn();
       $websessionManager = new IWebsessionManager($this->connection);
       $virtualbox = $websessionManager->logon("", "");
       $machines = $virtualbox->machines;
       return $machines;
   }
}



附件:http://down.51cto.com/data/2366921
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI