当前位置: 首页>>代码示例>>Golang>>正文


Golang ec2.New函数代码示例

本文整理汇总了Golang中launchpad/net/goamz/ec2.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()
	if flag.Arg(0) == "" {
		errorf("no command")
		os.Exit(2)
	}
	auth, err := aws.EnvAuth()
	if err != nil {
		fatalf("envauth: %v", err)
	}
	conn := ec2.New(auth, aws.USEast)

	if flag.Arg(0) == "help" {
		for _, c := range cmds {
			c.printUsage()
		}
		return
	}

	for _, c := range cmds {
		if flag.Arg(0) == c.name {
			c.run(conn, flag.Args()[1:])
			return
		}
	}
	errorf("unknown command %q", flag.Arg(0))
	os.Exit(2)
}
开发者ID:juanman2,项目名称:dot-emacs,代码行数:28,代码来源:ec2.go

示例2: getInstances

func getInstances() []*Instance {
	auth := aws.Auth{aws_access_key, aws_secret_key}
	c = ec2.New(auth, aws.Regions[ec2_region])

	filter := ec2.NewFilter()
	filter.Add("instance-state-name", "running")
	resp, err := c.Instances(nil, filter)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	instances := []*Instance{}
	for _, reservation := range resp.Reservations {
		for _, instance := range reservation.Instances {
			name := ""
			for _, tag := range instance.Tags {
				if tag.Key == "Name" {
					name = tag.Value
					break
				}
			}
			if name != "" {
				i := &Instance{instance.DNSName, name}
				instances = append(instances, i)
			}
		}
	}

	return instances
}
开发者ID:postprefix,项目名称:ec2-ssh-config,代码行数:31,代码来源:ec2-ssh-config.go

示例3: SetUpSuite

func (s *AmazonClientSuite) SetUpSuite(c *C) {
	if !testutil.Amazon {
		c.Skip("AmazonClientSuite tests not enabled")
	}
	s.srv.SetUp(c)
	s.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
开发者ID:nathanleclaire,项目名称:libswarm,代码行数:7,代码来源:ec2i_test.go

示例4: SetUpSuite

func (s *AmazonServerSuite) SetUpSuite(c *C) {
	if !*amazon {
		c.Skip("AmazonServerSuite tests not enabled")
	}
	s.srv.SetUp(c)
	s.ServerTests.ec2 = ec2.New(s.srv.auth, aws.USEast)
}
开发者ID:felixge,项目名称:goamz,代码行数:7,代码来源:ec2t_test.go

示例5: Grow

// Spawn instance will spawn an instance to whatever stack is specified in the environment
func (pool AmazonSpawnPool) Grow(conf string) (err error) {

	e := ec2.New(pool.auth, aws.USEast)

	options := ec2.RunInstances{
		ImageId:        "ami-5b632e32", // CoreOS
		InstanceType:   "t1.micro",
		KeyName:        "fiddler", // TODO: We should add this
		SecurityGroups: []ec2.SecurityGroup{pool.sg},
		UserData:       []byte(fmt.Sprintf("https://fiddler/%s/%s", pool.sg.Id, pool.name)), // We need something consistent here
	}

	resp, err := e.RunInstances(&options)
	if err != nil {
		return
	}

	for _, instance := range resp.Instances {
		log.Println("Now running", instance.InstanceId)
		// Next, we'll need to install Fiddler
		// It's kind of annoying, but we can ssh into our new box

	}

	return
}
开发者ID:hayesgm,项目名称:fiddler,代码行数:27,代码来源:aws.go

示例6: TestBootstrapPrivateDns

func (s *S) TestBootstrapPrivateDns(c *gocheck.C) {
	server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer server.Quit()
	h := instanceAgentsConfigHealer{}
	region := aws.SAEast
	region.EC2Endpoint = server.URL()
	h.e = ec2.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	resp, err := h.ec2().RunInstances(&ec2.RunInstances{MaxCount: 1})
	c.Assert(err, gocheck.IsNil)
	instance := resp.Instances[0]
	p := JujuProvisioner{}
	m := machine{
		AgentState:    "running",
		IpAddress:     "localhost",
		InstanceId:    instance.InstanceId,
		InstanceState: "running",
	}
	p.saveBootstrapMachine(m)
	conn, collection := p.bootstrapCollection()
	defer conn.Close()
	defer collection.Remove(m)
	dns, err := h.bootstrapPrivateDns()
	c.Assert(err, gocheck.IsNil)
	c.Assert(dns, gocheck.Equals, instance.PrivateDNSName)
}
开发者ID:kaiquewdev,项目名称:tsuru,代码行数:26,代码来源:healer_test.go

示例7: TestBootstrapInstanceIdHealerHeal

func (s *S) TestBootstrapInstanceIdHealerHeal(c *gocheck.C) {
	ec2Server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer ec2Server.Quit()
	s3Server, err := s3test.NewServer(nil)
	c.Assert(err, gocheck.IsNil)
	defer s3Server.Quit()
	h := bootstrapInstanceIdHealer{}
	region := aws.SAEast
	region.EC2Endpoint = ec2Server.URL()
	region.S3Endpoint = s3Server.URL()
	h.e = ec2.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	sg, err := h.ec2().CreateSecurityGroup("juju-delta-0", "")
	c.Assert(err, gocheck.IsNil)
	h.s = s3.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	jujuBucket := "ble"
	config.Set("juju:bucket", jujuBucket)
	bucket := h.s3().Bucket(jujuBucket)
	err = bucket.PutBucket(s3.PublicReadWrite)
	c.Assert(err, gocheck.IsNil)
	resp, err := h.ec2().RunInstances(&ec2.RunInstances{MaxCount: 1, SecurityGroups: []ec2.SecurityGroup{sg.SecurityGroup}})
	c.Assert(err, gocheck.IsNil)
	err = bucket.Put("provider-state", []byte("doesnotexist"), "binary/octet-stream", s3.PublicReadWrite)
	c.Assert(err, gocheck.IsNil)
	c.Assert(h.needsHeal(), gocheck.Equals, true)
	err = h.Heal()
	c.Assert(err, gocheck.IsNil)
	data, err := bucket.Get("provider-state")
	expected := "zookeeper-instances: [" + resp.Instances[0].InstanceId + "]"
	c.Assert(string(data), gocheck.Equals, expected)
}
开发者ID:kaiquewdev,项目名称:tsuru,代码行数:31,代码来源:healer_test.go

示例8: TestRegions

// Communicate with all EC2 endpoints to see if they are alive.
func (s *ClientTests) TestRegions(c *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, Matches, "InvalidGroup.NotFound")
			} else {
				c.Errorf("Non-EC2 error: %s", err)
			}
		} else {
			c.Errorf("Test should have errored but it seems to have succeeded")
		}
	}
}
开发者ID:nathanleclaire,项目名称:libswarm,代码行数:31,代码来源:ec2i_test.go

示例9: SetConfig

func (e *environ) SetConfig(cfg *config.Config) error {
	ecfg, err := providerInstance.newConfig(cfg)
	if err != nil {
		return err
	}
	e.ecfgMutex.Lock()
	defer e.ecfgMutex.Unlock()
	e.ecfgUnlocked = ecfg

	auth := aws.Auth{ecfg.accessKey(), ecfg.secretKey()}
	region := aws.Regions[ecfg.region()]
	publicBucketRegion := aws.Regions[ecfg.publicBucketRegion()]
	e.ec2Unlocked = ec2.New(auth, region)
	e.s3Unlocked = s3.New(auth, region)

	// create new storage instances, existing instances continue
	// to reference their existing configuration.
	e.storageUnlocked = &storage{
		bucket: e.s3Unlocked.Bucket(ecfg.controlBucket()),
	}
	if ecfg.publicBucket() != "" {
		e.publicStorageUnlocked = &storage{
			bucket: s3.New(auth, publicBucketRegion).Bucket(ecfg.publicBucket()),
		}
	} else {
		e.publicStorageUnlocked = nil
	}
	return nil
}
开发者ID:CSRedRat,项目名称:juju-core,代码行数:29,代码来源:ec2.go

示例10: awsInit

func awsInit(config *ec2Config) (ec2Conn *ec2.EC2, err error) {
	auth, err := aws.EnvAuth()

	if err != nil {
		return nil, err
	}

	return ec2.New(auth, config.region), nil
}
开发者ID:nathanleclaire,项目名称:libswarm,代码行数:9,代码来源:ec2.go

示例11: createEC2Handler

func createEC2Handler(region aws.Region) (*ec2.EC2, error) {
	keyId, err := config.GetString("iaas:ec2:key-id")
	if err != nil {
		return nil, err
	}
	secretKey, err := config.GetString("iaas:ec2:secret-key")
	if err != nil {
		return nil, err
	}
	auth := aws.Auth{AccessKey: keyId, SecretKey: secretKey}
	return ec2.New(auth, region), nil
}
开发者ID:tomzhang,项目名称:golang-devops-stuff,代码行数:12,代码来源:iaas.go

示例12: TestSignatureWithEndpointPath

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="})
}
开发者ID:realestate-com-au,项目名称:goamz-launchpad,代码行数:15,代码来源:ec2_test.go

示例13: TestGetPrivateDns

func (s *S) TestGetPrivateDns(c *gocheck.C) {
	server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer server.Quit()
	h := instanceAgentsConfigHealer{}
	region := aws.SAEast
	region.EC2Endpoint = server.URL()
	h.e = ec2.New(aws.Auth{AccessKey: "some", SecretKey: "thing"}, region)
	resp, err := h.ec2().RunInstances(&ec2.RunInstances{MaxCount: 1})
	c.Assert(err, gocheck.IsNil)
	instance := resp.Instances[0]
	dns, err := h.getPrivateDns(instance.InstanceId)
	c.Assert(err, gocheck.IsNil)
	c.Assert(dns, gocheck.Equals, instance.PrivateDNSName)
}
开发者ID:kaiquewdev,项目名称:tsuru,代码行数:15,代码来源:healer_test.go

示例14: getEC2Endpoint

func getEC2Endpoint() *ec2.EC2 {
	access, err := config.GetString("aws:access-key-id")
	if err != nil {
		log.Fatal(err.Error())
	}
	secret, err := config.GetString("aws:secret-access-key")
	if err != nil {
		log.Fatal(err.Error())
	}
	endpoint, err := config.GetString("aws:ec2:endpoint")
	if err != nil {
		log.Fatal(err.Error())
	}
	auth := aws.Auth{AccessKey: access, SecretKey: secret}
	return ec2.New(auth, aws.Region{EC2Endpoint: endpoint})
}
开发者ID:rpeterson,项目名称:tsuru,代码行数:16,代码来源:healer.go

示例15: getEC2Instances

func getEC2Instances(config map[string]string) (instances Instances) {
	instances = make(Instances)

	if _, ok := config["access_key"]; !ok {
		log.Fatal("Missing access_key for ", config["name"], " AWS cloud")
	}

	if _, ok := config["secret_key"]; !ok {
		log.Fatal("Missing secret_key for ", config["name"], " AWS cloud")
	}

	if _, ok := config["region"]; !ok {
		config["region"] = "us-east-1"
	}

	auth := aws.Auth{AccessKey: config["access_key"], SecretKey: config["secret_key"]}

	e := ec2.New(auth, aws.Regions[config["region"]])
	resp, err := e.Instances(nil, nil)

	if err != nil {
		log.Println(err)
		return
	}

	for _, res := range resp.Reservations {
		for _, inst := range res.Instances {

			if inst.DNSName != "" {
				var tags []Tag

				for _, tag := range inst.Tags {
					tags = append(tags, Tag{tag.Key, tag.Value})
				}

				for _, sg := range inst.SecurityGroups {
					tags = append(tags, Tag{"Security group", sg.Name})
				}

				instances[inst.DNSName] = tags
			}
		}
	}

	return
}
开发者ID:rasata,项目名称:cloud-ssh,代码行数:46,代码来源:aws.go


注:本文中的launchpad/net/goamz/ec2.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。