mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
new UI - accounts page - implement Resource limits action.
This commit is contained in:
parent
7abda2ee2d
commit
461149a390
@ -139,3 +139,60 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- account detail panel (end) -->
|
||||
|
||||
|
||||
<div id="dialog_resource_limits" title="Resource Limits" style="display:none">
|
||||
<p>Please specify limits to the various resources. A "-1" means the resource has no limits.</p>
|
||||
<div class="dialog_formcontent">
|
||||
<form action="#" method="post" id="form_acquire">
|
||||
<ol>
|
||||
<li>
|
||||
<label for="user_name">Instance Limit:</label>
|
||||
<input class="text" type="text" name="limits_vm" id="limits_vm" value="-1" />
|
||||
<div id="limits_vm_errormsg" class="dialog_formcontent_errormsg" style="display:none;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label for="user_name">Public IP Limit:</label>
|
||||
<input class="text" type="text" name="limits_ip" id="limits_ip" value="-1" />
|
||||
<div id="limits_ip_errormsg" class="dialog_formcontent_errormsg" style="display:none;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label for="user_name">Disk Volume Limit:</label>
|
||||
<input class="text" type="text" name="limits_volume" id="limits_volume" value="-1" />
|
||||
<div id="limits_volume_errormsg" class="dialog_formcontent_errormsg" style="display:none;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label for="user_name">Snapshot Limit:</label>
|
||||
<input class="text" type="text" name="limits_snapshot" id="limits_snapshot" value="-1" />
|
||||
<div id="limits_snapshot_errormsg" class="dialog_formcontent_errormsg" style="display:none;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label for="user_name">Template Limit:</label>
|
||||
<input class="text" type="text" name="limits_template" id="limits_template" value="-1" />
|
||||
<div id="limits_template_errormsg" class="dialog_formcontent_errormsg" style="display:none;"></div>
|
||||
</li>
|
||||
</ol>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- disable or lock an account (begin) -->
|
||||
<div id="dialog_disable_account" title="Disable Account" style="display:none">
|
||||
<p>Select <b>"Disable"</b> to prevent account access to the cloud and to shut down all existing virtual instances.<br></br>
|
||||
Select <b>"Lock"</b> to ONLY prevent account access to the cloud. <br></br>
|
||||
</p>
|
||||
<div class="dialog_formcontent">
|
||||
<form action="#" method="post" id="form1">
|
||||
<ol>
|
||||
<li>
|
||||
<label>Action: </label>
|
||||
<select class="select" id="change_state_type">
|
||||
<option value="disable" selected>Disable</option>
|
||||
<option value="lock">Lock</option>
|
||||
</select>
|
||||
</li>
|
||||
</ol>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- disable or lock an account (end) -->
|
||||
@ -1,5 +1,18 @@
|
||||
function afterLoadAccountJSP() {
|
||||
var systemAccountId = 1;
|
||||
var adminAccountId = 2;
|
||||
|
||||
function afterLoadAccountJSP() {
|
||||
activateDialog($("#dialog_resource_limits").dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
zIndex: 2000
|
||||
}));
|
||||
|
||||
activateDialog($("#dialog_disable_account").dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
zIndex: 2000
|
||||
}));
|
||||
}
|
||||
|
||||
function accountToMidmenu(jsonObj, $midmenuItem1) {
|
||||
@ -20,15 +33,135 @@ function accountToMidmenu(jsonObj, $midmenuItem1) {
|
||||
|
||||
function accountToRigntPanel($midmenuItem) {
|
||||
var jsonObj = $midmenuItem.data("jsonObj");
|
||||
accountJsonToDetailsTab(jsonObj);
|
||||
}
|
||||
|
||||
function accountJsonToDetailsTab(jsonObj) {
|
||||
var $detailsTab = $("#right_panel_content #tab_content_details");
|
||||
$detailsTab.data("jsonObj", jsonObj);
|
||||
$detailsTab.find("#id").text(jsonObj.id);
|
||||
$detailsTab.find("#role").text(toRole(jsonObj.accounttype));
|
||||
$detailsTab.find("#account").text(fromdb(jsonObj.name));
|
||||
$detailsTab.find("#domain").text(fromdb(jsonObj.domain));
|
||||
$detailsTab.find("#vm_total").text(jsonObj.vmtotal);
|
||||
$detailsTab.find("#ip_total").text(jsonObj.iptotal);
|
||||
$detailsTab.find("#bytes_received").text(jsonObj.receivedbytes);
|
||||
$detailsTab.find("#bytes_sent").text(jsonObj.sentbytes);
|
||||
$detailsTab.find("#state").text(jsonObj.state);
|
||||
|
||||
var $rightPanelContent = $("#right_panel_content");
|
||||
$rightPanelContent.find("#id").text(jsonObj.id);
|
||||
$rightPanelContent.find("#role").text(toRole(jsonObj.accounttype));
|
||||
$rightPanelContent.find("#account").text(fromdb(jsonObj.name));
|
||||
$rightPanelContent.find("#domain").text(fromdb(jsonObj.domain));
|
||||
$rightPanelContent.find("#vm_total").text(jsonObj.vmtotal);
|
||||
$rightPanelContent.find("#ip_total").text(jsonObj.iptotal);
|
||||
$rightPanelContent.find("#bytes_received").text(jsonObj.receivedbytes);
|
||||
$rightPanelContent.find("#bytes_sent").text(jsonObj.sentbytes);
|
||||
$rightPanelContent.find("#state").text(jsonObj.state);
|
||||
}
|
||||
//actions ***
|
||||
var $actionMenu = $("#right_panel_content #tab_content_details #action_link #action_menu");
|
||||
$actionMenu.find("#action_list").empty();
|
||||
if(jsonObj.id != systemAccountId && jsonObj.id != adminAccountId) {
|
||||
if (jsonObj.accounttype == roleTypeUser || jsonObj.accounttype == roleTypeDomainAdmin)
|
||||
buildActionLinkForDetailsTab("Resource limits", accountActionMap, $actionMenu, accountListAPIMap);
|
||||
|
||||
// if(jsonObj.state == "enabled")
|
||||
// buildActionLinkForDetailsTab("Disable", accountActionMap, $actionMenu, accountListAPIMap);
|
||||
// else if(jsonObj.state == "disabled")
|
||||
// buildActionLinkForDetailsTab("Enable", accountActionMap, $actionMenu, accountListAPIMap);
|
||||
}
|
||||
}
|
||||
|
||||
var accountActionMap = {
|
||||
"Resource limits": {
|
||||
customActionFn : doResourceLimits
|
||||
}
|
||||
};
|
||||
|
||||
var accountListAPIMap = {
|
||||
listAPI: "listAccounts",
|
||||
listAPIResponse: "listaccountsresponse",
|
||||
listAPIResponseObj: "account"
|
||||
};
|
||||
|
||||
function updateResourceLimit(domainId, account, type, max) {
|
||||
$.ajax({
|
||||
data: createURL("command=updateResourceLimit&domainid="+domainId+"&account="+account+"&resourceType="+type+"&max="+max),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function doResourceLimits () {
|
||||
var $detailsTab = $("#right_panel_content #tab_content_details");
|
||||
var jsonObj = $detailsTab.data("jsonObj");
|
||||
var domainId = jsonObj.domainid;
|
||||
var account = jsonObj.name;
|
||||
$.ajax({
|
||||
cache: false,
|
||||
data: createURL("command=listResourceLimits&domainid="+domainId+"&account="+account),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var limits = json.listresourcelimitsresponse.resourcelimit;
|
||||
var preInstanceLimit, preIpLimit, preDiskLimit, preSnapshotLimit, preTemplateLimit = -1;
|
||||
if (limits != null) {
|
||||
for (var i = 0; i < limits.length; i++) {
|
||||
var limit = limits[i];
|
||||
switch (limit.resourcetype) {
|
||||
case "0":
|
||||
preInstanceLimit = limit.max;
|
||||
$("#dialog_resource_limits #limits_vm").val(limit.max);
|
||||
break;
|
||||
case "1":
|
||||
preIpLimit = limit.max;
|
||||
$("#dialog_resource_limits #limits_ip").val(limit.max);
|
||||
break;
|
||||
case "2":
|
||||
preDiskLimit = limit.max;
|
||||
$("#dialog_resource_limits #limits_volume").val(limit.max);
|
||||
break;
|
||||
case "3":
|
||||
preSnapshotLimit = limit.max;
|
||||
$("#dialog_resource_limits #limits_snapshot").val(limit.max);
|
||||
break;
|
||||
case "4":
|
||||
preTemplateLimit = limit.max;
|
||||
$("#dialog_resource_limits #limits_template").val(limit.max);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$("#dialog_resource_limits")
|
||||
.dialog('option', 'buttons', {
|
||||
"Save": function() {
|
||||
// validate values
|
||||
var isValid = true;
|
||||
isValid &= validateNumber("Instance Limit", $("#dialog_resource_limits #limits_vm"), $("#dialog_resource_limits #limits_vm_errormsg"), -1, 32000, false);
|
||||
isValid &= validateNumber("Public IP Limit", $("#dialog_resource_limits #limits_ip"), $("#dialog_resource_limits #limits_ip_errormsg"), -1, 32000, false);
|
||||
isValid &= validateNumber("Disk Volume Limit", $("#dialog_resource_limits #limits_volume"), $("#dialog_resource_limits #limits_volume_errormsg"), -1, 32000, false);
|
||||
isValid &= validateNumber("Snapshot Limit", $("#dialog_resource_limits #limits_snapshot"), $("#dialog_resource_limits #limits_snapshot_errormsg"), -1, 32000, false);
|
||||
isValid &= validateNumber("Template Limit", $("#dialog_resource_limits #limits_template"), $("#dialog_resource_limits #limits_template_errormsg"), -1, 32000, false);
|
||||
if (!isValid) return;
|
||||
|
||||
var instanceLimit = trim($("#dialog_resource_limits #limits_vm").val());
|
||||
var ipLimit = trim($("#dialog_resource_limits #limits_ip").val());
|
||||
var diskLimit = trim($("#dialog_resource_limits #limits_volume").val());
|
||||
var snapshotLimit = trim($("#dialog_resource_limits #limits_snapshot").val());
|
||||
var templateLimit = trim($("#dialog_resource_limits #limits_template").val());
|
||||
|
||||
$(this).dialog("close");
|
||||
if (instanceLimit != preInstanceLimit) {
|
||||
updateResourceLimit(domainId, account, 0, instanceLimit);
|
||||
}
|
||||
if (ipLimit != preIpLimit) {
|
||||
updateResourceLimit(domainId, account, 1, ipLimit);
|
||||
}
|
||||
if (diskLimit != preDiskLimit) {
|
||||
updateResourceLimit(domainId, account, 2, diskLimit);
|
||||
}
|
||||
if (snapshotLimit != preSnapshotLimit) {
|
||||
updateResourceLimit(domainId, account, 3, snapshotLimit);
|
||||
}
|
||||
if (templateLimit != preTemplateLimit) {
|
||||
updateResourceLimit(domainId, account, 4, templateLimit);
|
||||
}
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user