Skip to content

Instantly share code, notes, and snippets.

@dlovell
Created December 21, 2013 15:56
Show Gist options
  • Save dlovell/8071181 to your computer and use it in GitHub Desktop.
Save dlovell/8071181 to your computer and use it in GitHub Desktop.
script to authorize a port from within 'starcluster shell' Cribbed from [ipcluster._authorize_port](https://github.com/jtriley/StarCluster/blob/develop/starcluster/plugins/ipcluster.py#L263)
# settings
port = 9999
service_name = 'my_service'
cluster_name = 'my_cluster'
protocol = 'tcp'
world_cidr = '0.0.0.0/0'
master = cm.get_cluster(cluster_name).master_node
group = master.cluster_groups[0]
if isinstance(port, tuple):
port_min, port_max = port
else:
port_min, port_max = port, port
port_open = master.ec2.has_permission(group, protocol, port_min, port_max,
world_cidr)
if not port_open:
log_str = "Authorizing tcp ports [%s-%s] on %s for: %s" % \
(port_min, port_max, world_cidr, service_name)
print log_str
master.ec2.conn.authorize_security_group(
group_id=group.id, ip_protocol='tcp',
from_port=port_min,
to_port=port_max, cidr_ip=world_cidr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment