package module
v0.4.0 Latest Latest

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 13 Imported by: 0


Go SaltStack

go 调用 salt-api 接口


go get


package main

import (

 salt ""

func main() {

 ctx := context.TODO()
 // 初始化客户端
 client := salt.NewClient("")
 if err := client.Login(ctx, "username", "password", "eauth"); err != nil {

 // 列表 minions
 minions, err := client.ListMinions(ctx)
 if err != nil {

 // 执行命令
 resp, err := client.LocalClient(ctx, "*", "", []string{"whoami"})
 if err != nil {





View Source
const (
	CP_APPLICATIONS      = "CherryPy Applications"


This section is empty.


func NewClient

func NewClient(baseAPI string, opts ...ClientOption) *client


type Applications

type Applications struct {
	Enabled             bool               `json:"Enabled"`
	BytesReadRequest    float64            `json:"Bytes Read/Request"`
	BytesReadSecond     float64            `json:"Bytes Read/Second"`
	BytesWrittenRequest float64            `json:"Bytes Written/Request"`
	BytesWrittenSecond  float64            `json:"Bytes Written/Second"`
	CurrentTime         float64            `json:"Current Time"`
	CurrentRequests     int                `json:"Current Requests"`
	RequestsSecond      float64            `json:"Requests/Second"`
	ServerVersion       string             `json:"Server Version"`
	StartTime           float64            `json:"Start Time"`
	TotalBytesRead      int                `json:"Total Bytes Read"`
	TotalBytesWritten   int                `json:"Total Bytes Written"`
	TotalRequests       int                `json:"Total Requests"`
	TotalTime           float64            `json:"Total Time"`
	Uptime              float64            `json:"Uptime"`
	Requests            map[string]Request `json:"Requests"`

type Client added in v0.3.0

type Client interface {
	Login(ctx context.Context, username, password, eauth string) error
	Logout(ctx context.Context) error
	ListMinions(ctx context.Context) ([]Minion, error)
	GetMinion(ctx context.Context, mid string) (*Minion, error)
	LocalClient(ctx context.Context, tgt, fun string, arg []string, opts ...RunOption) (map[string]LocalClientReturn, error)
	LocalClientAsync(ctx context.Context, tgt, fun string, arg []string, opts ...RunOption) (jid string, err error)
	ListJobs(ctx context.Context) ([]Job, error)
	GetJob(ctx context.Context, jid string) (*Job, error)
	Hook(ctx context.Context, id string, payload interface{}) error
	Stats(ctx context.Context) (*stats, error)
	// Wheel Client Keys
	ListKeys(ctx context.Context) (*ListKeysReturn, error)
	GetKeyString(ctx context.Context, match string) (map[string]string, error)
	GetKeyFinger(ctx context.Context, match string) (map[string]string, error)
	AcceptKey(ctx context.Context, match string) ([]string, error)
	RejectedKey(ctx context.Context, match string) ([]string, error)
	DeleteKey(ctx context.Context, match string) ([]string, error)
	// Runner Client
	ManageStatus(ctx context.Context) (*ManageStatusReturn, error)

type ClientOption added in v0.3.0

type ClientOption func(options *clientOptions)

func WithInsecure added in v0.3.0

func WithInsecure() ClientOption

func WithTimeout added in v0.3.0

func WithTimeout(timeout time.Duration) ClientOption

type CommandClient added in v0.3.0

type CommandClient string
const (
	LocalClient       CommandClient = "local"
	LocalAsyncClient  CommandClient = "local_async"
	RunnerClient      CommandClient = "runner"
	RunnerAsyncClient CommandClient = "runner_async"
	WheelClient       CommandClient = "wheel"
	WheelAsyncClient  CommandClient = "wheel_async"
	SSHClient         CommandClient = "ssh"

type HTTPServer

type HTTPServer struct {
	Enabled         bool                    `json:"Enabled"`
	BindAddress     string                  `json:"Bind Address"`
	RunTime         int                     `json:"Run time"`
	Accepts         int                     `json:"Accepts"`
	AcceptsSec      float64                 `json:"Accepts/sec"`
	Queue           int                     `json:"Queue"`
	Threads         int                     `json:"Threads"`
	ThreadsIdle     int                     `json:"Threads Idle"`
	SocketErrors    int                     `json:"Socket Errors"`
	Requests        int                     `json:"Requests"`
	BytesRead       int                     `json:"Bytes Read"`
	BytesWritten    int                     `json:"Bytes Written"`
	WorkTime        int                     `json:"Work Time"`
	ReadThroughput  float64                 `json:"Read Throughput"`
	WriteThroughput float64                 `json:"Write Throughput"`
	WorkerThreads   map[string]WorkerThread `json:"Worker Threads"`

type Job

type Job struct {
	JID       string        `json:"jid,omitempty"`
	Function  string        `json:"Function,omitempty"`
	Arguments []interface{} `json:"Arguments,omitempty"`
	// KWArguments map[string]interface{} `json:"KWArguments,omitempty"`
	Target     interface{}          `json:"Target,omitempty"`
	TargetType TargetType           `json:"Target-Type,omitempty"`
	StartTime  saltTime             `json:"StartTime"`
	User       string               `json:"User"`
	Minions    []string             `json:"Minions,omitempty"`
	Result     map[string]jobResult `json:"Result,omitempty"`
	Error      string               `json:"Error,omitempty"`

type ListKeysReturn added in v0.3.0

type ListKeysReturn struct {
	Local           []string `json:"local"`
	Minions         []string `json:"minions"`
	MinionsPre      []string `json:"minions_pre"`
	MinionsRejected []string `json:"minions_rejected"`
	MinionsDenied   []string `json:"minions_denied"`

type LocalClientReturn added in v0.3.0

type LocalClientReturn struct {
	Jid     string      `json:"jid"`
	Ret     interface{} `json:"ret"`
	Retcode int         `json:"retcode"`

type ManageStatusReturn added in v0.3.0

type ManageStatusReturn struct {
	UP   []string `json:"up"`
	Down []string `json:"down"`

type Minion

type Minion struct {
	ID        string      `json:"id"`
	CWD       string      `json:"cwd"`
	NodeName  string      `json:"nodename"`
	MachineID string      `json:"machine_id"`
	Master    string      `json:"master"`
	ServerID  int64       `json:"server_id"`
	Localhost string      `json:"localhost"`
	Host      string      `json:"host"`
	Domain    string      `json:"domain"`
	IPGW      interface{} `json:"ip_gw"`
	IP4GW     interface{} `json:"ip4_gw"`
	IP6GW     interface{} `json:"ip6_gw"`
	DNS       struct {
		Nameservers   []string `json:"nameservers"`
		IP4Namespaces []string `json:"ip4_namespaces"`
		IP6Namespaces []string `json:"ip6_namespaces"`
		SortList      []string `json:"sortlist"`
		Domain        string   `json:"domain"`
		Search        []string `json:"search"`
		Options       []string `json:"options"`
	} `json:"dns"`
	FQDN            string              `json:"fqdn"`
	FQDNs           []string            `json:"fqdns"`
	HWAddrInterface map[string]string   `json:"hwaddr_interface"`
	IP4Interfaces   map[string][]string `json:"ip4_interfaces"`
	IP6Interfaces   map[string][]string `json:"ip6_interfaces"`
	IPInterfaces    map[string][]string `json:"ip_interfaces"`
	IPv4            []string            `json:"ipv4"`
	IPv6            []string            `json:"ipv6"`
	FQDNIP4         []string            `json:"fqdn_ip4"`
	FQDNIP6         []string            `json:"fqdn_ip6"`
	Kernel          string              `json:"kernel"`
	KernelRelease   string              `json:"kernelrelease"`
	KernelVersion   string              `json:"kernelversion"`
	KernelParams    [][]string          `json:"kernelparams"`
	LocaleInfo      struct {
		DefaultLanguage  string `json:"defaultlanguage"`
		DefaultEncoding  string `json:"defaultencoding"`
		DetectedEncoding string `json:"detectedencoding"`
		TimeZone         string `json:"timezone"`
	} `json:"locale_info"`
	NumGPUS int `json:"num_gpus"`
	GPUS    []struct {
		Vendor string `json:"vendor"`
		Model  string `json:"model"`
	} `json:"gpus"`
	NumCPUS  int      `json:"num_cpus"`
	CPUArch  string   `json:"cpuarch"`
	CPUModel string   `json:"cpu_model"`
	CPUFlags []string `json:"cpu_flags"`
	Selinux  struct {
		Enabled  bool   `json:"enabled"`
		Enforced string `json:"enforced"`
	} `json:"selinux"`
	Systemd struct {
		Version  string `json:"version"`
		Features string `json:"features"`
	} `json:"systemd"`
	Init               string              `json:"init"`
	LSBDistribID       string              `json:"lsb_distrib_id"`
	LSBDistribCodename string              `json:"lsb_distrib_codename"`
	OS                 string              `json:"os"`
	OSFullName         string              `json:"osfullname"`
	OSRelease          string              `json:"osrelease"`
	OSReleaseInfo      []int               `json:"osrelease_info"`
	OSCodename         string              `json:"oscodename"`
	OSMajorRelease     int                 `json:"osmajorrelease"`
	OSFinger           string              `json:"osfinger"`
	OSFamily           string              `json:"os_family"`
	OSArch             string              `json:"osarch"`
	MemTotal           int                 `json:"mem_total"`
	SwapTotal          int                 `json:"swap_total"`
	BiosVersion        string              `json:"biosversion"`
	BiosReleaseDate    string              `json:"biosreleasedate"`
	ProductName        string              `json:"productname"`
	Manufacturer       string              `json:"manufacturer"`
	UUID               string              `json:"uuid"`
	SerialNumber       string              `json:"serialnumber"`
	Virtual            string              `json:"virtual"`
	PS                 string              `json:"ps"`
	Path               string              `json:"path"`
	SystemPath         []string            `json:"systempath"`
	PythonExecutable   string              `json:"pythonexecutable"`
	PythonPath         []string            `json:"pythonpath"`
	PythonVersion      []interface{}       `json:"pythonversion"`
	SaltPath           string              `json:"saltpath"`
	SaltVersion        string              `json:"saltversion"`
	SaltVersionInfo    []int               `json:"saltversioninfo"`
	ZMQVersion         string              `json:"zmqversion"`
	Disks              []string            `json:"disks"`
	SSDs               []string            `json:"ssds"`
	Shell              string              `json:"shell"`
	Lvm                map[string][]string `json:"lvm"`
	MDAdm              []string            `json:"mdadm"`
	Username           string              `json:"username"`
	GroupName          string              `json:"groupname"`
	Pid                int64               `json:"pid"`
	Gid                int                 `json:"gid"`
	Uid                int                 `json:"uid"`
	ZFSSupport         bool                `json:"zfs_support"`
	ZFSFeatureFlags    bool                `json:"zfs_feature_flags"`

type Request added in v0.3.0

type Request struct {
	BytesRead      int     `json:"Bytes Read"`
	BytesWritten   int     `json:"Bytes Written"`
	ResponseStatus string  `json:"Response Status"`
	StartTime      float64 `json:"Start Time"`
	EndTime        float64 `json:"End Time"`
	Client         string  `json:"Client"`
	ProcessingTime float64 `json:"Processing Time"`
	RequestLine    string  `json:"Request-Line"`

type RunOption added in v0.3.0

type RunOption func(*commandRequest)

func WithTargetType added in v0.3.0

func WithTargetType(t TargetType) RunOption

type TMPStats

type TMPStats map[string]interface{}

type TargetType added in v0.3.0

type TargetType string
const (
	Glob       TargetType = "glob"
	Pcre       TargetType = "pcre"
	List       TargetType = "list"
	Grain      TargetType = "grain"
	GrainPcre  TargetType = "grain_pcre"
	Pillar     TargetType = "pillar"
	PillarPcre TargetType = "pillar_pcre"
	NodeGroup  TargetType = "nodegroup"
	Range      TargetType = "range"
	Compound   TargetType = "compound"
	IPCidr     TargetType = "ipcidr"

type WorkerThread added in v0.3.0

type WorkerThread struct {
	Requests        int     `json:"Requests"`
	BytesRead       int     `json:"Bytes Read"`
	BytesWritten    int     `json:"Bytes Written"`
	WorkTime        float64 `json:"Work Time"`
	ReadThroughput  float64 `json:"Read Throughput"`
	WriteThroughput float64 `json:"Write Throughput"`

Jump to

Keyboard shortcuts

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