diff --git a/config/zentaopms.php b/config/zentaopms.php index 8c8e6b8a00..51434732d2 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -249,6 +249,7 @@ define('TABLE_USERTPL', '`' . $config->db->prefix . 'usertpl`'); define('TABLE_ZAHOST', '`' . $config->db->prefix . 'host`'); if(!defined('TABLE_ASSET')) define('TABLE_ASSET', '`' . $config->db->prefix . 'asset`'); +if(!defined('TABLE_VMTEMPLATE')) define('TABLE_VMTEMPLATE', '`' . $config->db->prefix . 'vmtemplate`'); define('TABLE_PRODUCT', '`' . $config->db->prefix . 'product`'); define('TABLE_BRANCH', '`' . $config->db->prefix . 'branch`'); diff --git a/module/action/lang/de.php b/module/action/lang/de.php index 97998907cf..c05c715921 100644 --- a/module/action/lang/de.php +++ b/module/action/lang/de.php @@ -112,6 +112,7 @@ $lang->action->objectTypes['testsuite'] = 'Suite'; $lang->action->objectTypes['testtask'] = 'Test Build'; $lang->action->objectTypes['testreport'] = 'Berichte'; $lang->action->objectTypes['zahost'] = 'Host'; +$lang->action->objectTypes['vmtemplate'] = 'Virtual Host Template'; $lang->action->objectTypes['doc'] = 'Dok'; $lang->action->objectTypes['api'] = 'Interface'; $lang->action->objectTypes['doclib'] = 'Dok Bibliothek'; @@ -614,6 +615,8 @@ $lang->action->dynamicAction->caselib['hidden'] = 'Hide Case Lib'; $lang->action->dynamicAction->zahost['created'] = 'Create Host'; +$lang->action->dynamicAction->vmtemplate['created'] = 'Create Virtual Host Template'; + $lang->action->dynamicAction->doclib['created'] = 'Create Doc Library'; $lang->action->dynamicAction->doclib['edited'] = 'Edit Doc Library'; $lang->action->dynamicAction->doclib['deleted'] = 'Delete Doc Library'; diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 306c28d0cd..47fff5fdb9 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -112,6 +112,7 @@ $lang->action->objectTypes['testsuite'] = 'Suite'; $lang->action->objectTypes['testtask'] = 'Test Build'; $lang->action->objectTypes['testreport'] = 'Report'; $lang->action->objectTypes['zahost'] = 'Host'; +$lang->action->objectTypes['vmtemplate'] = 'Virtual Host Template'; $lang->action->objectTypes['doc'] = 'Document'; $lang->action->objectTypes['api'] = 'Interface'; $lang->action->objectTypes['doclib'] = 'Document Library'; @@ -614,6 +615,8 @@ $lang->action->dynamicAction->caselib['hidden'] = 'Hide Case Lib'; $lang->action->dynamicAction->zahost['created'] = 'Create Host'; +$lang->action->dynamicAction->vmtemplate['created'] = 'Create Virtual Host Template'; + $lang->action->dynamicAction->doclib['created'] = 'Create Doc Library'; $lang->action->dynamicAction->doclib['edited'] = 'Edit Doc Library'; $lang->action->dynamicAction->doclib['deleted'] = 'Delete Doc Library'; diff --git a/module/action/lang/fr.php b/module/action/lang/fr.php index c917fcd4ce..4baf1ad0ad 100644 --- a/module/action/lang/fr.php +++ b/module/action/lang/fr.php @@ -614,6 +614,8 @@ $lang->action->dynamicAction->caselib['hidden'] = 'Masqué CasTest Lib'; $lang->action->dynamicAction->zahost['created'] = 'Create Host'; +$lang->action->dynamicAction->vmtemplate['created'] = 'Create Virtual Host Template'; + $lang->action->dynamicAction->doclib['created'] = 'Créer Doc Library'; $lang->action->dynamicAction->doclib['edited'] = 'Editer Doc Library'; $lang->action->dynamicAction->doclib['deleted'] = 'Delete Doc Library'; diff --git a/module/action/lang/vi.php b/module/action/lang/vi.php index 090e38e92e..659238be5b 100644 --- a/module/action/lang/vi.php +++ b/module/action/lang/vi.php @@ -89,6 +89,7 @@ $lang->action->objectTypes['testsuite'] = 'Suite'; $lang->action->objectTypes['testtask'] = 'Test bản dựng'; $lang->action->objectTypes['testreport'] = 'Báo cáo'; $lang->action->objectTypes['zahost'] = 'Host'; +$lang->action->objectTypes['vmtemplate'] = 'Virtual Host Template'; $lang->action->objectTypes['doc'] = 'Tài liệu'; $lang->action->objectTypes['doclib'] = 'Thư viện tài liệu'; $lang->action->objectTypes['todo'] = 'Việc làm'; @@ -475,6 +476,8 @@ $lang->action->dynamicAction->caselib['hidden'] = 'Ẩn Case Lib'; $lang->action->dynamicAction->zahost['created'] = 'Create Host'; +$lang->action->dynamicAction->vmtemplate['created'] = 'Create Virtual Host Template'; + $lang->action->dynamicAction->doclib['created'] = 'Tạo Doc thư viện'; $lang->action->dynamicAction->doclib['edited'] = 'Sửa Doc thư viện'; $lang->action->dynamicAction->doclib['deleted'] = 'Delete Doc Library'; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index 4336f42d23..2195dacd35 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -112,6 +112,7 @@ $lang->action->objectTypes['testsuite'] = '套件'; $lang->action->objectTypes['testtask'] = '测试单'; $lang->action->objectTypes['testreport'] = '报告'; $lang->action->objectTypes['zahost'] = '宿主机'; +$lang->action->objectTypes['vmtemplate'] = '虚拟机模板'; $lang->action->objectTypes['doc'] = '文档'; $lang->action->objectTypes['api'] = '接口'; $lang->action->objectTypes['doclib'] = '文档库'; @@ -614,6 +615,8 @@ $lang->action->dynamicAction->caselib['hidden'] = '隐藏用例库'; $lang->action->dynamicAction->zahost['created'] = '创建宿主机'; +$lang->action->dynamicAction->vmtemplate['created'] = '创建虚拟机模板'; + $lang->action->dynamicAction->doclib['created'] = '创建文档库'; $lang->action->dynamicAction->doclib['edited'] = '编辑文档库'; $lang->action->dynamicAction->doclib['deleted'] = '删除文档库'; diff --git a/module/common/lang/menu.php b/module/common/lang/menu.php index 35d5229042..f71684422f 100644 --- a/module/common/lang/menu.php +++ b/module/common/lang/menu.php @@ -397,7 +397,7 @@ $lang->qa->menuOrder[40] = 'caselib'; $lang->qa->menuOrder[45] = 'zahost'; $lang->qa->menu->zahost['subMenu'] = new stdclass(); -$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create'); +$lang->qa->menu->zahost['subMenu']->browse = array('link' => "{$lang->zahost->common}|zahost|browse", 'alias' => 'browse,create,createtemplate'); // $lang->qa->menu->automation['subMenu'] = new stdclass(); // $lang->qa->menu->automation['subMenu']->browse = array('link' => "{$lang->automation->common}|zahost|browse", 'alias' => 'create'); diff --git a/module/zahost/config.php b/module/zahost/config.php index b921b6dc40..351a352051 100644 --- a/module/zahost/config.php +++ b/module/zahost/config.php @@ -3,6 +3,24 @@ $config->zahost->create = new stdclass(); $config->zahost->create->requiredFields = 'name,hostType,publicIP,cpuCores,memory,diskSize,virtualSoftware,instanceNum'; $config->zahost->create->ipFields = 'publicIP'; +$config->zahost->createTemplate = new stdclass(); +$config->zahost->createTemplate->requiredFields = 'name,cpuCoreNum,memorySize,diskSize,osCategory,osType,osVersion,osLang'; + +$config->zahost->os = new stdClass(); +$config->zahost->os->list = array(); +$config->zahost->os->list['windows'] = 'Windows'; +$config->zahost->os->list['linux'] = 'Linux'; + +$config->zahost->os->type = array(); +$config->zahost->os->type['windows']['winServer'] = 'Windows Server'; +$config->zahost->os->type['windows']['win11'] = 'Windows 11'; +$config->zahost->os->type['windows']['win10'] = 'Windows 10'; +$config->zahost->os->type['windows']['win7'] = 'Windows 7'; +$config->zahost->os->type['windows']['winxp'] = 'Windows XP'; +$config->zahost->os->type['linux']['ubuntu'] = 'Ubuntu'; +$config->zahost->os->type['linux']['centos'] = 'CentOS'; +$config->zahost->os->type['linux']['debian'] = 'Debian'; + global $lang; $config->zahost->search['module'] = 'zahost'; $config->zahost->search['fields']['name'] = $lang->zahost->name; diff --git a/module/zahost/control.php b/module/zahost/control.php index e0690ebd10..e159a67f1f 100644 --- a/module/zahost/control.php +++ b/module/zahost/control.php @@ -74,4 +74,24 @@ class zahost extends control $this->view->title = $this->lang->zahost->create; $this->display(); } + + /** + * Create template. + * + * @access public + * @return void + */ + public function createTemplate() + { + if($_POST) + { + $this->zahost->createTemplate(); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inLink('browse'))); + } + + $this->view->title = $this->lang->zahost->createTemplate; + $this->display(); + } } diff --git a/module/zahost/js/createtemplate.js b/module/zahost/js/createtemplate.js new file mode 100755 index 0000000000..0f11e6e384 --- /dev/null +++ b/module/zahost/js/createtemplate.js @@ -0,0 +1,40 @@ +$(function() +{ + $('#osCategory').change(function() + { + var os = $('#osCategory').val(); + $('#osType').empty(); + var types = zahostConfig.os.type[os]; + for(code in types) $('#osType').append(''); + $('#osType').chosen().trigger('chosen:updated'); + $('#osType').change(); + }); + + $('#osType').change(function() + { + var type = $('#osType').val(); + $('#osVersion').empty(); + var versions = zahostLang.versionList[type]; + for(code in versions) $('#osVersion').append(''); + $('#osVersion').chosen().trigger('chosen:updated'); + $('#osVersion').change(); + }); + + $('#osVersion').change(function() + { + if(config.currentMethod != 'create') return; + + var os = $('#osCategory').val(); + var type = $('#osType').val(); + var version = $('#osVersion').val(); + var link = createLink('zahost', 'ajaxGetVmTemplateList', 'osCategory=' + os + '&osType=' + type + '&osVersion=' + version); + $.get(link, function(data) + { + $('#template').html('').append(data); + if(template) $('#vmTemplate').val(template.id); + $('#vmTemplate').chosen().trigger("chosen:updated"); + }); + }); + + $('#osCategory').change(); +}) diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index b168a3b19d..941d615211 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -13,7 +13,7 @@ $lang->zahost->all = '所有主机'; $lang->zahost->name = '名称'; $lang->zahost->IP = 'IP'; $lang->zahost->publicIP = 'IP'; -$lang->zahost->memory = '内存大小'; +$lang->zahost->memory = '内存'; $lang->zahost->cpuCores = 'CPU核心数'; $lang->zahost->diskSize = '硬盘容量'; $lang->zahost->instanceNum = '最大实例数'; @@ -26,6 +26,32 @@ $lang->zahost->editedBy = '由谁修改'; $lang->zahost->editedDate = '最后修改时间'; $lang->zahost->registerDate = '最后注册时间'; +$lang->zahost->createTemplate = '创建虚拟机模板'; + +$lang->zahost->memorySize = $lang->zahost->memory; +$lang->zahost->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->osType = '操作系统版本'; +$lang->zahost->osCategory = '操作系统平台'; +$lang->zahost->osVersion = '操作系统版本号'; +$lang->zahost->osLang = '系统语言'; +$lang->zahost->imageFile = '镜像文件'; + +$lang->zahost->vmTemplate = new stdclass; +$lang->zahost->vmTemplate->name = '名称'; +$lang->zahost->vmTemplate->cpuCoreNum = $lang->zahost->cpuCores; +$lang->zahost->vmTemplate->memorySize = $lang->zahost->memory; +$lang->zahost->vmTemplate->diskSize = $lang->zahost->diskSize; +$lang->zahost->vmTemplate->osType = $lang->zahost->osType; +$lang->zahost->vmTemplate->osCategory = $lang->zahost->osCategory; +$lang->zahost->vmTemplate->osVersion = $lang->zahost->osVersion; +$lang->zahost->vmTemplate->osLang = $lang->zahost->osLang; +$lang->zahost->vmTemplate->imageFile = $lang->zahost->imageFile; + +$lang->zahost->langList = array(); +$lang->zahost->langList['zh_cn'] = '简体中文'; +$lang->zahost->langList['zh_tw'] = '繁体中文'; +$lang->zahost->langList['en_us'] = '美式英语'; + $lang->zahost->empty = '暂时没有主机'; $lang->zahost->statusList['online'] = '已上架'; @@ -42,5 +68,33 @@ $lang->zahost->zaHostTypeList['physical'] = '实体主机'; $lang->zahost->confirmDelete = '是否删除该主机记录?'; +$lang->zahost->versionList = array(); +$lang->zahost->versionList['winxp']['all'] = 'Windows XP'; +$lang->zahost->versionList['win7']['home'] = '家庭版'; +$lang->zahost->versionList['win7']['professional'] = '专业版'; +$lang->zahost->versionList['win7']['enterprise'] = '企业版'; +$lang->zahost->versionList['win7']['ultimate'] = '旗舰版'; +$lang->zahost->versionList['win10']['home'] = '家庭版'; +$lang->zahost->versionList['win10']['professional'] = '专业版'; +$lang->zahost->versionList['win10']['enterprise'] = '企业版'; +$lang->zahost->versionList['win10']['ultimate'] = '旗舰版'; +$lang->zahost->versionList['win11']['home'] = '家庭版'; +$lang->zahost->versionList['win11']['professional'] = '专业版'; +$lang->zahost->versionList['win11']['enterprise'] = '企业版'; +$lang->zahost->versionList['win11']['ultimate'] = '旗舰版'; +$lang->zahost->versionList['winServer']['2008'] = '2008'; +$lang->zahost->versionList['winServer']['2012'] = '2012'; +$lang->zahost->versionList['winServer']['2016'] = '2016'; +$lang->zahost->versionList['winServer']['2019'] = '2019'; +$lang->zahost->versionList['debian']['9'] = '9'; +$lang->zahost->versionList['debian']['10'] = '10'; +$lang->zahost->versionList['debian']['11'] = '11'; +$lang->zahost->versionList['ubuntu']['16'] = '16'; +$lang->zahost->versionList['ubuntu']['18'] = '18'; +$lang->zahost->versionList['ubuntu']['20'] = '20'; +$lang->zahost->versionList['centos']['6'] = '6'; +$lang->zahost->versionList['centos']['7'] = '7'; +$lang->zahost->versionList['centos']['8'] = '8'; + $lang->zahost->notice = new stdclass(); $lang->zahost->notice->ip = '『%s』格式不正确!'; diff --git a/module/zahost/model.php b/module/zahost/model.php index b01042565a..c8f576dc25 100644 --- a/module/zahost/model.php +++ b/module/zahost/model.php @@ -20,7 +20,8 @@ class zahostModel extends model public function __construct() { parent::__construct(); - $this->app->lang->host = $this->lang->zahost; + $this->app->lang->host = $this->lang->zahost; + $this->app->lang->vmtemplate = $this->lang->zahost; } /** @@ -134,4 +135,27 @@ class zahostModel extends model ->page($pager) ->fetchAll(); } + + /** + * Create vm template. + * + * @access public + * @return void + */ + public function createTemplate() + { + $template = fixer::input('post') + ->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024) + ->get(); + + $this->dao->insert(TABLE_VMTEMPLATE)->data($template) + ->batchCheck($this->config->zahost->createTemplate->requiredFields, 'notempty') + ->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0) + ->autoCheck() + ->exec(); + if(dao::isError()) return false; + + $templateID = $this->dao->lastInsertID(); + $this->loadModel('action')->create('vmtemplate', $templateID, 'Created'); + } } diff --git a/module/zahost/view/createtemplate.html.php b/module/zahost/view/createtemplate.html.php new file mode 100644 index 0000000000..6363a1e6f2 --- /dev/null +++ b/module/zahost/view/createtemplate.html.php @@ -0,0 +1,80 @@ + + * @package zahost + * @version $Id$ + * @link http://www.zentao.net + */ +?> +getModuleRoot() . 'common/view/header.html.php';?> +zahost);?> +zahost);?> + +