* Snapshot list,create

This commit is contained in:
zenggang
2023-02-01 07:43:49 +00:00
parent d3986931a8
commit 08e10410f1
7 changed files with 275 additions and 2 deletions
+53 -1
View File
@@ -45,7 +45,7 @@ class zanode extends control
$showFeature = false;
$accounts = !empty($this->config->global->skipAutomation) ? $this->config->global->skipAutomation : '';
if(strpos(",$accounts,", $this->app->user->account) === false)
if(strpos(",$accounts,", $this->app->user->account) === false)
{
$showFeature = true;
$accounts .= ',' . $this->app->user->account;
@@ -164,6 +164,7 @@ class zanode extends control
$this->view->token = !empty($vnc->token) ? $vnc->token:'';
$this->view->title = $this->lang->zanode->view;
$this->view->zanode = $node;
$this->view->snapshotList = $this->zanode->getSnapshotList($id);
$this->view->actions = $this->loadModel('action')->getList('zanode', $id);
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->display();
@@ -285,6 +286,37 @@ class zanode extends control
$this->display();
}
/**
* Create snapshot.
*
* @param int $zanodeID
* @access public
* @return void
*/
public function createSnapshot($nodeID = 0)
{
$task = '';
$node = $this->zanode->getNodeByID($nodeID);
if($_POST)
{
$this->zanode->createSnapshot($nodeID);
if(dao::isError())
{
$response['result'] = 'fail';
$response['message'] = dao::getError();
return $this->send($response);
}
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'reload'));
}
$this->view->task = $task;
$this->view->node = $node;
$this->view->rate = !empty($task->rate) ? $task->rate : 0;
$this->display();
}
/**
* Desctroy node.
*
@@ -333,6 +365,26 @@ class zanode extends control
$this->display();
}
public function browseSnapshot($nodeID, $browseType = 'all', $param = 0, $orderBy = 'id', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->loadLang('zahost');
$this->app->loadClass('pager', $static = true);
$pager = pager::init($recTotal, $recPerPage, $pageID);
$snapshotList = $this->zanode->getSnapshotList($nodeID, $browseType, $param, $orderBy, $pager);
$this->view->title = $this->lang->zanode->browseSnapshot;
$this->view->nodeID = $nodeID;
$this->view->snapshotList = $snapshotList;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->view->browseType = $browseType;
$this->display();
}
/**
* Ajax get template pairs by api.
*
+6
View File
@@ -0,0 +1,6 @@
#main{min-width: 0!important;padding:0!important;}
body{background-color: #fff!important;}
.c-createdBy {width: 100px;}
.c-datetime {width: 130px;}
.c-status {width: 80px;}
+9
View File
@@ -79,6 +79,14 @@ $lang->zanode->createImageSuccess = '镜像导出成功,您可以使用此镜
$lang->zanode->createImageFail = '镜像导出失败';
$lang->zanode->createImageButton = '去创建';
$lang->zanode->snapshotName = '快照名称';
$lang->zanode->browseSnapshot = '快照列表';
$lang->zanode->createSnapshot = '创建快照';
$lang->zanode->editSnapshot = '编辑快照';
$lang->zanode->restoreSnapshot = '还原快照';
$lang->zanode->deleteSnapshot = '删除快照';
$lang->zanode->snapshotEmpty = '无快照';
$lang->zanode->imageNameEmpty = '名称不能为空';
$lang->zanode->runTimeout = '自动执行失败,请检查宿主机和执行节点状态';
@@ -89,6 +97,7 @@ $lang->zanode->apiError['fail'] = '执行失败,请检查宿主机和执行
$lang->zanode->publicList[0] = '不共享';
$lang->zanode->publicList[1] = '共享';
$lang->zanode->statusList['creating'] = '创建中';
$lang->zanode->statusList['created'] = '已创建';
$lang->zanode->statusList['launch'] = '运行中';
$lang->zanode->statusList['ready'] = '运行中';
+75 -1
View File
@@ -28,6 +28,10 @@ class zanodemodel extends model
const KVM_EXPORT_PATH = '/api/v1/kvm/exportVm';
const KVM_STATUS_PATH = '/api/v1/task/getStatus';
const SNAPSHOT_CREATE_PATH = '/api/v1/snaps/addCreateSnap';
const SNAPSHOT_REVERT_PATH = '/api/v1/snaps/addRevertSnap';
const SNAPSHOT_REMOVE_PATH = '/api/v1/snaps/removeSnap';
/**
* Set lang;
*
@@ -167,6 +171,64 @@ class zanodemodel extends model
return false;
}
/**
* Create Snapshot by zanode.
*
* @param int $zanodeID
* @access public
* @return void
*/
public function createSnapshot($zanodeID = 0)
{
$data = fixer::input('post')->get();
if(empty($data->name)) dao::$errors['name'] = $this->lang->zanode->imageNameEmpty;
if(dao::isError()) return false;
$node = $this->getNodeByID($zanodeID);
$newSnapshot = new stdClass();
$newSnapshot->host = $node->id;
$newSnapshot->name = $data->name;
$newSnapshot->desc = $data->desc;
$newSnapshot->status = 'creating';
$newSnapshot->osName = $node->osName;
$newSnapshot->from = 'snapshot';
$newSnapshot->createdBy = $this->app->user->account;
$newSnapshot->createdDate = helper::now();
$this->dao->insert(TABLE_IMAGE)
->data($newSnapshot)
->autoCheck()
->exec();
if(dao::isError()) return false;
$newID = $this->dao->lastInsertID();
/* Prepare create params. */
$agnetUrl = 'http://' . $node->ip . ':' . $node->hzap;
$param = array(
'name' => $data->name,
'task' => $newID,
'type' => 'createSnap',
'vm' => $node->name
);
$result = json_decode(commonModel::http($agnetUrl . static::SNAPSHOT_CREATE_PATH, json_encode($param,JSON_NUMERIC_CHECK), null, array("Authorization:$node->tokenSN")));
if(!empty($result) and $result->code == 'success')
{
$this->loadModel('action')->create('zanodesnapshot', $id, 'created');
return $newID;
}
$this->dao->delete()->from(TABLE_IMAGE)->where('id')->eq($newID)->exec();
dao::$errors[] = (!empty($result) and !empty($result->msg)) ? $result->msg : $this->app->lang->fail;
return false;
}
/**
* Action Node.
*
@@ -212,7 +274,7 @@ class zanodemodel extends model
public function destroy($id)
{
$node = $this->getNodeByID($id);
if($node)
{
$req = array( 'name' => $node->name );
@@ -520,6 +582,18 @@ class zanodemodel extends model
->fetch();
}
public function getSnapshotList($nodeID, $browseType = 'all', $param = 0, $orderBy = 'id', $pager = null)
{
$snapshotList = $this->dao->select('*')->from(TABLE_IMAGE)
->where('host')->eq($nodeID)
->andWhere('`from`')->eq('snapshot')
->orderBy($orderBy)
->page($pager)
->fetchAll('name');
return $snapshotList;
}
/**
* Get Node by id.
*
@@ -0,0 +1,56 @@
<?php
/**
* The snapshot browse view file of zahost module 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 xiawenlong <liyuchun@easycorp.ltd>
* @package zahost
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php js::set('nodeID', $nodeID);?>
<div id='mainContent' class='main-table'>
<?php $vars = "nodeID=$nodeID&browseType=all&param=0&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<?php if(empty($snapshotList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->zanode->snapshotEmpty;?></span>
</p>
</div>
<?php else:?>
<table class='table has-sort-head table-fixed' id='snapshotList'>
<thead>
<tr>
<th class='c-name'><?php common::printOrderLink('name', $orderBy, $vars, $lang->zahost->image->name);?></th>
<th class='c-status'><?php echo $lang->zahost->status;?></th>
<th class='c-createdBy'><?php echo $lang->zahost->createdBy;?></th>
<th class='c-datetime'><?php echo $lang->zahost->createdDate;?></th>
<th class='c-actions-3'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach($snapshotList as $snapshot):?>
<tr>
<?php $path = $snapshot->status == 'completed' ? zget($snapshot, 'path', '') : '';?>
<td title="<?php echo $snapshot->name;?>"><?php echo $snapshot->name;?></td>
<td class='snapshot-status-<?php echo zget($snapshot, 'id', 0);?>'><?php echo zget($lang->zanode->statusList, $snapshot->status, '');?></td>
<td class="c-createdBy"><?php echo zget($users, $snapshot->createdBy, '')?></td>
<td class='c-datetime'><?php echo $snapshot->createdDate;?></td>
<td class='c-actions'>
<?php if(common::hasPriv('zanode', 'editSnapshot')) echo html::a($this->createLink('zanode', 'editsnapshot', "snapshotID={$snapshot->id}"), '<i class="icon-edit"></i>', 'hiddenwin', "title={$lang->zanode->editSnapshot}");?>
<?php if(common::hasPriv('zahost', 'restoreSnapshot')) echo html::a($this->createLink('zahost', 'restoreSnapshot', "nodeID={$nodeID}&snapshotID={$snapshot->id}"), '<i class="icon-restart"></i>', 'hiddenwin', "title={$lang->zanode->restoreSnapshot}");?>
<?php if(common::hasPriv('zahost', 'deleteSnapshot')) echo html::a($this->createLink('zahost', 'deleteSnapshot', "snapshotID={$snapshot->id}"), '<i class="icon-trash"></i>', 'hiddenwin', "title={$lang->zanode->deleteSnapshot}");?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<div class='table-footer'>
<?php $pager->show('right', 'pagerjs');?>
</div>
<?php endif;?>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
@@ -0,0 +1,64 @@
<?php
/**
* The create file of snapshot of zanode.
*
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(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 chunsheng wang <chunsheng@cnezsoft.com>
* @package task
* @version
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/kindeditor.html.php';?>
<?php if($task):?>
<?php js::set('taskID', $task->task);?>
<?php js::set('nodeID', $node->id);?>
<?php js::set('zanodeLang', $lang->zanode); ?>
<style>.body-modal #mainContent{width:90%}
</style>
<?php endif;?>
<div id='mainContent' class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2>
<span><?php echo $lang->zanode->createSnapshot;?></span>
</h2>
</div>
<?php if($task):?>
<h5 class='text-center status-title'><?php echo $lang->zanode->pending;?></h5>
<div class="progress progress-striped">
<div class="progress-bar progress-bar-success rate" role="progressbar" aria-valuenow="<?php echo $task->rate;?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $task->rate;?>%">
</div>
</div>
<?php
$link = helper::createLink('zanode', 'create', "hostID={$node->parent}");
$link = str_replace('onlybody=yes', '', $link);
$link = trim($link, '?');
?>
<h6 class='hide text-center success'><?php echo $lang->zanode->createSnapshotSuccess . html::a($link, $lang->zanode->createSnapshotButton, "_parent", "style='color:#2e7fff;'");?></h6>
<h6 class='hide text-center fail'><?php echo $lang->zanode->createSnapshotFail;?></h6>
<?php else:?>
<form class="load-indicator main-form form-ajax" method='post' enctype='multipart/form-data' id='dataform'>
<table class='table table-form'>
<tr>
<th><?php echo $lang->zanode->snapshotName;?></th>
<td class='required'><?php echo html::input('name', '', "class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->zanode->desc;?></th>
<td colspan='2'><?php echo html::textarea('desc', '', "rows='6' class='form-control'");?></td>
</tr>
<tr>
<td colspan='3' class='text-center'>
<?php echo html::submitButton('', "");?>
</td>
</tr>
</table>
</form>
<?php endif;?>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>
+12
View File
@@ -147,6 +147,14 @@ $account = strpos($zanode->osName, "windows") ? $config->zanode->defaultWinAccou
<div class="detail zanode-detail">
<div class="detail-title"><?php echo $lang->zanode->desc; ?></div>
<div class="detail-content article-content"><?php echo !empty($zanode->desc) ? htmlspecialchars_decode($zanode->desc) : $lang->noData; ?></div>
<?php if(!empty($snapshotList)): ?>
<div class="detail">
<div class="detail-title"><?php echo $lang->zanode->browseSnapshot;?></div>
<div class="detail-content article-content">
<?php echo "<iframe width='100%' id='nodesIframe' src='" . $this->createLink('zanode', 'browseSnapshot', "nodeID=$zanode->id", '', true) . "' frameborder='no' allowfullscreen='true' mozallowfullscreen='true' webkitallowfullscreen='true' allowtransparency='true' scrolling='auto' onload='setIframeHeight(this)' style='min-height:300px;'></iframe>";?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php $this->printExtendFields($zanode, 'div', "position=left&inForm=0&inCell=1"); ?>
@@ -164,6 +172,9 @@ $account = strpos($zanode->osName, "windows") ? $config->zanode->defaultWinAccou
$rebootAttr = "title='{$lang->zanode->reboot}' target='hiddenwin'";
$rebootAttr .= $zanode->status == 'shutoff' ? ' class="btn disabled"' : "class='btn' target='hiddenwin' onclick='if(confirm(\"{$lang->zanode->confirmReboot}\")==false) return false;'";
$snapshotAttr = "title='{$lang->zanode->createSnapshot}'";
$snapshotAttr .= $zanode->status != 'running' ? ' class="btn disabled"' : ' class="btn iframe"';
common::printLink('zanode', 'getVNC', "id={$zanode->id}", "<i class='icon icon-remote'></i> " . $lang->zanode->getVNC, in_array($zanode->status ,array('running', 'launch', 'wait')) ? '_blank' : '', "title='{$lang->zanode->getVNC}' class='btn desktop " . (in_array($zanode->status ,array('running', 'launch', 'wait')) ? '':'disabled') . "'", '');
if($zanode->status == "suspend")
@@ -185,6 +196,7 @@ $account = strpos($zanode->osName, "windows") ? $config->zanode->defaultWinAccou
}
common::printLink('zanode', 'reboot', "zanodeID={$zanode->id}", "<i class='icon icon-restart'></i> " . $lang->zanode->rebootNode, '', $rebootAttr);
common::printLink('zanode', 'createSnapshot', "zanodeID={$zanode->id}", "<i class='icon icon-plus'></i> " . $lang->zanode->createSnapshot, '', $snapshotAttr, true, true);
}
?>