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
- For Windows Server VMs, use
PowerShell 3.0 or later.
We recommend that you use
ctrl+v
to paste the copied code blocks. -
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
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:
You have set the VM's availability options to live migrate during a maintenance event.
You have queried the
maintenance-event
metadata key at least once since the last maintenance event.If you have never queried the
maintenance-event
metadata key or have not queried the metadata key since the last migration, Compute Engine assumes that the VM doesn't require advance warning of maintenance events. The maintenance event initiates immediately and skips the 60-second warning.If you don't want to skip the 60-second warning, make sure your client code queries the
maintenance-event
metadata key at least once between migration events. You must query themaintenance-event
metadata key directly for Compute Engine to determine that you are watching this metadata key. Querying a higher level metadata doesn't trigger the advance notice.
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"
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
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.
Review the outputs
The initial and default value of the maintenance-event
metadata key is NONE
.
For VMs with attached GPUs, bare metal instances, or other instances that don't support live migration, maintenance event the value changes from
NONE
toTERMINATE_ON_HOST_MAINTENANCE
. This value is updated 60 minutes before the stopping event starts.For non-GPU VMs with a scheduling option of
migrate
, themaintenance-event
value changes as follows:- At the start of the migration event, the value changes from
NONE
toMIGRATE_ON_HOST_MAINTENANCE
. This value is updated 60 seconds before the stopping event starts. - Throughout the duration of the event and while your VM instance is being
live migrated, the value remains as
MIGRATE_ON_HOST_MAINTENANCE
. - After the maintenance event ends, the value returns to
NONE
.
- At the start of the migration event, the value changes from
For sole-tenant VMs, during a host maintenance event, the
maintenance-event
metadata key value doesn't change and remainsNONE
from the start to the end of the event.
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"
}
The upcoming-maintenance
metadata key is populated prior to a maintenance
event as follows:
- C3: up to 7 days
- C3D: up to 7 days
- X4: up to 60 days
- Z3: up to 7 days
What's next
- Learn about setting instance availability policies.
- Learn more about live migration.
- Learn more about VM metadata.