Exemplo n.º 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
		}
	}
}
Exemplo n.º 2
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

}