// listPlatforms returns a slice of platforms in the database.
483797
func listPlatforms(c context.Context, req *crimson.ListPlatformsRequest) ([]*crimson.Platform, error) {
	stmt := squirrel.Select("name", "description", "manufacturer").From("platforms")
	stmt = selectInString(stmt, "name", req.Names)
	stmt = selectInString(stmt, "manufacturer", req.Manufacturers)
	query, args, err := stmt.ToSql()
	if err != nil {
		return nil, errors.Annotate(err, "failed to generate statement").Err()
	}

	db := database.Get(c)
	rows, err := db.QueryContext(c, query, args...)
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch platforms").Err()
	}
	defer rows.Close()

	var platforms []*crimson.Platform
	for rows.Next() {
		p := &crimson.Platform{}
		if err = rows.Scan(&p.Name, &p.Description, &p.Manufacturer); err != nil {
			return nil, errors.Annotate(err, "failed to fetch platform").Err()
		}
		platforms = append(platforms, p)
	}
	return platforms, nil
}
1235371
func (s *Service) initPlatform() error {
	if s.platform != nil {
		return nil
	}
	epoller, err := console.NewEpoller()
	if err != nil {
		return errors.Wrap(err, "failed to initialize epoller")
	}
	s.platform = &linuxPlatform{
		epoller: epoller,
	}
	go epoller.Wait()
	return nil
}
241573
func (s *SigningProfileParameter) SetPlatform(v string) *SigningProfileParameter {
	s.Platform = &v
	return s
}
354967
func WithAllPlatforms(allPlatforms bool) V1ExporterOpt {
	return func(c *V1Exporter) error {
		c.AllPlatforms = allPlatforms
		return nil
	}
}
1076845
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
	dbKey := m.dbKey(dbID)
	if err := m.checkDBExists(dbKey); err != nil {
		return nil, errors.Trace(err)
	}

	res, err := m.txn.HGetAll(dbKey)
	if err != nil {
		return nil, errors.Trace(err)
	}

	tables := make([]*model.TableInfo, 0, len(res)/2)
	for _, r := range res {
		// only handle table meta
		tableKey := string(r.Field)
		if !strings.HasPrefix(tableKey, mTablePrefix) {
			continue
		}

		tbInfo := &model.TableInfo{}
		err = json.Unmarshal(r.Value, tbInfo)
		if err != nil {
			return nil, errors.Trace(err)
		}

		tables = append(tables, tbInfo)
	}

	return tables, nil
}
204452
func (s *EnvironmentDescription) SetPlatformArn(v string) *EnvironmentDescription {
	s.PlatformArn = &v
	return s
}
755888
func (s *ConfigurationSettingsDescription) SetPlatformArn(v string) *ConfigurationSettingsDescription {
	s.PlatformArn = &v
	return s
}
912350
func (c *horizontalPodAutoscalers) List(opts api.ListOptions) (result *extensions.HorizontalPodAutoscalerList, err error) {
	result = &extensions.HorizontalPodAutoscalerList{}
	err = c.client.Get().Namespace(c.ns).Resource("horizontalPodAutoscalers").VersionedParams(&opts, api.Scheme).Do().Into(result)
	return
}
998110
func ParsePlatform(v string) (Platform, error) {
	parts := strings.Split(v, "-")
	if len(parts) != 2 {
		return Platform{}, errors.Reason("platform must be <os>-<arch>: %q", v).Err()
	}
	return Platform{parts[0], parts[1]}, nil
}
1068552
func (s *SegmentDemographics) SetPlatform(v *SetDimension) *SegmentDemographics {
	s.Platform = v
	return s
}
661430
func (s *PlatformSummary) SetPlatformCategory(v string) *PlatformSummary {
	s.PlatformCategory = &v
	return s
}
765980
func (s *EventDescription) SetPlatformArn(v string) *EventDescription {
	s.PlatformArn = &v
	return s
}
1310155
func getPlatformsCmd(params *Parameters) *subcommands.Command {
	return &subcommands.Command{
		UsageLine: "get-platforms [-name <name>]... [-man <manufacturer>]...",
		ShortDesc: "retrieves platforms",
		LongDesc:  "Retrieves platforms matching the given names, or all platforms if names and manufacturers are omitted.\n\nExample to get all platforms:\ncrimson get-platforms\nExample to get all Apple platforms:\ncrimson get-platforms -man apple",
		CommandRun: func() subcommands.CommandRun {
			cmd := &GetPlatformsCmd{}
			cmd.Initialize(params)
			cmd.Flags.Var(flag.StringSlice(&cmd.req.Names), "name", "Name of a platform to filter by. Can be specified multiple times.")
			cmd.Flags.Var(flag.StringSlice(&cmd.req.Manufacturers), "man", "Manufacturer to filter by. Can be specified multiple times.")
			return cmd
		},
	}
}
1349310
func printPlatforms(tsv bool, platforms ...*crimson.Platform) {
	if len(platforms) > 0 {
		p := newStdoutPrinter(tsv)
		defer p.Flush()
		if !tsv {
			p.Row("Name", "Description", "Manufacturer")
		}
		for _, plat := range platforms {
			p.Row(plat.Name, plat.Description, plat.Manufacturer)
		}
	}
}
71572
func (s *MarketplaceService) ListPlans(ctx context.Context, opt *ListOptions) ([]*MarketplacePlan, *Response, error) {
	uri := s.marketplaceURI("plans")
	u, err := addOptions(uri, opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	var plans []*MarketplacePlan
	resp, err := s.client.Do(ctx, req, &plans)
	if err != nil {
		return nil, resp, err
	}

	return plans, resp, nil
}
208143
func (s *SystemVMService) ListSystemVms(p *ListSystemVmsParams) (*ListSystemVmsResponse, error) {
	resp, err := s.cs.newRequest("listSystemVms", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListSystemVmsResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
594670
func (p *PlatformFlag) Platforms(supported []Platform) []Platform {
	// NOTE: Reading this method alone is a bit hard to understand. It
	// is much easier to understand this method if you pair this with the
	// table of test cases it has.

	// Build a list of OS and archs NOT to build
	ignoreArch := make(map[string]struct{})
	includeArch := make(map[string]struct{})
	ignoreOS := make(map[string]struct{})
	includeOS := make(map[string]struct{})
	ignoreOSArch := make(map[string]Platform)
	includeOSArch := make(map[string]Platform)
	for _, v := range p.Arch {
		if v[0] == '!' {
			ignoreArch[v[1:]] = struct{}{}
		} else {
			includeArch[v] = struct{}{}
		}
	}
	for _, v := range p.OS {
		if v[0] == '!' {
			ignoreOS[v[1:]] = struct{}{}
		} else {
			includeOS[v] = struct{}{}
		}
	}
	for _, v := range p.OSArch {
		if v.OS[0] == '!' {
			v = Platform{
				OS:   v.OS[1:],
				Arch: v.Arch,
			}

			ignoreOSArch[v.String()] = v
		} else {
			includeOSArch[v.String()] = v
		}
	}

	// We're building a list of new platforms, so build the list
	// based only on the configured OS/arch pairs.
	var prefilter []Platform = nil
	if len(includeOSArch) > 0 {
		prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS)+len(includeOSArch))
		for _, v := range includeOSArch {
			prefilter = append(prefilter, v)
		}
	}

	if len(includeOS) > 0 && len(includeArch) > 0 {
		// Build up the list of prefiltered by what is specified
		if prefilter == nil {
			prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS))
		}

		for _, os := range p.OS {
			if _, ok := includeOS[os]; !ok {
				continue
			}

			for _, arch := range p.Arch {
				if _, ok := includeArch[arch]; !ok {
					continue
				}

				prefilter = append(prefilter, Platform{
					OS:   os,
					Arch: arch,
				})
			}
		}
	} else if len(includeOS) > 0 {
		// Build up the list of prefiltered by what is specified
		if prefilter == nil {
			prefilter = make([]Platform, 0, len(p.Arch)*len(p.OS))
		}

		for _, os := range p.OS {
			for _, platform := range supported {
				if platform.OS == os {
					prefilter = append(prefilter, platform)
				}
			}
		}
	}

	if prefilter != nil {
		// Remove any that aren't supported
		result := make([]Platform, 0, len(prefilter))
		for _, pending := range prefilter {
			found := false
			for _, platform := range supported {
				if pending.String() == platform.String() {
					found = true
					break
				}
			}

			if found {
				add := pending
				add.Default = false
				result = append(result, add)
			}
		}

		prefilter = result
	}

	if prefilter == nil {
		prefilter = make([]Platform, 0, len(supported))
		for _, v := range supported {
			if v.Default {
				add := v
				add.Default = false
				prefilter = append(prefilter, add)
			}
		}
	}

	// Go through each default platform and filter out the bad ones
	result := make([]Platform, 0, len(prefilter))
	for _, platform := range prefilter {
		if len(ignoreOSArch) > 0 {
			if _, ok := ignoreOSArch[platform.String()]; ok {
				continue
			}
		}

		// We only want to check the components (OS and Arch) if we didn't
		// specifically ask to include it via the osarch.
		checkComponents := true
		if len(includeOSArch) > 0 {
			if _, ok := includeOSArch[platform.String()]; ok {
				checkComponents = false
			}
		}

		if checkComponents {
			if len(ignoreArch) > 0 {
				if _, ok := ignoreArch[platform.Arch]; ok {
					continue
				}
			}
			if len(ignoreOS) > 0 {
				if _, ok := ignoreOS[platform.OS]; ok {
					continue
				}
			}
			if len(includeArch) > 0 {
				if _, ok := includeArch[platform.Arch]; !ok {
					continue
				}
			}
			if len(includeOS) > 0 {
				if _, ok := includeOS[platform.OS]; !ok {
					continue
				}
			}
		}

		result = append(result, platform)
	}

	return result
}