utils

package
v0.7.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 The Scitix Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableACS

func DisableACS(ctx context.Context, BDF string) error

func EnableACS

func EnableACS(ctx context.Context, deviceBDF string) error

func ExecCommand

func ExecCommand(ctx context.Context, command string, args ...string) ([]byte, error)

func ExtractClusterName added in v0.7.2

func ExtractClusterName() string

func GetACSCapablePCIEDevices

func GetACSCapablePCIEDevices(ctx context.Context) ([]string, error)

func GetACSStatus

func GetACSStatus(ctx context.Context, BDF string) (string, error)

func GetAllPCIeBDF

func GetAllPCIeBDF(ctx context.Context) ([]string, error)

func GetTerminalWidth

func GetTerminalWidth() (int, error)

func HasIOMMUGroups

func HasIOMMUGroups() (bool, error)

HasIOMMUGroups checks if IOMMU groups are present in /sys/kernel/iommu_groups

func InitLogger

func InitLogger(level logrus.Level, isJSON bool)

func InitLoggerWithConfig

func InitLoggerWithConfig(level logrus.Level, isJSON bool, config LogConfig)

InitLoggerWithConfig initializes logger with file rotation support

func IsACSDisabled

func IsACSDisabled(ctx context.Context, BDF string) (bool, string, error)

func IsInfinibandExist

func IsInfinibandExist() bool

func IsKernalModuleHolder

func IsKernalModuleHolder(holder, module string) (bool, error)

IsKernalModuleHolder checks if a specific module is holding another module

func IsKernalModuleLoaded

func IsKernalModuleLoaded(moduleName string) (bool, error)

IsKernalModuleLoaded checks if a specific kernel module is loaded

func IsLowSpeedIBBond added in v0.7.8

func IsLowSpeedIBBond(ibDev string) bool

IsLowSpeedIBBond returns true if the given IB device name looks like a bond (contains "bond") and its IB port rate is <= 100 Gb/sec, which indicates a non-HCA management bond (e.g. two 25G NIC slaves aggregated) rather than a business RoCE LAG / IB bond over high-speed HCAs.

Detection uses /sys/class/infiniband/<ibDev>/ports/1/rate — available inside containers that expose /sys/class/infiniband — instead of the ethernet-bond slave speed path which is often not visible there.

When the rate file cannot be read or parsed, returns false so callers conservatively keep the device rather than silently dropping a potential business port.

func IsNvidiaGPUExist

func IsNvidiaGPUExist() bool

func IsRoot

func IsRoot() bool

func IsRunningInKubernetes

func IsRunningInKubernetes() bool

func JSON

func JSON(c interface{}) (string, error)

func LoadFromYaml

func LoadFromYaml(file string, c interface{}) error

func ParseBoolToFloat

func ParseBoolToFloat(b bool) float64

func ParseStringToFloat

func ParseStringToFloat(str string) float64

func PrintTitle

func PrintTitle(text, paddingChar string)

func TimeTrack

func TimeTrack(start time.Time, name string)

TimeTrack Measure execution time of a function

func Yaml

func Yaml(c interface{}) (string, error)

Types

type LogConfig

type LogConfig struct {
	// LogFile is the path to the log file. If empty, logs will only go to stdout
	LogFile string
	// MaxSize is the maximum size in megabytes of the log file before it gets rotated
	MaxSize int // megabytes
	// MaxBackups is the maximum number of old log files to retain
	MaxBackups int
	// MaxAge is the maximum number of days to retain old log files
	MaxAge int // days
	// Compress determines if the rotated log files should be compressed
	Compress bool
	// AlsoOutputToStdout determines if logs should also be written to stdout in addition to file
	AlsoOutputToStdout bool
}

LogConfig holds configuration for logger

type PCIeACS

type PCIeACS struct {
	BDF       string
	ACSStatus string
}

func BatchDisableACS

func BatchDisableACS(ctx context.Context, acsEnabledDevices []PCIeACS) ([]PCIeACS, error)

func DisableAllACS

func DisableAllACS(ctx context.Context) ([]PCIeACS, error)

func GetACSEnabledDevices

func GetACSEnabledDevices(ctx context.Context) ([]PCIeACS, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL