* Add token for za api.

This commit is contained in:
tanghucheng
2022-12-05 13:07:16 +08:00
parent c397bfb177
commit 928048133f
6 changed files with 21 additions and 9 deletions
+4 -2
View File
@@ -192,7 +192,7 @@ class zanode extends control
$task = '';
$node = $this->zanode->getNodeByID($zanodeID);
$customImage = $this->zanode->getCustomImage($zanodeID, 'created,inprogress');
if($customImage) $task = $this->zanode->getTaskStatus($node->ip, $customImage->id, 'exportVm');
if($customImage) $task = $this->zanode->getTaskStatus($node->ip, $customImage->id, 'exportVm', '', $node->tokenSN);
if($_POST)
{
@@ -299,7 +299,9 @@ class zanode extends control
*/
public function ajaxGetTaskStatus($extranet, $taskID = 0, $type = '', $status = '')
{
$result = $this->zanode->getTaskStatus($extranet, $taskID, $type, $status);
$task = $this->zanode->getImageByID($taskID);
$node = $this->zanode->getNodeByID($task->from);
$result = $this->zanode->getTaskStatus($extranet, $taskID, $type, $status, $node->tokenSN);
return print(json_encode($result));
}
+2
View File
@@ -54,6 +54,8 @@ $lang->zanode->createImageNotice = 'The system will be created based on the cur
$lang->zanode->createImageSuccess = 'Successed, You can use this image to create node. <a href="%s">Created</a>';
$lang->zanode->createImageFail = 'Failed to create';
$lang->zanode->imageNameEmpty = 'Name can not be empty.';
$lang->zanode->apiError['-10100'] = 'Execution node not found.';
$lang->zanode->publicList[0] = 'Private';
+2
View File
@@ -54,6 +54,8 @@ $lang->zanode->createImageNotice = 'The system will be created based on the cur
$lang->zanode->createImageSuccess = 'Successed, You can use this image to create node. <a href="%s">Created</a>';
$lang->zanode->createImageFail = 'Failed to create';
$lang->zanode->imageNameEmpty = 'Name can not be empty.';
$lang->zanode->apiError['-10100'] = 'Execution node not found.';
$lang->zanode->publicList[0] = 'Private';
+2
View File
@@ -54,6 +54,8 @@ $lang->zanode->createImageNotice = 'The system will be created based on the cur
$lang->zanode->createImageSuccess = 'Successed, You can use this image to create node. <a href="%s">Created</a>';
$lang->zanode->createImageFail = 'Failed to create';
$lang->zanode->imageNameEmpty = 'Name can not be empty.';
$lang->zanode->apiError['-10100'] = 'Execution node not found.';
$lang->zanode->publicList[0] = 'Private';
+2
View File
@@ -54,6 +54,8 @@ $lang->zanode->createImageNotice = '系统将基于当前执行节点创建镜
$lang->zanode->createImageSuccess = '镜像创建成功,您可以使用此镜像创建执行节点。<a href="%s">去创建</a>';
$lang->zanode->createImageFail = '镜像创建失败';
$lang->zanode->imageNameEmpty = '名称不能为空';
$lang->zanode->apiError['-10100'] = '执行节点不存在';
$lang->zanode->publicList[0] = '不共享';
+9 -7
View File
@@ -118,13 +118,14 @@ class zanodemodel extends model
{
$data = fixer::input('post')->get();
if(empty($data->name)) dao::$errors['message'][] = '名称不能为空';
if(empty($data->name)) dao::$errors['message'][] = $this->lang->zanode->imageNameEmpty;
if(dao::isError()) return false;
$node = $this->getNodeByID($zanodeID);
$image = $this->getImageByID($node->image);
$newImage = new stdClass();
$newImage->host = $node->host;
$newImage->name = $data->name;
$newImage->status = 'created';
$newImage->osName = $node->osName;
@@ -148,7 +149,7 @@ class zanodemodel extends model
'vm' => $node->name
);
$result = json_decode(commonModel::http($agnetUrl . static::KVM_EXPORT_PATH, json_encode($param,JSON_NUMERIC_CHECK), null));
$result = json_decode(commonModel::http($agnetUrl . static::KVM_EXPORT_PATH, json_encode($param,JSON_NUMERIC_CHECK), null, array("Authorization:$node->tokenSN")));
if(!empty($result) and $result->code == 'success') return $newID;
@@ -458,7 +459,7 @@ class zanodemodel extends model
*/
public function getNodeByID($id)
{
return $this->dao->select('t1.*, t1.name as hostName, t2.extranet as ip,t3.osName')->from(TABLE_ZAHOST)->alias('t1')
return $this->dao->select('t1.*, t1.name as hostName, t2.extranet as ip, t2.tokenSN as tokenSN, t3.osName')->from(TABLE_ZAHOST)->alias('t1')
->leftJoin(TABLE_ZAHOST)->alias('t2')->on('t1.parent = t2.id')
->leftJoin(TABLE_IMAGE)->alias('t3')->on('t3.id = t1.image')
->where('t1.id')->eq($id)
@@ -538,17 +539,18 @@ class zanodemodel extends model
/**
* Get task status by zagent api.
*
* @param int $extranet
* @param string $extranet
* @param int $taskID
* @param string $type
* @param string $status
* @param string $token
* @access public
* @return void
* @return array
*/
public function getTaskStatus($extranet = '', $taskID = 0, $type = '', $status = '')
public function getTaskStatus($extranet = '', $taskID = 0, $type = '', $status = '', $token = '')
{
$agnetUrl = 'http://' . $extranet . ':8086' . static::KVM_STATUS_PATH;
$result = json_decode(commonModel::http("$agnetUrl", array(), array(CURLOPT_CUSTOMREQUEST => 'POST'), array(), 'json'));
$result = json_decode(commonModel::http("$agnetUrl", array(), array(CURLOPT_CUSTOMREQUEST => 'POST'), array("Authorization:$token"), 'json'));
if(empty($result) or $result->code != 'success') return false;
$data = $result->data;