- Community Home
- >
- Software
- >
- HPE Morpheus Software
- >
- HPE Morpheus Enterprise
- >
- Dynamically calculate and set the maxMemory and ma...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 06:04 AM
11-01-2023 06:04 AM
Dynamically calculate and set the maxMemory and maxCores property using customOptions in a catalog
This code is used to dynamically calculate and set the maxMemory
property based on the value of customOptions?.ram
in a catalog config. If customOptions?.ram
is defined and not empty, it calculates the maximum memory in bytes (assuming customOptions?.ram
is provided in gigabytes). Otherwise, it sets maxMemory
to 0%. Similarly, it can be used to dynamically set the maximum number of CPU cores based on the value of customOptions.cpu
. If customOptions.cpu
is provided, it uses that value. Otherwise, it defaults to 0.
"servicePlanOptions": {
"maxCores": "<%=customOptions.cpu ?: 0%>",
"coresPerSocket": 1,
"maxMemory": "<%=if (customOptions?.ram && customOptions?.ram != ''){customOptions?.ram?.toLong() * 1024 * 1024 * 1024} else {0}%>",
"forPlan": 1052,
},
Putting it all together:
1 - If customOptions.cpu
is defined and not null, the value of "maxCores"
will be set to customOptions.cpu
.
2 - If customOptions.cpu
is not defined or null, the value of "maxCores"
will be set to 0.
3 - if (customOptions?.ram && customOptions?.ram != ''){...} else {...}
: This is a conditional statement. It checks if customOptions?.ram
is defined and not an empty string. If the condition is true, it executes the code in the first block, otherwise, it executes the code in the second block.
4 - customOptions?.ram?.toLong() * 1024 * 1024 * 1024
: If the condition is true, this line multiplies the value of customOptions?.ram
(converted to a long integer) by 1024^3, effectively converting it from gigabytes to bytes.
5 - else {0}
: If the condition is false (i.e., customOptions?.ram
is either not defined or an empty string), this sets the value to 0.