本文整理汇总了Golang中github.com/rackspace/gophercloud.WaitFor函数的典型用法代码示例。如果您正苦于以下问题:Golang WaitFor函数的具体用法?Golang WaitFor怎么用?Golang WaitFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WaitFor函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSnapshots
func TestSnapshots(t *testing.T) {
client, err := newClient(t)
th.AssertNoErr(t, err)
v, err := volumes.Create(client, &volumes.CreateOpts{
Name: "gophercloud-test-volume",
Size: 1,
}).Extract()
th.AssertNoErr(t, err)
err = volumes.WaitForStatus(client, v.ID, "available", 120)
th.AssertNoErr(t, err)
t.Logf("Created volume: %v\n", v)
ss, err := snapshots.Create(client, &snapshots.CreateOpts{
Name: "gophercloud-test-snapshot",
VolumeID: v.ID,
}).Extract()
th.AssertNoErr(t, err)
err = snapshots.WaitForStatus(client, ss.ID, "available", 120)
th.AssertNoErr(t, err)
t.Logf("Created snapshot: %+v\n", ss)
err = snapshots.Delete(client, ss.ID).ExtractErr()
th.AssertNoErr(t, err)
err = gophercloud.WaitFor(120, func() (bool, error) {
_, err := snapshots.Get(client, ss.ID).Extract()
if err != nil {
return true, nil
}
return false, nil
})
th.AssertNoErr(t, err)
t.Log("Deleted snapshot\n")
err = volumes.Delete(client, v.ID).ExtractErr()
th.AssertNoErr(t, err)
err = gophercloud.WaitFor(120, func() (bool, error) {
_, err := volumes.Get(client, v.ID).Extract()
if err != nil {
return true, nil
}
return false, nil
})
th.AssertNoErr(t, err)
t.Log("Deleted volume\n")
}
开发者ID:RomainVabre,项目名称:origin,代码行数:57,代码来源:snapshots_test.go
示例2: 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
示例3: TestStackEvents
func TestStackEvents(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client := newClient(t)
stackName := "postman_stack_2"
resourceName := "hello_world"
var eventID string
createOpts := osStacks.CreateOpts{
Name: stackName,
Template: template,
Timeout: 5,
}
stack, err := stacks.Create(client, createOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("Created stack: %+v\n", stack)
defer func() {
err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Deleted stack (%s)", stackName)
}()
err = gophercloud.WaitFor(60, func() (bool, error) {
getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
if err != nil {
return false, err
}
if getStack.Status == "CREATE_COMPLETE" {
return true, nil
}
return false, nil
})
err = stackevents.List(client, stackName, stack.ID, nil).EachPage(func(page pagination.Page) (bool, error) {
events, err := osStackEvents.ExtractEvents(page)
th.AssertNoErr(t, err)
t.Logf("listed events: %+v\n", events)
eventID = events[0].ID
return false, nil
})
th.AssertNoErr(t, err)
err = stackevents.ListResourceEvents(client, stackName, stack.ID, resourceName, nil).EachPage(func(page pagination.Page) (bool, error) {
resourceEvents, err := osStackEvents.ExtractResourceEvents(page)
th.AssertNoErr(t, err)
t.Logf("listed resource events: %+v\n", resourceEvents)
return false, nil
})
th.AssertNoErr(t, err)
event, err := stackevents.Get(client, stackName, stack.ID, resourceName, eventID).Extract()
th.AssertNoErr(t, err)
t.Logf("retrieved event: %+v\n", event)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:54,代码来源:stackevents_test.go
示例4: waitForLB
func waitForLB(client *gophercloud.ServiceClient, id int, state lbs.Status) {
gophercloud.WaitFor(60, func() (bool, error) {
lb, err := lbs.Get(client, id).Extract()
if err != nil {
return false, err
}
if lb.Status != state {
return false, nil
}
return true, nil
})
}
开发者ID:RomainVabre,项目名称:origin,代码行数:12,代码来源:lb_test.go
示例5: WaitUntilActive
func (c context) WaitUntilActive(id string) {
err := gophercloud.WaitFor(60, func() (bool, error) {
inst, err := instances.Get(c.client, id).Extract()
if err != nil {
return false, err
}
if inst.Status == "ACTIVE" {
return true, nil
}
return false, nil
})
c.AssertNoErr(err)
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:13,代码来源:common.go
示例6: WaitForStatus
// WaitForStatus will continually poll a server until it successfully transitions to a specified
// status. It will do this for at most the number of seconds specified.
func WaitForStatus(c *gophercloud.ServiceClient, id, status string, secs int) error {
return gophercloud.WaitFor(secs, func() (bool, error) {
current, err := Get(c, id).Extract()
if err != nil {
return false, err
}
if current.Status == status {
return true, nil
}
return false, nil
})
}
开发者ID:40a,项目名称:bootkube,代码行数:16,代码来源:util.go
示例7: WaitUntilDeleted
// WaitUntilDeleted will continually poll a snapshot until it has been
// successfully deleted, i.e. returns a 404 status.
func (snapshot Snapshot) WaitUntilDeleted(c *gophercloud.ServiceClient, timeout int) error {
return gophercloud.WaitFor(timeout, func() (bool, error) {
// Poll resource
_, err := Get(c, snapshot.ID).Extract()
// Check for a 404
if casted, ok := err.(*perigee.UnexpectedResponseCodeError); ok && casted.Actual == 404 {
return true, nil
} else if err != nil {
return false, err
}
return false, nil
})
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:17,代码来源:results.go
示例8: TestStackResources
func TestStackResources(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client := newClient(t)
stackName := "postman_stack_2"
createOpts := stacks.CreateOpts{
Name: stackName,
Template: template,
Timeout: 5,
}
stack, err := stacks.Create(client, createOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("Created stack: %+v\n", stack)
defer func() {
err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Deleted stack (%s)", stackName)
}()
err = gophercloud.WaitFor(60, func() (bool, error) {
getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
if err != nil {
return false, err
}
if getStack.Status == "CREATE_COMPLETE" {
return true, nil
}
return false, nil
})
resourceName := "hello_world"
resource, err := stackresources.Get(client, stackName, stack.ID, resourceName).Extract()
th.AssertNoErr(t, err)
t.Logf("Got stack resource: %+v\n", resource)
metadata, err := stackresources.Metadata(client, stackName, stack.ID, resourceName).Extract()
th.AssertNoErr(t, err)
t.Logf("Got stack resource metadata: %+v\n", metadata)
err = stackresources.List(client, stackName, stack.ID, stackresources.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
resources, err := stackresources.ExtractResources(page)
th.AssertNoErr(t, err)
t.Logf("resources: %+v\n", resources)
return false, nil
})
th.AssertNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:48,代码来源:stackresources_test.go
示例9: WaitUntilComplete
// WaitUntilComplete will continually poll a snapshot until it successfully
// transitions to a specified state. It will do this for at most the number of
// seconds specified.
func (snapshot Snapshot) WaitUntilComplete(c *gophercloud.ServiceClient, timeout int) error {
return gophercloud.WaitFor(timeout, func() (bool, error) {
// Poll resource
current, err := Get(c, snapshot.ID).Extract()
if err != nil {
return false, err
}
// Has it been built yet?
if current.Progress == "100%" {
return true, nil
}
return false, nil
})
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:19,代码来源:results.go
示例10: TestStacks
func TestStacks(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client := newClient(t)
stackName1 := "gophercloud-test-stack-2"
createOpts := stacks.CreateOpts{
Name: stackName1,
Template: template,
Timeout: 5,
}
stack, err := stacks.Create(client, createOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("Created stack: %+v\n", stack)
defer func() {
err := stacks.Delete(client, stackName1, stack.ID).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Deleted stack (%s)", stackName1)
}()
err = gophercloud.WaitFor(60, func() (bool, error) {
getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
if err != nil {
return false, err
}
if getStack.Status == "CREATE_COMPLETE" {
return true, nil
}
return false, nil
})
updateOpts := stacks.UpdateOpts{
Template: template,
Timeout: 20,
}
err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
th.AssertNoErr(t, err)
err = gophercloud.WaitFor(60, func() (bool, error) {
getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
if err != nil {
return false, err
}
if getStack.Status == "UPDATE_COMPLETE" {
return true, nil
}
return false, nil
})
t.Logf("Updated stack")
err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
stackList, err := stacks.ExtractStacks(page)
th.AssertNoErr(t, err)
t.Logf("Got stack list: %+v\n", stackList)
return true, nil
})
th.AssertNoErr(t, err)
getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
th.AssertNoErr(t, err)
t.Logf("Got stack: %+v\n", getStack)
abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
th.AssertNoErr(t, err)
t.Logf("Abandonded stack %+v\n", abandonedStack)
th.AssertNoErr(t, err)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:68,代码来源:stacks_test.go
示例11: TestStackTemplates
func TestStackTemplates(t *testing.T) {
// Create a provider client for making the HTTP requests.
// See common.go in this directory for more information.
client := newClient(t)
stackName := "postman_stack_2"
createOpts := osStacks.CreateOpts{
Name: stackName,
Template: template,
Timeout: 5,
}
stack, err := stacks.Create(client, createOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("Created stack: %+v\n", stack)
defer func() {
err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Deleted stack (%s)", stackName)
}()
err = gophercloud.WaitFor(60, func() (bool, error) {
getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
if err != nil {
return false, err
}
if getStack.Status == "CREATE_COMPLETE" {
return true, nil
}
return false, nil
})
tmpl, err := stacktemplates.Get(client, stackName, stack.ID).Extract()
th.AssertNoErr(t, err)
t.Logf("retrieved template: %+v\n", tmpl)
validateOpts := osStacktemplates.ValidateOpts{
Template: map[string]interface{}{
"heat_template_version": "2013-05-23",
"description": "Simple template to test heat commands",
"parameters": map[string]interface{}{
"flavor": map[string]interface{}{
"default": "m1.tiny",
"type": "string",
},
},
"resources": map[string]interface{}{
"hello_world": map[string]interface{}{
"type": "OS::Nova::Server",
"properties": map[string]interface{}{
"key_name": "heat_key",
"flavor": map[string]interface{}{
"get_param": "flavor",
},
"image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
"user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n",
},
},
},
},
}
validatedTemplate, err := stacktemplates.Validate(client, validateOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("validated template: %+v\n", validatedTemplate)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:64,代码来源:stacktemplates_test.go
注:本文中的github.com/rackspace/gophercloud.WaitFor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论