Last active
August 29, 2015 14:09
-
-
Save pshchelo/f6d4aafd35f8eade6131 to your computer and use it in GitHub Desktop.
Sahara Nova network security group rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from novaclient import client | |
private_cidr = '10.0.0.1/24' | |
private_ports = [8020, 8021, 8030, 8031, 8032, 8033, 8040, 8041, 8042, 8088, | |
9000, 10020, 19888, 50010, 50020] | |
public_cidr = '0.0.0.0/0' | |
public_ports = [22, 80, 8080, 11000, 50030, 50060, 50070, 50075, 50090] | |
AUTH_URL = os.environ.get("OS_AUTH_URL") | |
USER = os.environ.get("OS_USERNAME") | |
PASS = os.environ.get("OS_PASSWORD") | |
TENANT = os.environ.get("OS_TENANT_NAME") | |
nc = client.Client("1.1", USER, PASS, TENANT, AUTH_URL) | |
all_groups = nc.security_groups.list() | |
default_groups = [g for g in all_groups if g.name == 'default'] | |
if len(default_groups) != 1: | |
raise Exception("could not find the single default security group") | |
default_id = default_groups[0].id | |
for port in public_ports: | |
nc.security_group_rules.create(default_id, ip_protocol='TCP', | |
from_port=port, | |
to_port=port, | |
cidr=public_cidr) | |
for port in private_ports: | |
nc.security_group_rules.create(default_id, ip_protocol='TCP', | |
from_port=port, | |
to_port=port, | |
cidr=private_cidr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment