建立以 Deployment Manager 為基礎的解決方案

為貴機構使用者建立 Service Catalog 解決方案時,您可以建立 Deployment Manager (DM) 解決方案,使用者可透過 Deployment Manager 範本啟動這類解決方案。建立解決方案後,您可以將解決方案新增至目錄,與使用者共用。

事前準備

  • 您必須擁有與專案相關聯的機構組織的「目錄管理員」(roles/cloudprivatecatalogproducer.admin) 「目錄管理員」(roles/cloudprivatecatalogproducer.manager) 角色,且該專案已啟用 Service Catalog。 Google CloudGoogle Cloud 如果您沒有這個角色,請與機構管理員聯絡,要求存取權。

  • Enable the Cloud Deployment Manager and Compute Engine APIs.

    Enable the APIs

準備部署範本

如要在 Service Catalog 中建立 Deployment Manager 解決方案,請先準備要上傳的 Deployment Manager 範本 ZIP 檔案,其中必須包含下列檔案:

  • 結尾為 .jinja 副檔名的 Jinja 範本檔案,或結尾為 .py 副檔名的 Python 範本檔案。
  • 結構定義檔案,結尾為 Jinja 範本的 .jinja.schema 副檔名,或 Python 範本的 py.schema 副檔名。

ZIP 檔案的名稱必須與結構定義和 Jinja 或 Python 檔案的名稱相符。舉例來說,如果 ZIP 檔案名為 android-dev-environment.zip,ZIP 檔案內的 Jinja 結構定義檔案必須命名為 android-dev-environment.jinja.schema,Jinja 範本則必須命名為 android-dev-environment.jinja

以下程式碼範例說明如何使用結構定義檔案建立部署表單:



info:
  title: Single Google Compute Engine Machine
  author: Google Inc.
  description: Creates a virtual machine based on zone and machine type selection.

required:
  - machinetype
  - zone

properties:
  machinetype:
    title: Machine type
    type: string
    enum:
      - n2-standard-2
      - n2-standard-4
      - n2-standard-8
      - n2-highmem-2
      - n2-highmem-4
      - n2-highmem-8
      - n2-highcpu-2
      - n2-highcpu-4
      - n2-highcpu-8
  zone:
    title: Zone
    type: string
    enum:
      - us-central1-a
      - us-central1-c
      - us-east1-b
      - us-east1-c
      - us-west1-a
      - us-west1-b
      - us-west1-c

以下程式碼範例說明如何使用 Jinja 檔案建立永久性 VM:



# Creates a Persistent VM
resources:
- type: compute.v1.instance
  name: vm-{{ env["deployment"] }}
  properties:
    zone: {{ properties["zone"] }}
    # Note the machineType definition at the end. n2-custom-4-5120 specifies n2 machine family with 4 CPUs and 5GB (5120 MB) of RAM. For custom machine types, refer to https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type
    machineType: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/machineTypes/{{ properties["machinetype"] }}
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: disk-{{ env["deployment"] }}
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/family/debian-9
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/{{ env["project"] }}/global/networks/default
      # Access Config required to give the instance a public IP address
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

在 Service Catalog 中建立解決方案

如要建立以 Deployment Manager 範本為基礎的解決方案,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的 Service Catalog Admin「Solutions」頁面
    前往「解決方案」頁面

  2. 按一下「選取」,選擇 Google Cloud 專案。

  3. 按一下「建立解決方案」。在下拉式清單中,選取「建立 DM 解決方案」

  4. 輸入解決方案的名稱、說明和宣傳標語。標語是解決方案的簡短說明,使用者瀏覽 Service Catalog 時會看到。

  5. 上傳包含部署設定檔案的 ZIP 檔案。

  6. (選用) 上傳解決方案的圖示。建議圖示尺寸為 80 x 80 像素。

  7. 視需要輸入創作者的支援連結和聯絡資訊。

  8. (選用) 新增解決方案的說明文件連結。

  9. 點選「建立」。

以下螢幕截圖說明如何建立以 Deployment Manager 為基礎的解決方案:

建立以 Cloud Deployment Manager 範本為基礎的解決方案

後續步驟