• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang tools.RandomString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createBackup

func (c *context) createBackup() {
	opts := backups.CreateOpts{
		Name:       tools.RandomString("backup_", 5),
		InstanceID: c.instanceID,
	}

	backup, err := backups.Create(c.client, opts).Extract()

	c.Logf("Created backup %#v", backup)
	c.AssertNoErr(err)

	err = gophercloud.WaitFor(60, func() (bool, error) {
		b, err := backups.Get(c.client, backup.ID).Extract()
		if err != nil {
			return false, err
		}
		if b.Status == "COMPLETED" {
			return true, nil
		}
		return false, nil
	})
	c.AssertNoErr(err)

	c.backupID = backup.ID
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:backup_test.go


示例2: createNetworkServer

func createNetworkServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices, networkID string) (*servers.Server, error) {
	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	name := tools.RandomString("ACPTTEST", 16)
	t.Logf("Attempting to create server: %s\n", name)

	pwd := tools.MakeNewPassword("")

	networks := make([]servers.Network, 1)
	networks[0] = servers.Network{
		UUID: networkID,
	}

	server, err := servers.Create(client, servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
		AdminPass: pwd,
		Networks:  networks,
	}).Extract()
	if err != nil {
		t.Fatalf("Unable to create server: %v", err)
	}

	th.AssertEquals(t, pwd, server.AdminPass)

	return server, err
}
开发者ID:RomainVabre,项目名称:origin,代码行数:30,代码来源:tenantnetworks_test.go


示例3: TestBootFromVolume

func TestBootFromVolume(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	options, err := optionsFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)
	t.Logf("Creating server [%s].", name)

	bd := []osBFV.BlockDevice{
		osBFV.BlockDevice{
			UUID:       options.imageID,
			SourceType: osBFV.Image,
			VolumeSize: 10,
		},
	}

	server, err := bootfromvolume.Create(client, servers.CreateOpts{
		Name:        name,
		FlavorRef:   "performance1-1",
		BlockDevice: bd,
	}).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created server: %+v\n", server)
	defer deleteServer(t, client, server)

	getServer(t, client, server)

	listServers(t, client)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:35,代码来源:bootfromvolume_test.go


示例4: createServer

func createServer(t *testing.T, client *gophercloud.ServiceClient, keyName string) *os.Server {
	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	options, err := optionsFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)

	opts := &servers.CreateOpts{
		Name:       name,
		ImageRef:   options.imageID,
		FlavorRef:  options.flavorID,
		DiskConfig: diskconfig.Manual,
	}

	if keyName != "" {
		opts.KeyPair = keyName
	}

	t.Logf("Creating server [%s].", name)
	s, err := servers.Create(client, opts).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Creating server.")

	err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300)
	th.AssertNoErr(t, err)
	t.Logf("Server created successfully.")

	return s
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:32,代码来源:servers_test.go


示例5: updateUser

func (c *context) updateUser() {
	opts := users.UpdateOpts{Name: tools.RandomString("new_name_", 5)}
	err := users.Update(c.client, c.instanceID, c.users[0], opts).ExtractErr()
	c.Logf("Updated user %s", c.users[0])
	c.AssertNoErr(err)
	c.users[0] = opts.Name
}
开发者ID:RomainVabre,项目名称:origin,代码行数:7,代码来源:user_test.go


示例6: createLB

func createLB(t *testing.T, client *gophercloud.ServiceClient, count int) []int {
	ids := []int{}

	for i := 0; i < count; i++ {
		opts := lbs.CreateOpts{
			Name:     tools.RandomString("test_", 5),
			Port:     80,
			Protocol: "HTTP",
			VIPs: []vips.VIP{
				vips.VIP{Type: vips.PUBLIC},
			},
		}

		lb, err := lbs.Create(client, opts).Extract()
		th.AssertNoErr(t, err)

		t.Logf("Created LB %d - waiting for it to build...", lb.ID)
		waitForLB(client, lb.ID, lbs.ACTIVE)
		t.Logf("LB %d has reached ACTIVE state", lb.ID)

		ids = append(ids, lb.ID)
	}

	return ids
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:lb_test.go


示例7: createServerInGroup

func createServerInGroup(t *testing.T, computeClient *gophercloud.ServiceClient, choices *ComputeChoices, serverGroup *servergroups.ServerGroup) (*servers.Server, error) {
	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	name := tools.RandomString("ACPTTEST", 16)
	t.Logf("Attempting to create server: %s\n", name)

	pwd := tools.MakeNewPassword("")

	serverCreateOpts := servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
		AdminPass: pwd,
	}
	server, err := servers.Create(computeClient, schedulerhints.CreateOptsExt{
		serverCreateOpts,
		schedulerhints.SchedulerHints{
			Group: serverGroup.ID,
		},
	}).Extract()
	if err != nil {
		t.Fatalf("Unable to create server: %v", err)
	}

	th.AssertEquals(t, pwd, server.AdminPass)

	return server, err
}
开发者ID:RomainVabre,项目名称:origin,代码行数:30,代码来源:servergroup_test.go


示例8: createTestImage

func createTestImage(t *testing.T, client *gophercloud.ServiceClient) images.Image {
	//creating image
	imageName := tools.RandomString("ACCPT", 16)
	containerFormat := "ami"
	createResult := images.Create(client, images.CreateOpts{Name: imageName,
		ContainerFormat: containerFormat,
		DiskFormat:      containerFormat})
	th.AssertNoErr(t, createResult.Err)
	image, err := createResult.Extract()
	th.AssertNoErr(t, err)
	t.Logf("Image %v", image)

	//checking status
	image, err = images.Get(client, image.ID).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, image.Status, images.ImageStatusQueued)

	//uploading image data
	data := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
	uploadResult := images.Upload(client, image.ID, bytes.NewReader(data))
	th.AssertNoErr(t, uploadResult.Err)

	//checking status
	image, err = images.Get(client, image.ID).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, image.Status, images.ImageStatusActive)
	th.AssertEquals(t, image.SizeBytes, 9)
	return *image
}
开发者ID:rackspace,项目名称:gophercloud,代码行数:29,代码来源:common.go


示例9: TestMultiEphemeral

func TestMultiEphemeral(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	choices, err := ComputeChoicesFromEnv()
	if err != nil {
		t.Fatal(err)
	}

	name := tools.RandomString("Gophercloud-", 8)
	t.Logf("Creating server [%s].", name)

	bd := []bootfromvolume.BlockDevice{
		bootfromvolume.BlockDevice{
			BootIndex:           0,
			UUID:                choices.ImageID,
			SourceType:          bootfromvolume.Image,
			DestinationType:     "local",
			DeleteOnTermination: true,
		},
		bootfromvolume.BlockDevice{
			BootIndex:           -1,
			SourceType:          bootfromvolume.Blank,
			DestinationType:     "local",
			DeleteOnTermination: true,
			GuestFormat:         "ext4",
			VolumeSize:          1,
		},
		bootfromvolume.BlockDevice{
			BootIndex:           -1,
			SourceType:          bootfromvolume.Blank,
			DestinationType:     "local",
			DeleteOnTermination: true,
			GuestFormat:         "ext4",
			VolumeSize:          1,
		},
	}

	serverCreateOpts := servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
	}
	server, err := bootfromvolume.Create(client, bootfromvolume.CreateOptsExt{
		serverCreateOpts,
		bd,
	}).Extract()
	th.AssertNoErr(t, err)
	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatal(err)
	}

	t.Logf("Created server: %+v\n", server)
	defer servers.Delete(client, server.ID)
	t.Logf("Deleting server [%s]...", name)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:60,代码来源:bootfromvolume_test.go


示例10: TestSecGroups

func TestSecGroups(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	serverID, needsDeletion := findServer(t, client)

	groupID := createSecGroup(t, client)

	listSecGroups(t, client)

	newName := tools.RandomString("secgroup_", 5)
	updateSecGroup(t, client, groupID, newName)

	getSecGroup(t, client, groupID)

	addRemoveRules(t, client, groupID)

	addServerToSecGroup(t, client, serverID, newName)

	removeServerFromSecGroup(t, client, serverID, newName)

	if needsDeletion {
		servers.Delete(client, serverID)
	}

	deleteSecGroup(t, client, groupID)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:secgroup_test.go


示例11: TestUpdateServer

func TestUpdateServer(t *testing.T) {
	client, err := newClient()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	choices, err := ComputeChoicesFromEnv()
	if err != nil {
		t.Fatal(err)
	}

	server, err := createServer(t, client, choices)
	if err != nil {
		t.Fatal(err)
	}
	defer servers.Delete(client, server.ID)

	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatal(err)
	}

	alternateName := tools.RandomString("ACPTTEST", 16)
	for alternateName == server.Name {
		alternateName = tools.RandomString("ACPTTEST", 16)
	}

	t.Logf("Attempting to rename the server to %s.", alternateName)

	updated, err := servers.Update(client, server.ID, servers.UpdateOpts{Name: alternateName}).Extract()
	if err != nil {
		t.Fatalf("Unable to rename server: %v", err)
	}

	if updated.ID != server.ID {
		t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID)
	}

	err = tools.WaitFor(func() (bool, error) {
		latest, err := servers.Get(client, updated.ID).Extract()
		if err != nil {
			return false, err
		}

		return latest.Name == alternateName, nil
	})
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:46,代码来源:servers_test.go


示例12: createDBs

func (c *context) createDBs() {
	dbs := []string{
		tools.RandomString("db_", 5),
		tools.RandomString("db_", 5),
		tools.RandomString("db_", 5),
	}

	opts := db.BatchCreateOpts{
		db.CreateOpts{Name: dbs[0]},
		db.CreateOpts{Name: dbs[1]},
		db.CreateOpts{Name: dbs[2]},
	}

	err := db.Create(c.client, c.instanceID, opts).ExtractErr()
	c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
	c.AssertNoErr(err)

	c.DBIDs = dbs
}
开发者ID:RomainVabre,项目名称:origin,代码行数:19,代码来源:database_test.go


示例13: updateSecGroup

func updateSecGroup(t *testing.T, client *gophercloud.ServiceClient, id, newName string) {
	opts := secgroups.UpdateOpts{
		Name:        newName,
		Description: tools.RandomString("dec_", 10),
	}
	group, err := secgroups.Update(client, id, opts).Extract()
	th.AssertNoErr(t, err)

	t.Logf("Updated %s's name to %s", group.ID, group.Name)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:10,代码来源:secgroup_test.go


示例14: createServer

func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) {
	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	var network networks.Network

	networkingClient, err := networkingClient()
	if err != nil {
		t.Fatalf("Unable to create a networking client: %v", err)
	}

	pager := networks.List(networkingClient, networks.ListOpts{
		Name:  choices.NetworkName,
		Limit: 1,
	})
	pager.EachPage(func(page pagination.Page) (bool, error) {
		networks, err := networks.ExtractNetworks(page)
		if err != nil {
			t.Errorf("Failed to extract networks: %v", err)
			return false, err
		}

		if len(networks) == 0 {
			t.Fatalf("No networks to attach to server")
			return false, err
		}

		network = networks[0]

		return false, nil
	})

	name := tools.RandomString("ACPTTEST", 16)
	t.Logf("Attempting to create server: %s\n", name)

	pwd := tools.MakeNewPassword("")

	server, err := servers.Create(client, servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
		Networks: []servers.Network{
			servers.Network{UUID: network.ID},
		},
		AdminPass: pwd,
	}).Extract()
	if err != nil {
		t.Fatalf("Unable to create server: %v", err)
	}

	th.AssertEquals(t, pwd, server.AdminPass)

	return server, err
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:55,代码来源:servers_test.go


示例15: TestCreateServerWithKeyPair

func TestCreateServerWithKeyPair(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
	publicKey := privateKey.PublicKey
	pub, err := ssh.NewPublicKey(&publicKey)
	th.AssertNoErr(t, err)
	pubBytes := ssh.MarshalAuthorizedKey(pub)
	pk := string(pubBytes)

	kp, err := keypairs.Create(client, keypairs.CreateOpts{
		Name:      keyName,
		PublicKey: pk,
	}).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created key pair: %s\n", kp)

	choices, err := ComputeChoicesFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)
	t.Logf("Creating server [%s] with key pair.", name)

	serverCreateOpts := servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
	}

	server, err := servers.Create(client, keypairs.CreateOptsExt{
		serverCreateOpts,
		keyName,
	}).Extract()
	th.AssertNoErr(t, err)
	defer servers.Delete(client, server.ID)
	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatalf("Unable to wait for server: %v", err)
	}

	server, err = servers.Get(client, server.ID).Extract()
	t.Logf("Created server: %+v\n", server)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, server.KeyName, keyName)

	t.Logf("Deleting key pair [%s]...", kp.Name)
	err = keypairs.Delete(client, keyName).ExtractErr()
	th.AssertNoErr(t, err)

	t.Logf("Deleting server [%s]...", name)
}
开发者ID:cdosso,项目名称:machine,代码行数:55,代码来源:keypairs_test.go


示例16: changeUserPwd

func (c *context) changeUserPwd() {
	opts := os.BatchCreateOpts{}

	for _, name := range c.users[:1] {
		opts = append(opts, os.CreateOpts{Name: name, Password: tools.RandomString("", 5)})
	}

	err := users.ChangePassword(c.client, c.instanceID, opts).ExtractErr()
	c.Logf("Updated 2 users' passwords")
	c.AssertNoErr(err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:user_test.go


示例17: updateConfigGrp

func (c *context) updateConfigGrp() {
	opts := os.UpdateOpts{
		Name: tools.RandomString("new_name_", 5),
		Values: map[string]interface{}{
			"connect_timeout": 250,
		},
	}
	err := config.Update(c.client, c.configGroupID, opts).ExtractErr()
	c.Logf("Updated config group %s", c.configGroupID)
	c.AssertNoErr(err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:config_group_test.go


示例18: createServerKeyPair

func createServerKeyPair(t *testing.T, client *gophercloud.ServiceClient) *oskey.KeyPair {
	name := tools.RandomString("importedkey-", 8)
	pubkey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlIQ3r+zd97kb9Hzmujd3V6pbO53eb3Go4q2E8iqVGWQfZTrFdL9KACJnqJIm9HmncfRkUTxE37hqeGCCv8uD+ZPmPiZG2E60OX1mGDjbbzAyReRwYWXgXHopggZTLak5k4mwZYaxwaufbVBDRn847e01lZnaXaszEToLM37NLw+uz29sl3TwYy2R0RGHPwPc160aWmdLjSyd1Nd4c9pvvOP/EoEuBjIC6NJJwg2Rvg9sjjx9jYj0QUgc8CqKLN25oMZ69kNJzlFylKRUoeeVr89txlR59yehJWk6Uw6lYFTdJmcmQOFVAJ12RMmS1hLWCM8UzAgtw+EDa0eqBxBDl [email protected]"

	k, err := keypairs.Create(client, oskey.CreateOpts{
		Name:      name,
		PublicKey: pubkey,
	}).Extract()
	th.AssertNoErr(t, err)

	return k
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:12,代码来源:servers_test.go


示例19: createUsers

func (c *context) createUsers() {
	c.users = []string{
		tools.RandomString("user_", 5),
		tools.RandomString("user_", 5),
		tools.RandomString("user_", 5),
	}

	db1 := db.CreateOpts{Name: c.DBIDs[0]}
	db2 := db.CreateOpts{Name: c.DBIDs[1]}
	db3 := db.CreateOpts{Name: c.DBIDs[2]}

	opts := os.BatchCreateOpts{
		os.CreateOpts{
			Name:      c.users[0],
			Password:  tools.RandomString("db_", 5),
			Databases: db.BatchCreateOpts{db1, db2, db3},
		},
		os.CreateOpts{
			Name:      c.users[1],
			Password:  tools.RandomString("db_", 5),
			Databases: db.BatchCreateOpts{db1, db2},
		},
		os.CreateOpts{
			Name:      c.users[2],
			Password:  tools.RandomString("db_", 5),
			Databases: db.BatchCreateOpts{db3},
		},
	}

	err := users.Create(c.client, c.instanceID, opts).ExtractErr()
	c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, c.users[0], c.users[1], c.users[2])
	c.AssertNoErr(err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:user_test.go


示例20: createUsers

func (c context) createUsers() {
	users := []string{
		tools.RandomString("user_", 5),
		tools.RandomString("user_", 5),
		tools.RandomString("user_", 5),
	}

	db1 := db.CreateOpts{Name: "db1"}
	db2 := db.CreateOpts{Name: "db2"}
	db3 := db.CreateOpts{Name: "db3"}

	opts := u.BatchCreateOpts{
		u.CreateOpts{
			Name:      users[0],
			Password:  tools.RandomString("", 5),
			Databases: db.BatchCreateOpts{db1, db2, db3},
		},
		u.CreateOpts{
			Name:      users[1],
			Password:  tools.RandomString("", 5),
			Databases: db.BatchCreateOpts{db1, db2},
		},
		u.CreateOpts{
			Name:      users[2],
			Password:  tools.RandomString("", 5),
			Databases: db.BatchCreateOpts{db3},
		},
	}

	err := u.Create(c.client, c.instanceID, opts).ExtractErr()
	c.AssertNoErr(err)
	c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2])
	c.users = users
}
开发者ID:RomainVabre,项目名称:origin,代码行数:34,代码来源:user_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang openstack.AuthOptionsFromEnv函数代码示例发布时间:2022-05-28
下一篇:
Golang gophercloud.ServiceClient类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap