mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
dialog assisted notebooks (#6564)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.6.6",
|
||||
"version": "3.7.3",
|
||||
"mimetype": "text/x-python",
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
@@ -22,7 +22,16 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": "\r\n## Run SQL Server 2019 CTP 3.1 container image with Docker\r\nThis notebook will use Docker to pull and run the SQL Server 2019 CTP 3.1 container image and connect to it in Azure Data Studio\r\n\r\n### Dependencies\r\n- Docker Engine. For more information, see [Install Docker](https://docs.docker.com/engine/installation/).",
|
||||
"source": [
|
||||
"\r\n",
|
||||
"## Run SQL Server 2019 CTP 3.2 container image with Docker\r\n",
|
||||
"This notebook will use Docker to pull and run the SQL Server 2019 CTP 3.2 container image and connect to it in Azure Data Studio\r\n",
|
||||
"\r\n",
|
||||
"### Dependencies\r\n",
|
||||
"- Docker Engine. For more information, see [Install Docker](https://docs.docker.com/engine/installation/).\r\n",
|
||||
"\r\n",
|
||||
"<span style=\"color:red\"><font size=\"3\">Please press the \"Run Cells\" button to run the notebook</font></span>"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
@@ -32,19 +41,43 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "def run_command():\r\n print(\"Executing: \" + cmd)\r\n !{cmd}\r\n if _exit_code != 0:\r\n raise SystemExit(f'Shell command:\\n\\n\\t{cmd}\\n\\nreturned non-zero exit code: ' + str(_exit_code) + '.\\n')\r\n print(f'Successfully executed: {cmd}')\r\n\r\ncmd = 'docker version'\r\nrun_command()",
|
||||
"source": [
|
||||
"import pandas,sys,os,getpass,json,html,time\r\n",
|
||||
"pandas_version = pandas.__version__.split('.')\r\n",
|
||||
"pandas_major = int(pandas_version[0])\r\n",
|
||||
"pandas_minor = int(pandas_version[1])\r\n",
|
||||
"pandas_patch = int(pandas_version[2])\r\n",
|
||||
"if not (pandas_major > 0 or (pandas_major == 0 and pandas_minor > 24) or (pandas_major == 0 and pandas_minor == 24 and pandas_patch >= 2)):\r\n",
|
||||
" sys.exit('Please upgrade the Notebook dependency before you can proceed, you can do it by running the \"Reinstall Notebook dependencies\" command in Azure Data Studio.')\r\n",
|
||||
"\r\n",
|
||||
"def run_command():\r\n",
|
||||
" print(\"Executing: \" + cmd)\r\n",
|
||||
" !{cmd}\r\n",
|
||||
" if _exit_code != 0:\r\n",
|
||||
" sys.exit(f'Command execution failed with exit code: {str(_exit_code)}.\\n\\t{cmd}\\n')\r\n",
|
||||
" print(f'Successfully executed: {cmd}')\r\n",
|
||||
"\r\n",
|
||||
"cmd = 'docker version'\r\n",
|
||||
"run_command()"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": "### List existing containers\r\nYou can view the ports that have been used by existing containers",
|
||||
"source": [
|
||||
"### List existing containers\r\n",
|
||||
"You can view the ports that have been used by existing containers"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "cmd = f'docker ps -a'\r\nrun_command()",
|
||||
"source": [
|
||||
"cmd = f'docker ps -a'\r\n",
|
||||
"run_command()"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 2
|
||||
@@ -56,7 +89,23 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "import getpass\r\npassword_name = 'SQL Server sa account password'\r\nsql_password = getpass.getpass(prompt = password_name)\r\npassword_confirm = getpass.getpass(prompt = f'Confirm {password_name}')\r\nif sql_password != password_confirm:\r\n raise SystemExit(f'{password_name} does not match the confirmation password')\r\nprint(f'{password_name}: ******')\r\nsql_port = input('SQL Server port, default value is 1433')\r\nif len(sql_port) == 0:\r\n sql_port = '1433'\r\nprint(f'Port: {sql_port}')",
|
||||
"source": [
|
||||
"env_var_flag = \"AZDATA_NB_VAR_DOCKER_PASSWORD\" in os.environ\r\n",
|
||||
"password_name = 'SQL Server sa account password'\r\n",
|
||||
"if env_var_flag:\r\n",
|
||||
" sql_password = os.environ[\"AZDATA_NB_VAR_DOCKER_PASSWORD\"]\r\n",
|
||||
" sql_port = os.environ[\"AZDATA_NB_VAR_DOCKER_PORT\"]\r\n",
|
||||
"else:\r\n",
|
||||
" sql_password = getpass.getpass(prompt = password_name)\r\n",
|
||||
" password_confirm = getpass.getpass(prompt = f'Confirm {password_name}')\r\n",
|
||||
" if sql_password != password_confirm:\r\n",
|
||||
" raise SystemExit(f'{password_name} does not match the confirmation password.')\r\n",
|
||||
" sql_port = input('SQL Server port, default value is 1433')\r\n",
|
||||
" if len(sql_port) == 0:\r\n",
|
||||
" sql_port = '1433'\r\n",
|
||||
"print(f'{password_name}: ******')\r\n",
|
||||
"print(f'Port: {sql_port}')"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 3
|
||||
@@ -68,7 +117,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "cmd = f'docker pull mcr.microsoft.com/mssql/server:2019-latest'\r\nrun_command()",
|
||||
"source": [
|
||||
"cmd = f'docker pull mcr.microsoft.com/mssql/server:2019-latest'\r\n",
|
||||
"run_command()"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 4
|
||||
@@ -80,7 +132,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "import time\r\ncontainer_name = 'sql2019-' + time.strftime(\"%Y%m%d%H%M%S\", time.localtime())\r\nprint('New container name: ' + container_name)\r\ncmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2019-latest'\r\nrun_command()",
|
||||
"source": [
|
||||
"if env_var_flag:\r\n",
|
||||
" container_name = os.environ[\"AZDATA_NB_VAR_DOCKER_CONTAINER_NAME\"]\r\n",
|
||||
"else:\r\n",
|
||||
" container_name = 'sql2019-' + time.strftime(\"%Y%m%d%H%M%S\", time.localtime())\r\n",
|
||||
"print('New container name: ' + container_name)\r\n",
|
||||
"cmd = f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD={sql_password}\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2019-latest'\r\n",
|
||||
"run_command()"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 5
|
||||
@@ -92,19 +152,29 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "cmd = f'docker ps -a'\r\nrun_command()",
|
||||
"source": [
|
||||
"cmd = f'docker ps -a'\r\n",
|
||||
"run_command()"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 6
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": "### Connect to SQL Server in Azure Data Studio\r\nIt might take a couple minutes for SQL Server to launch",
|
||||
"source": [
|
||||
"### Connect to SQL Server in Azure Data Studio\r\n",
|
||||
"It might take a couple minutes for SQL Server to launch"
|
||||
],
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "from IPython.display import *\r\ndisplay(HTML(\"<a href=\\\"command:azdata.connect?{"serverName":"localhost,\"+sql_port+\"","providerName":"MSSQL", "authenticationType":"SqlLogin","userName":"sa","password":"\"+sql_password+\""}\\\">Click here to connect to SQL Server</a>\"))",
|
||||
"source": [
|
||||
"from IPython.display import *\r\n",
|
||||
"connectionParameter = '{\"serverName\":\"localhost,' + sql_port + '\",\"providerName\":\"MSSQL\",\"authenticationType\":\"SqlLogin\",\"userName\":\"sa\",\"password\":' + json.dumps(sql_password) + '}'\r\n",
|
||||
"display(HTML('<br/><a href=\"command:azdata.connect?' + html.escape(connectionParameter)+'\"><font size=\"3\">Click here to connect to SQL Server</font></a><br/>'))"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 7
|
||||
@@ -116,10 +186,16 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": "stop_container_command = f'docker stop {container_name}'\r\nremove_container_command = f'docker rm {container_name}'\r\ndisplay(HTML(\"Use this link to: <a href=\\\"command:workbench.action.terminal.focus\\\">open the terminal window in Azure Data Studio</a> and use the links below to paste the command to the terminal.\"))\r\ndisplay(HTML(\"Stop the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+stop_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + stop_container_command + \"</a>\"))\r\ndisplay(HTML(\"Remove the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+remove_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + remove_container_command + \"</a>\"))",
|
||||
"source": [
|
||||
"stop_container_command = f'docker stop {container_name}'\r\n",
|
||||
"remove_container_command = f'docker rm {container_name}'\r\n",
|
||||
"display(HTML(\"Use this link to: <a href=\\\"command:workbench.action.terminal.focus\\\">open the terminal window in Azure Data Studio</a> and use the links below to paste the command to the terminal.\"))\r\n",
|
||||
"display(HTML(\"Stop the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+stop_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + stop_container_command + \"</a>\"))\r\n",
|
||||
"display(HTML(\"Remove the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+remove_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + remove_container_command + \"</a>\"))"
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"execution_count": 8
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user