func getRequestOptions(r *http.Request) (v2.RequestOptions, error) { supportedTypes := map[string]bool{ v2.TypeName: true, v2.TypeDocker: true, } // fill in the defaults. opt := v2.RequestOptions{ IdType: v2.TypeName, Count: 64, Recursive: false, } idType := r.URL.Query().Get("type") if len(idType) != 0 { if !supportedTypes[idType] { return opt, fmt.Errorf("unknown 'type' %q", idType) } opt.IdType = idType } count := r.URL.Query().Get("count") if len(count) != 0 { n, err := strconv.ParseUint(count, 10, 32) if err != nil { return opt, fmt.Errorf("failed to parse 'count' option: %v", count) } opt.Count = int(n) } recursive := r.URL.Query().Get("recursive") if recursive == "true" { opt.Recursive = true } return opt, nil }
func (m *manager) GetProcessList(containerName string, options v2.RequestOptions) ([]v2.ProcessInfo, error) { // override recursive. Only support single container listing. options.Recursive = false conts, err := m.getRequestedContainers(containerName, options) if err != nil { return nil, err } if len(conts) != 1 { return nil, fmt.Errorf("Expected the request to match only one container") } // TODO(rjnagal): handle count? Only if we can do count by type (eg. top 5 cpu users) ps := []v2.ProcessInfo{} for _, cont := range conts { ps, err = cont.GetProcessList(m.cadvisorContainer, m.inHostNamespace) if err != nil { return nil, err } } return ps, nil }