Skip to content

Commit

Permalink
Move security_groups_to_ids to ec2_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aske committed Oct 30, 2017
1 parent 92e0fac commit dad0ccf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
9 changes: 1 addition & 8 deletions nixops/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,7 @@ def _assign_elastic_ip(self, elastic_ipv4, check):
self.ssh_pinged = False

def security_groups_to_ids(self, subnetId, groups):
sg_names = filter(lambda g: not g.startswith('sg-'), groups)
if sg_names != [ ] and subnetId != "":
self.connect()
subnet_id_filter = {'Name': 'subnet-id', 'Values': [vpc_id]}
vpc_id = [vpc.vpc_id for vpc in self._conn.subnets.filter(Filters=[subnet_id_filter]).limit(1)][0]
groups = map(lambda g: nixops.ec2_utils.name_to_security_group(self._conn, g, vpc_id), groups)

return groups
return nixops.ec2_utils.security_groups_to_ids(self._conn, subnetId, groups)

def _get_network_interfaces(self, defn):
groups = self.security_groups_to_ids(defn.subnet_id, defn.security_group_ids)
Expand Down
10 changes: 10 additions & 0 deletions nixops/ec2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ def id_to_security_group_name(conn, sg_id, vpc_id):
name = sg.group_name
return name
raise Exception("could not resolve security group id '{0}' in VPC '{1}'".format(sg_id, vpc_id))

def security_groups_to_ids(conn, subnetId, groups):
sg_names = filter(lambda g: not g.startswith('sg-'), groups)
if sg_names != [ ] and subnetId != "":
self.connect()
subnet_id_filter = {'Name': 'subnet-id', 'Values': [vpc_id]}
vpc_id = [vpc.vpc_id for vpc in self._conn.subnets.filter(Filters=[subnet_id_filter]).limit(1)][0]
groups = map(lambda g: nixops.ec2_utils.name_to_security_group(self._conn, g, vpc_id), groups)

return groups
9 changes: 1 addition & 8 deletions nixops/resources/elastic_file_system_mount_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,4 @@ def destroy(self, wipe=False):

def security_groups_to_ids(self, region, access_key_id, subnetId, groups):
conn = nixops.ec2_utils.connect(region, access_key_id)
conn_vpc = nixops.ec2_utils.connect_vpc(region, access_key_id)

sg_names = filter(lambda g: not g.startswith('sg-'), groups)
if sg_names != [ ] and subnetId != "":
vpc_id = conn_vpc.get_all_subnets([subnetId])[0].vpc_id
groups = map(lambda g: nixops.ec2_utils.name_to_security_group(conn, g, vpc_id), groups)

return groups
return nixops.ec2_utils.security_groups_to_ids(set)

0 comments on commit dad0ccf

Please sign in to comment.