utils

package
v0.0.0-...-6cbd31a Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: AGPL-3.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharsetWindows1252 = "windows-1252"
	CharsetISO88591    = "ISO-8859-1"
	CharsetGB18030     = "GB-18030"
)
View Source
const (
	XForwardedFor = "X-Forwarded-For"
	XRealIP       = "X-Real-IP"
	XClientIP     = "x-client-ip"
)

Variables

This section is empty.

Functions

func AddAptSource

func AddAptSource(sourceType, repoURL, suite string, components []string) error

AddAptSource adds apt source or components to existing apt sources It reads /etc/apt/sources.list and any *.list files under /etc/apt/sources.list.d If a matching source exists, it merges the new components with existing ones If no matching source exists, it adds a new source line to /etc/apt/sources.list

func ArchAlias

func ArchAlias(arch string) string

func Base64decode

func Base64decode(s string) (string, error)

func CharsetConverts

func CharsetConverts(charset string, data []byte, c Charset) (string, error)

func CheckUrl

func CheckUrl(val string) bool

func ContainsUppercase

func ContainsUppercase(s string) bool

func CopyEmbed

func CopyEmbed(assets http.FileSystem, embeddedDir, dst string) error

func CreateDir

func CreateDir(path string) error

func DeleteFile

func DeleteFile(path string) error

func ExtractIP

func ExtractIP(host string) ([]string, error)

func ExtractIPAddress

func ExtractIPAddress(addr string) string

func FileMD5

func FileMD5(path string) (string, error)

func FormatBoolToInt

func FormatBoolToInt(b bool) int

func FormatBytes

func FormatBytes(bytes int64) string

func GbkToUtf8

func GbkToUtf8(data []byte) ([]byte, error)

func GenerateEncryptedPassword

func GenerateEncryptedPassword(length int) (string, string, error)

func GenerateNumberWithProbability

func GenerateNumberWithProbability(p float64) int

func GeneratePassword

func GeneratePassword(length int) (string, error)

func GetArgs

func GetArgs(argsMap map[string]string, args []string) ([]string, map[string]string)

func GetBufIOReaderOfTerminalInput

func GetBufIOReaderOfTerminalInput() (*bufio.Reader, error)

func GetDiskSpace

func GetDiskSpace(path string) (total uint64, free uint64, err error)

func GetDrives

func GetDrives() []string

func GetHttpStatus

func GetHttpStatus(url string) (int, error)

func GetMyExternalIPAddr

func GetMyExternalIPAddr() string

GetMyExternalIPAddr get my network outgoing ip address

func Home

func Home() (string, error)

Home returns the home directory for the executing user.

func Indent

func Indent(n int, text string) string

func InitConfig

func InitConfig(kubeConfig *rest.Config, namespace string) (*action.Configuration, *cli.EnvSettings, error)

InitConfig initializes the configuration for executing actions.

func InstallCharts

func InstallCharts(ctx context.Context, actionConfig *action.Configuration, settings *cli.EnvSettings,
	appName, chartsName, repoURL, namespace string, vals map[string]interface{}) error

InstallCharts installs helm chart using action config and environment settings.

func IsExist

func IsExist(path string) bool
func IsSymLink(path string) (bool, error)

func IsValidDomain

func IsValidDomain(domain string) bool

func IsValidIP

func IsValidIP(ip string) bool

func KubeVersionAlias

func KubeVersionAlias(version string) (string, string)

func LocalMd5Sum

func LocalMd5Sum(src string) string

func MD5

func MD5(str string) string

func Mkdir

func Mkdir(dirName string) error

func ParseInt

func ParseInt(s string) int

func ParseOlaresVersionString

func ParseOlaresVersionString(versionString string) (*semver.Version, error)

func Random

func Random() int

func ReleaseName

func ReleaseName(appname, owner string) string

ReleaseName returns application release name.

func RemoteIp

func RemoteIp(req *http.Request) string

func RemoveAnsiCodes

func RemoveAnsiCodes(input string) string

func Render

func Render(tmpl *template.Template, variables map[string]interface{}) (string, error)

Render text template with given `variables` Render-context

func ResetTmpDir

func ResetTmpDir(runtime connector.Runtime) error

func RollbackCharts

func RollbackCharts(cfg *action.Configuration, releaseName string) error

RollbackCharts rollback helm chart using action config.

func Round

func Round(val float64, precision int) float64

Round returns the result of rounding 'val' according to the specified 'precision' precision (the number of digits after the decimal point)。 and precision can be negative number or zero

func ToYAML

func ToYAML(v interface{}) string

func UninstallCharts

func UninstallCharts(cfg *action.Configuration, releaseName string) error

UninstallCharts upgrades helm chart using action config.

func UpgradeCharts

func UpgradeCharts(ctx context.Context, actionConfig *action.Configuration, settings *cli.EnvSettings,
	appName, chartName, repoURL, namespace string, vals map[string]interface{}, reuseValue bool) error

UpgradeCharts upgrades helm chart using action config and environment settings.

func Utf16ToUtf8

func Utf16ToUtf8(data []byte) string

func ValidateUserName

func ValidateUserName(username string) error

func WorkDir

func WorkDir() (string, error)

Types

type AptSource

type AptSource struct {
	Type       string   // deb or deb-src
	Options    []string // options in square brackets (e.g., [arch=amd64,trusted=yes])
	URL        string   // repository URL
	Suite      string   // distribution suite (e.g., trixie, bullseye)
	Components []string // components (e.g., main, contrib, non-free)
}

AptSource represents an apt source entry

type Charset

type Charset string
const (
	DEFAULT Charset = "DEFAULT"
	GBK     Charset = "GBK"
	UTF8    Charset = "UTF8"
	UTF16   Charset = "UTF16"
)

type CommandExecute

type CommandExecute interface {
	Run() (string, error)
	Exec() (string, error)
}

type CommandExecutor

type CommandExecutor struct {
	// contains filtered or unexported fields
}

func NewCommandExecutor

func NewCommandExecutor(name, prefix string, args []string, printOutput, printLine bool) *CommandExecutor

type Config

type Config struct {
	ActionCfg *action.Configuration
	Settings  *cli.EnvSettings
}

Config helm client config.

type Data

type Data map[string]interface{}

type DefaultCommandExecutor

type DefaultCommandExecutor struct {
	Commands    []string
	PrintOutput bool
	PrintLine   bool
}

func (*DefaultCommandExecutor) Exec

func (d *DefaultCommandExecutor) Exec() (string, error)

func (*DefaultCommandExecutor) Run

func (d *DefaultCommandExecutor) Run() (string, error)

func (*DefaultCommandExecutor) RunCmd

func (d *DefaultCommandExecutor) RunCmd(name string, charset Charset) (string, error)

type GB18030

type GB18030 struct {
	// contains filtered or unexported fields
}

func (*GB18030) Utf8

func (c *GB18030) Utf8() (string, error)

type GPU

type GPU struct {
	ID                  string `xml:"id,attr" json:"id"`
	ProductName         string `xml:"product_name" json:"product_name"`
	ProductBrand        string `xml:"product_brand" json:"product_brand"`
	ProductArchitecture string `xml:"product_architecture" json:"product_architecture"`
	DisplayMode         string `xml:"display_mode" json:"display_mode"`
	DisplayActive       string `xml:"display_active" json:"display_active"`
	// PersistenceMode     string `xml:"persistence_mode" json:"persistence_mode"`
	// mig_mode
	// mig_devices
	// AccountingMode           string `xml:"accounting_mode" json:"accounting_mode"`
	// AccountingModeBufferSize string `xml:"accounting_mode_buffer_size" json:"accounting_mode_buffer_size"`
	// CurrentDm                string `xml:"driver_model>current_dm" json:"current_dm"`
	// PendingDm                string `xml:"driver_model>pending_dm" json:"pending_dm"`
	// Serial        string `xml:"serial" json:"serial"`
	UUID string `xml:"uuid" json:"uuid"`
	// MinorNumber   string `xml:"minor_number" json:"minor_number"`
	VbiosVersion  string `xml:"vbios_version" json:"vbios_version"`
	MultigpuBoard string `xml:"multigpu_board" json:"multigpu_board"`
	BoardID       string `xml:"board_id" json:"board_id"`
	// gpu_part_number
	// gpu_module_id
	// ImgVersion string `xml:"inforom_version>img_version" json:"img_version"`
	// OemObject  string `xml:"inforom_version>oem_object" json:"oem_object"`
	// EccObject  string `xml:"inforom_version>ecc_object" json:"ecc_object"`
	// PwrObject  string `xml:"inforom_version>pwr_object" json:"pwr_object"`
	// CurrentGom string `xml:"gpu_operation_mode>current_gom" json:"current_gom"`
	// PendingGom string `xml:"gpu_operation_mode>pending_gom" json:"pending_gom"`
	// gsp_firmware_version
	// gpu_virtualization_mode
	// ibmnpu
	PciBus           string `xml:"pci>pci_bus" json:"pci_bus"`
	PciDevice        string `xml:"pci>pci_device" json:"pci_device"`
	PciDomain        string `xml:"pci>pci_domain" json:"pci_domain"`
	PciDeviceID      string `xml:"pci>pci_device_id" json:"pci_device_id"`
	PciBusID         string `xml:"pci>pci_bus_id" json:"pci_bus_id"`
	PciSubSystemID   string `xml:"pci>pci_sub_system_id" json:"pci_sub_system_id"`
	MaxLinkGen       string `xml:"pci>pci_gpu_link_info>pcie_gen>max_link_gen" json:"max_link_gen"`
	CurrentLinkGen   string `xml:"pci>pci_gpu_link_info>pcie_gen>current_link_gen" json:"current_link_gen"`
	MaxLinkWidth     string `xml:"pci>pci_gpu_link_info>link_widths>max_link_width" json:"max_link_width"`
	CurrentLinkWidth string `xml:"pci>pci_gpu_link_info>link_widths>current_link_width" json:"current_link_width"`
	// BridgeChipType   string `xml:"pci>pci_bridge_chip>bridge_chip_type" json:"bridge_chip_type"`
	// BridgeChipFw     string `xml:"pci>pci_bridge_chip>bridge_chip_fw" json:"bridge_chip_fw"`
	// ReplayCounter    string `xml:"pci>replay_counter" json:"replay_counter"`
	// replay_rollover_counter
	PciTxUtil                                     string `xml:"pci>tx_util" json:"pci_tx_util"`
	PciRxUtil                                     string `xml:"pci>rx_util" json:"pci_rx_util"`
	FanSpeed                                      string `xml:"fan_speed" json:"fan_speed"`
	PerformanceState                              string `xml:"performance_state" json:"performance_state"`
	ClocksThrottleReasonGpuIdle                   string `xml:"clocks_throttle_reasons>clocks_throttle_reason_gpu_idle" json:"clocks_throttle_reason_gpu_idle"`
	ClocksThrottleReasonApplicationsClocksSetting string `` /* 138-byte string literal not displayed */
	ClocksThrottleReasonSwPowerCap                string `xml:"clocks_throttle_reasons>clocks_throttle_reason_sw_power_cap" json:"clocks_throttle_reason_sw_power_cap"`
	ClocksThrottleReasonHwSlowdown                string `xml:"clocks_throttle_reasons>clocks_throttle_reason_hw_slowdown" json:"clocks_throttle_reason_hw_slowdown"`
	ClocksThrottleReasonHwThermalSlowdown         string `xml:"clocks_throttle_reasons>clocks_throttle_reason_hw_thermal_slowdown" json:"clocks_throttle_reason_hw_thermal_slowdown"`
	ClocksThrottleReasonHwPowerBrakeSlowdown      string `` /* 130-byte string literal not displayed */
	ClocksThrottleReasonSyncBoost                 string `xml:"clocks_throttle_reasons>clocks_throttle_reason_sync_boost" json:"clocks_throttle_reason_sync_boost"`
	ClocksThrottleReasonSwThermalSlowdown         string `xml:"clocks_throttle_reasons>clocks_throttle_reason_sw_thermal_slowdown" json:"clocks_throttle_reason_sw_thermal_slowdown"`
	ClocksThrottleReasonDisplayClocksSetting      string `` /* 128-byte string literal not displayed */
	// ClocksThrottleReasonUnknown                   string `xml:"clocks_throttle_reasons>clocks_throttle_reason_unknown" json:"clocks_throttle_reason_unknown"`
	FbMemoryUsageTotal    string `xml:"fb_memory_usage>total" json:"fb_memory_usage_total"`
	FbMemoryUsageReserved string `xml:"fb_memory_usage>reserved" json:"fb_memory_usage_reserved"`
	FbMemoryUsageUsed     string `xml:"fb_memory_usage>used" json:"fb_memory_usage_used"`
	FbMemoryUsageFree     string `xml:"fb_memory_usage>free" json:"fb_memory_usage_free"`
	Bar1Total             string `xml:"bar1_memory_usage>total" json:"bar1_total"`
	Bar1Used              string `xml:"bar1_memory_usage>used" json:"bar1_used"`
	Bar1Free              string `xml:"bar1_memory_usage>free" json:"bar1_free"`
	ComputeMode           string `xml:"compute_mode" json:"compute_mode"`
	GpuUtil               string `xml:"utilization>gpu_util" json:"gpu_util"`
	MemoryUtil            string `xml:"utilization>memory_util" json:"memory_util"`
	EncoderUtil           string `xml:"utilization>encoder_util" json:"encoder_util"`
	DecoderUtil           string `xml:"utilization>decoder_util" json:"decoder_util"`
	// encoder_stats
	// fbc_stats
	// CurrentEcc                                        string `xml:"ecc_mode>current_ecc" json:"current_ecc"`
	// PendingEcc                                        string `xml:"ecc_mode>pending_ecc" json:"pending_ecc"`
	// DeviceMemory                                      string `xml:"ecc_errors>volatile>single_bit>device_memory" json:"device_memory"`
	// L1Cache                                           string `xml:"ecc_errors>volatile>single_bit>l1_cache" json:"l_1_cache"`
	// TotalSingleBitVolatileEccErrorsGpu                string `xml:"ecc_errors>volatile>single_bit>total" json:"total_single_bit_volatile_ecc_errors_gpu"`
	// TextureMemory                                     string `xml:"ecc_errors>volatile>single_bit>texture_memory" json:"texture_memory"`
	// RegisterFile                                      string `xml:"ecc_errors>volatile>single_bit>register_file" json:"register_file"`
	// L2Cache                                           string `xml:"ecc_errors>volatile>single_bit>l2_cache" json:"l_2_cache"`
	// TextureMemoryDoubleBitVolatileEccErrorsGpu        string `xml:"ecc_errors>volatile>double_bit>texture_memory" json:"texture_memory_double_bit_volatile_ecc_errors_gpu"`
	// DeviceMemoryDoubleBitVolatileEccErrorsGpu         string `xml:"ecc_errors>volatile>double_bit>device_memory" json:"device_memory_double_bit_volatile_ecc_errors_gpu"`
	// RegisterFileDoubleBitVolatileEccErrorsGpu         string `xml:"ecc_errors>volatile>double_bit>register_file" json:"register_file_double_bit_volatile_ecc_errors_gpu"`
	// TotalDoubleBitVolatileEccErrorsGpu                string `xml:"ecc_errors>volatile>double_bit>total" json:"total_double_bit_volatile_ecc_errors_gpu"`
	// L2CacheDoubleBitVolatileEccErrorsGpu              string `xml:"ecc_errors>volatile>double_bit>l2_cache" json:"l_2_cache_double_bit_volatile_ecc_errors_gpu"`
	// L1CacheDoubleBitVolatileEccErrorsGpu              string `xml:"ecc_errors>volatile>double_bit>l1_cache" json:"l_1_cache_double_bit_volatile_ecc_errors_gpu"`
	// L2CacheSingleBitAggregateEccErrorsGpu             string `xml:"ecc_errors>aggregate>single_bit>l2_cache" json:"l_2_cache_single_bit_aggregate_ecc_errors_gpu"`
	// L1CacheSingleBitAggregateEccErrorsGpu             string `xml:"ecc_errors>aggregate>single_bit>l1_cache" json:"l_1_cache_single_bit_aggregate_ecc_errors_gpu"`
	// TextureMemorySingleBitAggregateEccErrorsGpu       string `xml:"ecc_errors>aggregate>single_bit>texture_memory" json:"texture_memory_single_bit_aggregate_ecc_errors_gpu"`
	// RegisterFileSingleBitAggregateEccErrorsGpu        string `xml:"ecc_errors>aggregate>single_bit>register_file" json:"register_file_single_bit_aggregate_ecc_errors_gpu"`
	// DeviceMemorySingleBitAggregateEccErrorsGpu        string `xml:"ecc_errors>aggregate>single_bit>device_memory" json:"device_memory_single_bit_aggregate_ecc_errors_gpu"`
	// TotalSingleBitAggregateEccErrorsGpu               string `xml:"ecc_errors>aggregate>single_bit>total" json:"total_single_bit_aggregate_ecc_errors_gpu"`
	// DeviceMemoryDoubleBitAggregateEccErrorsGpu        string `xml:"ecc_errors>aggregate>double_bit>device_memory" json:"device_memory_double_bit_aggregate_ecc_errors_gpu"`
	// TotalDoubleBitAggregateEccErrorsGpu               string `xml:"ecc_errors>aggregate>double_bit>total" json:"total_double_bit_aggregate_ecc_errors_gpu"`
	// RegisterFileDoubleBitAggregateEccErrorsGpu        string `xml:"ecc_errors>aggregate>double_bit>register_file" json:"register_file_double_bit_aggregate_ecc_errors_gpu"`
	// L2CacheDoubleBitAggregateEccErrorsGpu             string `xml:"ecc_errors>aggregate>double_bit>l2_cache" json:"l_2_cache_double_bit_aggregate_ecc_errors_gpu"`
	// L1CacheDoubleBitAggregateEccErrorsGpu             string `xml:"ecc_errors>aggregate>double_bit>l1_cache" json:"l_1_cache_double_bit_aggregate_ecc_errors_gpu"`
	// TextureMemoryDoubleBitAggregateEccErrorsGpu       string `xml:"ecc_errors>aggregate>double_bit>texture_memory" json:"texture_memory_double_bit_aggregate_ecc_errors_gpu"`
	// RetiredCount                                      string `xml:"retired_pages>multiple_single_bit_retirement>retired_count" json:"retired_count"`
	// RetiredPagelist                                   string `xml:"retired_pages>multiple_single_bit_retirement>retired_pagelist" json:"retired_pagelist"`
	// RetiredCountDoubleBitRetirementRetiredPagesGpu    string `xml:"retired_pages>double_bit_retirement>retired_count" json:"retired_count_double_bit_retirement_retired_pages_gpu"`
	// RetiredPagelistDoubleBitRetirementRetiredPagesGpu string `xml:"retired_pages>double_bit_retirement>retired_pagelist" json:"retired_pagelist_double_bit_retirement_retired_pages_gpu"`
	// pending_blacklist
	// PendingRetirement string `xml:"retired_pages>pending_retirement" json:"pending_retirement"`
	// remapped_rows
	GpuTemp                string `xml:"temperature>gpu_temp" json:"gpu_temp"`
	GpuTempMaxThreshold    string `xml:"temperature>gpu_temp_max_threshold" json:"gpu_temp_max_threshold"`
	GpuTempSlowThreshold   string `xml:"temperature>gpu_temp_slow_threshold" json:"gpu_temp_slow_threshold"`
	GpuTempMaxGpuThreshold string `xml:"temperature>gpu_temp_max_gpu_threshold" json:"gpu_temp_max_gpu_threshold"`
	GpuTargetTemp          string `xml:"temperature>gpu_target_temperature" json:"gpu_target_temperature"`
	MemoryTemp             string `xml:"temperature>memory_temp" json:"memory_temp"`
	GpuTempMaxMemThreshold string `xml:"temperature>gpu_temp_max_mem_threshold" json:"gpu_temp_max_mem_threshold"`
	GpuTargetTempMin       string `xml:"supported_gpu_target_temp>gpu_target_temp_min" json:"gpu_target_temp_min"`
	GpuTargetTempMax       string `xml:"supported_gpu_target_temp>gpu_target_temp_max" json:"gpu_target_temp_max"`
	PowerState             string `xml:"gpu_power_readings>power_state" json:"power_state"`
	PowerManagement        string `xml:"gpu_power_readings>power_management" json:"power_management"`
	PowerDraw              string `xml:"gpu_power_readings>power_draw" json:"power_draw"`
	PowerLimit             string `xml:"gpu_power_readings>current_power_limit" json:"power_limit"`
	DefaultPowerLimit      string `xml:"gpu_power_readings>default_power_limit" json:"default_power_limit"`
	EnforcedPowerLimit     string `xml:"gpu_power_readings>requested_power_limit" json:"enforced_power_limit"`
	MinPowerLimit          string `xml:"gpu_power_readings>min_power_limit" json:"min_power_limit"`
	MaxPowerLimit          string `xml:"gpu_power_readings>max_power_limit" json:"max_power_limit"`
	GraphicsClock          string `xml:"clocks>graphics_clock" json:"graphics_clock"`
	SmClock                string `xml:"clocks>sm_clock" json:"sm_clock"`
	MemClock               string `xml:"clocks>mem_clock" json:"mem_clock"`
	VideoClock             string `xml:"clocks>video_clock" json:"video_clock"`
	// GraphicsClockApplicationsClocksGpu        string `xml:"applications_clocks>graphics_clock" json:"graphics_clock_applications_clocks_gpu"`
	// MemClockApplicationsClocksGpu             string `xml:"applications_clocks>mem_clock" json:"mem_clock_applications_clocks_gpu"`
	// GraphicsClockDefaultApplicationsClocksGpu string `xml:"default_applications_clocks>graphics_clock" json:"graphics_clock_default_applications_clocks_gpu"`
	// MemClockDefaultApplicationsClocksGpu      string `xml:"default_applications_clocks>mem_clock" json:"mem_clock_default_applications_clocks_gpu"`
	GraphicsClockMax string `xml:"max_clocks>graphics_clock" json:"graphics_clock_max"`
	SmClockMax       string `xml:"max_clocks>sm_clock" json:"sm_clock_max"`
	MemClockMax      string `xml:"max_clocks>mem_clock" json:"mem_clock_max"`
	VideoClockMax    string `xml:"max_clocks>video_clock" json:"video_clock_max"`
}

type ISO8859

type ISO8859 struct {
	// contains filtered or unexported fields
}

func (*ISO8859) Utf8

func (c *ISO8859) Utf8() (string, error)

type NvidiaGpuInfo

type NvidiaGpuInfo struct {
	Timestamp     string `xml:"timestamp" json:"timestamp"`
	DriverVersion string `xml:"driver_version" json:"driver_version"`
	CudaVersion   string `xml:"cuda_version" json:"cuda_version"`
	AttachedGpus  string `xml:"attached_gpus" json:"attached_gpus"`
	GPUS          []GPU  `xml:"gpu" json:"gpus"`
}

func ExecNvidiaSmi

func ExecNvidiaSmi(execRuntime connector.Runtime) (gpuInfo *NvidiaGpuInfo, installed bool, err error)

type PowerShellCommandExecutor

type PowerShellCommandExecutor struct {
	Commands    []string
	PrintOutput bool
	PrintLine   bool
}

func (*PowerShellCommandExecutor) Run

type Windows1252

type Windows1252 struct {
	// contains filtered or unexported fields
}

func (*Windows1252) Gb2312

func (c *Windows1252) Gb2312() (string, error)

func (*Windows1252) Utf8

func (c *Windows1252) Utf8() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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