Skip to content

Commit 2c176ab

Browse files
sanjaytripathipranavs
authored andcommitted
CLOUDSTACK-1592:[UI] Add support to limit newly added resourcetypes
1 parent d13c185 commit 2c176ab

5 files changed

Lines changed: 254 additions & 11 deletions

File tree

client/WEB-INF/classes/resources/messages.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#new labels (begin) **********************************************************************************************
2020
message.redirecting.region=Redirecting to region...
2121
label.use.vm.ip=Use VM IP:
22+
label.cpu.limits=CPU limits
23+
label.memory.limits=Memory limits (MiB)
24+
label.primary.storage.limits=Primary Storage limits (GiB)
25+
label.secondary.storage.limits=Secondary Storage limits (GiB)
26+
label.max.cpus=Max. CPU cores
27+
label.max.memory=Max. memory (MiB)
28+
label.max.primary.storage=Max. primary (GiB)
29+
label.max.secondary.storage=Max. secondary (GiB)
2230
label.menu.regions=Regions
2331
label.region=Region
2432
label.add.region=Add Region

ui/dictionary.jsp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ under the License.
2727
dictionary = {
2828
'message.redirecting.region': '<fmt:message key="message.redirecting.region"/>',
2929
'label.use.vm.ip': '<fmt:message key="label.use.vm.ip"/>',
30+
'label.cpu.limits': '<fmt:message key="label.cpu.limits"/>',
31+
'label.memory.limits': '<fmt:message key="label.memory.limits"/>',
32+
'label.primary.storage.limits': '<fmt:message key="label.primary.storage.limits"/>',
33+
'label.secondary.storage.limits': '<fmt:message key="label.secondary.storage.limits"/>',
34+
'label.max.cpus': '<fmt:message key="label.max.cpus"/>',
35+
'label.max.memory': '<fmt:message key="label.max.memory"/>',
36+
'label.max.primary.storage': '<fmt:message key="label.max.primary.storage"/>',
37+
'label.max.secondary.storage': '<fmt:message key="label.max.secondary.storage"/>',
3038
'label.add.region': '<fmt:message key="label.add.region"/>',
3139
'label.remove.region': '<fmt:message key="label.remove.region"/>',
3240
'message.remove.region': '<fmt:message key="message.remove.region"/>',

ui/scripts/accounts.js

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,77 @@
409409
});
410410
}
411411

412+
if(args.data.cpuLimit != null) {
413+
var data = {
414+
resourceType: 8,
415+
max: args.data.cpuLimit,
416+
domainid: accountObj.domainid,
417+
account: accountObj.name
418+
};
419+
420+
$.ajax({
421+
url: createURL('updateResourceLimit'),
422+
data: data,
423+
async: false,
424+
success: function(json) {
425+
accountObj["cpuLimit"] = args.data.cpuLimit;
426+
}
427+
});
428+
}
429+
430+
if(args.data.memoryLimit != null) {
431+
var data = {
432+
resourceType: 9,
433+
max: args.data.memoryLimit,
434+
domainid: accountObj.domainid,
435+
account: accountObj.name
436+
};
437+
438+
$.ajax({
439+
url: createURL('updateResourceLimit'),
440+
data: data,
441+
async: false,
442+
success: function(json) {
443+
accountObj["memoryLimit"] = args.data.memoryLimit;
444+
}
445+
});
446+
}
447+
448+
if(args.data.primaryStorageLimit != null) {
449+
var data = {
450+
resourceType: 10,
451+
max: args.data.primaryStorageLimit,
452+
domainid: accountObj.domainid,
453+
account: accountObj.name
454+
};
455+
456+
$.ajax({
457+
url: createURL('updateResourceLimit'),
458+
data: data,
459+
async: false,
460+
success: function(json) {
461+
accountObj["primaryStorageLimit"] = args.data.primaryStorageLimit;
462+
}
463+
});
464+
}
465+
466+
if(args.data.secondaryStorageLimit != null) {
467+
var data = {
468+
resourceType: 11,
469+
max: args.data.secondaryStorageLimit,
470+
domainid: accountObj.domainid,
471+
account: accountObj.name
472+
};
473+
474+
$.ajax({
475+
url: createURL('updateResourceLimit'),
476+
data: data,
477+
async: false,
478+
success: function(json) {
479+
accountObj["secondaryStorageLimit"] = args.data.secondaryStorageLimit;
480+
}
481+
});
482+
}
412483
args.response.success({data: accountObj});
413484
}
414485
},
@@ -698,6 +769,42 @@
698769
return false;
699770
}
700771
},
772+
cpuLimit: {
773+
label: 'label.cpu.limits',
774+
isEditable: function(context) {
775+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
776+
return true;
777+
else
778+
return false;
779+
}
780+
},
781+
memoryLimit: {
782+
label: 'label.memory.limits',
783+
isEditable: function(context) {
784+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
785+
return true;
786+
else
787+
return false;
788+
}
789+
},
790+
primaryStorageLimit: {
791+
label: 'label.primary.storage.limits',
792+
isEditable: function(context) {
793+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
794+
return true;
795+
else
796+
return false;
797+
}
798+
},
799+
secondaryStorageLimit: {
800+
label: 'label.secondary.storage.limits',
801+
isEditable: function(context) {
802+
if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin
803+
return true;
804+
else
805+
return false;
806+
}
807+
},
701808

702809
vmtotal: { label: 'label.total.of.vm' },
703810
iptotal: { label: 'label.total.of.ip' },
@@ -725,19 +832,19 @@
725832
dataProvider: function(args) {
726833
var data = {
727834
id: args.context.accounts[0].id
728-
};
835+
};
729836
$.ajax({
730837
url: createURL('listAccounts'),
731-
data: data,
732-
success: function(json) {
838+
data: data,
839+
success: function(json) {
733840
var accountObj = json.listaccountsresponse.account[0];
734841
var data = {
735842
domainid: accountObj.domainid,
736843
account: accountObj.name
737844
};
738845
$.ajax({
739846
url: createURL('listResourceLimits'),
740-
data: data,
847+
data: data,
741848
success: function(json) {
742849
var limits = json.listresourcelimitsresponse.resourcelimit;
743850
if (limits != null) {
@@ -759,22 +866,34 @@
759866
case "4":
760867
accountObj["templateLimit"] = limit.max;
761868
break;
762-
case "7":
869+
case "7":
763870
accountObj["vpcLimit"] = limit.max;
764871
break;
872+
case "8":
873+
accountObj["cpuLimit"] = limit.max;
874+
break;
875+
case "9":
876+
accountObj["memoryLimit"] = limit.max;
877+
break;
878+
case "10":
879+
accountObj["primaryStorageLimit"] = limit.max;
880+
break;
881+
case "11":
882+
accountObj["secondaryStorageLimit"] = limit.max;
883+
break;
765884
}
766885
}
767-
}
886+
}
768887
args.response.success(
769888
{
770889
actionFilter: accountActionfilter,
771890
data: accountObj
772891
}
773-
);
892+
);
774893
}
775-
});
894+
});
776895
}
777-
});
896+
});
778897
}
779898
}
780899
}

ui/scripts/domains.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,50 @@
184184
});
185185
}
186186

187+
if(args.data.cpuLimit != null) {
188+
$.ajax({
189+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=8&max=" + args.data.cpuLimit),
190+
dataType: "json",
191+
async: false,
192+
success: function(json) {
193+
domainObj["cpuLimit"] = args.data.cpuLimit;
194+
}
195+
});
196+
}
197+
198+
if(args.data.memoryLimit != null) {
199+
$.ajax({
200+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=9&max=" + args.data.memoryLimit),
201+
dataType: "json",
202+
async: false,
203+
success: function(json) {
204+
domainObj["memoryLimit"] = args.data.memoryLimit;
205+
}
206+
});
207+
}
208+
209+
if(args.data.primaryStorageLimit != null) {
210+
$.ajax({
211+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=10&max=" + args.data.primaryStorageLimit),
212+
dataType: "json",
213+
async: false,
214+
success: function(json) {
215+
domainObj["primaryStorageLimit"] = args.data.primaryStorageLimit;
216+
}
217+
});
218+
}
219+
220+
if(args.data.secondaryStorageLimit != null) {
221+
$.ajax({
222+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=11&max=" + args.data.secondaryStorageLimit),
223+
dataType: "json",
224+
async: false,
225+
success: function(json) {
226+
domainObj["secondaryStorageLimit"] = args.data.secondaryStorageLimit;
227+
}
228+
});
229+
}
230+
187231
args.response.success({data: domainObj});
188232
}
189233
},
@@ -348,6 +392,42 @@
348392
return false;
349393
}
350394
},
395+
cpuLimit: {
396+
label: 'label.cpu.limits',
397+
isEditable: function(context) {
398+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
399+
return true;
400+
else
401+
return false;
402+
}
403+
},
404+
memoryLimit: {
405+
label: 'label.memory.limits',
406+
isEditable: function(context) {
407+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
408+
return true;
409+
else
410+
return false;
411+
}
412+
},
413+
primaryStorageLimit: {
414+
label: 'label.primary.storage.limits',
415+
isEditable: function(context) {
416+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
417+
return true;
418+
else
419+
return false;
420+
}
421+
},
422+
secondaryStorageLimit: {
423+
label: 'label.secondary.storage.limits',
424+
isEditable: function(context) {
425+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
426+
return true;
427+
else
428+
return false;
429+
}
430+
},
351431
accountTotal: { label: 'label.accounts' },
352432
vmTotal: { label: 'label.instances' },
353433
volumeTotal: { label: 'label.volumes' }
@@ -441,6 +521,18 @@
441521
case "7":
442522
domainObj["vpcLimit"] = limit.max;
443523
break;
524+
case "8":
525+
domainObj["cpuLimit"] = limit.max;
526+
break;
527+
case "9":
528+
domainObj["memoryLimit"] = limit.max;
529+
break;
530+
case "10":
531+
domainObj["primaryStorageLimit"] = limit.max;
532+
break;
533+
case "7":
534+
domainObj["secondaryStorageLimit"] = limit.max;
535+
break;
444536
}
445537
}
446538
}

ui/scripts/projects.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
var resourceLimits = $.grep(
7272
json.listresourcelimitsresponse.resourcelimit,
7373
function(resourceLimit) {
74-
return resourceLimit.resourcetype != 5 && resourceLimit.resourcetype != 8;
74+
return resourceLimit.resourcetype != 5 && resourceLimit.resourcetype != 12;
7575
}
7676
);
7777

@@ -111,7 +111,23 @@
111111
7: {
112112
id: 'vpc',
113113
label: 'label.max.vpcs'
114-
}
114+
},
115+
8: {
116+
id: 'cpu',
117+
label: 'label.max.cpus'
118+
},
119+
9: {
120+
id: 'memory',
121+
label: 'label.max.memory'
122+
},
123+
10: {
124+
id: 'primary_storage',
125+
label: 'label.max.primary.storage'
126+
},
127+
11: {
128+
id: 'secondary_storage',
129+
label: 'label.max.secondary.storage'
130+
}
115131
};
116132

117133
return {

0 commit comments

Comments
 (0)