Not sure about notebook but the HDInsight SDK for Python provides classes and methods that allow you to manage your HDInsight clusters. It includes operations to create, delete, update, list, resize, execute script actions, monitor, get properties of HDInsight clusters, and more.
PIP package for the same:
pip install azure-mgmt-hdinsight
The SDK first needs to be authenticated with your Azure subscription.
Login:
from azure.mgmt.hdinsight import HDInsightManagementClient
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.hdinsight.models import *
# Tenant ID for your Azure Subscription
TENANT_ID = ''
# Your Service Principal App Client ID
CLIENT_ID = ''
# Your Service Principal Client Secret
CLIENT_SECRET = ''
# Your Azure Subscription ID
SUBSCRIPTION_ID = ''
credentials = ServicePrincipalCredentials(
client_id = CLIENT_ID,
secret = CLIENT_SECRET,
tenant = TENANT_ID
)
client = HDInsightManagementClient(credentials, SUBSCRIPTION_ID)
HDInsight provides a configuration method called script actions that invokes custom scripts to customize the cluster.
script_action1 = RuntimeScriptAction(name="<Script Name>", uri="<URL To Script>", roles=[<List of Roles>]) #valid roles are "headnode", "workernode", "zookeepernode", and "edgenode"
client.clusters.execute_script_actions("<Resource Group Name>", "<Cluster Name>", <persist_on_success (bool)>, script_actions=[script_action1]) #add more RuntimeScriptActions to the list to execute multiple scripts
To list all persisted script actions for the specified cluster:
scripts_paged = client.script_actions.list_persisted_scripts(resource_group_name, cluster_name)
while True:
try:
for script in scripts_paged.advance_page():
print(script)
except StopIteration:
break
See if it helps.