Merge branch 'zenops_46_wangjianhua_74990' into zenops_46_zhaoke_74993

This commit is contained in:
zhaoke
2022-11-11 01:04:34 +00:00
7 changed files with 393 additions and 29 deletions
+2 -2
View File
@@ -254,8 +254,8 @@ define('TABLE_TESTRUN', '`' . $config->db->prefix . 'testrun`');
define('TABLE_TESTRESULT', '`' . $config->db->prefix . 'testresult`');
define('TABLE_USERTPL', '`' . $config->db->prefix . 'usertpl`');
define('TABLE_ZAHOST', '`' . $config->db->prefix . 'host`');
define('TABLE_EXECUTIONNODE', '`' . $config->db->prefix . 'executionnode`');
define('TABLE_IMAGE', '`' . $config->db->prefix . 'image`');
define('TABLE_EXECUTIONNODE', '`' . $config->db->prefix . 'executionnode`');
define('TABLE_IMAGE', '`' . $config->db->prefix . 'image`');
if(!defined('TABLE_ASSET')) define('TABLE_ASSET', '`' . $config->db->prefix . 'asset`');
if(!defined('TABLE_VMTEMPLATE')) define('TABLE_VMTEMPLATE', '`' . $config->db->prefix . 'vmtemplate`');
+59 -4
View File
@@ -143,6 +143,63 @@ class zahost extends control
return print(js::locate($this->createLink('zahost', 'browse'), 'parent'));
}
public function browseImage($hostID, $browseType = 'all', $param = 0, $orderBy = 'id', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->app->session->set('imageList', $this->app->getURI(true));
$this->app->loadClass('pager', $static = true);
$pager = pager::init($recTotal, $recPerPage, $pageID);
$imageList = $this->zahost->getImageList($hostID, $browseType, $param, $orderBy, $pager);
$this->view->title = $this->lang->zahost->image->list;
$this->view->hostID = $hostID;
$this->view->imageList = $imageList;
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->view->browseType = $browseType;
$this->display();
}
/**
* Create template.
*
* @access public
* @return void
*/
public function createImage($hostID)
{
$host = $this->zahost->getById($hostID);
if($_POST)
{
$this->zahost->createImage();
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inLink('browseTemplate', "id={$hostID}")));
}
$this->view->imageOptions = array('' => $this->lang->zahost->notice->loading);
$this->view->host = $host;
$this->display();
}
/**
* Sent download image request to Host.
*
* @param int $imageID
* @access public
* @return object
*/
public function ajaxDownloadImage($imageID)
{
$image = $this->zahost->getImageByID($imageID);
$this->zahost->downloadImage($image);
return $this->send(array('result' => 'success', 'message' => $this->lang->zahost->image->startDowload)));
}
/**
* Create template.
*
@@ -302,11 +359,9 @@ class zahost extends control
* @access public
* @return void
*/
public function ajaxImageList($hostID, $templateID = 0)
public function ajaxImageList()
{
$host = $this->zahost->getById($hostID);
$imageList = $this->zahost->getImageList($host, $templateID);
$imageList = array('1' => 'Ubuntu20');
if($imageList) return $this->send(array('result' => 'success', 'message' => '', 'data' => $imageList));
return $this->send(array('result' => 'fail', 'message' => array('imageName' => array($this->lang->zahost->notice->noImage))));
+28 -1
View File
@@ -40,11 +40,13 @@ $lang->zahost->osLang = '系统语言';
$lang->zahost->imageName = '镜像文件';
$lang->zahost->initHost = new stdclass;
$lang->zahost->initHost->statusTitle = "服务状态";
$lang->zahost->initHost->checkStatus = "检测服务状态";
$lang->zahost->initHost->not_install = "未安装";
$lang->zahost->initHost->not_available = "已安装,未启动";
$lang->zahost->initHost->ready = "已就绪";
$lang->zahost->initHost->next = "下一步";
$lang->zahost->initHost->initSuccessNotice = "初始化成功,请点击下一步完成后续操作。";
$lang->zahost->initHost->initFailNotice = "初始化失败,请查看初始化脚本执行日志并尝试以下两种解决方案:<br/>1. 重新执行脚本 <br/>2. 查看初始化常见问题";
$lang->zahost->initHost->serviceStatus = [
@@ -58,7 +60,32 @@ $lang->zahost->initHost->descLi = [
"下载初始化脚本至宿主机:wget xxx -o xxx",
"在宿主机上执行初始化脚本,Ubuntu下执行命令示例:xxxx"
];
$lang->zahost->initHost->statusTitle = "服务状态";
$lang->zahost->image = new stdclass;
$lang->zahost->image->list = '镜像列表';
$lang->zahost->image->browseImage = '镜像列表';
$lang->zahost->image->createImage = '创建镜像';
$lang->zahost->image->choseImage = '选择镜像';
$lang->zahost->image->downloadImage = '下载镜像';
$lang->zahost->image->startDowload = '开始下载';
$lang->zahost->image->name = '名称';
$lang->zahost->image->common = '镜像';
$lang->zahost->image->memory = $lang->zahost->memory;
$lang->zahost->image->disk = $lang->zahost->diskSize;
$lang->zahost->image->osType = $lang->zahost->osType;
$lang->zahost->image->osCategory = $lang->zahost->osCategory;
$lang->zahost->image->osVersion = $lang->zahost->osVersion;
$lang->zahost->image->osLang = $lang->zahost->osLang;
$lang->zahost->image->imageName = $lang->zahost->imageName;
$lang->zahost->image->imageEmpty = '无镜像';
$lang->zahost->image->statusList['waiting'] = '未下载';
$lang->zahost->image->statusList['downloading'] = '下载中';
$lang->zahost->image->statusList['finish'] = '已下载';
$lang->zahost->image->statusList['fail'] = '下载失败';
$lang->zahost->vmTemplate = new stdclass;
$lang->zahost->vmTemplate->name = '名称';
+63 -22
View File
@@ -171,39 +171,80 @@ class zahostModel extends model
return common::createChanges($oldHost, $templateInfo);
}
/**
* Get image by ID.
*
* @param int $imageID
* @access public
* @return object
*/
public function getImageByID($imageID)
{
return $this->dao->select('*')->from(TABLE_IMAGE)->where('deleted')->eq(0)->andWhere('id')->eq($imageID)->fetch();
}
/**
* Get image files from ZAgent server.
*
* @param object $host
* @param int $templateID
* @param object $hostID
* @access public
* @return array
*/
public function getImageList($host, $templateID = 0)
public function getImageList($hostID, $browseType = 'all', $param = 0, $orderBy = 'id', $pager = null)
{
$result = json_decode(commonModel::http("http://{$host->publicIP}:8086/api/v1/kvm/listTmpl"));
if(empty($result) || $result->code != 200)
{
$result = new stdclass;
$result->data = array();
}
$usedImageList = $this->dao->select('imageName')->from(TABLE_VMTEMPLATE)->where('hostID')->eq($host->hostID)->fetchAll('imageName');
$imageList = array();
foreach($result->data as $image)
{
if(array_key_exists($image->name, $usedImageList)) continue;
$imageList[] = array('name' => $image->name);
}
/* Template ID is not empty means editing template. */
if($templateID) foreach($usedImageList as $usedImage) $imageList[] = array('name' => $usedImage->imageName);
$imageList = $this->dao->select('*')->from(TABLE_IMAGE)
->where('hostID')->eq($hostID)
->orderBy($orderBy)
->page($pager)
->fetchAll();
return $imageList;
}
/**
* create image.
*
* @access public
* @return void
*/
public function createImage()
{
$vmImage = fixer::input('post')
->get();
$this->dao->insert(TABLE_IMAGE)->data($vmImage)
->batchCheck($this->config->zahost->createimage->requiredFields, 'notempty')
->autoCheck()->exec();
if(dao::isError()) return false;
$imageID = $this->dao->lastInsertID();
$this->loadModel('action')->create('image', $imageID, 'Created');
}
/**
* Send download image command to HOST.
*
* @param object $image
* @access public
* @return bool
*/
public function downloadImage($image)
{
$host = $this->getById($image->hostID);
$downloadApi = 'http://' . $host->address . '/api/v1/download/add';
$apiParams['md5'] = $image->md5;
$apiParams['task'] = 1;
$apiParams['url'] = $image->address;
$response = json_decode(commonModel::http($downloadApi, $apiParams));
if($response->code == 200) return true;
dao::$errors[] = $response->msg;
return false;
}
/**
* Get host by id.
*
+82
View File
@@ -0,0 +1,82 @@
<?php
/**
* The image 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 '../../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->image->browseImage}</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', 'createImage')):?>
<div class="btn-toolbar pull-right" id='createActionMenu'>
<?php
$misc = "class='btn btn-primary'";
$link = $this->createLink('zahost', 'createImage', "hostID={$hostID}");
echo html::a($link, "<i class='icon icon-plus'></i>" . $lang->zahost->image->createImage, '', $misc);
?>
</div>
<?php endif;?>
</div>
<div id='queryBox' class='cell <?php if($browseType =='bysearch') echo 'show';?>' data-module='vmTemplate'></div>
<div id='mainContent' class='main-table'>
<?php $vars = "hostID=$hostID&browseType=all&param=0&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<?php if(empty($imageList)):?>
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->zahost->image->imageEmpty;?></span>
<?php if(common::hasPriv('zahost', 'createImage')) common::printLink('zahost', 'createImage', "hostID={$hostID}", '<i class="icon icon-plus"></i> ' . $lang->zahost->image->createImage, '', 'class="btn btn-info"');?>
</p>
</div>
<?php else:?>
<table class='table has-sort-head table-fixed' id='vmList'>
<thead>
<tr>
<th class='c-id'><?php common::printOrderLink('id', $orderBy, $vars, $lang->idAB);?></th>
<th class='c-name'><?php common::printOrderLink('name', $orderBy, $vars, $lang->zahost->image->name);?></th>
<th class='c-number'><?php common::printOrderLink('memory', $orderBy, $vars, $lang->zahost->image->memory);?></th>
<th class='c-number'><?php common::printOrderLink('disk', $orderBy, $vars, $lang->zahost->image->disk);?></th>
<th class='c-os'><?php common::printOrderLink('osCategory', $orderBy, $vars, $lang->zahost->image->osCategory);?></th>
<th class='c-os'><?php common::printOrderLink('osType', $orderBy, $vars, $lang->zahost->image->osType);?></th>
<th class='c-os'><?php common::printOrderLink('osVersion', $orderBy, $vars, $lang->zahost->image->osVersion);?></th>
<th class='c-lang'><?php common::printOrderLink('osLang', $orderBy, $vars, $lang->zahost->image->osLang);?></th>
<th><?php echo $lang->zahost->status;?></th>
<th class='c-actions-2 text-center'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach($imageList as $image):?>
<tr>
<td><?php echo $image->id;?></td>
<td title="<?php echo $image->name;?>"><?php echo $image->name;?></td>
<td><?php echo $image->memory . zget($this->lang->zahost->unitList, 'GB');?></td>
<td><?php echo $image->disk . zget($this->lang->zahost->unitList, 'GB');?></td>
<td><?php echo zget($config->zahost->os->list, $image->osCategory);?></td>
<td><?php echo zget($config->zahost->os->type[$image->osCategory], $image->osType);?></td>
<td><?php echo zget($lang->zahost->versionList[$image->osType], $image->osVersion);?></td>
<td><?php echo zget($lang->zahost->langList, $image->osLang);?></td>
<td><?php echo zget($lang->zahost->image->statusList, $image->status, '');?></td>
<td class='c-actions'>
<?php common::printIcon('zahost', 'downloadImage', "id={$image->id}", $image, 'list', 'download');?>
<?php if(common::hasPriv('zahost', 'downloadImage')) echo html::a($this->createLink('zahost', 'downloadImage', "id={$image->id}"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->zahost->image->downloadImage}' class='btn'");?>
<?php common::printIcon('zahost', 'editImage', "id={$image->id}", $image, 'list', 'edit');?>
<?php //if(common::hasPriv('zahost', 'deleteImage')) echo html::a($this->createLink('zahost', 'deleteImage', "id={$image->id}"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->zahost->delete}' class='btn'");?>
</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';?>
+79
View File
@@ -0,0 +1,79 @@
<?php
/**
* The create vm image view file of zahost module of ZenTaoPMS.
*
* @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 Jianhua Wang<wangjianhua@easycorp.ltd>
* @package zahost
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php js::set('zahostConfig', $config->zahost);?>
<?php js::set('zahostLang', $lang->zahost);?>
<?php js::set('hostID', $host->hostID);?>
<div id='mainContent' class='main-content'>
<div class='main-header'>
<h2><?php echo $lang->zahost->image->createImage;?></h2>
</div>
<form method='post' id='ajaxForm' class="load-indicator main-form form-ajax">
<table class='table table-form'>
<tr>
<th class='w-150px'><?php echo $lang->zahost->common;?></th>
<td class='w-300px'><?php echo $host->name;?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->image->choseImage;?></th>
<td><?php echo html::select('address', $imageOptions, '', "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->name;?></th>
<td><?php echo html::input('name', '', "class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->zahost->memory;?></th>
<td>
<div class='input-group'>
<?php echo html::input('memory', '', "class='form-control'");?>
<span class='input-group-addon'>MB</span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zahost->diskSize;?></th>
<td>
<div class='input-group'>
<?php echo html::input('disk', '', "class='form-control'");?>
<span class='input-group-addon' id='unit'>GB</span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zahost->image->osCategory;?></th>
<td><?php echo html::select('osCategory', $config->zahost->os->list, '', "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->image->osType;?></th>
<td><?php echo html::select('osType', '', '', "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->image->osVersion;?></th>
<td><?php echo html::select('osVersion', '', '', "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->image->osLang;?></th>
<td><?php echo html::select('osLang', $lang->zahost->langList, '', "class='form-control chosen'")?></td>
<tr>
<td colspan='2' class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::backButton();?>
<?php echo html::hidden('hostID', $host->id);?>
</td>
</tr>
</table>
</form>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>
+80
View File
@@ -0,0 +1,80 @@
<?php
/**
* The create vm template view file of zahost module of ZenTaoPMS.
*
* @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 Jianhua Wang<wangjianhua@easycorp.ltd>
* @package zahost
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php js::set('zahostConfig', $config->zahost);?>
<?php js::set('zahostLang', $lang->zahost);?>
<?php js::set('template', $template);?>
<?php js::set('hostID', $template->hostID);?>
<div id='mainContent' class='main-content'>
<div class='main-header'>
<h2><?php echo $lang->zahost->createTemplate;?></h2>
</div>
<form method='post' target='hiddenwin' id='ajaxForm' class="load-indicator main-form form-ajax">
<table class='table table-form'>
<tr>
<th class='w-120px'><?php echo $lang->zahost->name;?></th>
<td><?php echo html::input('name', $template->name, "class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->zahost->cpuCores;?></th>
<td><?php echo html::input('cpuCoreNum', $template->cpuCoreNum, "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->memory;?></th>
<td>
<div class='input-group'>
<?php echo html::input('memorySize', $template->memorySize, "class='form-control'");?>
<span class='input-group-addon'>MB</span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zahost->diskSize;?></th>
<td>
<div class='input-group'>
<?php echo html::input('diskSize', intval($template->diskSize/1024), "class='form-control'");?>
<span class='input-group-addon' id='unit'>GB</span>
</div>
</td>
</tr>
<tr>
<th><?php echo $lang->zahost->vmTemplate->osCategory;?></th>
<td><?php echo html::select('osCategory', $config->zahost->os->list, $template->osCategory, "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->vmTemplate->osType;?></th>
<td><?php echo html::select('osType', '', $template->osType, "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->vmTemplate->osVersion;?></th>
<td><?php echo html::select('osVersion', '', $template->osVersion, "class='form-control chosen'")?></td>
</tr>
<tr>
<th><?php echo $lang->zahost->vmTemplate->osLang;?></th>
<td><?php echo html::select('osLang', $lang->zahost->langList, $template->osLang, "class='form-control chosen'")?></td>
<tr>
<th><?php echo $lang->zahost->vmTemplate->imageName;?></th>
<td><?php echo html::select('imageName', $imageOptions, $template->imageName, "class='form-control chosen'")?></td>
</tr>
<tr>
<td colspan='2' class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::backButton();?>
<?php echo html::hidden('type', 'za');?>
</td>
</tr>
</table>
</form>
</div>
<?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>