Пример #1
0
// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *check.C) {
	name := sessionName("goamz-region-test")
	perms := []ec2.IPPerm{{
		Protocol:  "tcp",
		FromPort:  80,
		ToPort:    80,
		SourceIPs: []string{"127.0.0.1/32"},
	}}
	errs := make(chan error, len(allRegions))
	for _, region := range allRegions {
		go func(r aws.Region) {
			e := ec2.New(s.ec2.Auth, r)
			_, err := e.AuthorizeSecurityGroup(ec2.SecurityGroup{Name: name}, perms)
			errs <- err
		}(region)
	}
	for _ = range allRegions {
		err := <-errs
		if err != nil {
			ec2_err, ok := err.(*ec2.Error)
			if ok {
				c.Check(ec2_err.Code, check.Matches, "InvalidGroup.NotFound")
			} else {
				c.Errorf("Non-EC2 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
Пример #2
0
func (s *AmazonClientSuite) SetUpSuite(c *check.C) {
	if !testutil.Amazon {
		c.Skip("AmazonClientSuite tests not enabled")
	}
	s.srv.SetUp(c)
	s.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
func main() {
	kingpin.Version("1.2.1")
	kingpin.Parse()

	sl, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "[varnish-purge-proxy]")
	defer sl.Close()
	if err != nil {
		log.Println("Error writing to syslog")
	} else {
		log.SetFlags(0)
		log.SetOutput(sl)
	}

	if len(*tags) == 0 {
		fmt.Println("No tags specified")
		return
	}

	// Set up access to ec2
	auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Duration(24*365*time.Hour)))
	if err != nil {
		log.Println(err)
		return
	}
	ec2region := ec2.New(auth, region)

	go serveHTTP(*port, ec2region)

	select {}
}
Пример #4
0
func (s *AmazonServerSuite) SetUpSuite(c *C) {
	if !testutil.Amazon {
		c.Skip("AmazonServerSuite tests not enabled")
	}
	s.srv.SetUp(c)
	s.ServerTests.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
Пример #5
0
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)
}
Пример #6
0
func (s *S) TestSignatureWithEndpointPath(c *check.C) {
	ec2.FakeTime(true)
	defer ec2.FakeTime(false)

	testServer.Response(200, nil, RebootInstancesExample)

	// https://bugs.launchpad.net/goamz/+bug/1022749
	ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})

	_, err := ec2.RebootInstances("i-10a64379")
	c.Assert(err, check.IsNil)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Signature"], check.DeepEquals, []string{"VVoC6Y6xfES+KvZo+789thP8+tye4F6fOKBiKmXk4S4="})
}
Пример #7
0
func (s *S) TestSignatureWithEndpointPath(c *gocheck.C) {
	ec2.FakeTime(true)
	defer ec2.FakeTime(false)

	testServer.Response(200, nil, RebootInstancesExample)

	// https://bugs.launchpad.net/goamz/+bug/1022749
	ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})

	_, err := ec2.RebootInstances("i-10a64379")
	c.Assert(err, gocheck.IsNil)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Signature"], gocheck.DeepEquals, []string{"klxs+VwDa1EKHBsxlDYYN58wbP6An+RVdhETv1Fm/os="})
}
Пример #8
0
func (s *S) TestSignatureWithEndpointPath(c *C) {
	ec2.FakeTime(true)
	defer ec2.FakeTime(false)

	testServer.Response(200, nil, RebootInstancesExample)

	// https://bugs.launchpad.net/goamz/+bug/1022749
	ec2 := ec2.New(s.ec2.Auth, aws.Region{EC2Endpoint: testServer.URL + "/services/Cloud"})

	_, err := ec2.RebootInstances("i-10a64379")
	c.Assert(err, IsNil)

	req := testServer.WaitRequest()
	c.Assert(req.Form["Signature"], DeepEquals, []string{"gdG/vEm+c6ehhhfkrJy3+wuVzw/rzKR42TYelMwti7M="})
}
Пример #9
0
func main() {
	flag.Parse()

	auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Hour))
	if err != nil {
		panic(err)
	}

	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "running")
	filter.Add("tag:env", "prod")

	c := ec2.New(auth, aws.USEast)
	resp, err := c.DescribeInstances(nil, filter)
	if err != nil {
		log.Panicln(err)
	}
	rezzies := resp.Reservations

	for _, rv := range rezzies {
		for _, inst := range rv.Instances {
			if len(inst.BlockDevices) < 3 {
				for _, bd := range inst.BlockDevices {
					vid := bd.EBS.VolumeId
					name, err := getName(inst.Tags)
					log.Printf("Creating snapshot for: %s volume: %v\n", name, vid)
					if err != nil {
						log.Fatalf("Error getting name:", err)
					}

					stamp := time.Now().UTC().Format(TIME_FORMAT)
					snprsp, err := c.CreateSnapshot(vid, fmt.Sprintf("%s %s %s", name, *period, stamp))
					if err != nil {
						log.Printf("Failed to snap: %s, Error: %s\n", vid, err)
						break
					} else {
						log.Printf("Created snap: %s\n", snprsp.Id)
						t := ec2.Tag{Key: "inst_snap", Value: fmt.Sprintf("%s/%s", inst.InstanceId, *period)}
						tags = append(inst.Tags, t)
						wg.Add(1)
						go tagSnapshot(inst.InstanceId, snprsp.Id, tags, c)
					}
				}
			}
		}
	}
	wg.Wait()
}
Пример #10
0
func (s *LocalServerSuite) SetUpSuite(c *gocheck.C) {
	s.srv.SetUp(c)
	s.ServerTests.ec2 = ec2.New(s.srv.auth, s.srv.region)
	s.clientTests.ec2 = ec2.New(s.srv.auth, s.srv.region)
}
Пример #11
0
func (s *S) SetUpSuite(c *check.C) {
	testServer.Start()
	auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
	s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL})
}
Пример #12
0
func getInstanceStatus(region string, auth *aws.Auth, instances []string, filter *ec2.Filter) ([]ec2.InstanceStatus, error) {
	endpoint := "https://ec2." + region + ".amazonaws.com"
	ec2 := ec2.New(*auth, aws.Region{EC2Endpoint: endpoint})
	resp, err := ec2.DescribeInstanceStatus(nil, filter)
	return resp.InstanceStatuses, err
}
Пример #13
0
func (s *S) SetUpSuite(c *C) {
	testServer.Start()
	auth := aws.Auth{"abc", "123"}
	s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL})
}