[ Web Proxy ]
URL:
Viewing: https://cloud.google.com/compute/docs/metadata/getting-live-migration-notice [Back]  [Original]

Query metadata server for maintenance event notices  |  Compute Engine  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback

Query metadata server for maintenance event notices Stay organized with collections Save and categorize content based on your preferences.

The metadata server provides information about a Compute Engine instance's scheduling options and settings, through the scheduling/ metadata directory listing and the maintenance-event metadata key. You can use these metadata keys to learn about a VM's scheduling options, and also to notify you of an upcoming maintenance event.

The metadata server receives maintenance event notices before a compute instance is live migrated or terminated. To learn more about maintenance events and instance behavior during the events, see Host maintenance overview.

For a specific set of VMs, your VM maintenance options are more flexible. To learn more, see Monitor and plan for a host maintenance event.

Before you begin

Get live migration notices

You can learn when live migration is about to happen for your instance by querying the maintenance-event metadata key periodically.

The maintenance-event metadata key is populated for maintenance events only if you have set your VM's scheduling option to migrate or if your VM has a GPU attached.

The value of this metadata key changes 60 seconds before a maintenance event starts, giving your application code a way to trigger any tasks you want to perform prior to a maintenance event, such as backing up data or updating logs.

Compute Engine gives the 60-second warning only if:

For VMs with attached GPUs, the value changes 60 minutes before the VMs are stopped to give you time to shutdown and restart again on another host. VMs with attached GPUs are not live migrated and are instead stopped and optionally restarted. To learn more, see Handling GPU host maintenance events.

Query the maintenance event metadata key

Linux VMs

To query the maintenance-event metadata key on Linux VMs, run the following command:

user@myinst:~$ curl http://metadata.google.internal/computeMetadata/v1/instance/maintenance-event -H "Metadata-Flavor: Google"

The output is similar to the following:

NONE

You can also use the wait-for-change option. With this option specified, the request only returns an output when a maintenance event is about to start and end.

user@myinst:~$ curl http://metadata.google.internal/computeMetadata/v1/instance/maintenance-event?wait_for_change=true -H "Metadata-Flavor: Google"
Note: For Shielded VM, you can query the metadata by using the HTTPS metadata server endpoint.

Windows VMs

To query the maintenance-event metadata key on Windows VMs, run the following command:

PS C:\> 
$value = (Invoke-RestMethod `
         -Headers @{'Metadata-Flavor' = 'Google'} `
         -Uri "http://metadata.google.internal/computeMetadata/v1/instance/maintenance-event")
$value

The output is similar to the following:

NONE

You can also use the wait-for-change option. With this option specified, the request only returns an output when a maintenance event is about to start and end.

PS C:\> 
$value = (Invoke-RestMethod `
         -Headers @{'Metadata-Flavor' = 'Google'} `
         -Uri "http://metadata.google.internal/computeMetadata/v1/instance/maintenance-event?wait_for_change=true")
$value
Note: For Shielded VM, you can query the metadata by using the HTTPS metadata server endpoint.

Python

You can use the maintenance-event metadata key with the waiting for updates feature to notify your scripts and applications when a maintenance event is about to start and end. This lets you automate any actions that you might want to run before or after the event.

The following Python sample provides an example of how you might implement these two features together.

import time
from typing import Callable, NoReturn, Optional

import requests


METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/"
METADATA_HEADERS = {"Metadata-Flavor": "Google"}


def wait_for_maintenance(callback: Callable[[Optional[str]], None]) -> NoReturn:
    """Start an infinite loop waiting for maintenance signal.

    Args:
        callback: Function to be called when a maintenance is scheduled.

    Returns:
        Never returns, unless there's an error.
    """
    url = METADATA_URL + "instance/maintenance-event"
    last_maintenance_event = None
    last_etag = "0"

    while True:
        r = requests.get(
            url,
            params={"last_etag": last_etag, "wait_for_change": True},
            headers=METADATA_HEADERS,
        )

        # During maintenance the service can return a 503, so these should
        # be retried.
        if r.status_code == 503:
            time.sleep(1)
            continue
        r.raise_for_status()

        last_etag = r.headers["etag"]

        if r.text == "NONE":
            maintenance_event = None
        else:
            maintenance_event = r.text

        if maintenance_event != last_maintenance_event:
            last_maintenance_event = maintenance_event
            callback(maintenance_event)


def maintenance_callback(event: Optional[str]) -> None:
    """Example callback function to handle the maintenance event.

    Args:
        event: details about scheduled maintenance.
    """
    if event:
        print(f"Undergoing host maintenance: {event}")
    else:
        print("Finished host maintenance")


def main():
    wait_for_maintenance(maintenance_callback)


if __name__ == "__main__":
    main()

Review the outputs

The initial and default value of the maintenance-event metadata key is NONE.

For machine series that support advanced maintenance capabilities, prior to a maintenance event you can query the metadata key upcoming-maintenance. If there is a notification available for your instance you should see values similar to the following:

{
   "maintenanceType":"SCHEDULED"
   "canReschedule": "true"
   "latestWindowStartTime": "2025-08-28T21:56:21Z"
   "maintenanceStatus": "PENDING"
   "windowEndTime": "2025-08-29T01:56:20Z"
   "windowStartTime": "2025-08-28T21:56:26Z"
}

To determine how long before a maintenance event the upcoming-maintenance metadata key is populated, see the "Maintenance experience" documentation for the machine series. For example, for Z3 machine types, see Maintenance experience for Z3 instances.

Note: During the maintenance event, the metadata server might briefly return a 503 Service Unavailable code. If your application receives a 503 error code, you should retry your request.

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-08-11 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page