如何使用 Azure Python SDK 提供 Databricks 服务?
How to use the Azure Python SDK to provision a Databricks service?
[之前在此 post 中,我询问了如何在没有任何工作空间的情况下提供数据块服务。现在我想问的是如何使用工作区提供服务,因为第一种情况似乎不可行。]
作为一名云管理员,我被要求使用 Azure Python SDK 编写一个脚本,该脚本将为我们的一个大数据开发团队提供 Databricks 服务。
之外,我在 Azure Python SDK 中找不到太多关于 Databricks 的在线信息
和
这些似乎提供了一些帮助配置工作区,但我还没有完全做到。
我错过了什么?
编辑:
感谢@Laurent Mazuel 和@Jim Xu 的帮助。
这是我现在 运行 的代码,以及我收到的错误:
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get("example_rg_name", "example_databricks_workspace_name")
WorkspacesOperations.create_or_update(
workspace_obj,
"example_rg_name",
"example_databricks_workspace_name",
custom_headers=None,
raw=False,
polling=True
)
错误:
TypeError: create_or_update() missing 1 required positional argument: 'workspace_name'
我对这个错误感到有点困惑,因为我提供了工作区名称作为第三个参数,并且根据 this documentation,这正是此方法所需要的。
我也试过下面的代码:
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get("example_rg_name", "example_databricks_workspace_name")
client.workspaces.create_or_update(
workspace_obj,
"example_rg_name",
"example_databricks_workspace_name"
)
这导致:
Traceback (most recent call last):
File "./build_azure_visibility_core.py", line 112, in <module>
ca_databricks.create_or_update_databricks(SUB_PREFIX)
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/expd_az_databricks.py", line 34, in create_or_update_databricks
self.databricks_workspace_name
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/azure/mgmt/databricks/operations/workspaces_operations.py", line 264, in create_or_update
**operation_config
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/azure/mgmt/databricks/operations/workspaces_operations.py", line 210, in _create_or_update_initial
body_content = self._serialize.body(parameters, 'Workspace')
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/msrest/serialization.py", line 589, in body
raise ValidationError("required", "body", True)
msrest.exceptions.ValidationError: Parameter 'body' can not be None.
ERROR: Job failed: exit status 1
所以serialization.py中的第589行有错误。我看不出我的代码中的错误是在哪里导致的。感谢所有慷慨解囊的人!
您需要创建一个数据块客户端,工作区将附加到它:
client = DatabricksClient(credentials, subscription_id)
workspace = client.workspaces.get(resource_group_name, workspace_name)
我认为创建没有工作区的服务是不可能的,尝试在门户上创建数据块服务,您会看到还需要工作区名称
所以使用 SDK 我会查看 client.workspaces.create_or_update
的文档
(我在 MS SDK 团队工作)
在@Laurent Mazuel 和微软支持工程师的帮助下,我有了一个解决方案:
managed_resource_group_ID = ("/subscriptions/"+sub_id+"/resourceGroups/"+managed_rg_name)
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get(rg_name, databricks_workspace_name)
client.workspaces.create_or_update(
{
"managedResourceGroupId": managed_resource_group_ID,
"sku": {"name":"premium"},
"location":location
},
rg_name,
databricks_workspace_name
).wait()
[之前在此 post 中,我询问了如何在没有任何工作空间的情况下提供数据块服务。现在我想问的是如何使用工作区提供服务,因为第一种情况似乎不可行。]
作为一名云管理员,我被要求使用 Azure Python SDK 编写一个脚本,该脚本将为我们的一个大数据开发团队提供 Databricks 服务。
之外,我在 Azure Python SDK 中找不到太多关于 Databricks 的在线信息和
这些似乎提供了一些帮助配置工作区,但我还没有完全做到。
我错过了什么?
编辑:
感谢@Laurent Mazuel 和@Jim Xu 的帮助。
这是我现在 运行 的代码,以及我收到的错误:
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get("example_rg_name", "example_databricks_workspace_name")
WorkspacesOperations.create_or_update(
workspace_obj,
"example_rg_name",
"example_databricks_workspace_name",
custom_headers=None,
raw=False,
polling=True
)
错误:
TypeError: create_or_update() missing 1 required positional argument: 'workspace_name'
我对这个错误感到有点困惑,因为我提供了工作区名称作为第三个参数,并且根据 this documentation,这正是此方法所需要的。
我也试过下面的代码:
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get("example_rg_name", "example_databricks_workspace_name")
client.workspaces.create_or_update(
workspace_obj,
"example_rg_name",
"example_databricks_workspace_name"
)
这导致:
Traceback (most recent call last):
File "./build_azure_visibility_core.py", line 112, in <module>
ca_databricks.create_or_update_databricks(SUB_PREFIX)
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/expd_az_databricks.py", line 34, in create_or_update_databricks
self.databricks_workspace_name
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/azure/mgmt/databricks/operations/workspaces_operations.py", line 264, in create_or_update
**operation_config
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/azure/mgmt/databricks/operations/workspaces_operations.py", line 210, in _create_or_update_initial
body_content = self._serialize.body(parameters, 'Workspace')
File "/home/gitlab-runner/builds/XrbbggWj/0/SA-Cloud/azure-visibility-core/azure-visibility-core/lib64/python3.6/site-packages/msrest/serialization.py", line 589, in body
raise ValidationError("required", "body", True)
msrest.exceptions.ValidationError: Parameter 'body' can not be None.
ERROR: Job failed: exit status 1
所以serialization.py中的第589行有错误。我看不出我的代码中的错误是在哪里导致的。感谢所有慷慨解囊的人!
您需要创建一个数据块客户端,工作区将附加到它:
client = DatabricksClient(credentials, subscription_id)
workspace = client.workspaces.get(resource_group_name, workspace_name)
我认为创建没有工作区的服务是不可能的,尝试在门户上创建数据块服务,您会看到还需要工作区名称
所以使用 SDK 我会查看 client.workspaces.create_or_update
(我在 MS SDK 团队工作)
在@Laurent Mazuel 和微软支持工程师的帮助下,我有了一个解决方案:
managed_resource_group_ID = ("/subscriptions/"+sub_id+"/resourceGroups/"+managed_rg_name)
client = DatabricksClient(credentials, subscription_id)
workspace_obj = client.workspaces.get(rg_name, databricks_workspace_name)
client.workspaces.create_or_update(
{
"managedResourceGroupId": managed_resource_group_ID,
"sku": {"name":"premium"},
"location":location
},
rg_name,
databricks_workspace_name
).wait()