Search code examples
powershellvirtual-machineopenstack

Unable to fetch server IP in openstack VM


I have a windows instance running in openstack, named vm-name. I executed the following code to fetch the details of the VM:

$vmName = "vm-name"
$url = "http://xx.xx.xx.xx:8774/v2.1/servers?name=$vmName"
# $headers have the API token

$response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers

The result, $response is supposed to also return the server.addresses field, but it only has the fields id, links, and name. links contain two urls, termed self and bookmark in the format http://xx.xx.xx.xx:8774/v2.1/servers/id. Any idea on how to get the server URL?. I am able to see the IP via openstack UI console.


Solution

  • Network details can not be fetched by /servers endpoint.

    To get the IP address use the following:

    $url = "http://xx.xx.xx.xx:8774/v2.1/servers/$serverId/ips"
    # $headers have the API token
    
    $response = Invoke-RestMethod -Method Get -Uri $url -Headers $headers
    $response.addresses
    

    $serverId can be fetched from the rest call in the question.