Created
February 26, 2020 22:37
-
-
Save Menziess/e2fe3708e74e14885d83e9bd56cd5284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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