* Add support physics machine in zanode module,finish task #85169 cost:10h.

This commit is contained in:
zhaoke
2023-03-14 17:40:43 +08:00
parent a762eb46e5
commit 5db08a5f04
15 changed files with 131 additions and 71 deletions
+14 -7
View File
@@ -28,8 +28,8 @@ class hostHeartbeatEntry extends baseEntry
/* Check param. */
$status = $this->requestBody->status;
$vms = $this->requestBody->Vms;
$zap = $this->requestBody->port;
$vms = !empty($this->requestBody->Vms) ? $this->requestBody->Vms : array();
$zap = !empty($this->requestBody->port) ? $this->requestBody->port : 0;
$now = helper::now();
if(!$status) return $this->sendError(400, 'Params error.');
@@ -37,7 +37,7 @@ class hostHeartbeatEntry extends baseEntry
$conditionValue = $secret ? $secret : $token;
$this->dao = $this->loadModel('common')->dao;
$hostInfo = $this->dao->select('id,tokenSN')->from(TABLE_ZAHOST)
$hostInfo = $this->dao->select('id,tokenSN,hostType')->from(TABLE_ZAHOST)
->beginIF($secret)->where('secret')->eq($secret)->fi()
->beginIF(!$secret)->where('tokenSN')->eq($token)
->andWhere('tokenTime')->gt($now)->fi()
@@ -83,11 +83,18 @@ class hostHeartbeatEntry extends baseEntry
if($heartbeat > 0) $vmData['heartbeat'] = date("Y-m-d H:i:s", $heartbeat);
$this->dao->update(TABLE_ZAHOST)->data($vmData)->where('mac')->eq($vm->macAddress)->exec();
if($vm->status == 'running')
if($hostInfo->hostType == 'physics')
{
$node = $this->loadModel('zanode')->getNodeByMac($vm->macAddress);
$this->dao->update(TABLE_ZAHOST)->data($vmData)->where('id')->eq($hostInfo->id)->exec();
}
else
{
$this->dao->update(TABLE_ZAHOST)->data($vmData)->where('mac')->eq($vm->macAddress)->exec();
}
if($vm->status == 'running' && $hostInfo->hostType != 'physics')
{
$node = $this->loadModel('zanode')->getNodeByMac($vm->macAddress);
if(!empty($node))
{
$snaps = $this->loadModel('zanode')->getSnapshotList($node->id);