-
Notifications
You must be signed in to change notification settings - Fork 1
/
ds-sg-list
executable file
·38 lines (31 loc) · 984 Bytes
/
ds-sg-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import time
import collections
import openstack
def config_from_env():
config = {}
for k in ('auth_url', 'project_name', 'username',
'password', 'region_name'):
v = os.environ.get('OS_%s' % (k.upper()))
config[k] = v
return config
openstack.enable_logging()
conn = openstack.connect(**config_from_env())
projects = {p.id: p.name for p in conn.identity.projects()}
for sg in conn.network.security_groups():
print("%s/%s %s" % (
projects.get(sg.project_id, sg.project_id),
sg.name,
sg.id))
for rule in sg.security_group_rules:
print(" %-10s %-10s %-10s %s:%s:%s" % (
rule['direction'],
rule['ethertype'],
rule['protocol'] or 'any',
rule['remote_ip_prefix'] or '-',
rule['port_range_min'] or '-',
rule['port_range_max'] or '-'
))