* Edit VM template.
This commit is contained in:
@@ -9,6 +9,9 @@ $config->zahost->edit->requiredFields = 'name,hostType,cpuCores,memory,diskSize,
|
||||
$config->zahost->createtemplate = new stdclass();
|
||||
$config->zahost->createtemplate->requiredFields = 'name,cpuCoreNum,memorySize,diskSize,osCategory,osType,osVersion,osLang,imageName';
|
||||
|
||||
$config->zahost->edittemplate = new stdclass();
|
||||
$config->zahost->edittemplate->requiredFields = 'name,cpuCoreNum,memorySize,diskSize,osCategory,osType,osVersion,osLang,imageName';
|
||||
|
||||
$config->zahost->os = new stdClass();
|
||||
$config->zahost->os->list = array();
|
||||
$config->zahost->os->list['windows'] = 'Windows';
|
||||
|
||||
@@ -76,7 +76,7 @@ class zahost extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* Create host.
|
||||
* Edit host.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @access public
|
||||
@@ -166,6 +166,38 @@ class zahost extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit template
|
||||
*
|
||||
* @param int $templateID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function editTemplate($templateID)
|
||||
{
|
||||
$template = $this->zahost->getTemplateById($templateID);
|
||||
if($_POST)
|
||||
{
|
||||
$changes = $this->zahost->updateTemplate($templateID);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
if($changes)
|
||||
{
|
||||
$actionID = $this->loadModel('action')->create('vmtemplate', $templateID, 'Edited');
|
||||
if(!empty($changes)) $this->action->logHistory($actionID, $changes);
|
||||
}
|
||||
|
||||
if(isonlybody()) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent'));
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browsetemplate', "hostID={$template->hostID}")));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->zahost->edit;
|
||||
$this->view->template = $template;
|
||||
$this->view->imageOptions = array('' => $this->lang->zahost->notice->loading);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/*
|
||||
* Browse VM template.
|
||||
*
|
||||
@@ -228,13 +260,14 @@ class zahost extends control
|
||||
* Get image list by ajax.
|
||||
*
|
||||
* @param int $hostID
|
||||
* @param int $templateID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function ajaxImageList($hostID)
|
||||
public function ajaxImageList($hostID, $templateID = null)
|
||||
{
|
||||
$host = $this->zahost->getById($hostID);
|
||||
$imageList = $this->zahost->getImageList($host);
|
||||
$imageList = $this->zahost->getImageList($host, $templateID);
|
||||
|
||||
if($imageList) return $this->send(array('result' => 'success', 'message' => '', 'data' => array($imageList)));
|
||||
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
$(function()
|
||||
{
|
||||
$.get(createLink('zahost', 'ajaxImageList', 'hostID=' + hostID), function(response)
|
||||
if(typeof(hostID) != 'undefined')
|
||||
{
|
||||
var resultData = JSON.parse(response);
|
||||
var options = '';
|
||||
if(resultData.result == 'success')
|
||||
var templateID = 0;
|
||||
if(typeof(template) == 'object') templateID = template.id;
|
||||
$.get(createLink('zahost', 'ajaxImageList', 'hostID=' + hostID + '&templateID=' + templateID), function(response)
|
||||
{
|
||||
resultData.data.forEach(function(item)
|
||||
var resultData = JSON.parse(response);
|
||||
var options = '';
|
||||
if(resultData.result == 'success')
|
||||
{
|
||||
options += "<option value='" + item.name + "'>" + item.name + "</option>";
|
||||
});
|
||||
}
|
||||
|
||||
$('#imageName').replaceWith("<select name='imageName' id='imageName' class='form-control'>" + options + "</select>");
|
||||
$("#imageName_chosen").remove();
|
||||
$("#imageName").next('.picker').remove();
|
||||
$('#imageName').chosen();
|
||||
|
||||
if(resultData.result == 'fail')
|
||||
{
|
||||
$('#imageName_chosen a:first-child').addClass('has-error');
|
||||
if(resultData.message.imageName)
|
||||
{
|
||||
var errors = resultData.message.imageName.join('');
|
||||
$('#imageName_chosen').after("<div id='imageNameLabel' class='text-danger helper-text'>" + errors + "</div>");
|
||||
resultData.data.forEach(function(item)
|
||||
{
|
||||
options += "<option value='" + item.name + "'>" + item.name + "</option>";
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#imageName').replaceWith("<select name='imageName' id='imageName' class='form-control'>" + options + "</select>");
|
||||
$("#imageName_chosen").remove();
|
||||
$("#imageName").next('.picker').remove();
|
||||
$('#imageName').chosen();
|
||||
|
||||
if(resultData.result == 'fail')
|
||||
{
|
||||
$('#imageName_chosen a:first-child').addClass('has-error');
|
||||
if(resultData.message.imageName)
|
||||
{
|
||||
var errors = resultData.message.imageName.join('');
|
||||
$('#imageName_chosen').after("<div id='imageNameLabel' class='text-danger helper-text'>" + errors + "</div>");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#osCategory').change(function()
|
||||
{
|
||||
+35
-3
@@ -37,7 +37,7 @@ class zahostModel extends model
|
||||
->get();
|
||||
|
||||
$this->dao->table = 'zahost';
|
||||
$this->dao->update(TABLE_ZAHOST)->data($hostInfo)
|
||||
$this->dao-> update(TABLE_ZAHOST)->data($hostInfo)
|
||||
->batchCheck($this->config->zahost->create->requiredFields, 'notempty')
|
||||
->batchCheck('cpuCores,diskSize,instanceNum', 'gt', 0)
|
||||
->batchCheck('diskSize,memory', 'float')
|
||||
@@ -140,6 +140,37 @@ class zahostModel extends model
|
||||
$this->loadModel('action')->create('vmtemplate', $templateID, 'Created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit template
|
||||
*
|
||||
* @param int $templateID
|
||||
* @access public
|
||||
* @return bool|object
|
||||
*/
|
||||
public function updateTemplate($templateID)
|
||||
{
|
||||
$oldHost = $this->getTemplateById($templateID);
|
||||
$templateInfo = fixer::input('post')
|
||||
->setIF($this->post->diskSize > 0, 'diskSize', $this->post->diskSize * 1024)
|
||||
->get();
|
||||
|
||||
$this->dao->update(TABLE_VMTEMPLATE)->data($templateInfo)
|
||||
->batchCheck($this->config->zahost->edittemplate->requiredFields, 'notempty')
|
||||
->batchCheck('cpuCoreNum,diskSize,memorySize', 'gt', 0)
|
||||
->autoCheck();
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$templateInfo->editedBy = $this->app->user->account;
|
||||
$templateInfo->editedDate = helper::now();
|
||||
|
||||
$this->dao->update(TABLE_VMTEMPLATE)->data($templateInfo)->autoCheck()
|
||||
->where('id')->eq($oldHost->id)
|
||||
->exec();
|
||||
if(dao::isError()) return false;
|
||||
|
||||
return common::createChanges($oldHost, $templateInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image files from ZAgent server.
|
||||
*
|
||||
@@ -147,12 +178,13 @@ class zahostModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getImageList($host)
|
||||
public function getImageList($host, $templateID = null)
|
||||
{
|
||||
$result = json_decode(commonModel::http("http://{$host->publicIP}:8086/api/v1/kvm/listTmpl?token={$host->secret}"));
|
||||
if(empty($result) || $result->code != 200) return array();
|
||||
|
||||
$usedImageList = $this->dao->select('imageName')->from(TABLE_VMTEMPLATE)->where('hostID')->eq($host->hostID)->fetchAll('imageName');
|
||||
$usedImageList = array();
|
||||
if(empty($templateID)) $usedImageList = $this->dao->select('imageName')->from(TABLE_VMTEMPLATE)->where('hostID')->eq($host->hostID)->fetchAll('imageName');
|
||||
|
||||
$imageList = array();
|
||||
foreach($result->data as $image)
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
<th class='c-os'><?php common::printOrderLink('osType', $orderBy, $vars, $lang->zahost->osType);?></th>
|
||||
<th class='c-os'><?php common::printOrderLink('osVersion', $orderBy, $vars, $lang->zahost->osVersion);?></th>
|
||||
<th class='c-lang'><?php common::printOrderLink('osLang', $orderBy, $vars, $lang->zahost->osLang);?></th>
|
||||
<th class='c-actions-2 text-center'><?php echo $lang->actions;?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -62,6 +63,10 @@
|
||||
<td><?php echo zget($config->zahost->os->type[$template->osCategory], $template->osType);?></td>
|
||||
<td><?php echo zget($lang->zahost->versionList[$template->osType], $template->osVersion);?></td>
|
||||
<td><?php echo zget($lang->zahost->langList, $template->osLang);?></td>
|
||||
<td class='c-actions'>
|
||||
<?php common::printIcon('zahost', 'editTemplate', "id={$template->id}", $template, 'list', 'edit');?>
|
||||
<?php if(common::hasPriv('zahost', 'deleteTemplate')) echo html::a($this->createLink('zahost', 'delete', "id={$template->id}"), '<i class="icon-trash"></i>', 'hiddenwin', "title='{$lang->zahost->delete}' class='btn'");;?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
|
||||
@@ -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-100px'><?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';?>
|
||||
Reference in New Issue
Block a user