Archived
* fixed some easy typos on sql db wizard. * Fixed some instructions in the notebook * - Added option to enable or disable firewall rules * converted toggle firewall dropdown to checkbox
7.9 KiB
7.9 KiB
In [ ]:
import sys, os, json, time, string, random, subprocess
def run_command(command, json_decode = True, printOutput = True):
print(command)
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
if process.returncode != 0:
print("Process failed %d \n%s" % (process.returncode, error.decode("utf-8")))
raise Exception()
if output:
output = output.decode("utf-8")
if printOutput:
print(output)
try:
return json.loads(output)
except:
return output
In [ ]:
subscriptions = run_command('az account list', printOutput = False)
if azure_sqldb_subscription not in (subscription["id"] for subscription in subscriptions):
run_command('az login')In [ ]:
run_command(
'az account set '
'--subscription {0}'
.format(
azure_sqldb_subscription));In [ ]:
if azure_sqldb_enable_firewall_rule == True:
create_firewall_rule_result = run_command(
'az sql server firewall-rule create '
'--start-ip-address {0} '
'--end-ip-address {1} '
'--server {2} '
'--name {3} '
'--resource-group {4} '
.format(
azure_sqldb_ip_start,
azure_sqldb_ip_end,
azure_sqldb_server_name,
azure_sqldb_firewall_name,
azure_sqldb_resource_group_name));In [ ]:
create_database_result = run_command(
'az sql db create '
'--server {0} '
'--name {1} '
'--edition GeneralPurpose '
'--compute-model Serverless '
'--family Gen5 '
'--resource-group {2} '
'--min-capacity 0.5 '
'--max-size 32GB '
'--capacity 1 '
'--collation {3} '
.format(
azure_sqldb_server_name,
azure_sqldb_database_name,
azure_sqldb_resource_group_name,
azure_sqldb_collation));