// TODO(wallyworld) - remove when we use UUID everywhere
327285
func applicationOfferUUID(st *State, offerName string) (string, error) {
	appOffers := &applicationOffers{st: st}
	offer, err := appOffers.ApplicationOffer(offerName)
	if err != nil {
		return "", errors.Trace(err)
	}
	return offer.OfferUUID, nil
}
81317
func (p *Packet) UUIDs() []ble.UUID {
	var u []ble.UUID
	if b := p.Field(someUUID16); b != nil {
		u = uuidList(u, b, 2)
	}
	if b := p.Field(allUUID16); b != nil {
		u = uuidList(u, b, 2)
	}
	if b := p.Field(someUUID32); b != nil {
		u = uuidList(u, b, 4)
	}
	if b := p.Field(allUUID32); b != nil {
		u = uuidList(u, b, 4)
	}
	if b := p.Field(someUUID128); b != nil {
		u = uuidList(u, b, 16)
	}
	if b := p.Field(allUUID128); b != nil {
		u = uuidList(u, b, 16)
	}
	return u
}
455628
func (u *UUID) UnmarshalJSON(b []byte) error {
	var j string
	err := json.Unmarshal(b, &j)
	if err == nil {
		v := ParseUUID(string(j))
		if v != nil {
			*u = v
		} else {
			err = fmt.Errorf("Bad UUID: %v", string(j))
		}
	}
	return err
}
361529
func (kvmsg *Kvmsg) SetUuid() {
	kvmsg.frame[frame_UUID] = string(uuid.NewRandom()) // raw 16 bytes
	kvmsg.present[frame_UUID] = true

}
295034
func UUIDToBase64(uuid uuid.UUID) string {
	return base64.StdEncoding.EncodeToString([]byte(uuid))
}
70537
func IsValidUUID(uuid string) bool {
	r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$")
	return r.MatchString(uuid)
}
1144685
func Get8UUID() string {
	u1 := uuid.NewV4()
	str := fmt.Sprintf("%s", u1)
	return str[0:8]
}
225095
func (u UUID) Bytes() ([]byte, error) {
	id, err := uuid.FromString(string(u))
	if err != nil {
		return nil, errors.Wrap(err, "invalid uuid string")
	}
	return id.Bytes(), nil
}
1082525
func MustParseUUID(s string) UUID {
	u, err := ParseUUID(s)
	if err != nil {
		panic(err)
	}
	return u
}
260703
func resolveUUID(dataDir, uuid string) (*types.UUID, error) {
	uuid = strings.ToLower(uuid)
	m, err := matchUUID(dataDir, uuid)
	if err != nil {
		return nil, err
	}

	if len(m) == 0 {
		return nil, fmt.Errorf("no matches found for %q", uuid)
	}

	if len(m) > 1 {
		return nil, fmt.Errorf("ambiguous uuid, %d matches", len(m))
	}

	u, err := types.NewUUID(m[0])
	if err != nil {
		return nil, errwrap.Wrap(errors.New("invalid UUID"), err)
	}

	return u, nil
}
579743
func matchUUID(dataDir, uuid string) ([]string, error) {
	if uuid == "" {
		return nil, types.ErrNoEmptyUUID
	}

	ls, err := listPods(dataDir, IncludeMostDirs)
	if err != nil {
		return nil, err
	}

	var matches []string
	for _, p := range ls {
		if strings.HasPrefix(p, uuid) {
			matches = append(matches, p)
		}
	}

	return matches, nil
}
663272
func (rh *RequestHistory) UuidIndex(uuid string) int {
	rh.lock.RLock()
	defer rh.lock.RUnlock()

	return rh.uuidIndexNoLock(uuid)
}
1188282
func formatVirtualDiskUUID(uuid string) string {
	uuidwithNoSpace := strings.Replace(uuid, " ", "", -1)
	uuidWithNoHypens := strings.Replace(uuidwithNoSpace, "-", "", -1)
	return strings.ToLower(uuidWithNoHypens)
}
920558
func (c *ClusterManager) Uuid() string {
	if len(c.config.ClusterUuid) == 0 {
		return c.config.ClusterId
	}
	return c.config.ClusterUuid
}
762412
func ID() string {
	u, err := uuid.NewV4()
	if err != nil {
		panic(err)
	}
	return "_" + u.String()
}
1156194
func MustNewUUID() *UUID {
	uuid, err := NewUUID()
	if err != nil {
		panic(err)
	}
	return uuid
}
657874
func FormatUUID(part string) (string, error) {
	if len(part) < 1 {
		return "", fmt.Errorf("Empty UUID")
	}
	if len(part) < 32 {
		part = strings.Repeat(part, 32)
	}
	if len(part) > 32 {
		part = part[:32]
	}
	uuid := part[:8] + "-" + part[8:12] + "-1" + part[13:16] + "-" + part[16:20] + "-" + part[20:32]

	err := IsUUID(uuid)
	if err != nil {
		return "", err
	}

	return uuid, nil
}