* Add vm heartbeat api and add vm status.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* The executionnode entry point of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2022 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Yuchun Li <liyuchun@easycorp.ltd>
|
||||
* @package entries
|
||||
* @version 1
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
class executionnodeHeartbeatEntry extends baseEntry
|
||||
{
|
||||
/**
|
||||
* Listen vm heartbeat.
|
||||
*
|
||||
* @param int|string $userID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function post()
|
||||
{
|
||||
/* Check authorize. */
|
||||
$header = getallheaders();
|
||||
$token = isset($header['Authorization']) ? substr($header['Authorization'], 7) : '';
|
||||
$secret = isset($this->requestBody->secret) ? $this->requestBody->secret : '';
|
||||
if(!$secret and !$token) return $this->sendError(401, 'Unauthorized');
|
||||
|
||||
/* Check param. */
|
||||
$status = $this->requestBody->status;
|
||||
$now = helper::now();
|
||||
if(!$status) return $this->sendError(400, 'Params error.');
|
||||
|
||||
$this->dao = $this->loadModel('common')->dao;
|
||||
$assetID = $this->dao->select('assetID')->from(TABLE_HOST)
|
||||
->beginIF($secret)->where('secret')->eq($secret)->fi()
|
||||
->beginIF(!$secret)->where('token')->eq($token)
|
||||
->andWhere('expiredDate')->gt($now)->fi()
|
||||
->fetch('assetID');
|
||||
if(!$assetID) return $this->sendError(400, 'Secret error.');
|
||||
|
||||
$conditionField = $secret ? 'secret' : 'token';
|
||||
$conditionValue = $secret ? $secret : $token;
|
||||
if($secret)
|
||||
{
|
||||
$host = new stdclass();
|
||||
$host->token = md5($secret . $now);
|
||||
$host->expiredDate = date('Y-m-d H:i:s', time() + 7200);
|
||||
$this->dao->update(TABLE_HOST)->data($host)->where($conditionField)->eq($conditionValue)->exec();
|
||||
}
|
||||
|
||||
$node = new stdclass();
|
||||
$node->vmIP = $this->requestBody->ip;
|
||||
$node->agentPort = $this->requestBody->agentPortOnHost;
|
||||
$node->status = $this->requestBody->status;
|
||||
$this->dao->update(TABLE_VM)->data($node)->where('macAddress')->eq($this->requestBody->macAddress)->exec();
|
||||
|
||||
if(!$secret) return $this->sendSuccess(200, 'success');
|
||||
|
||||
$host->expiredTimeUnix = strtotime($host->expiredDate);
|
||||
unset($host->status);
|
||||
unset($host->expiredDate);
|
||||
return $this->send(200, $host);
|
||||
}
|
||||
}
|
||||
@@ -162,6 +162,8 @@ $routes['/reports'] = 'reports';
|
||||
|
||||
$routes['/host/heartbeat'] = 'hostHeartbeat';
|
||||
|
||||
$routes['/executionnode/heartbeat'] = 'executionnodeHeartbeat';
|
||||
|
||||
$routes['/z/folders'] = 'zfolders';
|
||||
$routes['/z/folders/:id'] = 'zfolder';
|
||||
$routes['/z/files/:id'] = 'zfile';
|
||||
|
||||
@@ -287,6 +287,7 @@ class repo extends control
|
||||
$this->view->oldRevision = $revision;
|
||||
$this->view->file = $file;
|
||||
$this->view->entry = $entry;
|
||||
$this->view->info = $info;
|
||||
$this->view->content = '';
|
||||
$this->view->pathInfo = $pathInfo;
|
||||
$this->view->suffix = 'c';
|
||||
|
||||
@@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English';
|
||||
$lang->zahost->empty = 'No Host';
|
||||
$lang->zahost->templateEmpty = 'No Template';
|
||||
|
||||
$lang->zahost->statusList['ready'] = 'Ready';
|
||||
$lang->zahost->statusList['online'] = 'Online';
|
||||
|
||||
$lang->zahost->virtualSoftware = 'VM Software';
|
||||
|
||||
@@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English';
|
||||
$lang->zahost->empty = 'No Host';
|
||||
$lang->zahost->templateEmpty = 'No Template';
|
||||
|
||||
$lang->zahost->statusList['ready'] = 'Ready';
|
||||
$lang->zahost->statusList['online'] = 'Online';
|
||||
|
||||
$lang->zahost->virtualSoftware = 'VM Software';
|
||||
|
||||
@@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = 'American English';
|
||||
$lang->zahost->empty = 'No Host';
|
||||
$lang->zahost->templateEmpty = 'No Template';
|
||||
|
||||
$lang->zahost->statusList['ready'] = 'Ready';
|
||||
$lang->zahost->statusList['online'] = 'Online';
|
||||
|
||||
$lang->zahost->virtualSoftware = 'VM Software';
|
||||
|
||||
@@ -59,6 +59,7 @@ $lang->zahost->langList['zh_cn'] = 'Simplified Chinese';
|
||||
$lang->zahost->langList['zh_tw'] = 'Traditional Chinese';
|
||||
$lang->zahost->langList['en_us'] = 'American English';
|
||||
|
||||
$lang->zahost->statusList['ready'] = 'Ready';
|
||||
$lang->zahost->statusList['online'] = 'Online';
|
||||
|
||||
$lang->zahost->virtualSoftware = 'VM Software';
|
||||
|
||||
@@ -59,6 +59,7 @@ $lang->zahost->langList['en_us'] = '美式英语';
|
||||
$lang->zahost->empty = '暂时没有主机';
|
||||
$lang->zahost->templateEmpty = '暂时没有模板';
|
||||
|
||||
$lang->zahost->statusList['ready'] = '准备中';
|
||||
$lang->zahost->statusList['online'] = '已上架';
|
||||
|
||||
$lang->zahost->virtualSoftware = '虚拟化软件';
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='mainMenu' class='clearfix'>
|
||||
<div class='pull-left btn-toolbar'>
|
||||
<?php echo html::a($this->createLink('zahost', 'browse'), "<span class='text'>{$lang->zahost->browseTemplate}</span>", '', "class='btn btn-link btn-active-text'");?>
|
||||
<a href='#' class='btn btn-link querybox-toggle' id='bysearchTab'><i class='icon-search icon'></i> <?php echo $lang->zahost->byQuery;?></a>
|
||||
</div>
|
||||
<?php if(common::hasPriv('zahost', 'createTemplate')):?>
|
||||
|
||||
Reference in New Issue
Block a user