Even though Windows instances aren’t officially supported on Linode, there are ways to get a Windows based instance up and running (a bit of googling will help you around that).
Once you deployed your Windows instance, you will notice that all attempts to reach the Linode’s metadata service will fail.
Let’s take a quick look on how metadata service works.
#We get the token into a TOKEN variable
export TOKEN=$(curl -X PUT -H "Metadata-Token-Expiry-Seconds: 3600" http://169.254.169.254/v1/token)
#Send a request to the metadata service.
curl -H "Metadata-Token: $TOKEN" http://169.254.169.254/v1/instance
If we translate these commands into PowerShell, we get something which looks like this
# Define the URL for the token request
$tokenUrl = "http://169.254.169.254/v1/token"
# Define the headers for the token request
$tokenHeaders = @{
"Metadata-Token-Expiry-Seconds" = "3600"
}
# Make the PUT request to get the token
$tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method Put -Headers
If we execute Invoke-RestMethod command out of the box, the request will fail with the following message: Unable to connect to the remote server
Problem occurs because our server doesn’t know where to route the request for http://169.254.169.254 and can easily be fixed by adding a route on your server which will route requests for 169.254.169.254 via your instance gateway.
ROUTE ADD 169.254.169.254 mask 255.255.255.255 172.233.45.1 METRIC 10
Make sure to replace 172.233.45.1 with your gateway IP address. Don’t use the one provided above. After adding the route, we should be able to send requests to our metadata service. Below you can find an example PowerShell script which will return basic instance information.
# Define the URL for the token request
$tokenUrl = "http://169.254.169.254/v1/token"
# Define the headers for the token request
$tokenHeaders = @{
"Metadata-Token-Expiry-Seconds" = "3600"
}
# Make the PUT request to get the token
$tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method Put -Headers $tokenHeaders
# Extract the token from the response
$token = $tokenResponse
# Define the URL for the instance info request
$networkUrl = "http://169.254.169.254/v1/instance"
# Define the headers for the network request
$networkHeaders = @{
"Metadata-Token" = $token
"Accept" = "application/json" #specify we want the results in JSON format
}
# Make the GET request to retrieve instance information
$Response = Invoke-RestMethod -Uri $networkUrl -Method Get -Headers $networkHeaders
return $Response
Finally, if you want the route for the metadata service to be persistent across reboots, make sure to add the “-p” flag to your “route add” command.
Cheers,
Alex.