群集策略 CLI

重要

此功能目前以公共预览版提供。

只有管理员用户才能创建、编辑和删除策略。 管理员用户也有权访问所有策略。

有关群集策略的要求和限制,请参阅管理群集策略

可以通过将 Databricks 群集策略 CLI 子命令追加到 databricks cluster-policies 后面来运行这些子命令。

databricks cluster-policies --help
Usage: databricks cluster-policies [OPTIONS] COMMAND [ARGS]...

  Utility to interact with Databricks cluster policies.

Options:
  -v, --version   [VERSION]
  --debug         Debug mode. Shows full stack trace on error.
  --profile TEXT  CLI connection profile to use. The default profile is
                  "DEFAULT".

  -h, --help      Show this message and exit.

Commands:
  create  Creates a Databricks cluster policy.
  delete  Removes a Databricks cluster policy given its ID.
  edit    Edits a Databricks cluster policy.
  get     Retrieves metadata about a Databricks cluster policy.
  list    Lists Databricks cluster policies.

创建群集策略

若要显示使用情况文档,请运行 databricks cluster-policies create --help

databricks cluster-policies create --json-file create-cluster-policy.json

create-cluster-policy.json:

{
  "name": "Example Policy",
  "definition": "{\"spark_version\":{\"type\":\"fixed\",\"value\":\"next-major-version-scala2.12\",\"hidden\":true}}"
}
{
  "policy_id": "1A234567B890123C"
}

删除群集策略

若要查看帮助,请运行 databricks cluster-policies delete --help

databricks cluster-policies delete --policy-id 1A234567B890123C

成功时,此命令不会显示任何内容。

更改群集策略

若要显示使用情况文档,请运行 databricks cluster-policies edit --help

databricks cluster-policies edit --json-file edit-cluster-policy.json

edit-cluster-policy.json:

{
  "policy_id": "1A234567B890123C",
  "name": "Example Policy",
  "definition": "{\"spark_version\":{\"type\":\"fixed\",\"value\":\"next-major-version-scala2.12\",\"hidden\":false}}",
  "created_at_timestamp": 1619477108000
}

成功时,此命令不会显示任何内容。

列出有关群集策略的信息

若要显示使用情况文档,请运行 databricks cluster-policies get --help

databricks cluster-policies get --policy-id A123456BCD789012
{
  "policy_id": "A123456BCD789012",
  "name": "Cluster Policy Demo",
  "definition": "{\n  \"spark_env_vars.PYSPARK_PYTHON\": {\n    \"type\": \"fixed\",\n    \"value\": \"/databricks/python3/bin/python27\"\n  }\n}",
  "created_at_timestamp": 1615504519000
}

列出有关可用群集策略的信息

若要显示使用情况文档,请运行 databricks cluster-policies list --help

databricks cluster-policies list --output JSON
{
  "policies": [
    {
      "policy_id": "A123456BCD789012",
      "name": "Cluster Policy Demo",
      "definition": "{\n  \"spark_env_vars.PYSPARK_PYTHON\": {\n    \"type\": \"fixed\",\n    \"value\": \"/databricks/python3/bin/python27\"\n  }\n}",
      "created_at_timestamp": 1615504519000
    },
    ...
  ],
  "total_count": 16
}