【问题标题】:How Can One Use gcloud To Enable APIs如何使用 gcloud 启用 API
【发布时间】:2017-08-23 09:41:48
【问题描述】:

我无法找到一种方法来使用gcloud 命令行程序来更改项目的已启用 API。我的预感是它会出现在计费“竞技场”中,但我一直在努力找到它,并且很幸运。

【问题讨论】:

    标签: google-cloud-platform gcloud


    【解决方案1】:

    选择您的应用程序将被注册的项目(请参阅有关 gcloud config set 的文档)

    gcloud config set project myProject
    

    要查看项目的可用服务列表,请运行:

    gcloud services list --available
    

    在当前项目中启用服务(参见有关gcloud services enable的文档)

    gcloud services enable my-consumed-service
    

    【讨论】:

      【解决方案2】:

      2021年,改为

      gcloud services list
      

      详情是here

      【讨论】:

        【解决方案3】:

        编辑:这已被弃用。见gcloud services答案。

        查看service-management 表面。请参阅gcloud help service-management 获取更多帮助,以及gcloud help service-management enable 获取有关启用新服务的帮助。使用gcloud service-management list 列出可用服务,以便您找到要启用的服务的名称。

        【讨论】:

        • 是的,我注意到了那个。好的,我会深入研究。谢谢!
        • 看起来很有希望。我特别喜欢这个gcloud service-management list --available
        • gcloud service-management 已被弃用,现在分成两个单独的命令 - gcloud endpointsgcloud services。后者 (gcloud services) 用于为项目启用/禁用 Google Cloud API。
        【解决方案4】:

        使用

        gcloud services enable <service name>
        

        gcloud Documentation for this

        例子:

        gcloud services enable containerregistry.googleapis.com
        

        【讨论】:

          【解决方案5】:

          启用容器引擎 API 对我有用 -

          gcloud 服务启用 containerregistry.googleapis.com

          【讨论】:

            【解决方案6】:

            问题 对于您当前的默认项目,请执行 gcloud service-management list --enabled 列出所有启用的可用 API。

            $ gcloud service-management list --enabled
            Listed 0 items.
            

            如果您看到类似上面的内容,即 0 items ,那么您很可能会在项目的某些命令中收到以下错误。

            ERROR: (gcloud.compute.machine-types.list) Some requests did not succeed:
             - Project {PROJECT_ID} is not found and cannot be used for API calls
            

            解决方案 你需要做的是下面的

            1. 列出可供项目启用的 API

            输出很长,所以我建议你使用全局选项 page-size 例如

            $ gcloud service-management list  --available --page-size=10 --sort-by="NAME"
            NAME                           TITLE
            picker.googleapis.com          Google Picker API
            bigquery-json.googleapis.com   BigQuery API
            chromewebstore.googleapis.com  Chrome Web Store API
            tracing.googleapis.com         Google Tracing API
            youtube.googleapis.com         YouTube Data API v3
            actions.googleapis.com         Google Actions API
            dataflow.googleapis.com        Google Dataflow API
            serviceuser.googleapis.com     Google Service User API
            fusiontables.googleapis.com    Fusion Tables API
            surveys.googleapis.com         Surveys API
            
            NAME                                 TITLE
            reseller.googleapis.com              Google Apps Reseller API
            speech.googleapis.com                Google Cloud Speech API
            appsmarket-component.googleapis.com  Google Apps Marketplace SDK
            bigtabletableadmin.googleapis.com    Google Cloud Bigtable Table Admin API
            container.googleapis.com             Google Container Engine API
            vision.googleapis.com                Google Cloud Vision API
            storage-api.googleapis.com           Google Cloud Storage JSON API
            weavecompanion.googleapis.com        Weave Companion API
            ml.googleapis.com                    Google Cloud Machine Learning Engine
            firebaserules.googleapis.com         Firebase Rules API
            
            ...
            
            1. 最好还是检查您需要的特定可用 API 例如,检查我想要启用的 Google Compute Engine API

              $ gcloud service-management list --available --filter='NAME:compute*' NAME TITLE compute-component.googleapis.com Google Compute Engine API

            2. 为项目启用计费。

              $ gcloud alpha billing accounts projects link amghouse-some-project-1 --account-id=XXFFXX-B9XX37-2D5DX --format=json { "billingAccountName": "billingAccounts/XXFFXX-B9XX37-2D5DX", "billingEnabled": true, "name": "projects/amghouse-some-project-1 /billingInfo", "projectId": "amghouse-some-project-1 " }

            3. 最终为您的项目启用 api

            `

            $gcloud service-management enable compute-component.googleapis.com
            Waiting for async operation operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 to complete...
            Operation finished successfully. The following command can describe the Operation details:
             gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682
            

            `

            1. 为了更好的衡量,验证不会有什么坏处

            `

            $ gcloud service-management operations describe operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682 --format=json
                    {
                      "done": true,
                      "metadata": {
                        "@type": "type.googleapis.com/google.api.servicemanagement.v1.OperationMetadata",
                        "persisted": true,
                        "resourceNames": [
                          "services/compute-component.googleapis.com/projectSettings/"
                        ],
                        "startTime": "2017-04-08 23:30:22 WAT"
                      },
                      "name": "operations/projectSettings.c6d11ddc-915f-4d66-9b98-237e473e7682",
                      "response": {
                        "@type": "type.googleapis.com/google.api.servicemanagement.v1.EnableServiceResponse"
                      }
                    }
            

            `

            注意 请注意,如果项目未链接到帐单信息,尝试启用 api 将失败并出现类似于

            的错误
            $ gcloud service-management enable compute-component.googleapis.com
            ERROR: (gcloud.service-management.enable) FAILED_PRECONDITION: Operation does not satisfy the following requirements: billing-enabled {Billing must be enabled for activation of service '' in project 'amghouse-bct-sms-1' to proceed., https://console.developers.google.com/project/amghouse-bct-sms-1/settings}
            

            【讨论】:

            • 从这个彻底的回复中了解了一些关于 gcloud 的信息。谢谢!
            • @the0ther 感谢您的反馈。很高兴知道这很有帮助。
            • 我认为这是一个很好的答案,但是命令需要更新,对我有用的是:gcloud services enable indexing.googleapis.com commands on this answer now provide error: ERROR: (gcloud .service-management.list) service-management list 命令已替换为 endpoints services listservices list
            • @FelipeValdes 感谢您的更新。必须跟上发布节奏。
            • gcloud service-management operations describe 也已被弃用。 gcloud services operations describe operations/acf.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 有效但不输出 JSON,而是得到了 Operation "operations/acf.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" finished successfully.
            猜你喜欢
            • 2020-09-14
            • 1970-01-01
            • 2020-08-26
            • 2023-01-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-09-01
            • 1970-01-01
            相关资源
            最近更新 更多