本文整理汇总了Golang中github.com/gophercloud/gophercloud/acceptance/tools.RandomString函数的典型用法代码示例。如果您正苦于以下问题:Golang RandomString函数的具体用法?Golang RandomString怎么用?Golang RandomString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandomString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CreateSnapshot
// CreateSnapshot will create a volume snapshot based off of a given volume and
// with a random name. An error will be returned if the snapshot failed to be
// created.
func CreateSnapshot(t *testing.T, client *gophercloud.ServiceClient, volume *volumes.Volume) (*snapshots.Snapshot, error) {
if testing.Short() {
t.Skip("Skipping test that requires snapshot creation in short mode.")
}
snapshotName := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create snapshot %s based on volume %s", snapshotName, volume.ID)
createOpts := snapshots.CreateOpts{
Name: snapshotName,
VolumeID: volume.ID,
}
snapshot, err := snapshots.Create(client, createOpts).Extract()
if err != nil {
return snapshot, err
}
err = snapshots.WaitForStatus(client, snapshot.ID, "available", 60)
if err != nil {
return snapshot, err
}
return snapshot, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:blockstorage.go
示例2: CreateRouter
// CreateRouter creates a router on a specified Network ID. An error will be
// returned if the creation failed.
func CreateRouter(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*routers.Router, error) {
routerName := tools.RandomString("TESTACC-", 8)
t.Logf("Attempting to create router: %s", routerName)
adminStateUp := true
gatewayInfo := routers.GatewayInfo{
NetworkID: networkID,
}
createOpts := routers.CreateOpts{
Name: routerName,
AdminStateUp: &adminStateUp,
GatewayInfo: &gatewayInfo,
}
router, err := routers.Create(client, createOpts).Extract()
if err != nil {
return router, err
}
if err := WaitForRouterToCreate(client, router.ID, 60); err != nil {
return router, err
}
t.Logf("Created router: %s", routerName)
return router, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:31,代码来源:layer3.go
示例3: CreateMonitor
// CreateMonitor will create a monitor with a random name for a specific pool.
// An error will be returned if the monitor could not be created.
func CreateMonitor(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool) (*monitors.Monitor, error) {
monitorName := tools.RandomString("TESTACCT-", 8)
t.Logf("Attempting to create monitor %s", monitorName)
createOpts := monitors.CreateOpts{
PoolID: pool.ID,
Name: monitorName,
Delay: 10,
Timeout: 5,
MaxRetries: 5,
Type: "PING",
}
monitor, err := monitors.Create(client, createOpts).Extract()
if err != nil {
return monitor, err
}
t.Logf("Successfully created monitor: %s", monitorName)
if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
return monitor, fmt.Errorf("Timed out waiting for loadbalancer to become active")
}
return monitor, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:lbaas_v2.go
示例4: CreatePortsbinding
// CreatePortsbinding will create a port on the specified subnet. An error will be
// returned if the port could not be created.
func CreatePortsbinding(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID, hostID string) (*portsbinding.Port, error) {
portName := tools.RandomString("TESTACC-", 8)
iFalse := false
t.Logf("Attempting to create port: %s", portName)
createOpts := portsbinding.CreateOpts{
CreateOptsBuilder: ports.CreateOpts{
NetworkID: networkID,
Name: portName,
AdminStateUp: &iFalse,
FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}},
},
HostID: hostID,
}
port, err := portsbinding.Create(client, createOpts).Extract()
if err != nil {
return port, err
}
t.Logf("Successfully created port: %s", portName)
return port, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:portsbinding.go
示例5: CreateListener
// CreateListener will create a listener for a given load balancer on a random
// port with a random name. An error will be returned if the listener could not
// be created.
func CreateListener(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*listeners.Listener, error) {
listenerName := tools.RandomString("TESTACCT-", 8)
listenerPort := tools.RandomInt(1, 100)
t.Logf("Attempting to create listener %s on port %d", listenerName, listenerPort)
createOpts := listeners.CreateOpts{
Name: listenerName,
LoadbalancerID: lb.ID,
Protocol: "TCP",
ProtocolPort: listenerPort,
}
listener, err := listeners.Create(client, createOpts).Extract()
if err != nil {
return listener, err
}
t.Logf("Successfully created listener %s", listenerName)
if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
return listener, fmt.Errorf("Timed out waiting for loadbalancer to become active")
}
return listener, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:lbaas_v2.go
示例6: TestNetworksCRUD
func TestNetworksCRUD(t *testing.T) {
client, err := clients.NewNetworkV2Client()
if err != nil {
t.Fatalf("Unable to create a network client: %v", err)
}
// Create a network
network, err := CreateNetwork(t, client)
if err != nil {
t.Fatalf("Unable to create network: %v", err)
}
defer DeleteNetwork(t, client, network.ID)
PrintNetwork(t, network)
newName := tools.RandomString("TESTACC-", 8)
updateOpts := &networks.UpdateOpts{
Name: newName,
}
_, err = networks.Update(client, network.ID, updateOpts).Extract()
if err != nil {
t.Fatalf("Unable to update network: %v", err)
}
newNetwork, err := networks.Get(client, network.ID).Extract()
if err != nil {
t.Fatalf("Unable to retrieve network: %v", err)
}
PrintNetwork(t, newNetwork)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:32,代码来源:networks_test.go
示例7: CreateExternalRouter
// CreateExternalRouter creates a router on the external network. This requires
// the OS_EXTGW_ID environment variable to be set. An error is returned if the
// creation failed.
func CreateExternalRouter(t *testing.T, client *gophercloud.ServiceClient) (*routers.Router, error) {
var router *routers.Router
choices, err := clients.AcceptanceTestChoicesFromEnv()
if err != nil {
return router, err
}
routerName := tools.RandomString("TESTACC-", 8)
t.Logf("Attempting to create external router: %s", routerName)
adminStateUp := true
gatewayInfo := routers.GatewayInfo{
NetworkID: choices.ExternalNetworkID,
}
createOpts := routers.CreateOpts{
Name: routerName,
AdminStateUp: &adminStateUp,
GatewayInfo: &gatewayInfo,
}
router, err = routers.Create(client, createOpts).Extract()
if err != nil {
return router, err
}
if err := WaitForRouterToCreate(client, router.ID, 60); err != nil {
return router, err
}
t.Logf("Created router: %s", routerName)
return router, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:38,代码来源:layer3.go
示例8: CreatePool
// CreatePool will create a pool with a random name with a specified listener
// and loadbalancer. An error will be returned if the pool could not be
// created.
func CreatePool(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer) (*pools.Pool, error) {
poolName := tools.RandomString("TESTACCT-", 8)
t.Logf("Attempting to create pool %s", poolName)
createOpts := pools.CreateOpts{
Name: poolName,
Protocol: pools.ProtocolTCP,
LoadbalancerID: lb.ID,
LBMethod: pools.LBMethodLeastConnections,
}
pool, err := pools.Create(client, createOpts).Extract()
if err != nil {
return pool, err
}
t.Logf("Successfully created pool %s", poolName)
if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
return pool, fmt.Errorf("Timed out waiting for loadbalancer to become active")
}
return pool, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:lbaas_v2.go
示例9: CreateVolumeFromImage
// CreateVolumeFromImage will create a volume from with a random name and size of
// 1GB. An error will be returned if the volume was unable to be created.
func CreateVolumeFromImage(t *testing.T, client *gophercloud.ServiceClient, choices *clients.AcceptanceTestChoices) (*volumes.Volume, error) {
if testing.Short() {
t.Skip("Skipping test that requires volume creation in short mode.")
}
volumeName := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create volume: %s", volumeName)
createOpts := volumes.CreateOpts{
Size: 1,
Name: volumeName,
ImageID: choices.ImageID,
}
volume, err := volumes.Create(client, createOpts).Extract()
if err != nil {
return volume, err
}
err = volumes.WaitForStatus(client, volume.ID, "available", 60)
if err != nil {
return volume, err
}
return volume, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:28,代码来源:blockstorage.go
示例10: CreatePort
// CreatePort will create a port on the specified subnet. An error will be
// returned if the port could not be created.
func CreatePort(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID string) (*ports.Port, error) {
portName := tools.RandomString("TESTACC-", 8)
t.Logf("Attempting to create port: %s", portName)
createOpts := ports.CreateOpts{
NetworkID: networkID,
Name: portName,
AdminStateUp: gophercloud.Enabled,
FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}},
}
port, err := ports.Create(client, createOpts).Extract()
if err != nil {
return port, err
}
if err := WaitForPortToCreate(client, port.ID, 60); err != nil {
return port, err
}
newPort, err := ports.Get(client, port.ID).Extract()
if err != nil {
return newPort, err
}
t.Logf("Successfully created port: %s", portName)
return newPort, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:32,代码来源:networking.go
示例11: CreateRule
// CreateRule will create a Firewall Rule with a random source address and
//source port, destination address and port. An error will be returned if
// the rule could not be created.
func CreateRule(t *testing.T, client *gophercloud.ServiceClient) (*rules.Rule, error) {
ruleName := tools.RandomString("TESTACC-", 8)
sourceAddress := fmt.Sprintf("192.168.1.%d", tools.RandomInt(1, 100))
sourcePort := strconv.Itoa(tools.RandomInt(1, 100))
destinationAddress := fmt.Sprintf("192.168.2.%d", tools.RandomInt(1, 100))
destinationPort := strconv.Itoa(tools.RandomInt(1, 100))
t.Logf("Attempting to create rule %s with source %s:%s and destination %s:%s",
ruleName, sourceAddress, sourcePort, destinationAddress, destinationPort)
createOpts := rules.CreateOpts{
Name: ruleName,
Protocol: rules.ProtocolTCP,
Action: "allow",
SourceIPAddress: sourceAddress,
SourcePort: sourcePort,
DestinationIPAddress: destinationAddress,
DestinationPort: destinationPort,
}
rule, err := rules.Create(client, createOpts).Extract()
if err != nil {
return rule, err
}
t.Logf("Rule %s successfully created", ruleName)
return rule, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:32,代码来源:fwaas.go
示例12: CreateSubnetWithNoGateway
// CreateSubnetWithNoGateway will create a subnet with no gateway on the
// specified Network ID. An error will be returned if the subnet could not be
// created.
func CreateSubnetWithNoGateway(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*subnets.Subnet, error) {
var noGateway = ""
subnetName := tools.RandomString("TESTACC-", 8)
subnetOctet := tools.RandomInt(1, 250)
subnetCIDR := fmt.Sprintf("192.168.%d.0/24", subnetOctet)
dhcpStart := fmt.Sprintf("192.168.%d.10", subnetOctet)
dhcpEnd := fmt.Sprintf("192.168.%d.200", subnetOctet)
createOpts := subnets.CreateOpts{
NetworkID: networkID,
CIDR: subnetCIDR,
IPVersion: 4,
Name: subnetName,
EnableDHCP: gophercloud.Disabled,
GatewayIP: &noGateway,
AllocationPools: []subnets.AllocationPool{
{
Start: dhcpStart,
End: dhcpEnd,
},
},
}
t.Logf("Attempting to create subnet: %s", subnetName)
subnet, err := subnets.Create(client, createOpts).Extract()
if err != nil {
return subnet, err
}
t.Logf("Successfully created subnet.")
return subnet, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:35,代码来源:networking.go
示例13: CreateShareType
// CreateShareType will create a share type with a random name. An
// error will be returned if the share type was unable to be created.
func CreateShareType(t *testing.T, client *gophercloud.ServiceClient) (*sharetypes.ShareType, error) {
if testing.Short() {
t.Skip("Skipping test that requires share type creation in short mode.")
}
shareTypeName := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create share type: %s", shareTypeName)
extraSpecsOps := sharetypes.ExtraSpecsOpts{
DriverHandlesShareServers: true,
}
createOpts := sharetypes.CreateOpts{
Name: shareTypeName,
IsPublic: true,
ExtraSpecs: extraSpecsOps,
}
shareType, err := sharetypes.Create(client, createOpts).Extract()
if err != nil {
return shareType, err
}
return shareType, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:27,代码来源:sharetypes.go
示例14: TestLayer3RouterCreateDelete
func TestLayer3RouterCreateDelete(t *testing.T) {
client, err := clients.NewNetworkV2Client()
if err != nil {
t.Fatalf("Unable to create a network client: %v", err)
}
router, err := CreateExternalRouter(t, client)
if err != nil {
t.Fatalf("Unable to create router: %v", err)
}
defer DeleteRouter(t, client, router.ID)
PrintRouter(t, router)
newName := tools.RandomString("TESTACC-", 8)
updateOpts := routers.UpdateOpts{
Name: newName,
}
_, err = routers.Update(client, router.ID, updateOpts).Extract()
if err != nil {
t.Fatalf("Unable to update router: %v", err)
}
newRouter, err := routers.Get(client, router.ID).Extract()
if err != nil {
t.Fatalf("Unable to get router: %v", err)
}
PrintRouter(t, newRouter)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:31,代码来源:routers_test.go
示例15: CreateMember
// CreateMember will create a member with a random name, port, address, and
// weight. An error will be returned if the member could not be created.
func CreateMember(t *testing.T, client *gophercloud.ServiceClient, lb *loadbalancers.LoadBalancer, pool *pools.Pool, subnetID, subnetCIDR string) (*pools.Member, error) {
memberName := tools.RandomString("TESTACCT-", 8)
memberPort := tools.RandomInt(100, 1000)
memberWeight := tools.RandomInt(1, 10)
cidrParts := strings.Split(subnetCIDR, "/")
subnetParts := strings.Split(cidrParts[0], ".")
memberAddress := fmt.Sprintf("%s.%s.%s.%d", subnetParts[0], subnetParts[1], subnetParts[2], tools.RandomInt(10, 100))
t.Logf("Attempting to create member %s", memberName)
createOpts := pools.CreateMemberOpts{
Name: memberName,
ProtocolPort: memberPort,
Weight: memberWeight,
Address: memberAddress,
SubnetID: subnetID,
}
t.Logf("Member create opts: %#v", createOpts)
member, err := pools.CreateMember(client, pool.ID, createOpts).Extract()
if err != nil {
return member, err
}
t.Logf("Successfully created member %s", memberName)
if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
return member, fmt.Errorf("Timed out waiting for loadbalancer to become active")
}
return member, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:36,代码来源:lbaas_v2.go
示例16: CreateLoadBalancer
// CreateLoadBalancer will create a load balancer with a random name on a given
// subnet. An error will be returned if the loadbalancer could not be created.
func CreateLoadBalancer(t *testing.T, client *gophercloud.ServiceClient, subnetID string) (*loadbalancers.LoadBalancer, error) {
lbName := tools.RandomString("TESTACCT-", 8)
t.Logf("Attempting to create loadbalancer %s on subnet %s", lbName, subnetID)
createOpts := loadbalancers.CreateOpts{
Name: lbName,
VipSubnetID: subnetID,
AdminStateUp: gophercloud.Enabled,
}
lb, err := loadbalancers.Create(client, createOpts).Extract()
if err != nil {
return lb, err
}
t.Logf("Successfully created loadbalancer %s on subnet %s", lbName, subnetID)
t.Logf("Waiting for loadbalancer %s to become active", lbName)
if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil {
return lb, err
}
t.Logf("LoadBalancer %s is active", lbName)
return lb, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:29,代码来源:lbaas_v2.go
示例17: TestServersUpdate
func TestServersUpdate(t *testing.T) {
client, err := clients.NewComputeV2Client()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
choices, err := clients.AcceptanceTestChoicesFromEnv()
if err != nil {
t.Fatal(err)
}
server, err := CreateServer(t, client, choices)
if err != nil {
t.Fatal(err)
}
defer DeleteServer(t, client, server)
alternateName := tools.RandomString("ACPTTEST", 16)
for alternateName == server.Name {
alternateName = tools.RandomString("ACPTTEST", 16)
}
t.Logf("Attempting to rename the server to %s.", alternateName)
updateOpts := servers.UpdateOpts{
Name: alternateName,
}
updated, err := servers.Update(client, server.ID, updateOpts).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:jrperritt,项目名称:gophercloud-1,代码行数:46,代码来源:servers_test.go
示例18: 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:jrperritt,项目名称:gophercloud-1,代码行数:34,代码来源:user_test.go
示例19: TestSecGroupsUpdate
func TestSecGroupsUpdate(t *testing.T) {
client, err := clients.NewComputeV2Client()
if err != nil {
t.Fatalf("Unable to create a compute client: %v", err)
}
securityGroup, err := CreateSecurityGroup(t, client)
if err != nil {
t.Fatalf("Unable to create security group: %v", err)
}
defer DeleteSecurityGroup(t, client, securityGroup)
updateOpts := secgroups.UpdateOpts{
Name: tools.RandomString("secgroup_", 4),
Description: tools.RandomString("dec_", 10),
}
updatedSecurityGroup, err := secgroups.Update(client, securityGroup.ID, updateOpts).Extract()
if err != nil {
t.Fatalf("Unable to update security group: %v", err)
}
t.Logf("Updated %s's name to %s", updatedSecurityGroup.ID, updatedSecurityGroup.Name)
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:23,代码来源:secgroup_test.go
示例20: CreateSecurityGroup
// CreateSecurityGroup will create a security group with a random name.
// An error will be returned if one was failed to be created.
func CreateSecurityGroup(t *testing.T, client *gophercloud.ServiceClient) (secgroups.SecurityGroup, error) {
createOpts := secgroups.CreateOpts{
Name: tools.RandomString("secgroup_", 5),
Description: "something",
}
securityGroup, err := secgroups.Create(client, createOpts).Extract()
if err != nil {
return *securityGroup, err
}
t.Logf("Created security group: %s", securityGroup.ID)
return *securityGroup, nil
}
开发者ID:jrperritt,项目名称:gophercloud-1,代码行数:16,代码来源:compute.go
注:本文中的github.com/gophercloud/gophercloud/acceptance/tools.RandomString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论