Filtering nova instance list based on network/subnet

asked 2014-09-15 20:33:24 -0600

magesh-gv gravatar image

updated 2014-09-16 17:26:42 -0600

mpetason gravatar image

I am able to filter nova instance list based on IP Address.

nova list --ip=xxxx

However, I am unable to filter based on either network or subnet.

Tried all possible keys. Is filtering based on network or a subnet even supported in nova ?

I am not using nova networking if it matters.

Solution with direct api call using curl is also fine

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-16 20:25:15 -0600

larsks gravatar image

I don't believe the Nova API supports this sort of filtering on the server side, although you are welcome to check through the documentation to see if I missed anything.

This sort of filtering would be reasonably easy to implement on the client side; getting a list of servers and metadata is as simple as:

#!/usr/bin/python

import os
import sys
import argparse

from novaclient.v1_1 import client as novaclient

def get_nova_client():
    return novaclient.Client(
        os.environ['OS_USERNAME'],
        os.environ['OS_PASSWORD'],
        None,
        auth_url=os.environ['OS_AUTH_URL'],
        tenant_id=os.environ['OS_TENANT_ID'],
    )


def main():
    nc = get_nova_client()
    # Print a list of running servers.
    for server in nc.servers.list():
        print server.id, server.name
        for network_name, network in server.networks.items():
            print '    ', network_name, ', '.join(network)

if __name__ == '__main__':
    main()

You could put any logic you want inside the for loop to filter out which servers to display.

edit flag offensive delete link more

Comments

Thanks Larsks.

I was hoping to avoid fetching a long list of instances with full details.

This looks like a minor limitation in Nova. Is this not supported because when Neutron is used for networking they do not have the network association information in nova db on which the filters are applied

magesh-gv gravatar imagemagesh-gv ( 2014-09-17 11:56:16 -0600 )edit

I haven't looked at how filters are implemented so I'm not sure.

larsks gravatar imagelarsks ( 2014-09-17 12:54:01 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2014-09-15 20:33:24 -0600

Seen: 887 times

Last updated: Sep 16 '14