func (s *AmazonServerSuite) SetUpSuite(c *gocheck.C) { if !*amazon { c.Skip("AmazonServerSuite tests not enabled") } s.srv.SetUp(c) s.ServerTests.elb = elb.New(s.srv.auth, aws.USEast) }
func (s *AmazonClientSuite) SetUpSuite(c *C) { if !*amazon { c.Skip("AmazonClientSuite tests not enabled") } s.srv.SetUp(c) s.elb = elb.New(s.srv.auth, aws.USEast) s.ec2 = ec2.New(s.srv.auth, aws.USEast) }
func main() { auth := aws.Auth{ AccessKey: os.Getenv("ACCESS_KEY_ID"), SecretKey: os.Getenv("SECRET_ACCESS_KEY"), } e := elb.New(auth, aws.Region{ELBEndpoint: "https://elasticloadbalancing.amazonaws.com"}) fmt.Println(elbName) resp, err := e.CreateLoadBalancer("testing") if err != nil { panic(err) } fmt.Printf(resp) }
func (s *S) SetUpSuite(c *check.C) { s.HTTPSuite.SetUpSuite(c) auth := aws.Auth{AccessKey: "abc", SecretKey: "123"} s.elb = elb.New(auth, aws.Region{ELBEndpoint: testServer.URL}) }
func (s *LocalServerSuite) SetUpSuite(c *gocheck.C) { s.srv.SetUp(c) s.ServerTests.elb = elb.New(s.srv.auth, s.srv.region) s.clientTests.elb = elb.New(s.srv.auth, s.srv.region) }
func main() { var inst_id string if instanceID == "" { inst_id := aws.InstanceId() if inst_id == "unknown" { log.Fatalln("Unable to get instance id") } } else { inst_id = instanceID } auth, err := aws.GetAuth(accesskey, secretkey, "", time.Time{}) if err != nil { log.Fatalln("Unable to get AWS auth", err) } if securityGroupID != "" { awsec2 = ec2.New(auth, aws.GetRegion(region)) groupMap := getSecurityGroupIds(inst_id) groupMap[securityGroupID] = true groupIds := make([]string, 0, len(groupMap)) for id := range groupMap { groupIds = append(groupIds, id) } opts := &ec2.ModifyInstanceAttributeOptions{SecurityGroups: ec2.SecurityGroupIds(groupIds...)} resp, err := awsec2.ModifyInstanceAttribute(inst_id, opts) if err != nil || !resp.Return { log.Fatalln("Error adding security group to instance", err) } log.Printf("Added security group %s to instance %s\n", securityGroupID, inst_id) } awselb := elb.New(auth, aws.GetRegion(region)) for _, lbname := range lbnames { _, err = awselb.RegisterInstancesWithLoadBalancer([]string{inst_id}, lbname) if err != nil { log.Fatalln("Error registering instance", err) } log.Printf("Registered instance %s with elb %s\n", inst_id, lbname) } c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) // this waits until we get a kill signal <-c for _, lbname := range lbnames { _, err = awselb.DeregisterInstancesFromLoadBalancer([]string{inst_id}, lbname) if err != nil { log.Fatalln("Error deregistering instance", err) } log.Printf("Deregistered instance %s with elb %s\n", inst_id, lbname) } if securityGroupID != "" { groupMap := getSecurityGroupIds(inst_id) delete(groupMap, securityGroupID) groupIds := make([]string, 0, len(groupMap)) for id := range groupMap { groupIds = append(groupIds, id) } opts := &ec2.ModifyInstanceAttributeOptions{SecurityGroups: ec2.SecurityGroupIds(groupIds...)} resp, err := awsec2.ModifyInstanceAttribute(inst_id, opts) if err != nil || !resp.Return { log.Fatalln("Error removing security group from instance", err) } log.Printf("Removed security group %s from instance %s\n", securityGroupID, inst_id) } }
func getAllElbs(region string, auth *aws.Auth) ([]elb.LoadBalancerDescription, error) { endpoint := "https://elasticloadbalancing." + region + ".amazonaws.com" elbConn := elb.New(*auth, aws.Region{ELBEndpoint: endpoint}) resp, err := elbConn.DescribeLoadBalancers() return resp.LoadBalancerDescriptions, err }
func main() { flag.Parse() dockerClient, err := docker.NewClient(*dockerEndpoint) if err != nil { fmt.Printf("cannot connect to docker: %s\n", err) os.Exit(1) } // Wait for the container to start // TODO(ross): this could be done with the events interface perhaps? for { _, err := dockerClient.InspectContainer(*containerID) if err == nil { break } if _, ok := err.(*docker.NoSuchContainer); ok { time.Sleep(time.Second) continue } fmt.Printf("docker: %s: %s\n", *containerID, err) os.Exit(1) } instanceID := aws.InstanceId() if instanceID == "unknown" { fmt.Printf("cannot determine AWS instance ID. not running in EC2?\n") os.Exit(1) } awsAuth, err := aws.GetAuth("", "", "", time.Time{}) if err != nil { fmt.Printf("cannot get AWS auth: %s\n", err) os.Exit(1) } elbConn := elb.New(awsAuth, aws.GetRegion(aws.InstanceRegion())) _, err = elbConn.RegisterInstancesWithLoadBalancer( []string{instanceID}, *loadBalancerName) if err != nil { fmt.Printf("cannot register instance: %s\n", err) os.Exit(1) } fmt.Printf("registered instance %s from ELB %s\n", instanceID, *loadBalancerName) // Wait for the container to exit _, err = dockerClient.WaitContainer(*containerID) if err != nil { fmt.Printf("docker: %s: waiting: %s\n", *containerID, err) } else { fmt.Printf("docker: %s exited\n", *containerID) } _, err = elbConn.DeregisterInstancesFromLoadBalancer( []string{instanceID}, *loadBalancerName) if err != nil { fmt.Printf("cannot unregister instance: %s\n", err) os.Exit(1) } fmt.Printf("unregisterd instance %s from ELB %s\n", instanceID, *loadBalancerName) }