mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 17:22:25 -05:00
* Arc/Azdata string updates * more updates (cherry picked from commit 2c6f7ac4472e0197650be299ec899388bb495fd8) * couple more fixes * more
214 lines
9.7 KiB
Plaintext
214 lines
9.7 KiB
Plaintext
{
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"name": "python3",
|
|
"display_name": "Python 3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.6.6",
|
|
"mimetype": "text/x-python",
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"pygments_lexer": "ipython3",
|
|
"nbconvert_exporter": "python",
|
|
"file_extension": ".py"
|
|
}
|
|
},
|
|
"nbformat_minor": 2,
|
|
"nbformat": 4,
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"\n",
|
|
" \n",
|
|
"## Create SQL managed instance - Azure Arc on an existing Azure Arc Data Controller\n",
|
|
" \n",
|
|
"This notebook walks through the process of creating a <a href=\"https://docs.microsoft.com/azure/sql-database/sql-database-managed-instance\">SQL managed instance - Azure Arc</a> on an existing Azure Arc Data Controller.\n",
|
|
" \n",
|
|
"* Follow the instructions in the **Prerequisites** cell to install the tools if not already installed.\n",
|
|
"* Make sure you have the target Azure Arc Data Controller already created.\n",
|
|
"\n",
|
|
"<span style=\"color:red\"><font size=\"3\">Please press the \"Run All\" button to run the notebook</font></span>"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "e4ed0892-7b5a-4d95-bd0d-a6c3eb0b2c99"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"### **Check prerequisites**"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "68531b91-ddce-47d7-a1d8-2ddc3d17f3e7"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import sys,os,json,subprocess\n",
|
|
"def run_command():\n",
|
|
" print(\"Executing: \" + cmd)\n",
|
|
" output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )\n",
|
|
" if output.returncode != 0:\n",
|
|
" print(f'Command: {cmd} failed \\n')\n",
|
|
" print(f'\\t>>>Error output: {output.stderr.decode(\"utf-8\")}\\n')\n",
|
|
" sys.exit(f'exit code: {output.returncode}\\n')\n",
|
|
" print(f'Successfully executed: {cmd}')\n",
|
|
" print(f'\\t>>>Output: {output.stdout.decode(\"utf-8\")}\\n')\n",
|
|
" return output.stdout.decode(\"utf-8\")\n",
|
|
"cmd = 'azdata --version'\n",
|
|
"out = run_command()\n",
|
|
""
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "749d8dba-3da8-46e9-ae48-2b38056ab7a2",
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"#### **Ensure SQL instance name, username and password exist**"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "68ec0760-27d1-4ded-9a9f-89077c40b8bb"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Required Values\n",
|
|
"env_var = \"AZDATA_NB_VAR_CONTROLLER_ENDPOINT\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" controller_endpoint = os.environ[\"AZDATA_NB_VAR_CONTROLLER_ENDPOINT\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_CONTROLLER_ENDPOINT was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_CONTROLLER_USERNAME\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" controller_username = os.environ[\"AZDATA_NB_VAR_CONTROLLER_USERNAME\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_CONTROLLER_USERNAME was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_CONTROLLER_PASSWORD\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" controller_password = os.environ[\"AZDATA_NB_VAR_CONTROLLER_PASSWORD\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_CONTROLLER_PASSWORD was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_SQL_INSTANCE_NAME\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" mssql_instance_name = os.environ[\"AZDATA_NB_VAR_SQL_INSTANCE_NAME\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_INSTANCE_NAME was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_SQL_USERNAME\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" mssql_username = os.environ[\"AZDATA_NB_VAR_SQL_USERNAME\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_USERNAME was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_SQL_PASSWORD\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" mssql_password = os.environ[\"AZDATA_NB_VAR_SQL_PASSWORD\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_PASSWORD was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_SQL_STORAGE_CLASS_DATA\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" mssql_storage_class_data = os.environ[\"AZDATA_NB_VAR_SQL_STORAGE_CLASS_DATA\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_STORAGE_CLASS_DATA was not defined. Exiting\\n')\n",
|
|
"\n",
|
|
"env_var = \"AZDATA_NB_VAR_SQL_STORAGE_CLASS_LOGS\" in os.environ\n",
|
|
"if env_var:\n",
|
|
" mssql_storage_class_logs = os.environ[\"AZDATA_NB_VAR_SQL_STORAGE_CLASS_LOGS\"]\n",
|
|
"else:\n",
|
|
" sys.exit(f'environment variable: AZDATA_NB_VAR_SQL_STORAGE_CLASS_LOGS was not defined. Exiting\\n') \n",
|
|
""
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "53769960-e1f8-4477-b4cf-3ab1ea34348b",
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"#### **Get optional parameters for the SQL instance**"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "1baae5a3-1f7d-4993-ae56-6d191c394952"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"sql_instance_cores_request = os.environ.get(\"AZDATA_NB_VAR_SQL_CORES_REQUEST\")\n",
|
|
"sql_instance_cores_limit = os.environ.get(\"AZDATA_NB_VAR_SQL_CORES_LIMIT\")\n",
|
|
"sql_instance_memory_request = os.environ.get(\"AZDATA_NB_VAR_SQL_MEMORY_REQUEST\")\n",
|
|
"sql_instance_memory_limit = os.environ.get(\"AZDATA_NB_VAR_SQL_MEMORY_LIMIT\")"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "39b0465a-7567-40d6-a5a1-3aef519c1cb9"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"### **Creating the SQL managed instance - Azure Arc instance**"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "90b0e162-2987-463f-9ce6-12dda1267189"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Login to the data controller.\n",
|
|
"#\n",
|
|
"os.environ[\"AZDATA_PASSWORD\"] = controller_password\n",
|
|
"cmd = f'azdata login -e {controller_endpoint} -u {controller_username}'\n",
|
|
"out=run_command()"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "1437c536-17e8-4a7f-80c1-aa43ad02686c"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"print (f'Creating the SQL managed instance - Azure Arc instance')\n",
|
|
"\n",
|
|
"cores_request_option = f' -cr \"{sql_instance_cores_request}\"' if sql_instance_cores_request else \"\"\n",
|
|
"cores_limit_option = f' -cl \"{sql_instance_cores_limit}\"' if sql_instance_cores_limit else \"\"\n",
|
|
"memory_request_option = f' -mr \"{sql_instance_memory_request}Mi\"' if sql_instance_memory_request else \"\"\n",
|
|
"memory_limit_option = f' -ml \"{sql_instance_memory_limit}Mi\"' if sql_instance_memory_limit else \"\"\n",
|
|
"\n",
|
|
"os.environ[\"AZDATA_USERNAME\"] = mssql_username\n",
|
|
"os.environ[\"AZDATA_PASSWORD\"] = mssql_password\n",
|
|
"cmd = f'azdata arc sql mi create -n {mssql_instance_name} -scd {mssql_storage_class_data} -scl {mssql_storage_class_logs}{cores_request_option}{cores_limit_option}{memory_request_option}{memory_limit_option}'\n",
|
|
"out=run_command()"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "4fbaf071-55a1-40bc-be7e-7b9b5547b886"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
}
|
|
]
|
|
}
|