Beispiel #1
0
func (s *AmazonClientSuite) SetUpSuite(c *gocheck.C) {
	if !testutil.Amazon {
		c.Skip("AmazonClientSuite tests not enabled")
	}
	s.srv.SetUp(c)
	s.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
Beispiel #2
0
func CreateTags() {
	flags := flag.NewFlagSet("create-tags", flag.ExitOnError)
	regionString := flags.String("r", "us-east-1", "the AWS region")
	tagKey := flags.String("k", "", "tag key")
	tagValue := flags.String("v", "", "tag value")
	flags.Parse(os.Args[4:])
	instanceIdString := os.Args[3]
	auth, authErr := aws.GetAuth("", "", "", time.Now().Add(time.Second*3600))
	if authErr != nil {
		panic(authErr)
	}
	region := aws.Regions[*regionString]
	connection := ec2.New(auth, region)
	instanceIds := make([]string, 1)
	instanceIds[0] = instanceIdString
	tag := ec2.Tag{Key: *tagKey, Value: *tagValue}
	tags := make([]ec2.Tag, 1)
	tags[0] = tag
	resp, err := connection.CreateTags(instanceIds, tags)
	if err != nil {
		panic(err)
		os.Exit(1)
	}
	j, err := json.Marshal(resp)
	os.Stdout.Write(j)
}
func DescribeInstances() {
	var filterFlags filterOption
	filter := ec2.NewFilter()
	flags := flag.NewFlagSet("describe-instances", flag.ExitOnError)
	//config := flags.String("c", "none", "the configuration file")
	regionString := flags.String("r", "us-east-1", "the AWS region")
	flags.Var(&filterFlags, "f", "the filter")
	flags.Parse(os.Args[3:])
	auth, err := aws.GetAuth("", "", "", time.Now().Add(time.Second*3600))
	if err != nil {
		panic(err)
	}
	region := aws.Regions[*regionString]
	connection := ec2.New(auth, region)
	for idx := range filterFlags {
		tokens := strings.Split(filterFlags[idx], "=")
		filter.Add(tokens[0], tokens[1])
		//fmt.Printf("foo bar %s", *config)
	}
	resp, err := connection.DescribeInstances(nil, filter)
	if err != nil {
		panic(err)
	}
	reservations := resp.Reservations
	j, err := json.Marshal(reservations)
	if err != nil {
		panic(err)
	}
	os.Stdout.Write(j)
}
Beispiel #4
0
// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *gocheck.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, gocheck.Matches, "InvalidGroup.NotFound")
			} else {
				c.Errorf("Non-EC2 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
Beispiel #5
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="})
}
Beispiel #6
0
func DeleteSnapshot() {
	flags := flag.NewFlagSet("delete-snapshot", flag.ExitOnError)
	regionString := flags.String("r", "us-east-1", "the AWS region")
	flags.Parse(os.Args[4:])
	snapshotIds := strings.Split(os.Args[3], ",")
	auth, authErr := aws.GetAuth("", "", "", time.Now().Add(time.Second*3600))
	if authErr != nil {
		panic(authErr)
	}
	region := aws.Regions[*regionString]
	connection := ec2.New(auth, region)

	resp, err := connection.DeleteSnapshots(snapshotIds)
	if err != nil {
		panic(err)
		os.Exit(1)
	}
	j, err := json.Marshal(resp)
	os.Stdout.Write(j)
}
Beispiel #7
0
func CreateSnapshot() {
	flags := flag.NewFlagSet("create-snapshot", flag.ExitOnError)
	regionString := flags.String("r", "us-east-1", "the AWS region")
	descriptionString := flags.String("d", "", "description")
	flags.Parse(os.Args[4:])
	volumeIdString := os.Args[3]
	auth, authErr := aws.GetAuth("", "", "", time.Now().Add(time.Second*3600))
	if authErr != nil {
		panic(authErr)
	}
	region := aws.Regions[*regionString]
	connection := ec2.New(auth, region)
	resp, err := connection.CreateSnapshot(volumeIdString, *descriptionString)
	if err != nil {
		panic(err)
		os.Exit(1)
	}
	j, err := json.Marshal(resp)
	os.Stdout.Write(j)
}
Beispiel #8
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)
}
Beispiel #9
0
func (s *S) SetUpSuite(c *gocheck.C) {
	testServer.Start()
	auth := aws.Auth{AccessKey: "abc", SecretKey: "123"}
	s.ec2 = ec2.New(auth, aws.Region{EC2Endpoint: testServer.URL})
}