// TODO(stevvooe): Consolidate "Hostname" style validation here.
// Runtime returns the runtime name from a given spec.
16815
func Runtime(t api.TaskSpec) (string, error) {
	switch r := t.GetRuntime().(type) {
	case *api.TaskSpec_Attachment:
		return "attachment", nil
	case *api.TaskSpec_Container:
		return "container", nil
	case *api.TaskSpec_Generic:
		return strings.ToLower(r.Generic.Kind), nil
	default:
		return "", errUnknownRuntime
	}
}
74155
func Runtime(term *ast.Term) func(*Basic) {
	return func(b *Basic) {
		b.runtime = term
	}
}
236482
func nameOfRuntimeType(_type *Variable) (typename string, kind int64, err error) {
	if e, ok := _type.bi.nameOfRuntimeType[_type.Addr]; ok {
		return e.typename, e.kind, nil
	}

	var tflag int64

	if tflagField := _type.loadFieldNamed("tflag"); tflagField != nil && tflagField.Value != nil {
		tflag, _ = constant.Int64Val(tflagField.Value)
	}
	if kindField := _type.loadFieldNamed("kind"); kindField != nil && kindField.Value != nil {
		kind, _ = constant.Int64Val(kindField.Value)
	}

	// Named types are defined by a 'type' expression, everything else
	// (for example pointers to named types) are not considered named.
	if tflag&tflagNamed != 0 {
		typename, err = nameOfNamedRuntimeType(_type, kind, tflag)
		return typename, kind, err
	}

	typename, err = nameOfUnnamedRuntimeType(_type, kind, tflag)
	return typename, kind, err
}
441092
func (conf *Config) GetDefaultRuntimeName() string {
	conf.Lock()
	rt := conf.DefaultRuntime
	conf.Unlock()

	return rt
}
215506
func (s *CreateStackInput) SetHostnameTheme(v string) *CreateStackInput {
	s.HostnameTheme = &v
	return s
}
981491
func ValidateHostname(hostname string) error {
	if len(hostname) > 255 {
		return fmt.Errorf("length exceeds 255 bytes")
	}
	if !hostnameRegexp.MatchString(hostname) {
		return fmt.Errorf("hostname does not match regex %q", hostnameRegexp)
	}
	for _, s := range strings.Split(hostname, ".") {
		if len(s) > 63 {
			return fmt.Errorf("segment %q exceeds 63 bytes", s)
		}
	}
	return nil
}
726800
func (q *Query) WithRuntime(runtime *ast.Term) *Query {
	q.runtime = runtime
	return q
}
903900
func hostname() string {
	hostname, err := os.Hostname()
	if err != nil {
		return "unknown"
	}

	name, _ := parseHostname(hostname)
	return sanitizeHostname(name)
}
975570
func GetClusterNameSchema(extensionSchema string) string {
	var clusterNameSchema string
	if clusterNameSchema == "" {
		clusterNameSchema = fmt.Sprintf(ClusterNameSpecSchemaTemplate, "")
	} else {
		clusterNameSchema = fmt.Sprintf(ClusterNameSpecSchemaTemplate, ","+extensionSchema)
	}
	return fmt.Sprintf(V2SchemaTemplate, MetadataSchema, clusterNameSchema, DefaultDefinitions)
}
493524
func GetResourceName(res Resource) string {
	switch v := res.(type) {
	case *v2.ClusterLoadAssignment:
		return v.GetClusterName()
	case *v2.Cluster:
		return v.GetName()
	case *v2.RouteConfiguration:
		return v.GetName()
	case *v2.Listener:
		return v.GetName()
	case *auth.Secret:
		return v.GetName()
	default:
		return ""
	}
}
595119
func (r Spec) Hostname() string {
	i := strings.Index(r.Locator, "/")

	if i < 0 {
		i = len(r.Locator) + 1
	}
	return r.Locator[:i]
}
1232804
func (s *Stack) SetHostnameTheme(v string) *Stack {
	s.HostnameTheme = &v
	return s
}
1296802
func isExportedRuntime(name string) bool {
	const n = len("runtime.")
	return len(name) > n && name[:n] == "runtime." && 'A' <= name[n] && name[n] <= 'Z'
}
350101
func (s *Scheme) nameFunc(t reflect.Type) string {
	// find the preferred names for this type
	gvks, ok := s.typeToGVK[t]
	if !ok {
		return t.Name()
	}

	for _, gvk := range gvks {
		internalGV := gvk.GroupVersion()
		internalGV.Version = APIVersionInternal // this is hacky and maybe should be passed in
		internalGVK := internalGV.WithKind(gvk.Kind)

		if internalType, exists := s.gvkToType[internalGVK]; exists {
			return s.typeToGVK[internalType][0].Kind
		}
	}

	return gvks[0].Kind
}
713185
func NameFromEnv() string {
	n := os.Getenv(EnvName)
	if n == "" {
		return os.Getenv("HOSTNAME")
	}
	return n
}
825310
func enumItemName(enumName string, spec *compile.EnumItem) (string, error) {
	name, err := goNameAnnotation(spec)
	if err != nil {
		return "", err
	}
	if name == "" {
		name = pascalCase(false, /* all caps */
			strings.Split(spec.ThriftName(), "_")...)
	}
	return enumName + name, err
}
262073
func (s *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) {
	id, count, err := s.GetHostID(name, opts...)
	if err != nil {
		return nil, count, err
	}

	r, count, err := s.GetHostByID(id, opts...)
	if err != nil {
		return nil, count, err
	}
	return r, count, nil
}