Skip to content

Instantly share code, notes, and snippets.

@Menziess
Created February 26, 2020 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Menziess/e2fe3708e74e14885d83e9bd56cd5284 to your computer and use it in GitHub Desktop.
Save Menziess/e2fe3708e74e14885d83e9bd56cd5284 to your computer and use it in GitHub Desktop.
# Databricks notebook source
# MAGIC %md
# MAGIC
# MAGIC ## Utility for mounting blob
# COMMAND ----------
dbutils.widgets.text('mount_point', '/mnt/?', 'Mount Point')
dbutils.widgets.text('container_name', '?', 'Container Name')
dbutils.widgets.text('storage_account_key', '?', 'SA Key')
dbutils.widgets.text('storage_account_name', '?', 'SA Name')
# COMMAND ----------
mount_point = dbutils.widgets.get('mount_point')
container_name = dbutils.widgets.get('container_name')
storage_account_key = dbutils.widgets.get('storage_account_key')
storage_account_name = dbutils.widgets.get('storage_account_name')
print("To mount container `{}@{}`, using key:".format(storage_account_name, container_name), end=' ')
for i in range(min(len(storage_account_key), 3)):
print(storage_account_key[i], end=' ')
print('...')
mount_point, container_name, storage_account_name
# COMMAND ----------
name = 'fs.azure.account.key.{}.blob.core.windows.net'.format(
storage_account_name)
source = "wasbs://{}@{}.blob.core.windows.net".format(
container_name, storage_account_name)
extra_configs = {name: storage_account_key}
try:
dbutils.fs.mount(
source=source,
mount_point=mount_point,
extra_configs=extra_configs)
dbutils.widgets.removeAll()
print(mount_point, 'mounted')
except Exception as e:
msg = 'already mounted'
if msg in str(e):
print(mount_point, msg)
else:
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment