簡體   English   中英

如何使用 gcp 附加本地 ssd 創建實例

[英]How to create an instance with local ssd attached with gcp

我嘗試使用 python googleapiclient 創建一個帶有啟動盤和本地 ssd 磁盤的實例。 這是構建系統的 gcp 映像,我想要更好的性能

def create_instance(compute, image_name):
    image_response = compute.images().get(project=GCP_PROJECT_ID,
                                          image=GCP_IMAGE_NAME).execute()
    source_disk_image = image_response['selfLink']
    machine_type = f"zones/{GCP_ZONE}/machineTypes/n2-standard-4"
    config = {
        'name': image_name,
        'machineType': machine_type,

        # Specify the boot disk and the image to use as a source.
        'disks': [
            {
                'boot': True,
                'autoDelete': True,
                'initializeParams': {
                    'sourceImage': source_disk_image,
                }
            },
            {
                'boot': False,
                'autoDelete': True,
                'initializeParams': {
                    'disk_type': 'local-ssd'
                }
            }
        ],

        # Specify a network interface with NAT to access the public
        # internet.
        'networkInterfaces': [{
            'network': 'global/networks/default',
            'accessConfigs': [
                {'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
            ]
        }],

        # Allow the instance to access cloud storage and logging.
        'serviceAccounts': [{
            'email': 'default',
            'scopes': [
                "https://www.googleapis.com/auth/cloud-platform"
            ]
        }]
    }

    operation = compute.instances().insert(
        project=GCP_PROJECT_ID,
        zone=GCP_ZONE,
        body=config).execute()
    return operation

作為。 很難我嘗試給不同的 initializeParams diskTypes 它總是為我創建一個標准的持久 500GB 磁盤而不是本地 ssd。 我已經試過了:

但沒有任何幫助。

我錯了什么?

使用GCP 官方文檔關於使用本地 SSD 創建實例,並參考 Google 的 API,我們可以查看以下內容:

接口說明

除了上述信息之外,以下是一個示例請求有效負載,它創建了一個具有引導磁盤和本地 SSD 設備的實例:

示例請求有效負載

與使用 Python Google 的 API 客戶端的有效負載請求相比,您似乎沒有指定每個磁盤的“類型”。 API 要求本地 SSD 輸入“ SCRATCH ”,而可引導磁盤需要輸入“ PERSISTENT ”。 嘗試這樣做,看看它是否有任何影響。

作為文檔 [1,本地 SSD 位於運行您的虛擬機實例的物理機上,它們只能在實例創建過程中創建。 本地 SSD 不能用作啟動設備。

創建本地 SSD 后,我們必須在使用之前格式化並掛載設備 [2]。

[1] https://cloud.google.com/compute/docs/disks/local-ssd#create_local_ssd

[2] https://cloud.google.com/compute/docs/disks/local-ssd#format_and_mount_a_local_ssd_device

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM