Example #1
0
func (command *commandList) Execute(resource *handler.Resource) {

	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := stacks.List(command.Ctx.ServiceClient, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := osStacks.ExtractStacks(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, stack := range info {
			result[j] = stackSingle(&stack)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := osStacks.ExtractStacks(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, stack := range info {
				result[j] = stackSingle(&stack)
			}
			resource.Result = result
			if len(info) >= limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
Example #2
0
func stackList(client *gophercloud.ServiceClient) ([]map[string]interface{}, error) {
	pager := osStacks.List(client, nil)
	pages, err := pager.AllPages()
	if err != nil {
		return nil, err
	}
	info, err := osStacks.ExtractStacks(pages)
	if err != nil {
		return nil, err
	}
	result := make([]map[string]interface{}, len(info))
	for j, stack := range info {
		result[j] = structs.Map(&stack)
		result[j]["CreationTime"] = stack.CreationTime
		result[j]["UpdatedTime"] = stack.UpdatedTime
	}
	return result, nil
}
Example #3
0
func TestListStack(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleListSuccessfully(t, os.FullListOutput)

	count := 0
	err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := os.ExtractStacks(page)
		th.AssertNoErr(t, err)

		th.CheckDeepEquals(t, os.ListExpected, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.CheckEquals(t, count, 1)
}
Example #4
0
func (command *commandGet) Execute(resource *handler.Resource) {

	pager := stacks.List(command.Ctx.ServiceClient, nil)
	//fmt.Println(pager)
	pages, err := pager.AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	//fmt.Println(pages)
	info, err := osStacks.ExtractStacks(pages)
	//fmt.Println("Yeah!")
	if err != nil {
		resource.Err = err
		return
	}
	result := make([]map[string]interface{}, len(info))
	for j, stack := range info {
		result[j] = structs.Map(stack)
	}
	fmt.Println(result)
	resource.Result = result

}