Update VM Prism Central Category (Python)

December 23, 2021

by David Teague

Intended Audience Level: Beginner/Intro

Code Sample Type: Complete Script

Nutanix Technologies: Prism Central

Minimum Product Version: 5.17

Script/Code Language: Python

REST API Sample? Yes

REST API Version: v3

Python script for use with Nutanix Era. Provisions Linux-based database engines, to call X-Play playbook that set VM categories in Prism Central. 

Code Sample Details

Note this section may be empty, if additional code sample details are not available.

Python script for use with Nutanix Era. Provisions Linux-based database engines, to call X-Play playbook that set VM categories in Prism Central. 

To use update the below fields with your environments info.

  • Username and password that as access to Prism Central.
    • $user = youruser
    • $password = yourpassword
  • Valid ip address or FQDN for Prism Central
    • $pcaddress = yourpcaddress
  • Webhook ID copied from X-Play playbook that sets catagory
    • webhookid = yourwebhookid
import urllib3
import requests
from base64 import b64encode
import json
#Edit below variabls
#update user name and password with valid Prism Central Credentials
username = 'youruser'
password = 'yourpassword'
#update pcaddress with ipaddress or fqdn of Prism Central
pcaddress = 'yourpcaddress'
#update webhookid wtih webhook_id from playbook you are using
webhookid = 'yourwebhookid'

# Do not change below
encoded_credentials = b64encode(bytes(f'{username}:{password}',encoding='ascii')).decode('ascii')
auth_header = f'Basic {encoded_credentials}'
url = 'https://%s:9440/api/nutanix/v3/action_rules/trigger' % (pcaddress)
payload = json.dumps({
  "trigger_type": "incoming_webhook_trigger
  "trigger_instance_list": [
    {
      "webhook_id": "{webhookid}",
      "string1": "DUR-SQL19-WD01"
    }
  ]
})
headers = {
  'Authorization': f"{auth_header}",
  'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=payload, verify=False)
print(response.text)

# These code samples are intended as a standalone examples.  Subject to licensing restrictions defined on Nutanix.dev, 
# these can be downloaded, copied and/or modified in any way you see fit.  
# Please be aware that all public code samples provided by Nutanix are unofficial in nature, 
# are provided as examples only, are unsupported and 
# will need to be heavily scrutinized and potentially modified before they can be used in a production environment.  
# All such code samples are provided on an as-is basis, 
# and Nutanix expressly disclaims all warranties, express or implied.  
# All code samples are © Nutanix, Inc., and are provided as-is under the MIT license (https://opensource.org/licenses/MIT).