Skip to main content

Hi Community,

We are working on enhancing our automation flows in Nutanix Self-Service blueprints and would like some guidance on the best way to approach two things:

  1. Enable memory overcommit automatically for every VM deployed from a blueprint: Our goal is that VMs should always have this applied at deployment time without requiring manual adjustment later.
  2. Ensure category assignment is mandatory for deployed VMs: We would like to implement a check so that if a VM doesn’t have a category assigned during creation, the workflow requires a category before it can proceed.

Is there a preferable script type or approach for implementing these checks and automations within Self-Service? Any suggestions on best practices - especially regarding script selection - would be highly appreciated.

 

Thank you in advance!

Hello ​@mariakalendarova 

 

Let me answer the second part of your question:
 

  • In the BP launch form itself, you cannot force categories to be a mandatory field.
  • There is a way to do it, but the applications will start, then it will fail with a specific message.
  • Here is what you need to do:
  1. Create a credential for Prism Central (an account with permissions to run APIs)
  2. In every Service (VM) you configure in the BP, create a ‘Pre Create’ task (execute-escript type)
  3. Paste the following code in the tasks (paste on each task, depending on the number of services you created):
import requests

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}

username = "@@{API_PC.username}@@"
password = '@@{API_PC.secret}@@'


URL = "https://<Prism Central Server>:9440/api/nutanix/v3/apps/{}".format("@@{calm_application_uuid}@@")
PAYLOAD = json.dumps({})

RESPONSE = requests.get(URL, headers=headers, verify=False, auth=(username, password))

if RESPONSE.status_code == 200:
response_json = RESPONSE.json()

# Take the first deployment because the categories are at the application level (every VM will get it)
deployment = response_jsonp'status']['resources']e'deployment_list']e0]
action_list = deploymentd'substrate_configuration']g'action_list']
action_create = next((a for a in action_list if a.get('name') == 'action_create'), None)
task_definition_list = action_createi'runbook']''task_definition_list']
task_definition = next((a for a in task_definition_list if a.get('type', '').startswith('PROVISION')), None)
categories = task_definitiond'attrs']n'categories']
if not categories:
print("Categories are a mandatory field. Please select at least one category when launching your blueprint")
exit(1)
else:
exit(0)
else:
print("Error trying to fetch application data. status code was {}".format(RESPONSE.status_code))
exit(1)

If no category was selected by the user, the process will fail and a message will be displayed in the output window of the Pre Created task

Good luck on that!

I will find time to answer your first part of the question.


@Avico 

Thank you so much! Much appreciated! :) 


Reply