// machineName returns the InstanceId, unless DisplayName is set.
555203
func (s machineStatus) machineName() string {
	if s.DisplayName == "" {
		return string(s.InstanceId)
	}
	return s.DisplayName
}
489271
func machineID() (string, error) {
	id, err := readHostid()
	if err != nil {
		// try fallback
		id, err = readKenv()
	}
	if err != nil {
		return "", err
	}
	return id, nil
}
843879
func (s *AttachDiskInput) SetInstanceName(v string) *AttachDiskInput {
	s.InstanceName = &v
	return s
}
807796
func (pc *PCCloud) InstanceID(ctx context.Context, nodeName k8stypes.NodeName) (string, error) {
	name := string(nodeName)
	if name == pc.localK8sHostname {
		return pc.localInstanceID, nil
	}
	// We assume only master need to get InstanceID of a node other than itself
	id, err := getInstanceID(pc, name)
	if err != nil {
		klog.Errorf("Photon Cloud Provider: getInstanceID failed for InstanceID. Error[%v]", err)
	}
	return id, err

}
454561
func renameMachine(c context.Context, name, newName string) (*crimson.Machine, error) {
	switch {
	case name == "":
		return nil, status.Error(codes.InvalidArgument, "machine name is required and must be non-empty")
	case newName == "":
		return nil, status.Error(codes.InvalidArgument, "new name is required and must be non-empty")
	case name == newName:
		return nil, status.Error(codes.InvalidArgument, "new name must be different")
	}

	tx, err := database.Begin(c)
	if err != nil {
		return nil, errors.Annotate(err, "failed to begin transaction").Err()
	}
	defer tx.MaybeRollback(c)

	res, err := tx.ExecContext(c, `
		UPDATE machines
		SET name = ?
		WHERE name = ?
	`, newName, name)
	if err != nil {
		switch e, ok := err.(*mysql.MySQLError); {
		case !ok:
			// Type assertion failed.
		case e.Number == mysqlerr.ER_DUP_ENTRY:
			// e.g. "Error 1062: Duplicate entry 'machine-name' for key 'name'".
			return nil, status.Errorf(codes.AlreadyExists, "duplicate machine %q", newName)
		}
		return nil, errors.Annotate(err, "failed to rename machine").Err()
	}
	switch rows, err := res.RowsAffected(); {
	case err != nil:
		return nil, errors.Annotate(err, "failed to fetch affected rows").Err()
	case rows == 0:
		return nil, status.Errorf(codes.NotFound, "machine %q does not exist", name)
	}

	machines, err := listMachines(c, tx, &crimson.ListMachinesRequest{
		Names: []string{newName},
	})
	if err != nil {
		return nil, errors.Annotate(err, "failed to fetch renamed machine").Err()
	}

	if err := tx.Commit(); err != nil {
		return nil, errors.Annotate(err, "failed to commit transaction").Err()
	}
	return machines[0], nil
}
1064980
func (s *Owner) SetDisplayName(v string) *Owner {
	s.DisplayName = &v
	return s
}
1335683
func deviceName(zone string, diskId uint64) string {
	return fmt.Sprintf("%s-%d", zone, diskId)
}
292168
func (c *Client) Hostname() (string, error) {
	var hostname string
	err := c.doGet("hostname", func(r io.Reader) error {
		hostnameraw, err := ioutil.ReadAll(r)
		hostname = string(hostnameraw)
		return err
	})
	return hostname, err
}
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
}
495784
func (cs *CSCloud) InstanceID(ctx context.Context, name types.NodeName) (string, error) {
	instance, count, err := cs.client.VirtualMachine.GetVirtualMachineByName(
		string(name),
		cloudstack.WithProject(cs.projectID),
	)
	if err != nil {
		if count == 0 {
			return "", cloudprovider.InstanceNotFound
		}
		return "", fmt.Errorf("error retrieving instance ID: %v", err)
	}

	return instance.Id, nil
}
218405
func (az *Cloud) InstanceID(ctx context.Context, name types.NodeName) (string, error) {
	nodeName := mapNodeNameToVMName(name)
	unmanaged, err := az.IsNodeUnmanaged(nodeName)
	if err != nil {
		return "", err
	}
	if unmanaged {
		// InstanceID is same with nodeName for unmanaged nodes.
		klog.V(4).Infof("InstanceID: getting ID %q for unmanaged node %q", name, name)
		return nodeName, nil
	}

	if az.UseInstanceMetadata {
		metadata, err := az.metadata.GetMetadata()
		if err != nil {
			return "", err
		}

		if metadata.Compute == nil {
			return "", fmt.Errorf("failure of getting instance metadata")
		}

		isLocalInstance, err := az.isCurrentInstance(name, metadata.Compute.Name)
		if err != nil {
			return "", err
		}

		// Not local instance, get instanceID from Azure ARM API.
		if !isLocalInstance {
			return az.vmSet.GetInstanceIDByNodeName(nodeName)
		}

		// Get resource group name.
		resourceGroup := strings.ToLower(metadata.Compute.ResourceGroup)

		// Compose instanceID based on nodeName for standard instance.
		if az.VMType == vmTypeStandard {
			return az.getStandardMachineID(resourceGroup, nodeName), nil
		}

		// Get scale set name and instanceID from vmName for vmss.
		ssName, instanceID, err := extractVmssVMName(metadata.Compute.Name)
		if err != nil {
			if err == ErrorNotVmssInstance {
				// Compose machineID for standard Node.
				return az.getStandardMachineID(resourceGroup, nodeName), nil
			}
			return "", err
		}
		// Compose instanceID based on ssName and instanceID for vmss instance.
		return az.getVmssMachineID(resourceGroup, ssName, instanceID), nil
	}

	return az.vmSet.GetInstanceIDByNodeName(nodeName)
}
385220
func (s *PutInstancePublicPortsInput) SetInstanceName(v string) *PutInstancePublicPortsInput {
	s.InstanceName = &v
	return s
}
526207
func (s *OpenInstancePublicPortsInput) SetInstanceName(v string) *OpenInstancePublicPortsInput {
	s.InstanceName = &v
	return s
}
615862
func (s *UpdateStackInput) SetDisplayName(v string) *UpdateStackInput {
	s.DisplayName = &v
	return s
}
325349
func (s *DeleteKnownHostKeysInput) SetInstanceName(v string) *DeleteKnownHostKeysInput {
	s.InstanceName = &v
	return s
}
1299597
func (s *CreateDiskSnapshotInput) SetInstanceName(v string) *CreateDiskSnapshotInput {
	s.InstanceName = &v
	return s
}
1343326
func (v *Cloud) InstanceID(ctx context.Context, nodeName types.NodeName) (string, error) {
	name := mapNodeNameToInstanceName(nodeName)
	instance, err := v.fetchInstance(name)
	if err != nil {
		return "", err
	}
	// TODO: define a way to identify the provider instance to complete
	// the format <provider_instance_id>/<instance_id>.
	return "/" + instance.UUID, err
}