當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ec2test.NewServer函數代碼示例

本文整理匯總了Golang中launchpad/net/goamz/ec2/ec2test.NewServer函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewServer函數的具體用法?Golang NewServer怎麽用?Golang NewServer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewServer函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: startServer

func (srv *localServer) startServer(c *gc.C) {
	var err error
	srv.ec2srv, err = ec2test.NewServer()
	if err != nil {
		c.Fatalf("cannot start ec2 test server: %v", err)
	}
	srv.s3srv, err = s3test.NewServer(srv.config)
	if err != nil {
		c.Fatalf("cannot start s3 test server: %v", err)
	}
	aws.Regions["test"] = aws.Region{
		Name:                 "test",
		EC2Endpoint:          srv.ec2srv.URL(),
		S3Endpoint:           srv.s3srv.URL(),
		S3LocationConstraint: true,
		Sign:                 aws.SignV2,
	}
	s3inst := s3.New(aws.Auth{}, aws.Regions["test"])
	storage := ec2.BucketStorage(s3inst.Bucket("juju-dist"))
	envtesting.UploadFakeTools(c, storage)
	srv.addSpice(c)

	zones := make([]amzec2.AvailabilityZoneInfo, 3)
	zones[0].Region = "test"
	zones[0].Name = "test-available"
	zones[0].State = "available"
	zones[1].Region = "test"
	zones[1].Name = "test-impaired"
	zones[1].State = "impaired"
	zones[2].Region = "test"
	zones[2].Name = "test-unavailable"
	zones[2].State = "unavailable"
	srv.ec2srv.SetAvailabilityZones(zones)
}
開發者ID:zhouqt,項目名稱:juju,代碼行數:34,代碼來源:local_test.go

示例3: 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

示例4: main

func main() {
	server, err := ec2test.NewServer()
	if err != nil {
		log.Fatalf("Failed to start server: %s.", err)
	}
	defer server.Quit()
	if *initialState != "" {
		var code int
		switch *initialState {
		case "pending":
			code = 0
		case "running":
			code = 16
		case "shutting-down":
			code = 32
		case "terminated":
			code = 48
		case "stopping":
			code = 64
		case "stopped":
			code = 80
		default:
			log.Fatalf("Invalid initial state: %q.\nSee http://goo.gl/y3ZBq for a list of valid states.", *initialState)
		}
		state := ec2.InstanceState{Code: code, Name: *initialState}
		server.SetInitialInstanceState(state)
	}
	fmt.Printf("Server is listening at %s.\nPress Ctrl-C to close it.\n", server.URL())
	for {
	}
}
開發者ID:fsouza,項目名稱:fakeaws,代碼行數:31,代碼來源:server.go

示例5: SetUp

func (s *LocalServer) SetUp(c *C) {
	srv, err := ec2test.NewServer()
	c.Assert(err, IsNil)
	c.Assert(srv, NotNil)

	s.srv = srv
	s.region = aws.Region{EC2Endpoint: srv.URL()}
}
開發者ID:realestate-com-au,項目名稱:goamz-launchpad,代碼行數:8,代碼來源:ec2t_test.go

示例6: SetUpSuite

func (s *S) SetUpSuite(c *gocheck.C) {
	var err error
	s.srv, err = ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	s.region = aws.Region{
		Name:        "myregion",
		EC2Endpoint: s.srv.URL(),
	}
	aws.Regions["myregion"] = s.region
	config.Set("iaas:ec2:key-id", "mykey")
	config.Set("iaas:ec2:secret-key", "mysecret")
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:12,代碼來源:iaas_test.go

示例7: SetUp

func (s *LocalServer) SetUp(c *C) {
	srv, err := ec2test.NewServer()
	c.Assert(err, IsNil)
	c.Assert(srv, NotNil)

	// Add default attributes.
	srv.SetInitialAttributes(map[string][]string{
		"supported-platforms": []string{"VPC", "EC2"},
		"default-vpc":         []string{"vpc-xxxxxxx"},
	})

	s.srv = srv
	s.region = aws.Region{EC2Endpoint: srv.URL()}
}
開發者ID:BillTheBest,項目名稱:libswarm,代碼行數:14,代碼來源:ec2t_test.go

示例8: 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

示例9: startServer

func (srv *localServer) startServer(c *C) {
	var err error
	srv.ec2srv, err = ec2test.NewServer()
	if err != nil {
		c.Fatalf("cannot start ec2 test server: %v", err)
	}
	srv.s3srv, err = s3test.NewServer(srv.config)
	if err != nil {
		c.Fatalf("cannot start s3 test server: %v", err)
	}
	aws.Regions["test"] = aws.Region{
		Name:                 "test",
		EC2Endpoint:          srv.ec2srv.URL(),
		S3Endpoint:           srv.s3srv.URL(),
		S3LocationConstraint: true,
	}
	s3inst := s3.New(aws.Auth{}, aws.Regions["test"])
	putFakeTools(c, ec2.BucketStorage(s3inst.Bucket("public-tools")))
	srv.addSpice(c)
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:20,代碼來源:local_test.go

示例10: TestBootstrapInstanceIdHealerNeedsHeal

func (s *S) TestBootstrapInstanceIdHealerNeedsHeal(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)
	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)
	err = bucket.Put("provider-state", []byte("doesnotexist"), "binary/octet-stream", s3.PublicReadWrite)
	c.Assert(err, gocheck.IsNil)
	c.Assert(h.needsHeal(), gocheck.Equals, true)
}
開發者ID:kaiquewdev,項目名稱:tsuru,代碼行數:22,代碼來源:healer_test.go

示例11: TestInstanceAgenstConfigHealerHeal

func (s *S) TestInstanceAgenstConfigHealerHeal(c *gocheck.C) {
	server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer server.Quit()
	id := server.NewInstances(1, "small", "ami-123", ec2.InstanceState{Code: 16, Name: "running"}, nil)[0]
	p := JujuProvisioner{}
	m := machine{
		AgentState:    "not-started",
		IpAddress:     "localhost",
		InstanceId:    id,
		InstanceState: "running",
	}
	p.saveBootstrapMachine(m)
	conn, collection := p.bootstrapCollection()
	defer conn.Close()
	defer collection.Remove(m)
	a := app.App{
		Name:  "as_i_rise",
		Units: []app.Unit{{Name: "as_i_rise/0", State: "down", Ip: "server-1081.novalocal"}},
	}
	err = s.conn.Apps().Insert(&a)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": "as_i_rise"})
	sshTmpdir, err := commandmocker.Error("ssh", "", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(sshTmpdir)
	h := instanceAgentsConfigHealer{}
	auth := aws.Auth{AccessKey: "access", SecretKey: "secret"}
	region := aws.SAEast
	region.EC2Endpoint = server.URL()
	h.e = ec2.New(auth, region)
	err = h.Heal()
	c.Assert(err, gocheck.IsNil)
	sshOutput := []string{
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"grep",
		"",
		"/etc/init/juju-machine-agent.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"sudo",
		"sed",
		"-i",
		"'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\":2181\"/g'",
		"/etc/init/juju-machine-agent.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"grep",
		"",
		"/etc/init/juju-as_i_rise-0.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"sudo",
		"sed",
		"-i",
		"'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\":2181\"/g'",
		"/etc/init/juju-as_i_rise-0.conf",
	}
	c.Assert(commandmocker.Ran(sshTmpdir), gocheck.Equals, true)
	c.Assert(commandmocker.Parameters(sshTmpdir), gocheck.DeepEquals, sshOutput)
}
開發者ID:kaiquewdev,項目名稱:tsuru,代碼行數:78,代碼來源:healer_test.go


注:本文中的launchpad/net/goamz/ec2/ec2test.NewServer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。