예제 #1
0
파일: host.go 프로젝트: ncantor/origin
// buildHostDiagnostics builds host Diagnostic objects based on the host environment.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildHostDiagnostics() ([]types.Diagnostic, bool, error) {
	requestedDiagnostics := intersection(sets.NewString(o.RequestedDiagnostics...), availableHostDiagnostics).List()
	if len(requestedDiagnostics) == 0 { // no diagnostics to run here
		return nil, true, nil // don't waste time on discovery
	}
	isHost := o.IsHost
	// check for standard host config paths if not given
	if len(o.MasterConfigLocation) == 0 {
		if _, err := os.Stat(StandardMasterConfigPath); !os.IsNotExist(err) {
			o.MasterConfigLocation = StandardMasterConfigPath
			isHost = true
		}
	} else {
		isHost = true
	}
	if len(o.NodeConfigLocation) == 0 {
		if _, err := os.Stat(StandardNodeConfigPath); !os.IsNotExist(err) {
			o.NodeConfigLocation = StandardNodeConfigPath
			isHost = true
		}
	} else {
		isHost = true
	}

	// If we're not looking at a host, don't try the diagnostics
	if !isHost {
		return nil, true, nil
	}

	diagnostics := []types.Diagnostic{}
	systemdUnits := systemddiags.GetSystemdUnits(o.Logger)
	for _, diagnosticName := range requestedDiagnostics {
		switch diagnosticName {
		case systemddiags.AnalyzeLogsName:
			diagnostics = append(diagnostics, systemddiags.AnalyzeLogs{SystemdUnits: systemdUnits})

		case systemddiags.UnitStatusName:
			diagnostics = append(diagnostics, systemddiags.UnitStatus{SystemdUnits: systemdUnits})

		case hostdiags.MasterConfigCheckName:
			if len(o.MasterConfigLocation) > 0 {
				diagnostics = append(diagnostics, hostdiags.MasterConfigCheck{MasterConfigFile: o.MasterConfigLocation})
			}

		case hostdiags.NodeConfigCheckName:
			if len(o.NodeConfigLocation) > 0 {
				diagnostics = append(diagnostics, hostdiags.NodeConfigCheck{NodeConfigFile: o.NodeConfigLocation})
			}

		default:
			return diagnostics, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
		}
	}

	return diagnostics, true, nil
}
예제 #2
0
파일: host.go 프로젝트: RomainVabre/origin
// buildHostDiagnostics builds host Diagnostic objects based on the host environment.
// Returns the Diagnostics built, "ok" bool for whether to proceed or abort, and an error if any was encountered during the building of diagnostics.) {
func (o DiagnosticsOptions) buildHostDiagnostics() ([]types.Diagnostic, bool, error) {
	requestedDiagnostics := availableHostDiagnostics.Intersection(sets.NewString(o.RequestedDiagnostics...)).List()
	if len(requestedDiagnostics) == 0 { // no diagnostics to run here
		return nil, true, nil // don't waste time on discovery
	}
	isHost := o.IsHost
	if len(o.MasterConfigLocation) > 0 || len(o.NodeConfigLocation) > 0 {
		isHost = true
	}

	// If we're not looking at a host, don't try the diagnostics
	if !isHost {
		return nil, true, nil
	}

	diagnostics := []types.Diagnostic{}
	systemdUnits := systemddiags.GetSystemdUnits(o.Logger)
	for _, diagnosticName := range requestedDiagnostics {
		var d types.Diagnostic
		switch diagnosticName {
		case systemddiags.AnalyzeLogsName:
			d = systemddiags.AnalyzeLogs{SystemdUnits: systemdUnits}
		case systemddiags.UnitStatusName:
			d = systemddiags.UnitStatus{SystemdUnits: systemdUnits}
		case hostdiags.MasterConfigCheckName:
			d = hostdiags.MasterConfigCheck{MasterConfigFile: o.MasterConfigLocation}
		case hostdiags.NodeConfigCheckName:
			d = hostdiags.NodeConfigCheck{NodeConfigFile: o.NodeConfigLocation}
		default:
			return diagnostics, false, fmt.Errorf("unknown diagnostic: %v", diagnosticName)
		}
		diagnostics = append(diagnostics, d)
	}

	return diagnostics, true, nil
}