Openstack Python API novaclient - SecurityGroup Rule list with description

178 views Asked by At

i have been familiar with the python API for a while and there is an annoying thing i can't solve.

in short, I want to get all the security rules in my environment.

it works, which bothers me that I can't get the "description" associated with them at all.

my PY code:

from keystoneauth1 import session
from novaclient import client
import json
from requests import get

...AUTH....

sg_list = nova.security_groups.list() 
print(sg_list) 

....OUTPUT:

[<SecurityGroup description=192.168.140.0/24, id=123213xxxc2e6156243, name=asdasdasd, rules=[{'from_port': 1, 'group': {}, 'ip_protocol': 'tcp', 'to_port': 65535, 'parent_group_id': '615789e4-d4e214213136156243', 'ip_range': {'cidr': '192.168.140.0/24'},....

Is there a solution for this?

Thanks !

1

There are 1 answers

0
Norbert_Cs On

The output is a list , so you can do on first element:

sg_list[0].split("description",1)[1]

and you will get the description only