// MachineID returns the uuid specified `/etc/machine-id`
// it first prepends the provided root to the filepath
// if there is an error reading the file it returns the empty string
558090
func MachineID(root string) string {
	fullPath := filepath.Join(root, "/etc/machine-id")
	id, err := ioutil.ReadFile(fullPath)
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(id))
}
59605
func ParseFilesystemAttachmentIds(stringIds []string) ([]params.MachineStorageId, error) {
	ids := make([]params.MachineStorageId, len(stringIds))
	for i, s := range stringIds {
		m, f, err := state.ParseFilesystemAttachmentId(s)
		if err != nil {
			return nil, err
		}
		ids[i] = params.MachineStorageId{
			MachineTag:    m.String(),
			AttachmentTag: f.String(),
		}
	}
	return ids, nil
}
1141878
func ParseFilesystemAttachmentId(id string) (names.Tag, names.FilesystemTag, error) {
	fields := strings.SplitN(id, ":", 2)
	isValidHost := names.IsValidMachine(fields[0]) || names.IsValidUnit(fields[0])
	if len(fields) != 2 || !isValidHost || !names.IsValidFilesystem(fields[1]) {
		return names.MachineTag{}, names.FilesystemTag{}, errors.Errorf("invalid filesystem attachment ID %q", id)
	}
	var hostTag names.Tag
	if names.IsValidMachine(fields[0]) {
		hostTag = names.NewMachineTag(fields[0])
	} else {
		hostTag = names.NewUnitTag(fields[0])
	}
	filesystemTag := names.NewFilesystemTag(fields[1])
	return hostTag, filesystemTag, nil
}
676342
func (self *Wind) Id() string {
	return fmt.Sprintf("%02x:%02x", self.id>>8, self.id&0xff)
}
230507
func InstanceID(ctx types.Context) (*types.InstanceID, error) {

	// UUID can be obtained as descried in
	// https://azure.microsoft.com/en-us/blog/accessing-and-using-azure-vm-unique-id/
	// but this code will use hostname as ID

	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}
	return &types.InstanceID{
		ID:     hostname,
		Driver: azureud.Name,
	}, nil
}
696072
func (g *IDGenerator) ID() platform.ID {
	var id platform.ID
	for !id.Valid() {
		id = platform.ID(g.Generator.Next())
	}
	return id
}
427319
func machineID() (string, error) {
	buf := &bytes.Buffer{}
	err := run(buf, os.Stderr, "ioreg", "-rd1", "-c", "IOPlatformExpertDevice")
	if err != nil {
		return "", err
	}
	id, err := extractID(buf.String())
	if err != nil {
		return "", err
	}
	return trim(id), nil
}
555203
func (s machineStatus) machineName() string {
	if s.DisplayName == "" {
		return string(s.InstanceId)
	}
	return s.DisplayName
}
188442
func (u *Unit) MachineId() string {
	u.mu.Lock()
	defer u.mu.Unlock()
	return u.details.MachineId
}
1271757
func GenerateID() string {
	b := make([]byte, 32)
	rand.Read(b)
	return hex.EncodeToString(b)
}
503775
func generateID(appendWith string) (string, error) {
	random, err := rand.Int(rand.Reader, maxInt64)
	if err != nil {
		return "", nil
	}
	hostname, err := os.Hostname()
	if err != nil {
		hostname = "localhost"
	}
	pid := os.Getpid()
	nanoTime := time.Now().UTC().UnixNano()
	if len(appendWith) == 0 {
		return fmt.Sprintf("%d.%d.%d@%s", nanoTime, pid, random, hostname), nil
	}
	return fmt.Sprintf("%d.%d.%d.%s@%s", nanoTime, pid, random, appendWith, hostname), nil
}
52084
func (u *Unit) AssignedMachineId() (id string, err error) {
	if u.IsPrincipal() {
		if u.doc.MachineId == "" {
			return "", unitNotAssignedError(u)
		}
		return u.doc.MachineId, nil
	}

	units, closer := u.st.db().GetCollection(unitsC)
	defer closer()

	pudoc := unitDoc{}
	err = units.FindId(u.doc.Principal).One(&pudoc)
	if err == mgo.ErrNotFound {
		return "", errors.NotFoundf("principal unit %q of %q", u.doc.Principal, u)
	} else if err != nil {
		return "", err
	}
	if pudoc.MachineId == "" {
		return "", unitNotAssignedError(u)
	}
	return pudoc.MachineId, nil
}
810459
func InstanceID() (*types.InstanceID, error) {

	macs, err := getMacs()
	if err != nil {
		return nil, err
	}

	iid := &types.InstanceID{Driver: vbox.Name}
	if err := iid.MarshalMetadata(macs); err != nil {
		return nil, err
	}

	return iid, nil
}
693005
func controllerMachineIds(st *state.State, m *state.Machine) ([]string, error) {
	info, err := st.ControllerInfo()
	if err != nil {
		return nil, err
	}
	result := set.NewStrings(info.MachineIds...)
	result.Remove(m.Id())
	return result.SortedValues(), nil
}
1061995
func (c *CloudAPI) DeleteMachine(machineID string) error {
	if err := c.ProcessFunctionHook(c, machineID); err != nil {
		return err
	}

	for i, machine := range c.machines {
		if machine.Id == machineID {
			if machine.State == "stopped" {
				c.machines = append(c.machines[:i], c.machines[i+1:]...)
				return nil
			}

			return fmt.Errorf("Cannot Delete machine %s, machine is not stopped.", machineID)
		}
	}

	return fmt.Errorf("Machine %s not found", machineID)
}
113944
func (m *machineTracker) Id() string {
	m.mu.Lock()
	defer m.mu.Unlock()
	return m.id
}
1082987
func MakeID(codec kbfscodec.Codec, md RootMetadata) (ID, error) {
	// Make sure that the serialized metadata is set; otherwise we
	// won't get the right ID.
	if md.GetSerializedPrivateMetadata() == nil {
		return ID{}, errors.WithStack(MissingDataError{md.TlfID()})
	}

	buf, err := codec.Encode(md)
	if err != nil {
		return ID{}, err
	}

	h, err := kbfshash.DefaultHash(buf)
	if err != nil {
		return ID{}, err
	}

	return ID{h}, nil
}