models

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GroupHostMode  = 0
	GroupOtherMode = 1
)
View Source
const (
	InstanceStatusRunning = "running"
	InstanceStatusDone    = "done"
)
View Source
const (
	DBDriverMysql    = "mysql"
	DBDriverPostgres = "postgres"
	DBDriverSqlite   = "sqlite"
)

Variables

This section is empty.

Functions

func ClearInstance

func ClearInstance(sinceBefore time.Time, jobId int) (err error)

func DeleteCommandHistoryById

func DeleteCommandHistoryById(id int) error

func DeleteGroupById

func DeleteGroupById(id int) error

func DeleteJobById

func DeleteJobById(id int) error

func DeletePlayBookById

func DeletePlayBookById(id int) error

func DeletePrivateKeyById

func DeletePrivateKeyById(id int) error

func DeleteQuicklyCommandById

func DeleteQuicklyCommandById(id int) error

func DeleteTagById

func DeleteTagById(id int) error

func DeleteTunnelById

func DeleteTunnelById(id int) error

func ExistedGroup

func ExistedGroup(name string) bool

func ExistedHost

func ExistedHost(name string, addr string) bool

func ExistedPlayBook

func ExistedPlayBook(name string, steps string) bool

func ExistedPrivateKey

func ExistedPrivateKey(keyFile string) bool

func ExistedTag

func ExistedTag(name string) bool

func ExistedTunnel

func ExistedTunnel(id int) bool

func GetPaginateQuery

func GetPaginateQuery[T *TaskInstance | *[]*TaskInstance | *Host | *[]*Host](
	instance T, pageSize, page int, params map[string]interface{}, preload bool) (int64, error)

func InitModels

func InitModels(dsn, dbName, user, pass, driver, _dataPath string) error

func InsertOrUpdateCommandHistory

func InsertOrUpdateCommandHistory(cmd string) error

func RefreshJob

func RefreshJob(job *Job) error

RefreshJob 刷新job的状态

func RefreshTunnel

func RefreshTunnel(tunnel *Tunnel) error

func UpdateHostStatus

func UpdateHostStatus(host *Host) error

func UpdateTaskInstanceLogTrace

func UpdateTaskInstanceLogTrace(instance *TaskInstance, logPath string) error

Types

type CommandHistory

type CommandHistory struct {
	Id    int    `json:"id"`
	Cmd   string `gorm:"not null;index:idx_cmd;unique" json:"cmd"`
	Times uint32 `gorm:"index:idx_times" json:"times"`
}

func SearchCommandHistory

func SearchCommandHistory(keyword string, limit int) ([]*CommandHistory, error)

type DataBase

type DataBase struct {
	*gorm.DB
	// contains filtered or unexported fields
}

func (*DataBase) Lock

func (d *DataBase) Lock()

func (*DataBase) Unlock

func (d *DataBase) Unlock()

type Group

type Group struct {
	Id     int    `json:"id"`
	Name   string `gorm:"size:256;not null" json:"name"`
	Mode   int    `gorm:"default:0;not null" json:"mode"` //0.主机模式, 1.其他匹配模式主机不生效
	Host   []Host `json:"-"`
	Params string `json:"params"`
}

func GetAllGroup

func GetAllGroup() ([]*Group, error)

func GetGroupById

func GetGroupById(id int) (*Group, error)

func GetGroupByName

func GetGroupByName(name string) (*Group, error)

func InsertGroup

func InsertGroup(name string, params string, mode int) (*Group, error)

func UpdateGroup

func UpdateGroup(id int, name string, params string, mode int) (*Group, error)

type Host

type Host struct {
	Id           int        `json:"id"`
	Name         string     `gorm:"size:128;not null" json:"name"`
	User         string     `gorm:"size:128;not null" json:"user"`
	Addr         string     `gorm:"size:128;not null" json:"addr"`
	Port         int        `gorm:"default:22" json:"port"`
	VNCPort      int        `gorm:"default:5900" json:"vnc_port"`
	PassWord     string     `gorm:"size:128;not null" json:"-"`
	Status       bool       `gorm:"default:false" json:"status"`
	PrivateKey   PrivateKey `gorm:"constraint:OnDelete:SET NULL;" json:"-"`
	PrivateKeyID int        `json:"private_key_id"`
	GroupId      int        `json:"group_id"`
	Group        Group      `gorm:"constraint:OnDelete:SET NULL;" json:"group"`
	Tags         []Tag      `gorm:"many2many:host_tag" json:"tags"`
	Tunnels      []Tunnel   `gorm:"constraint:OnDelete:CASCADE;" json:"tunnels"`
}

Host Struct

func DeleteHostById

func DeleteHostById(id int) (*Host, error)

func GetAllHost

func GetAllHost() ([]*Host, error)

func GetAllHostWithOutPreload

func GetAllHostWithOutPreload() ([]*Host, error)

func GetHostByAddr

func GetHostByAddr(addr string) ([]*Host, error)

func GetHostByGlob

func GetHostByGlob(glob string) ([]*Host, error)

func GetHostById

func GetHostById(id int) (*Host, error)

func GetHostByIdWithPreload

func GetHostByIdWithPreload(id int) (*Host, error)

func GetHostByReg

func GetHostByReg(regStr string) ([]*Host, error)

func GetHostsByGroup

func GetHostsByGroup(group *Group) ([]*Host, error)

func GetHostsByTag

func GetHostsByTag(tag *Tag) ([]*Host, error)

func InsertHost

func InsertHost(hostname string, user string, addr string, port int, password string, groupId int, tags []int, privateKeyID, vncPort int) (*Host, error)

func ParseHostList

func ParseHostList(pType string, id int) ([]*Host, error)

func UpdateHost

func UpdateHost(id int, hostname string, user string, addr string, port int, password string, groupId int, tags []int, privateKeyID, vncPort int) (*Host, error)

type HostExport

type HostExport struct {
	Name        string   `csv:"name"`
	User        string   `csv:"user"`
	Addr        string   `csv:"addr"`
	Port        int      `csv:"port"`
	VNCPort     int      `csv:"vnc_port"`
	PassWord    string   `csv:"password"`
	Group       string   `csv:"group"`
	GroupParams string   `csv:"group_params"`
	Tags        []string `csv:"tags"`
	KeyFile     string   `csv:"key_file"`
	KeyName     string   `csv:"key_name"`
	KeyPhrase   string   `csv:"key_phrase"`
}

type Job

type Job struct {
	Id          int            `json:"id"`
	Name        string         `gorm:"size:128" json:"name"`
	Type        string         `gorm:"size:32;not null" json:"type"`
	Spec        string         `gorm:"size:128" json:"spec"`
	Cmd         string         `gorm:"size:512" json:"cmd"`
	CmdId       int            `json:"cmd_id"`
	CmdType     string         `gorm:"size:128" json:"cmd_type"`
	Status      string         `gorm:"size:64;default: ready" json:"status"`
	ExecuteID   int            `json:"execute_id"`
	ExecuteType string         `gorm:"size:64" json:"execute_type"`
	Instances   []TaskInstance `gorm:"constraint:OnDelete:CASCADE;" json:"instances"`
}

func GetAllJob

func GetAllJob() ([]*Job, error)

func GetJobById

func GetJobById(id int) (*Job, error)

func InsertJob

func InsertJob(name, t, spec, cmd string, executeID, cmdId int, executeType, cmdType string) (*Job, error)

func UpdateJob

func UpdateJob(id int, name, t, spec, cmd, cmdType string, cmdId, executeId int, executeType string) (*Job, error)

func UpdateJobStatus

func UpdateJobStatus(id int, status string) (*Job, error)

type PlayBook

type PlayBook struct {
	Id       int     `json:"id"`
	Name     string  `gorm:"size:256" json:"name"`
	Steps    string  `gorm:"type:text" json:"-"`
	StepsObj []*Step `gorm:"-" json:"steps"`
}

func GetAllPlayBook

func GetAllPlayBook() ([]*PlayBook, error)

func GetPlayBookById

func GetPlayBookById(id int) (*PlayBook, error)

func InsertPlayBook

func InsertPlayBook(name, steps string) (*PlayBook, error)

func UpdatePlayBook

func UpdatePlayBook(id int, name string, steps string) (*PlayBook, error)

func (*PlayBook) GetStepsObj

func (p *PlayBook) GetStepsObj() error

type PrivateKey

type PrivateKey struct {
	Id         int    `json:"id"`
	Name       string `gorm:"size:128;not null" json:"name"`
	KeyFile    string `gorm:"type:text" json:"-"`
	Passphrase string `json:"-"`
}

func GetAllPrivateKey

func GetAllPrivateKey() ([]*PrivateKey, error)

func GetPrivateKeyById

func GetPrivateKeyById(id int) (*PrivateKey, error)

func GetPrivateKeyByName

func GetPrivateKeyByName(name string) (*PrivateKey, error)

func InsertPrivateKey

func InsertPrivateKey(name, keyFile, passphrase string) (*PrivateKey, error)

func UpdatePrivateKey

func UpdatePrivateKey(id int, name, keyFile, passphrase string) (*PrivateKey, error)

type QuicklyCommand

type QuicklyCommand struct {
	Id       int    `json:"id"`
	Name     string `gorm:"not null;unique" json:"name"`
	Cmd      string `gorm:"not null;" json:"cmd"`
	AppendCR bool   `json:"append_cr"` // 是否追加CR
}

func GetAllQuicklyCommand

func GetAllQuicklyCommand() ([]*QuicklyCommand, error)

func GetQuicklyCommandById

func GetQuicklyCommandById(id int) (*QuicklyCommand, error)

func InsertQuicklyCommand

func InsertQuicklyCommand(name, cmd string, appendCR bool) (*QuicklyCommand, error)

func UpdateQuicklyCommand

func UpdateQuicklyCommand(id int, name, cmd string, appendCR bool) (*QuicklyCommand, error)

type Step

type Step struct {
	Seq    int    `json:"seq"`
	Type   string `json:"type"`
	Name   string `json:"name"`
	Caches string `json:"caches,omitempty"`
	Params string `json:"params"`
}

func (*Step) GetCaches

func (s *Step) GetCaches() []string

type StepSlice

type StepSlice []Step

func (StepSlice) Len

func (s StepSlice) Len() int

func (StepSlice) Less

func (s StepSlice) Less(i, j int) bool

func (StepSlice) Swap

func (s StepSlice) Swap(i, j int)

type Tag

type Tag struct {
	Id    int    `json:"id"`
	Name  string `gorm:"size:100;not null;unique" json:"name"`
	Hosts []Host `gorm:"many2many:host_tag;" json:"-"`
}

func GetAllTag

func GetAllTag() ([]*Tag, error)

func GetTagById

func GetTagById(id int) (*Tag, error)

func GetTagByName

func GetTagByName(name string) (*Tag, error)

func InsertTag

func InsertTag(name string) (*Tag, error)

func UpdateTag

func UpdateTag(id int, name string) (*Tag, error)

type TaskInstance

type TaskInstance struct {
	Id        int       `json:"id"`
	Uid       string    `json:"uid"`
	JobId     int       `json:"job_id"`
	Job       Job       `json:"-"`
	StartTime time.Time `gorm:"index" json:"start_time"`
	EndTime   time.Time `json:"end_time"`
	Status    string    `gorm:"size:64;default: ready" json:"status"`
	LogPath   string    `gorm:"size:256" json:"log_path"`
	LogData   string    `gorm:"type:text" json:"log_data"`
}

func GetTaskInstanceById

func GetTaskInstanceById(id int) (*TaskInstance, error)

func InsertTaskInstance

func InsertTaskInstance(jobId int, start time.Time) (*TaskInstance, error)

func (*TaskInstance) Done

func (ti *TaskInstance) Done() error

func (*TaskInstance) GenerateLogPath

func (ti *TaskInstance) GenerateLogPath(tmpPath string) string

func (*TaskInstance) UpdateStatus

func (ti *TaskInstance) UpdateStatus(status string) error

type Tunnel

type Tunnel struct {
	Id          int    `json:"id"`
	Mode        string `gorm:"size:64" json:"mode"`
	Source      string `gorm:"size:128;not null" json:"source"`
	Destination string `gorm:"size:128;not null" json:"destination"`
	Status      int    `gorm:"default:0" json:"status"`
	ErrorMsg    string `gorm:"size:512" json:"error_msg"`
	HostId      int    `json:"host_id"`
	Host        Host   `json:"-"`
}

func GetAllTunnel

func GetAllTunnel() ([]*Tunnel, error)

func GetTunnelById

func GetTunnelById(id int) (*Tunnel, error)

func GetTunnelsByHostId

func GetTunnelsByHostId(id int) ([]*Tunnel, error)

func InsertTunnel

func InsertTunnel(mode, src, dest string, host *Host) (*Tunnel, error)

func UpdateTunnel

func UpdateTunnel(id int, mode, src, dest string) (*Tunnel, error)

func UpdateTunnelStatus

func UpdateTunnelStatus(id int, status bool, msg string) (*Tunnel, error)

Jump to

Keyboard shortcuts

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