יצירת תמונות בהתאמה אישית

אתם יכולים ליצור תמונות בהתאמה אישית מדיסקים, תמונות, snapshots או תמונות שמאוחסנות ב-Cloud Storage, ולהשתמש בתמונות האלה כדי ליצור מופעים של מכונות וירטואליות (VM). תמונות בהתאמה אישית הן אידיאליות למצבים שבהם יצרתם ושיניתם דיסק אתחול מתמיד או תמונה ספציפית למצב מסוים, ואתם צריכים לשמור את המצב הזה כדי ליצור מכונות וירטואליות.

לחלופין, אפשר להשתמש בכלי לייבוא דיסק וירטואלי כדי לייבא קובצי אימג' של דיסק אתחול ל-Compute Engine מהמערכות הקיימות ולהוסיף אותן לרשימת התמונות המותאמות אישית.

לפני שמתחילים

תפקידים והרשאות נדרשים

כדי לקבל את ההרשאות שדרושות ליצירת קובץ אימג' בהתאמה אישית, בקשו מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

התפקידים המוגדרים מראש האלה כוללים את ההרשאות שנדרשות ליצירת קובץ אימג' בהתאמה אישית. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי ליצור תמונה בהתאמה אישית, צריך את ההרשאות הבאות:

  • compute.images.create
  • כדי ליצור אימג' בהתאמה אישית מדיסק: compute.disks.useReadOnly בדיסק
  • כדי ליצור קובץ אימג' בהתאמה אישית מקובץ אימג' קיים: ‫compute.images.useReadOnly בקובץ האימג' של המקור
  • כדי ליצור אימג' בהתאמה אישית מ-snapshot רגיל או מקובץ snapshot של ארכיון: compute.snapshots.useReadOnly ב-snapshot המקור
  • כדי להוסיף תווית לתמונה החדשה: compute.images.setLabels לוחצים על התווית

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

יצירת תמונה בהתאמה אישית

כאן מוסבר איך ליצור קובץ אימג' בהתאמה אישית במכונה וירטואלית של Linux. מידע על יצירת תמונת Windows זמין במאמר יצירת תמונת Windows.

בחירת מיקום לאחסון התמונות

כשיוצרים תמונה בהתאמה אישית, אפשר לציין את המיקום של התמונה ב-Cloud Storage, לא כולל מיקומים בשני אזורים. כשמציינים את מיקום האחסון של התמונות, אפשר לעמוד בדרישות הרגולטוריות ובדרישות התאימות שלכם לגבי סביבת נתונים, וגם בדרישות הזמינות הגבוהה שלכם, על ידי יתירות באזורים שונים. כדי ליצור, לשנות ולמחוק תמונות שמאוחסנות ב-Cloud Storage, צריך להיות לכם roles/compute.storageAdmin.

התכונה 'מיקום האחסון' היא אופציונלית. אם לא בוחרים מיקום, Compute Engine מאחסן את התמונה במספר אזורים הקרוב ביותר למקור התמונה. לדוגמה, כשיוצרים קובץ אימג' מדיסק מקור שנמצא ב-us-central1, אם לא מציינים מיקום לקובץ האימג' בהתאמה אישית, Compute Engine מאחסן את קובץ האימג' במספר אזורים ב-us.

אם התמונה לא זמינה באזור שבו אתם יוצרים מכונה וירטואלית, מערכת Compute Engine שומרת את התמונה במטמון באזור הזה בפעם הראשונה שאתם יוצרים מכונה וירטואלית.

כדי לראות את המיקום שבו התמונה מאוחסנת, משתמשים בפקודה images describe מ-gcloud compute:

gcloud compute images describe IMAGE_NAME \
    --project=PROJECT_ID

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: השם של התמונה.

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייכת התמונה.

כל התמונות הקיימות מלפני השקת התכונה הזו נשארות במקומן, והשינוי היחיד הוא שאפשר לראות את מיקום התמונה של כל התמונות. אם יש לכם תמונה קיימת שאתם רוצים להעביר, אתם צריכים ליצור אותה מחדש במיקום החדש.

הכנת ה-VM ליצירת קובץ אימג'

אפשר ליצור תמונה מדיסק גם כשהוא מצורף למכונה וירטואלית פעילה. עם זאת, התמונה תהיה אמינה יותר אם תעבירו את המכונה הווירטואלית למצב שיהיה קל יותר לצלם את התמונה. בקטע הזה מוסבר איך להכין את דיסק האתחול בשביל קובץ האימג'.

מזעור כתיבת הנתונים לדיסק האחסון המתמיד

כדי לצמצם את פעולות הכתיבה לדיסק, אפשר להשתמש באחד מהתהליכים הבאים:

  • מפסיקים את המכונה הווירטואלית כדי שהיא תוכל להיסגר ולהפסיק לכתוב נתונים בדיסק אחסון מתמיד (persistent disk).

  • אם אתם לא יכולים לעצור את ה-VM לפני שאתם יוצרים את קובץ האימג', צמצמו את כמות הכתיבות לדיסק וסנכרנו את מערכת הקבצים. כדי לצמצם את הכתיבה ל-Persistent Disk, פועלים לפי השלבים הבאים:

    1. משהים אפליקציות או תהליכים של מערכת ההפעלה שכותבים נתונים לדיסק המתמשך.
    2. אם צריך, מריצים את האפליקציה כדי לרוקן את הנתונים לדיסק. לדוגמה, ל-MySQL יש הצהרה FLUSH. יכול להיות שבאפליקציות אחרות יש תהליכים דומים.
    3. מפסיקים את הכתיבה של האפליקציות לדיסק האחסון המתמיד (persistent disk).
    4. מריצים את sudo sync.

השבתת אפשרות המחיקה האוטומטית של הדיסק

כברירת מחדל, אפשרות המחיקה האוטומטית מופעלת בדיסקים לאתחול. לפני שיוצרים קובץ אימג' מדיסק, משביתים את המחיקה האוטומטית כדי למנוע את מחיקת הדיסק באופן אוטומטי כשמוחקים את ה-VM.

כדי להשבית את המחיקה האוטומטית של הדיסק, משתמשים באחת מהשיטות הבאות:

המסוף

  1. נכנסים לדף VM instances במסוף Cloud de Confiance .

    לדף VM instances

  2. לוחצים על השם של המכונה הווירטואלית שמשמשת כמקור ליצירת תמונה.

    הדף VM instance details נפתח.

  3. לוחצים על Edit.

  4. בקטע דיסק אתחול, מוודאים שבכלל מחיקה מסומנת האפשרות Keep disk (שמירת הדיסק).

  5. לוחצים על Save.

gcloud

ב-Google Cloud CLI, משתמשים בפקודה gcloud compute instances set-disk-auto-delete כדי להשבית את אפשרות המחיקה האוטומטית של הדיסק.

gcloud compute instances set-disk-auto-delete VM_NAME \
    --no-auto-delete \
    --disk=SOURCE_DISK

מחליפים את מה שכתוב בשדות הבאים:

  • ‫VM_NAME: השם של מופע ה-VM.
  • ‫SOURCE_DISK: השם של הדיסק שממנו רוצים ליצור את התמונה.

המשך

Go

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Goהוראות ההגדרה שבמדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Go API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
)

// setDiskAutodelete sets the autodelete flag of a disk to given value.
func setDiskAutoDelete(
	w io.Writer,
	projectID, zone, instanceName, diskName string, autoDelete bool,
) error {
	// projectID := "your_project_id"
	// zone := "us-west3-b"
	// instanceName := "your_instance_name"
	// diskName := "your_disk_name"
	// autoDelete := true

	ctx := context.Background()
	instancesClient, err := compute.NewInstancesRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewInstancesRESTClient: %w", err)
	}
	defer instancesClient.Close()

	getInstanceReq := &computepb.GetInstanceRequest{
		Project:  projectID,
		Zone:     zone,
		Instance: instanceName,
	}

	instance, err := instancesClient.Get(ctx, getInstanceReq)
	if err != nil {
		return fmt.Errorf("unable to get instance: %w", err)
	}

	diskExists := false

	for _, disk := range instance.GetDisks() {
		if disk.GetDeviceName() == diskName {
			diskExists = true
			break
		}
	}

	if !diskExists {
		return fmt.Errorf(
			"instance %s doesn't have a disk named %s attached",
			instanceName,
			diskName,
		)
	}

	req := &computepb.SetDiskAutoDeleteInstanceRequest{
		Project:    projectID,
		Zone:       zone,
		Instance:   instanceName,
		DeviceName: diskName,
		AutoDelete: autoDelete,
	}

	op, err := instancesClient.SetDiskAutoDelete(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to set disk autodelete field: %w", err)
	}

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "disk autoDelete field updated.\n")

	return nil
}

Java

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Javaהוראות ההגדרה שבמדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Java API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.


import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstancesClient;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.SetDiskAutoDeleteInstanceRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class SetDiskAutodelete {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.

    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // The zone of the disk that you want to modify.
    String zone = "europe-central2-b";

    // Name of the instance the disk is attached to.
    String instanceName = "YOUR_INSTANCE_NAME";

    // The name of the disk for which you want to modify the autodelete flag.
    String diskName = "YOUR_DISK_NAME";

    // The new value of the autodelete flag.
    boolean autoDelete = true;

    setDiskAutodelete(projectId, zone, instanceName, diskName, autoDelete);
  }

  // Sets the autodelete flag of a disk to given value.
  public static void setDiskAutodelete(String projectId, String zone, String instanceName,
      String diskName, boolean autoDelete)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `instancesClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {

      // Retrieve the instance given by the instanceName.
      Instance instance = instancesClient.get(projectId, zone, instanceName);

      // Check if the instance contains a disk that matches the given diskName.
      boolean diskNameMatch = instance.getDisksList()
          .stream()
          .anyMatch(disk -> disk.getDeviceName().equals(diskName));

      if (!diskNameMatch) {
        throw new Error(
            String.format("Instance %s doesn't have a disk named %s attached", instanceName,
                diskName));
      }

      // Create the request object.
      SetDiskAutoDeleteInstanceRequest request = SetDiskAutoDeleteInstanceRequest.newBuilder()
          .setProject(projectId)
          .setZone(zone)
          .setInstance(instanceName)
          .setDeviceName(diskName)
          // Update the autodelete property.
          .setAutoDelete(autoDelete)
          .build();

      // Wait for the update instance operation to complete.
      Operation response = instancesClient.setDiskAutoDeleteAsync(request)
          .get(3, TimeUnit.MINUTES);

      if (response.hasError()) {
        System.out.println("Failed to update Disk autodelete field!" + response);
        return;
      }
      System.out.println(
          "Disk autodelete field updated. Operation Status: " + response.getStatus());
    }
  }
}

Node.js

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.jsהוראות ההגדרה שבמדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Node.js API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const zone = 'europe-central2-b';
// const instanceName = 'YOUR_INSTANCE_NAME';
// const diskName = 'YOUR_DISK_NAME';
// const autoDelete = true;

const compute = require('@google-cloud/compute');

async function setDiskAutodelete() {
  const instancesClient = new compute.InstancesClient();

  const [instance] = await instancesClient.get({
    project: projectId,
    zone,
    instance: instanceName,
  });

  if (!instance.disks.some(disk => disk.deviceName === diskName)) {
    throw new Error(
      `Instance ${instanceName} doesn't have a disk named ${diskName} attached.`
    );
  }

  const [response] = await instancesClient.setDiskAutoDelete({
    project: projectId,
    zone,
    instance: instanceName,
    deviceName: diskName,
    autoDelete,
  });
  let operation = response.latestResponse;
  const operationsClient = new compute.ZoneOperationsClient();

  // Wait for the update instance operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await operationsClient.wait({
      operation: operation.name,
      project: projectId,
      zone: operation.zone.split('/').pop(),
    });
  }

  console.log('Disk autoDelete field updated.');
}

setDiskAutodelete();

Python

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Pythonהוראות ההגדרה שבמדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Python API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from __future__ import annotations

import sys
from typing import Any

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


def set_disk_autodelete(
    project_id: str, zone: str, instance_name: str, disk_name: str, autodelete: bool
) -> None:
    """
    Set the autodelete flag of a disk to given value.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        zone: name of the zone in which is the disk you want to modify.
        instance_name: name of the instance the disk is attached to.
        disk_name: the name of the disk which flag you want to modify.
        autodelete: the new value of the autodelete flag.
    """
    instance_client = compute_v1.InstancesClient()
    instance = instance_client.get(
        project=project_id, zone=zone, instance=instance_name
    )

    for disk in instance.disks:
        if disk.device_name == disk_name:
            break
    else:
        raise RuntimeError(
            f"Instance {instance_name} doesn't have a disk named {disk_name} attached."
        )

    disk.auto_delete = autodelete

    operation = instance_client.update(
        project=project_id,
        zone=zone,
        instance=instance_name,
        instance_resource=instance,
    )

    wait_for_extended_operation(operation, "disk update")

REST

כדי להגדיר את אפשרות המחיקה האוטומטית של דיסק, שולחים בקשת POST אל ה-method‏ instances.setDiskAutoDelete.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setDiskAutoDelete?autoDelete=false&deviceName=SOURCE_DISK

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייכת המכונה הווירטואלית של המקור.
  • ‫ZONE: האזור שבו נמצאת מכונת המקור.
  • ‫VM_NAME: השם של מכונת המקור.
  • ‫SOURCE_DISK: שם המכשיר של הדיסק שממנו רוצים ליצור את התמונה.

אחרי שמכינים את המכונה הווירטואלית, יוצרים את האימג'.

יצירת התמונה

אפשר ליצור תמונות דיסק מהמקורות הבאים:

  • דיסק לאחסון מתמיד, גם כשהדיסק מחובר ל-VM
  • תמונת מצב של דיסק אחסון מתמיד (persistent disk)
  • תמונה אחרת בפרויקט
  • תמונה ששותפה מפרויקט אחר
  • תמונת RAW דחוסה ב-Cloud Storage

אפשר ליצור קובץ אימג' פעם ב-10 דקות. אם רוצים לשלוח מספר גדול של בקשות ליצירת קובץ אימג', אפשר לשלוח עד 6 בקשות ב-60 דקות. מידע נוסף זמין במאמר בנושא מגבלות על תדירות יצירת תמונות מצב.

המסוף

  1. נכנסים לדף Create an image במסוף Cloud de Confiance .

    כניסה לדף Create an image

  2. מציינים את שם קובץ האימג'.

  3. מציינים את המקור שממנו רוצים ליצור תמונה. זה יכול להיות Persistent Disk, קובץ snapshot, תמונה אחרת או קובץ disk.raw ב-Cloud Storage.

  4. אם אתם יוצרים תמונה מדיסק שמצורף למכונת VM שפועלת, צריך לבחור באפשרות Keep instance running (השארת המכונה הווירטואלית במצב פעיל) כדי לאשר שאתם רוצים ליצור את התמונה בזמן שהמכונה הווירטואלית פועלת. אפשר להכין את המכונה הווירטואלית לפני שיוצרים את התמונה.

  5. ברשימה הנפתחת Based on source disk location (default), מציינים את המיקום שבו רוצים לאחסן את קובץ האימג'. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים ב-us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine מאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

  6. אופציונלי: מציינים את המאפיינים של התמונה.

    • משפחה: משפחת התמונות שאליה התמונה החדשה שייכת.
    • תיאור: תיאור של התמונה בהתאמה אישית.
    • ‫Label: תווית לקיבוץ משאבים.
  7. מציינים את מפתח ההצפנה. אפשר לבחור בין מפתח Google Cloud-powered encryption key, מפתח Cloud Key Management Service ‏ (Cloud KMS) או מפתח הצפנה שסופק על ידי הלקוח (CSEK) (הוצא משימוש). אם לא מצוין מפתח הצפנה, התמונות מוצפנות באמצעות Google Cloud-powered encryption key.

  8. כדי ליצור את התמונה, לוחצים על יצירה.

gcloud

ב-Google Cloud CLI, משתמשים בפקודה gcloud compute images create כדי ליצור תמונה בהתאמה אישית.

כדי ליצור תמונה מדיסק מקור:

הדגל --force הוא דגל אופציונלי שמאפשר ליצור את התמונה ממופע פעיל. כברירת מחדל, אי אפשר ליצור תמונות ממופעים פעילים. מציינים את הדגל הזה רק אם בטוחים שרוצים ליצור את התמונה בזמן שהמופע פועל.

gcloud compute images create IMAGE_NAME \
    --source-disk=SOURCE_DISK \
    --source-disk-zone=ZONE \
    [--family=IMAGE_FAMILY] \
    [--storage-location=LOCATION] \
    [--force]

מחליפים את מה שכתוב בשדות הבאים:

  • IMAGE_NAME: שם לתמונה החדשה
  • ‫SOURCE_DISK: הדיסק שממנו רוצים ליצור את התמונה
  • ‫ZONE: האזור שבו נמצא הדיסק
  • ‫IMAGE_FAMILY: אופציונלי: דגל שמציין לאיזו משפחת תמונות התמונה הזו שייכת.
  • ‫LOCATION: אופציונלי: דגל שמאפשר לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, אפשר לציין us כדי לאחסן את התמונה במספר אזורים us, או לציין us-central1 כדי לאחסן אותה באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' באזור במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

יצירת תמונה על סמך תמונת מקור:

gcloud compute images create IMAGE_NAME \
  --source-image=SOURCE_IMAGE \
  [--source-image-project=IMAGE_PROJECT] \
  [--family=IMAGE_FAMILY] \
  [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • IMAGE_NAME: שם לתמונה החדשה.
  • ‫SOURCE_IMAGE: התמונה שממנה רוצים ליצור את התמונה החדשה.
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שבו נמצאת תמונת המקור. משתמשים בפרמטר הזה אם רוצים להעתיק תמונה מפרויקט אחר.
  • ‫IMAGE_FAMILY: אופציונלי: משפחת התמונות שאליה שייכת התמונה החדשה.
  • ‫LOCATION: אופציונלי: מאפשר לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, מציינים us כדי לאחסן את התמונה בusמספר אזורים בארה"ב, או us-central1 כדי לאחסן אותה ב אזור us-central1. אם לא תבחרו מיקום, Compute Engine מאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

כדי ליצור תמונה מקובץ snapshot:

gcloud compute images create IMAGE_NAME \
    --source-snapshot=SOURCE_SNAPSHOT \
    [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • IMAGE_NAME: שם לתמונה החדשה
  • ‫SOURCE_SNAPSHOT: קובץ ה-snapshot שממנו רוצים ליצור את התמונה
  • ‫LOCATION: אופציונלי: דגל שמאפשר לכם לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, אפשר לציין us כדי לאחסן את התמונה במספר אזורים us, או לציין us-central1 כדי לאחסן אותה באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' באזור במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

צפייה במיקום של תמונה:

משתמשים בפקודה gcloud compute images describe כדי לראות את מיקום קובץ האימג'.

gcloud compute images describe IMAGE_NAME

מחליפים את IMAGE_NAME בשם של האימג' שרוצים לבדוק.

המשך

Go

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Go במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Go API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
)

// Creates a disk image from an existing disk
func createImageFromDisk(
	w io.Writer,
	projectID, zone, sourceDiskName, imageName string,
	storageLocations []string,
	forceCreate bool,
) error {
	// projectID := "your_project_id"
	// zone := "us-central1-a"
	// sourceDiskName := "your_disk_name"
	// imageName := "my_image"
	// // If storageLocations empty, automatically selects the closest one to the source
	// storageLocations = []string{}
	// // If forceCreate is set to `true`, proceeds even if the disk is attached to
	// // a running instance. This may compromise integrity of the image!
	// forceCreate = false

	ctx := context.Background()
	disksClient, err := compute.NewDisksRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewDisksRESTClient: %w", err)
	}
	defer disksClient.Close()
	imagesClient, err := compute.NewImagesRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewImagesRESTClient: %w", err)
	}
	defer imagesClient.Close()

	// Get the source disk
	source_req := &computepb.GetDiskRequest{
		Disk:    sourceDiskName,
		Project: projectID,
		Zone:    zone,
	}

	disk, err := disksClient.Get(ctx, source_req)
	if err != nil {
		return fmt.Errorf("unable to get source disk: %w", err)
	}

	// Create the image
	req := computepb.InsertImageRequest{
		ForceCreate: &forceCreate,
		ImageResource: &computepb.Image{
			Name:             &imageName,
			SourceDisk:       disk.SelfLink,
			StorageLocations: storageLocations,
		},
		Project: projectID,
	}

	op, err := imagesClient.Insert(ctx, &req)

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Disk image %s created\n", imageName)

	return nil
}

Java

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Javaהוראות ההגדרה שבמדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Java API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.Image;
import com.google.cloud.compute.v1.ImagesClient;
import com.google.cloud.compute.v1.InsertImageRequest;
import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstancesClient;
import com.google.cloud.compute.v1.Operation;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateImage {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.

    // Project ID or project number of the Cloud project you use.
    String project = "your-project-id";
    // Zone of the disk you copy from.
    String zone = "europe-central2-b";
    // Name of the source disk you copy from.
    String sourceDiskName = "source-disk-name";
    // Name of the image you want to create.
    String imageName = "your-image-name";
    // Storage location for the image. If the value is undefined,
    // function will store the image in the multi-region closest to your image's source location.
    String storageLocation = "eu";
    // Create the image even if the source disk is attached to a running instance.
    boolean forceCreate = false;

    createImage(project, zone, sourceDiskName, imageName, storageLocation, forceCreate);
  }

  // Creates a new disk image from the specified source disk.
  public static void createImage(String project, String zone, String sourceDiskName,
      String imageName, String storageLocation, boolean forceCreate)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `client.close()` method on the client to safely
    // clean up any remaining background resources.
    try (ImagesClient imagesClient = ImagesClient.create();
        InstancesClient instancesClient = InstancesClient.create();
        DisksClient disksClient = DisksClient.create()) {

      Disk disk = disksClient.get(project, zone, sourceDiskName);

      // Getting instances where source disk is attached.
      for (String fullInstanceName : disk.getUsersList()) {
        Map<String, String> instanceInfo = parseInstanceName(fullInstanceName);
        Instance instance = instancesClient.get(instanceInfo.get("instanceProjectId"),
            instanceInfo.get("instanceZone"), instanceInfo.get("instanceName"));

        // Сheck whether the instances are stopped.
        if (!Arrays.asList("TERMINATED", "STOPPED").contains(instance.getStatus())
            && !forceCreate) {
          throw new IllegalStateException(
              String.format(
                  "Instance %s should be stopped. For Windows instances please stop the instance "
                      + "using GCESysprep command. For Linux instances just shut it down normally."
                      + " You can suppress this error and create an image of the disk by setting "
                      + "'forceCreate' parameter to true (not recommended). "
                      + "More information here: "
                      + "* https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image#api"
                      + "* https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#prepare_instance_for_image",
                  instanceInfo.get("instanceName")));
        }
      }

      if (forceCreate) {
        System.out.println(
            "Warning: forceCreate option compromise the integrity of your image. "
                + "Stop the instance before you create the image if possible.");
      }

      // Create Image.
      IImageimage = IImagenewBuilder()
          .setName(imageName)
          .setSourceDisk(String.format("/zones/%s/disks/%s", zone, sourceDiskName))
          .addStorageLocations(storageLocation.isEmpty() ? "" : storageLocation)
          .build();

      IInsertImageRequestinsertImageRequest = IInsertImageRequestnewBuilder()
          .setProject(project)
          .ssetForceCreateforceCreate)
          .setImageResource(image)
          .build();

      OOperationresponse = imagesClient.insertAsync(insertImageRequest).get(5, TimeUnit.MINUTES);

      if (rresponse.hasError() {
        System.out.println("Image creation failed ! ! " + response);
        return;
      }

      System.out.println("Image created.");
    }
  }


  public static Map<String, String> parseInstanceName(String name) {
    String[] parsedName = name.split("/");
    int splitLength = parsedName.length;

    if (splitLength < 5) {
      throw new IllegalArgumentException(
          "Provide correct instance name in the following format: "
              + "https://www.googleapis.com/compute/v1/projects/PROJECT/zones/ZONE/instances/INSTANCE_NAME");
    }

    return new HashMap<>() {
      {
        put("instanceName", parsedName[splitLength - 1]);
        put("instanceZone", parsedName[splitLength - 3]);
        put("instanceProjectId", parsedName[splitLength - 5]);
      }
    };
  }

}

Python

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Python API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from __future__ import annotations

import sys
from typing import Any
import warnings

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


STOPPED_MACHINE_STATUS = (
    compute_v1.Instance.Status.TERMINATED.name,
    compute_v1.Instance.Status.STOPPED.name,
)


def create_image_from_disk(
    project_id: str,
    zone: str,
    source_disk_name: str,
    image_name: str,
    storage_location: str | None = None,
    force_create: bool = False,
) -> compute_v1.Image:
    """
    Creates a new disk image.

    Args:
        project_id: project ID or project number of the Cloud project you use.
        zone: zone of the disk you copy from.
        source_disk_name: name of the source disk you copy from.
        image_name: name of the image you want to create.
        storage_location: storage location for the image. If the value is undefined,
            function will store the image in the multi-region closest to your image's
            source location.
        force_create: create the image even if the source disk is attached to a
            running instance.

    Returns:
        An Image object.
    """
    image_client = compute_v1.ImagesClient()
    disk_client = compute_v1.DisksClient()
    instance_client = compute_v1.InstancesClient()

    # Get source disk
    disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name)

    for disk_user in disk.users:
        instance_name = disk_user.split("/")[-1]
        instance = instance_client.get(
            project=project_id, zone=zone, instance=instance_name
        )
        if instance.status in STOPPED_MACHINE_STATUS:
            continue
        if not force_create:
            raise RuntimeError(
                f"Instance {disk_user} should be stopped. For Windows instances please "
                f"stop the instance using `GCESysprep` command. For Linux instances just "
                f"shut it down normally. You can supress this error and create an image of"
                f"the disk by setting `force_create` parameter to true (not recommended). \n"
                f"More information here: \n"
                f" * https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image#api \n"
                f" * https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#prepare_instance_for_image"
            )
        else:
            warnings.warn(
                f"Warning: The `force_create` option may compromise the integrity of your image. "
                f"Stop the {disk_user} instance before you create the image if possible."
            )

    # Create image
    image = compute_v1.Image()
    image.source_disk = disk.self_link
    image.name = image_name
    if storage_location:
        image.storage_locations = [storage_location]

    operation = image_client.insert(project=project_id, image_resource=image)

    wait_for_extended_operation(operation, "image creation from disk")

    return image_client.get(project=project_id, image=image_name)

REST

שולחים בקשת POST אל השיטה images().insert, כתובת URL בגוף הבקשה שמפנה לאובייקט המקור שממנו רוצים ליצור את התמונה. ציינו את כתובות ה-URL של המשאבים באמצעות מזהה הפרויקט ושמות המשאבים שלכם.

יצירת קובץ אימג' מדיסק אחסון מתמיד (persistent disk):

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
  "name": "IMAGE_NAME",
  "sourceDisk": "/zones/ZONE/disks/SOURCE_DISK",
  ("storageLocations": "LOCATION",)
  ("forceCreate": "TRUE")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייך התמונה.
  • ‫IMAGE_NAME: שם לתמונה החדשה שרוצים ליצור.
  • ‫ZONE: האזור שבו נמצא דיסק המקור.
  • ‫SOURCE_DISK: הדיסק שממנו רוצים ליצור את התמונה.
  • ‫LOCATION: אופציונלי: מיקום האחסון של התמונה. לדוגמה, מציינים us כדי לאחסן את התמונה באזור us שכולל מספר אזורים, או us-central1 כדי לאחסן אותה באזור us-central1. אם לא בוחרים אזור, מערכת Compute Engine מאחסנת את התמונה באזור המרובה הקרוב ביותר למיקום המקור של התמונה.

הפרמטר האופציונלי forceCreate מאפשר ליצור את האימג' ממכונה וירטואלית (VM) שפועלת. מציינים TRUE רק אם בטוחים שרוצים ליצור את התמונה ממכונה וירטואלית פעילה. הגדרת ברירת המחדל forceCreate היא FALSE.

כדי ליצור תמונה מתמונה אחרת:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
  "name": "IMAGE_NAME",
  "sourceImage": "/global/images/SOURCE_IMAGE",
  ("storageLocations": "LOCATION")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: הפרויקט שהתמונה שייכת אליו.
  • ‫IMAGE_NAME: שם לתמונה החדשה שרוצים ליצור.
  • ‫SOURCE_IMAGE: התמונה שממנה רוצים ליצור את התמונה.
  • ‫LOCATION: אופציונלי: מיקום האחסון של התמונה. לדוגמה, מציינים us כדי לאחסן את התמונה באזור us שכולל מספר אזורים, או us-central1 כדי לאחסן אותה באזור us-central1. אם לא בוחרים אזור, מערכת Compute Engine מאחסנת את התמונה באזור הרב-אזורי הקרוב ביותר למיקום המקור של התמונה.

כדי ליצור תמונה מקובץ snapshot:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images
{
  "name": "IMAGE_NAME",
  "sourceSnapshot": "(/SOURCE_PROJECT_ID)/global/snapshots/SOURCE_SNAPSHOT",
  ("storageLocations": "LOCATION")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: הפרויקט שאליו התמונה שייכת.
  • ‫IMAGE_NAME: שם לתמונה החדשה שרוצים ליצור.
  • ‫SOURCE_PROJECT_ID: אופציונלי: הפרויקט שבו נמצאת התמונה. צריכה להיות לכם הרשאה לגשת למשאב של התמונה המלאה בפרויקט הזה.
  • ‫SOURCE_SNAPSHOT: קובץ ה-snapshot שממנו רוצים ליצור את התמונה.
  • ‫LOCATION: אופציונלי: מיקום האחסון של התמונה. לדוגמה, מציינים us כדי לאחסן את התמונה באזור us שכולל מספר אזורים, או us-central1 כדי לאחסן אותה באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

מידע נוסף על הוספת תמונות זמין במאמר בנושא תמונות.

שיתוף התמונה

אחרי שיוצרים קובץ אימג' בהתאמה אישית, אפשר לשתף אותו בין פרויקטים. אם מאפשרים למשתמשים מפרויקט אחר להשתמש בתמונות המותאמות אישית, הם יכולים לגשת לתמונות האלה על ידי ציון פרויקט התמונה בבקשה שלהם.

הפעלת תכונות של מערכת הפעלה לאורחים

אפשר להשתמש בתכונות של מערכת הפעלה (OS) אורחת כדי להגדיר את האפשרויות הבאות של רשת, אבטחה, אחסון ומערכת הפעלה בתמונות מותאמות אישית. תמונות בהתאמה אישית עם התכונות המוגדרות האלה משמשות כדיסקי אתחול.

gcloud

כדי ליצור קובץ אימג' חדש בהתאמה אישית מקובץ אימג' קיים בהתאמה אישית, משתמשים בפקודה gcloud compute images create עם הדגל --guest-os-features.

gcloud compute images create IMAGE_NAME \
    --source-image=SOURCE_IMAGE \
    [--source-image-project=IMAGE_PROJECT] \
    --guest-os-features="FEATURES,..." \
    [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: השם של התמונה החדשה
  • ‫SOURCE_IMAGE: תמונה שעליה יתבססו התמונות החדשות
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שמכיל את קובץ האימג' של המקור

    משתמשים בפרמטר הזה כדי להעתיק תמונה מפרויקט אחר.

  • ‫FEATURES: תגי מערכת הפעלה של אורח כדי להפעיל תכונות למכונות וירטואליות שיוצרים מתמונות

    כדי להוסיף כמה ערכים, צריך להפריד ביניהם באמצעות פסיקים. מגדירים אחד או יותר מהערכים הבאים:

    • VIRTIO_SCSI_MULTIQUEUE.אפשר להשתמש בממשק הזה במכשירי SSD מקומיים כחלופה ל-NVMe. למידע נוסף על קובצי אימג' שתומכים ב-SCSI, ראו בחירת ממשק.

      בתמונות של Linux, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם גרסאות ליבה 3.17 ואילך. בתמונות של Windows, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם מנהל ההתקן של Windows ב-Compute Engine בגרסה 1.2.

    • WINDOWS. תיוג של קובצי אימג' לאתחול מותאמים אישית של Windows Server כתמונות של Windows.
    • MULTI_IP_SUBNET. הגדרת ממשקים עם מסכת רשת שונה מ-/32. מידע נוסף על הגדרת מסכות רשת זמין במאמר בנושא מסכות רשת של מכונות Compute.
    • UEFI_COMPATIBLE. אתחול עם קושחת UEFI והתכונות הבאות של מכונה וירטואלית מוגנת:
    • GVNIC. תמיכה ברוחבי פס גבוהים יותר ברשת, במהירויות של 50Gbps עד 100Gbps. מידע נוסף זמין במאמר בנושא שימוש ב-Google Virtual NIC.
    • IDPF. תמיכה בממשקי רשת של פונקציית (IDPF) נתיב נתונים של תשתית Intel.
    • SEV_CAPABLE או SEV_SNP_CAPABLE. משתמשים בתגים האלה אם רוצים להשתמש בתמונה במופע של Confidential VM עם תמיכה ב-AMD Secure Encrypted Virtualization ‏ (SEV) או ב-AMD Secure Encrypted Virtualization-Secure Nested Paging ‏ (SEV-SNP). כדי לבדוק אם הליבה שלכם תומכת ב-AMD SEV או ב-AMD SEV-SNP, אפשר לעיין ב פרטים על ליבת Linux.
    • SEV_LIVE_MIGRATABLE_V2. משתמשים בתג הזה אם רוצים להשתמש בתמונה במופע של Confidential VM שתומך ב מיגרציה פעילה ב-AMD SEV. כדי לבדוק אם הליבה תומכת במיגרציה פעילה, קראו את הפרטים על ליבת Linux.
    • TDX_CAPABLE. משתמשים בתג הזה אם רוצים להשתמש בתמונה במופע של Confidential VM עם תמיכה ב-Intel Trust Domain Extensions ‏ (TDX). כדי לבדוק אם ליבת המערכת תומכת ב-Intel TDX, אפשר לעיין ב פרטים על ליבת Linux.
  • ‫LOCATION: אופציונלי: אזור או מספר אזורים שבהם רוצים לאחסן את התמונה

    לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא בוחרים אזור, Compute Engine מאחסן את התמונה באזור המרובה הקרוב ביותר למיקום המקור של התמונה.

REST

משתמשים בשיטה images().insert עם הדגל guestOsFeatures כדי ליצור תמונה חדשה בהתאמה אישית מתמונה קיימת בהתאמה אישית.


POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
 "name": "IMAGE_NAME",
 "sourceImage": "(projects/IMAGE_PROJECT)/global/images/SOURCE_IMAGE",
 ("storageLocations": "LOCATION",)
 "guestOsFeatures": [
  {
   "type": "FEATURES"
  }
 ]
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שבו רוצים ליצור את קובץ האימג' החדש
  • IMAGE_NAME: שם לתמונה החדשה
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שמכיל את קובץ האימג' של המקור

    אפשר להשתמש בפרמטר הזה כדי להעתיק תמונה מפרויקט אחר.

  • ‫SOURCE_IMAGE: התמונה שעליה יתבססו התמונה החדשה

  • ‫LOCATION: אופציונלי: אזור או מספר אזורים שבהם התמונה תאוחסן

    לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא בוחרים אזור, מערכת Compute Engine מאחסנת את התמונה באזור המרובה הקרוב ביותר למיקום המקור של התמונה.

  • ‫FEATURES: תגי מערכת הפעלה של אורח כדי להפעיל תכונות למכונות וירטואליות שיוצרים מתמונות

    כדי להוסיף כמה ערכים, צריך להפריד ביניהם באמצעות פסיקים. מגדירים אחד או יותר מהערכים הבאים:

    • ‫VIRTIO_SCSI_MULTIQUEUE. אפשר להשתמש בו במכשירי SSD מקומיים כחלופה ל-NVMe. למידע נוסף על קובצי אימג' שתומכים ב-SCSI, קראו את המאמר בחירת ממשק.

      בתמונות של Linux, אפשר להפעיל SCSI עם תורים מרובים במכשירי SSD מקומיים בתמונות עם גרסאות ליבה 3.17 ואילך. בתמונות של Windows, אפשר להפעיל SCSI מרובה תורים במכשירי SSD מקומיים בתמונות עם מנהל התקן של Windows ב-Compute Engine בגרסה 1.2.

    • WINDOWS. תיוג של קובצי אימג' לאתחול מותאמים אישית של Windows Server כתמונות של Windows.
    • MULTI_IP_SUBNET. הגדרת ממשקים עם מסכת רשת שונה מ-/32. מידע נוסף על הגדרת מסכות רשת זמין במאמר מסכות רשת של מכונות Compute.
    • UEFI_COMPATIBLE. אתחול עם קושחת UEFI והתכונות הבאות של מכונה וירטואלית מוגנת:
    • GVNIC. תמיכה ברוחבי פס גבוהים יותר ברשת, במהירויות של 50Gbps עד 100Gbps. מידע נוסף זמין במאמר בנושא שימוש ב-Google Virtual NIC.
    • IDPF. תמיכה בממשקי רשת של פונקציית (IDPF) נתיב נתונים של תשתית Intel.
    • SEV_CAPABLE או SEV_SNP_CAPABLE. משתמשים בתגים האלה אם רוצים להשתמש בתמונה במופע של Confidential VM עם תמיכה ב-AMD Secure Encrypted Virtualization ‏ (SEV) או ב-AMD Secure Encrypted Virtualization-Secure Nested Paging ‏ (SEV-SNP). כדי לבדוק אם הליבה שלכם תומכת ב-AMD SEV או ב-AMD SEV-SNP, אפשר לעיין ב פרטים על ליבת Linux.
    • SEV_LIVE_MIGRATABLE_V2. משתמשים בתג הזה אם רוצים להשתמש בתמונה במכונה של Confidential VM שתומכת ב מיגרציה פעילה ב-AMD SEV. כדי לבדוק אם הליבה תומכת במיגרציה פעילה, אפשר לעיין ב פרטים על ליבת Linux.
    • TDX_CAPABLE. משתמשים בתג הזה אם רוצים להשתמש בתמונה במופע של Confidential VM עם תמיכה ב-Intel Trust Domain Extensions ‏ (TDX). כדי לבדוק אם ליבת המערכת תומכת ב-Intel TDX, אפשר לעיין ב פרטים על ליבת Linux.

הימנעות משימוש במידע רגיש במשתני UEFI

משתני Unified Extensible Firmware Interface‏ (UEFI) הם משתנים של צמדי מפתח/ערך שמשמשים את קושחת ה-UEFI בזמן האתחול כדי לאתחל את מערכת ההפעלה של מכונה וירטואלית. בניגוד למכונות פיזיות, שבהן המשתנים מאוחסנים בשבב חומרה, ב-Compute Engine האחסון של המשתנים האלה הוא וירטואלי. לכן, במערכות הפעלה רבות, כל האפליקציות והמשתמשים יכולים לגשת למשתנים האלה ולמידע הזה.

לכן, Google ממליצה מאוד לא לכתוב או לאחסן מידע רגיש או פרטים אישיים מזהים, כמו סיסמאות או מפתחות פרטיים, במשתני UEFI.

שיקולים לגבי תמונות Arm

‫Google מציעה את סדרות המכונות A4X,‏ C4A ו-Tau T2A שפועלות בפלטפורמות של מעבדי Arm. אפשר להפעיל מכונה וירטואלית עם אחת מסדרות המכונות האלה, ואז להשתמש במכונת ה-VM הזו כמקור ליצירת תמונת Arm. התהליך ליצירת תמונת Arm מותאמת אישית זהה לתהליך ליצירת תמונת x86.

כדי לעזור למשתמשים להבחין בין תמונות Arm לבין תמונות x86, בתמונות Arm השדה architecture יוגדר לערך ARM64. הערכים האפשריים בשדה הזה הם:

  • ARCHITECTURE_UNSPECIFIED
  • X86_64
  • ARM64

משתמשי התמונות יכולים לסנן את השדה הזה כדי למצוא תמונות שמבוססות על x86 או על Arm.

המאמרים הבאים