Ever wanted a 5min warning that Azure is about to reboot your IaaS VM? There’s an API for that now.
On the VM itself, run: Invoke-WebRequest -Uri http://169.254.169.254/metadata/v1/maintenance
This uses a special reserved IP address (kind of like localhost) that returns maintenance information.
The In-VM Metadata service allows a standard method to pull the maintenance status of that VM by executing the command:
The standard results set will include three main attributes: InstanceID, placement upgrade-domains and placement fault-domains. If an on-going maintenance activity is about to begin (within 5 minutes) an additional maintenance event will be added.
Results when your VM is about to reboot:
Note: This does not appear to work on PaaS.
“Preview: ‘What is about to happen to my VM?’ In-VM Notification Service” – https://azure.microsoft.com/en-us/blog/what-just-happened-to-my-vm-in-vm-metadata-service/
“Manage the availability of virtual machines” – https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-manage-availability/