util

package
v0.0.0-...-c01ef62 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REMOTE_REPOMD_FILE  = "/repodata/repomd.xml"
	REPO_AGE_FILE       = ".rege_age"
	PRIMARY_REPOMD_TYPE = "primary"
)
View Source
const (
	X86_64  = "x86_64"
	AARCH64 = "aarch64"
	NONLSE  = "nonlse"

	EL7 = "7"
	EL8 = "8"
)
View Source
const (
	DEFALUT_SSH_PORT     = 22
	DEFALUT_OBSHELL_PORT = 2886
	DEFALUT_SSH_PATH     = ".ssh"
)
View Source
const FLAG_ROOT_PWD = "password"

Variables

View Source
var (

	// Base mirrors
	OB_COMMUNITY_STABLE_BASE = NewBaseMirror("OceanBase-community-stable-el$releasever", "https://mirrors.oceanbase.com/oceanbase/community/stable/el/$releasever/$basearch/")
	OB_DEVELOPMENT_KIT_BASE  = NewBaseMirror("OceanBase-development-kit-el$releasever", "https://mirrors.oceanbase.com/oceanbase/development-kit/el/$releasever/$basearch/")

	// Mirrors
	OB_COMMUNITY_STABLE_MIRROR Mirror
	OB_DEVELOPMENT_KIT_MIRROR  Mirror
	OB_MIRRORS                 []Mirror
)
View Source
var (

	// Unlike the Python SDK, the Go SDK does not use rsync by default, but instead uses sftp for chunked transfer.
	// This is because the rsync implementation in the GO SDK is not fully developed and can only be used with default key configuration for passwordless login.
	// At the same time, the performance of the sftp chunked transfer in the GO SDK is comparable to rsync.
	UseRsync = false

	// The size of each sftp chunked transfer, default is 64M.
	// Since the maximum size of a single file in the current OB, observer, is around 450M, with 64M, it can be divided into 7-8 chunks.
	// This would require 7-8 concurrent connections, and since the default MaxSessions in the sshd configuration is 10, this value is appropriate.
	// If you want to improve the performance of sftp chunked transfer, you can reduce this value to increase the number of concurrent connections.
	// However, you will need to correspondingly increase the MaxSessions configuration on the target machine.
	CHUNK_SIZE = 1024 * 1024 * 64
	// The maximum number of parallel SFTP transfers to avoid exceeding the MaxSessions limit
	PARALLEL_SFTP_MAX = 8

	// Since using in-memory backup for small files results in higher batch transfer efficiency, only files larger than SCP_THRESHOLD will be transferred using SCP.
	// You can disable SCP by setting SCP_THRESHOLD=0.
	SCP_THRESHOLD int64 = 1024 * 1024 * 1
)

Functions

func DownloadPackage

func DownloadPackage(destDir string, entry PackageEntry) (string, error)

DownloadPackage searches for the specified package entry across all mirrors defined in OB_MIRRORS and downloads the first match to the destination directory. If no matching package is found in any mirror, or an error occurs, it returns an error.

func InitNodes

func InitNodes(rpmPackagePaths []string, forceClean bool, configs ...NodeConfig) error

func InstallObshell

func InstallObshell(rpmPackagePath string, configs ...NodeConfig) error

将Obshell安装到指定的服务器上, 自会将obshell RPM包

func NewBaseMirror

func NewBaseMirror(name, baseUrl string) *baseMirror

func SearchPackage

func SearchPackage(entry PackageEntry) ([]packageInfo, error)

SearchPackage searches for packages that match the provided package entry across all mirrors defined in OB_MIRRORS. If no matching packages are found, or an error occurs during the search, it returns an error.

func StartObshell

func StartObshell(configs ...NodeConfig) error

func Takeover

func Takeover(password string, configs ...NodeConfig) error

Types

type Location

type Location struct {
	BaseUrl string `xml:"base,attr"`
	Href    string `xml:"href,attr"`
}

type Mirror

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

func (Mirror) Download

func (m Mirror) Download(destDir string, entry PackageEntry) (string, error)

Download searches for the specified package entry in the mirror and downloads the first match to the destination directory. If no matching package is found, or an error occurs during the search, it returns an error.

func (Mirror) Search

func (m Mirror) Search(entry PackageEntry) ([]packageInfo, error)

Search looks for packages that match the provided package entry within the mirror. If no matching packages are found or an error occurs during the search, it returns an error.

type NodeClient

type NodeClient struct {
	*ssh.Client
	NodeConfig
	// contains filtered or unexported fields
}

func NewNodeClient

func NewNodeClient(config NodeConfig) (*NodeClient, error)

func (*NodeClient) ExecuteCommand

func (client *NodeClient) ExecuteCommand(cmd string) SshRetun

func (*NodeClient) WriteFile

func (client *NodeClient) WriteFile(context []byte, filePath string, mode fs.FileMode) (err error)

type NodeConfig

type NodeConfig struct {
	SSHConfig
	// contains filtered or unexported fields
}

func NewNodeConfig

func NewNodeConfig(ip string, workDir string, obshellPort ...int) NodeConfig

func NewNodeConfigWithSShConfig

func NewNodeConfigWithSShConfig(ip string, workDir string, config SSHConfig, obshellPort ...int) NodeConfig

type PackageEntry

type PackageEntry struct {
	Name    string `xml:"name,attr"`
	Flags   string `xml:"flags,attr,omitempty"`
	Epoch   string `xml:"epoch,attr,omitempty"`
	Version string `xml:"ver,attr,omitempty"`
	Release string `xml:"rel,attr,omitempty"`
}

type SSHConfig

type SSHConfig struct {
	*ssh.ClientConfig
	// contains filtered or unexported fields
}

func NewSSHConfig

func NewSSHConfig(config ssh.ClientConfig, sshPort ...int) SSHConfig

type SshRetun

type SshRetun struct {
	Stdout string
	Stderr string
	Code   int
}

Jump to

Keyboard shortcuts

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