Permalink
Browse files

Only try to assign elastic IPs when they have been specified

  • Loading branch information...
1 parent 91b2616 commit 8db2724c8ca44b00810601226b15c1d2a85e7e21 @nickmarden committed Dec 11, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/ironfan/provider/ec2/elastic_ip.rb
@@ -51,11 +51,12 @@ def self.load!(cluster=nil)
def self.save!(computer)
return unless computer.created?
- elastic_ip = computer.server.ec2.elastic_ip
- Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
- Ironfan.unless_dry_run do
- Ironfan.safely do
- Ec2.connection.associate_address( computer.machine.id, elastic_ip )
+ if elastic_ip = computer.server.ec2.elastic_ip
+ Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
+ Ironfan.unless_dry_run do
+ Ironfan.safely do
+ Ec2.connection.associate_address( computer.machine.id, elastic_ip )
+ end
end
end
end

4 comments on commit 8db2724

@nickmarden
Owner

@schade, this fix looks right to me but can you verify that I've put the conditional logic in the right place?

@schade
schade commented on 8db2724 Dec 12, 2012

Actually there is a better way... above the first line ( elastic_ip = computer.server.ec2.elastic_ip ) add this line:
return unless computer.server.ec2.elastic_ip.nil?

and it will harmlessly bypass if no elastic_ip is set in the facet definition. I suppose you could also put it at the end of the line referenced as well.

@schade
schade commented on 8db2724 Dec 12, 2012

But I see now that Nathan beat me to it and just combined my code with the first test; so all good. Guess I should read further before answering next time. Working as a team on github is still a little new to me right now. :)

@nickmarden
Owner

I had originally thought about doing the

return unless ...

approach, but I generally shy away from early return statements as they tend to be widowmakers in more complex code.

At any rate, all's well that ends well. Don't worry about being a newbie on github collaboration - it's better for Ironfan if there is some imperfect collaboration than none at all, and we'll all get better quickly as time goes on.

Please sign in to comment.