lib/simple_deploy/stack.rb in simple_deploy-0.7.8 vs lib/simple_deploy/stack.rb in simple_deploy-0.8.0
- old
+ new
@@ -19,10 +19,11 @@
@config = SimpleDeploy.config
@logger = SimpleDeploy.logger
@use_internal_ips = !!args[:internal]
+ @use_external_ips = !!args[:external]
@entry = Entry.new :name => @name
end
def create(args)
attributes = stack_attribute_formatter.updated_attributes args[:attributes]
@@ -118,17 +119,13 @@
def resources
stack_reader.resources
end
def instances
- stack_reader.instances.map do |instance|
+ stack_reader.instances.map do |instance|
instance['instancesSet'].map do |info|
- if info['vpcId'] || @use_internal_ips
- info['privateIpAddress']
- else
- info['ipAddress']
- end
+ determine_ip_address(info)
end
end.flatten.compact
end
def raw_instances
@@ -206,9 +203,21 @@
:name => @name,
:stack => self,
:instances => instances,
:ssh_user => ssh_user,
:ssh_key => ssh_key
+ end
+
+ def determine_ip_address(info)
+ if info['vpcId']
+ address = @use_external_ips ? info['ipAddress'] : info['privateIpAddress']
+ unless address
+ @logger.warn "Instance '#{info['instanceId']}' does not have an external address, skipping."
+ end
+ address
+ else
+ @use_internal_ips ? info['privateIpAddress'] : info['ipAddress']
+ end
end
def ssh_key
ENV['SIMPLE_DEPLOY_SSH_KEY'] ||= "#{ENV['HOME']}/.ssh/id_rsa"
end