From 73c18013c4fbbb53be025ff312fce8e132e6b146 Mon Sep 17 00:00:00 2001 From: Aaron Feng Date: Tue, 22 Jul 2014 08:22:23 -0400 Subject: [PATCH] Instead of hardcoding AZ, retrieve it from AWS Docker-DCO-1.1-Signed-off-by: Aaron Feng aaron.feng@gmail.com (github: aaronfeng) --- backends/ec2.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backends/ec2.go b/backends/ec2.go index af9ece3535..6f6ce33391 100644 --- a/backends/ec2.go +++ b/backends/ec2.go @@ -122,12 +122,17 @@ func defaultSshKeyPath() string { return path.Join(dir, ".ssh", "id_rsa") } +func (c *ec2Client) defaultAvailabilityZones() string { + filter := ec2.NewFilter() + resp, _ := c.ec2Conn.AvailabilityZones(filter) + return resp.Zones[0].Name +} + func defaultConfigValues() (config *ec2Config) { config = new(ec2Config) config.region = aws.USEast config.ami = "ami-7c807d14" config.instanceType = "t1.micro" - config.zone = "us-east-1a" config.sshUser = "ec2-user" config.tag = "docker-ec2-swarm" config.sshLocalPort = "4910" @@ -363,6 +368,10 @@ func Ec2() libswarm.Sender { client.Server.OnVerb(libswarm.Ls, libswarm.Handler(client.ls)) client.Server.OnVerb(libswarm.Get, libswarm.Handler(client.get)) + if config.zone == "" { + config.zone = client.defaultAvailabilityZones() + } + signalHandler(client) _, err = ctx.Ret.Send(&libswarm.Message{Verb: libswarm.Ack, Ret: client.Server})