Setting up windows servers for the metadata service for bare metal servers
To access bare metal server metadata from Windows servers, you have extra requirements to locate a default gateway and add a route.
Overview
To use the metadata service on Windows, you set up a default route to a link-local address for the metadata. To use the metadata service on Windows, you need to locate the IP address of the default gateway, then add a route to the link-local address. After this initial setup, you make calls to access the bare metal server metadata.
The following information is presented as separate steps. More likely, you need to set up a cloudbaseinit
automation process that does all the steps in a single process. The examples illustrate what you need, but you can use other
methods to get the default gateway and add the route.
Step 1 - Locating the IP of the default gateway
Running as administrator, locate the IP of the default gateway. A convenient way is to use Powershell Get-NetRoute
command.
Locate the IP of the default gateway by using the PowerShell Get-NetRoute cmdlet. This command gets the next hop for the default route, also known as the default gateway. For more information, see the Windows Powershell documentation for Get-NetRoute.
From the Windows terminal, the following example invokes the Powershell Get-NetRoute
command to get the default IP routes and pass the routes to the SelectObject cmdlet, which then displays the NextHop property for each default
route.
C:\> powershell "Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -ExpandProperty "NextHop""
The first IP address that is retrieved is the default route. Place the output into a variable.
Step 2: Adding a route to the default gateway
The metadata service uses a link-local address (169.254.169.254) to set up access to the service and retrieve metadata from the bare metal server.
Set up the default route so that the link-local address can get to the default gateway. From the windows or Powershell terminal, you would specify:
C:> route -p add 169.254.169.254 MASK 255.255.255.255 $DEFAULT_GATEWAY
A Python automation script might contain code like this:
command = 'route -p add 169.254.169.254 MASK 255.255.255.255 ()'.format(default_gateway)
These examples use the route
command, but can also use the Powershell New-NetRoute
command and pipe the route in a single command. For example, to combine steps 1 and 2 in a single command, use the following example.
C:\> powershell "Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -ExpandProperty "NextHop" | New-NetRoute"
To add routes, you must run as an administrator on the Windows server.
Step 3: Retrieving bare metal server metadata programmatically
After you add a route to the default gateway, you can access bare metal server metadata by using the link-local address. Construct your automation script by using the tool of your choice to transfer data over the network, such as curl
.
To see curl
commands to invoke the metadata service API and retrieve data, see Retrieve bare metal server metadata from your bare metal server.