Exemplo n.º 1
0
func listSecRules(t *testing.T) {
	err := rsRules.List(Client, osRules.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		list, err := osRules.ExtractRules(page)
		if err != nil {
			t.Errorf("Failed to extract sec rules: %v", err)
			return false, err
		}

		for _, r := range list {
			t.Logf("Listing security rule: ID [%s]", r.ID)
		}

		return true, nil
	})

	th.AssertNoErr(t, err)
}
Exemplo n.º 2
0
Arquivo: list.go Projeto: flazz/rack
func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := securityGroupRules.List(command.Ctx.ServiceClient, *opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := osSecurityGroupRules.ExtractRules(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, rule := range info {
			result[j] = securityGroupRuleSingle(&rule)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := osSecurityGroupRules.ExtractRules(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, rule := range info {
				result[j] = securityGroupRuleSingle(&rule)
			}
			resource.Result = result
			if len(info) >= limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.WaitGroup.Add(1)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}