0

I am trying to mount a folder in one drive business in databricks community edition. I am unable to use onedrivesdk because it is deprecated.

I created a app registration, assigned read and write permissions to that and using the client id and secret.i tried to mount using api requests but it was not giving the access token. First of all i want to know , whether it is possible to mount one drive to databricks community edition. if yes, what are the ways..? Below is the code i used to mount one drive using api requests.


# Import the necessary libraries
import requests

# Set up the client
client_id = ""
client_secret = ""
tenant_id = ""
redirect_uri = "http://localhost:8080/"

# Get the access token
response = requests.post(
    "https://login.microsoftonline.com/{}/oauth2/token".format(tenant_id),
    data={
        "client_id": client_id,
        "client_secret": client_secret,
        "redirect_uri": redirect_uri,
        "grant_type": "client_credentials",
        "resource": "https://graph.microsoft.com"
    }
)
access_token = response.json()["access_token"]

# Mount the OneDrive folder to DBFS
folder_id = ""
mount_point = "/mnt/onedrive"
dbutils.fs.mount(
    source="graph",
    mount_point=mount_point,
    extra_configs={
        "graph.access_token": access_token,
        "graph.folder_id": folder_id
    }
)

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • since data Bricks community edition can be hosted either in azure or aws, i added the azure tag. But yeah, I have removed it now. – Saravana Kumar Jan 30 '23 at 11:38

2 Answers2

1

No, you can't use dbutils.fs.mount with OneDrive - DBFS mounts are supported only for specific cloud storage implementations (S3, ADLS Gen2, Azure Blob Storage, ... - see docs).

If you need to access data in OneDrive, you need to use REST API directly (or find another Python library)

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
0

You can install the Rclone (https://rclone.org/) inside the Databricks. This allow you to connect to Onedrive and execute commands like copy/write/move/ls, but it does not allow you to mount the Onedrive.

You can install it using the following code:

!sudo -v ; curl https://rclone.org/install.sh | sudo bash
!pip install rclone
!pip install rclone-python

To use the Rclone you need to source a valid rclone.conf. This file contains the secret token to access the OneDrive/SharePoint files.

You can identify where is the rclone.conf using.

!rclone version
!rclone config file

I have used the rclone to find some desired file, so I have copied the file from OneDrive to some place inside Databricks and then I could read the content of file.

I have tried many times to mount the Onedrive using commands like 'rclone mount' (https://rclone.org/commands/rclone_mount/), but this was not possible because the FUSE needs an elevation that is not possible by root (I know that is not make much sense??!!). This code generate an error that needs elevation.

!rclone mount My_OneDrive: /tmp --no-check-certificate --vfs-cache-mode writes 

But now... I am seeing you code and I will make some new tests. Would be great if I could use dbutils.fs.mount/extra_configs together with rclone.