Skip to content

Commit

Permalink
Only set CharonNetworkName tag in EC2 when it is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbvermaa committed Jun 14, 2017
1 parent 039fe74 commit 2a8d9b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions nixops/resources/ec2_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ def _retry(self, fun, **kwargs):
tags = nixops.util.attr_property("ec2.tags", {}, 'json')

def get_common_tags(self):
return {'CharonNetworkUUID': self.depl.uuid,
'CharonNetworkName': self.depl.name,
tags = {'CharonNetworkUUID': self.depl.uuid,
'CharonMachineName': self.name,
'CharonStateFile': "{0}@{1}:{2}".format(getpass.getuser(), socket.gethostname(), self.depl._db.db_file)}
if self.depl.name:
tags['CharonNetworkName'] = self.depl.name,
return tags

def get_default_name_tag(self):
return "{0} [{1}]".format(self.depl.description, self.name)
Expand Down
15 changes: 12 additions & 3 deletions nixops/resources/ec2_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.security_group_description = defn.security_group_description
self.vpc_id = defn.vpc_id

from pprint import pprint

grp = None
if check:
with self.depl._db:
self._connect()

try:
grp = self._conn.get_all_security_groups([ defn.security_group_name ])[0]
grp = self.get_security_group()
self.state = self.UP
self.security_group_id = grp.id
self.security_group_description = grp.description
Expand All @@ -123,14 +125,17 @@ def create(self, defn, check, allow_reboot, allow_recreate):
new_rule = [ rule.ip_protocol, int(rule.from_port), int(rule.to_port) ]
if grant.cidr_ip:
new_rule.append(grant.cidr_ip)
else:
elif 'groupName' in vars(grant):
new_rule.append(grant.groupName)
new_rule.append(grant.owner_id)
else:
new_rule.append(grant.groupId)
new_rule.append(grant.owner_id)
rules.append(new_rule)
self.security_group_rules = rules
except boto.exception.EC2ResponseError as e:
if e.error_code == u'InvalidGroup.NotFound':
self.state = self.Missing
self.state = self.MISSING
else:
raise

Expand All @@ -145,6 +150,9 @@ def create(self, defn, check, allow_reboot, allow_recreate):
else:
old_rules.remove(tupled_rule)

pprint(old_rules)
pprint(new_rules)

if self.state == self.MISSING or self.state == self.UNKNOWN:
self._connect()
try:
Expand All @@ -158,6 +166,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):

if new_rules:
self.logger.log("adding new rules to EC2 security group ‘{0}’...".format(self.security_group_name))
pprint(new_rules)
if grp is None:
self._connect()
grp = self.get_security_group()
Expand Down

0 comments on commit 2a8d9b9

Please sign in to comment.