简体   繁体   中英

Configuring databricks-connect using python OS module

I want to configure databricks-connect configure through python OS module after installing databricks-connect through os.system("pip install databricks-connect==6.5")

Once databricks-connect is successfully install we need to configure it by passing the following values:

host= "https://<location>.azuredatabricks.net",
port= "8787",
token = "<Token>",
cluster_id = "<ClusterId>",
org_id = "<OrgId>"

In the terminal if we type databricks-connect configure , it will start asking you above parameter one by one as shown in the figure:

在此处输入图像描述

Now I want same thing to be run using python os.system

os.system("pip install databricks-connect")
os.system("databricks-connect configure")

After this how to pass host, port, token etc.?
After every value we have to press enter as well.

when I run this on terminal this work fine,

echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure

but giving me error when i try to run this python os.module

os.sytem("echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure")

Error "New host value must start with https://, eg, https://demo.cloud.databricks.com")

You can just pipe the data as stdin to the program.

import os


host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
command = "echo '{}' | {}".format(stdin_string, "databricks-connect configure")
os.system(command)

A small modification to @Anmol

import subprocess

host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
echo = subprocess.Popen((['echo', '-e', stdin_string]), std_out=subprocess.PIPE)
output = subprocess.check_output(('databricks-connect', 'configure'), stdin=echo.stdout)
echo.wait()
print(output.decode())
echo -e

takes care of the enter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM