common

package
v0.0.0-...-e4c7a12 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 29 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DEFAULT     = "default"
	TABLE       = "table"
	TABLE_LIGHT = "table-light"
	JSON        = "json"
	YAML        = "yaml"
)

Variables

View Source
var (
	CONF      ConfGroup
	CONF_FILE string
)
View Source
var (
	FORMAT_TABLE_LIGHT        = "table-light"
	FORMAT_TABLE              = "table"
	DEFAULT_TOKEN_EXPIRE_TIME = 60 * 30
)
View Source
var (
	DEFAULT_GUEST_CONNECT_TIMEOUT = 60 * 5
	DEFAULT_QGA_CONNECT_TIMEOUT   = 60 * 10
	DEFAULT_PING_INTERVAL         = float32(1.0)
)
View Source
var CONF_FILES = []string{
	"etc/skyman.yaml",
	"/etc/skyman/skyman.yaml",
}
View Source
var (
	STYLE_LIGHT = "light"
)

Functions

func ClientWithRegion

func ClientWithRegion(region string) *openstack.Openstack

func DefaultClient

func DefaultClient() *openstack.Openstack

func GetOutputFormats

func GetOutputFormats() []string

func GetYaml

func GetYaml(v interface{}) (string, error)

func LastItems

func LastItems(items []interface{}, last int) []interface{}

func LoadConfig

func LoadConfig(configFile string) error

func MarshalModel

func MarshalModel(obj interface{}, indent bool) string

func NewCommand

func NewCommand[T any](command Cli[T]) *cobra.Command

func PathExtSplit

func PathExtSplit(file string) (string, string)

func PrintAgents

func PrintAgents(items []neutron.Agent, long bool)

func PrintAggregate

func PrintAggregate(item nova.Aggregate)

func PrintAggregates

func PrintAggregates(items []nova.Aggregate, long bool)

func PrintBackup

func PrintBackup(backup cinder.Backup)

func PrintBackups

func PrintBackups(items []cinder.Backup, long bool)

func PrintEndpoint

func PrintEndpoint(item keystone.Endpoint, serviceMap map[string]keystone.Service)

func PrintEndpoints

func PrintEndpoints(items []keystone.Endpoint, long bool, serviceMap map[string]keystone.Service)

func PrintImage

func PrintImage(item glance.Image, human bool)

func PrintImages

func PrintImages(items []glance.Image, long bool)

func PrintItem

func PrintItem[T any](fields, moreFields []datatable.Field[T], item T, opt TableOptions)

func PrintItems

func PrintItems[T any](columns, moreColumns []datatable.Column[T], items []T, opt TableOptions)

func PrintKeypair

func PrintKeypair(item nova.Keypair)

func PrintNetwork

func PrintNetwork(item neutron.Network)

func PrintNetworks

func PrintNetworks(items []neutron.Network, long bool)

func PrintPort

func PrintPort(item neutron.Port)

func PrintPorts

func PrintPorts(items []neutron.Port, long bool)

func PrintPrettyItemTable

func PrintPrettyItemTable(table PrettyItemTable) string

func PrintPrettyTable

func PrintPrettyTable(table PrettyTable, long bool) string

func PrintPrettyTableFormat

func PrintPrettyTableFormat(table PrettyTable, long bool, format string) string

func PrintProject

func PrintProject(item model.Project)

func PrintProjects

func PrintProjects(items []model.Project, long bool)

func PrintQosPolicy

func PrintQosPolicy(item neutron.QosPolicy)

func PrintQosPolicyRule

func PrintQosPolicyRule(item neutron.QosRule)

func PrintQosPolicyRules

func PrintQosPolicyRules(items []neutron.QosRule, long bool)

func PrintQosPolicys

func PrintQosPolicys(items []neutron.QosPolicy, long bool)

func PrintQuotaSet

func PrintQuotaSet(item nova.QuotaSet, more bool)

func PrintRegions

func PrintRegions(items []keystone.Region, long bool)

keystone

func PrintRouter

func PrintRouter(item neutron.Router)

func PrintRouters

func PrintRouters(items []neutron.Router, long bool)

func PrintSecurityGroup

func PrintSecurityGroup(item neutron.SecurityGroup)

func PrintSecurityGroupRule

func PrintSecurityGroupRule(item neutron.SecurityGroupRule)

func PrintSecurityGroupRules

func PrintSecurityGroupRules(items []neutron.SecurityGroupRule, long bool)

func PrintSecurityGroups

func PrintSecurityGroups(items []neutron.SecurityGroup, long bool)

func PrintServers

func PrintServers(items []nova.Server, long bool, c *openstack.Openstack, sortDsc bool)

nova

func PrintService

func PrintService(item keystone.Service)

func PrintServices

func PrintServices(items []keystone.Service, long bool)

func PrintSnapshot

func PrintSnapshot(snapshot cinder.Snapshot)

func PrintSnapshots

func PrintSnapshots(items []cinder.Snapshot, long bool)

func PrintSubnet

func PrintSubnet(item neutron.Subnet)

func PrintSubnets

func PrintSubnets(items []neutron.Subnet, long bool)

func PrintUser

func PrintUser(item model.User)

func PrintUsers

func PrintUsers(items []model.User, long bool)

func PrintVolume

func PrintVolume(volume cinder.Volume)

func PrintVolumeServices

func PrintVolumeServices(items []cinder.Service, long bool)

func PrintVolumeType

func PrintVolumeType(volumeType cinder.VolumeType)

func PrintVolumeTypes

func PrintVolumeTypes(items []cinder.VolumeType, long bool)

func PrintVolumes

func PrintVolumes(items []cinder.Volume, long bool)

func RegistryLongFlag

func RegistryLongFlag(cmd ...*cobra.Command)

func RepeatFunc

func RepeatFunc(nums int, function func())

func SplitKeyValue

func SplitKeyValue(kv string) ([]string, error)

func ValidIpv4

func ValidIpv4(cidr string, maxMask ...int) bool

Types

type Api

type Api struct {
	Version string `yaml:"version"`
}

type Auth

type Auth struct {
	Url             string          `yaml:"url"`
	Region          keystone.Region `yaml:"region"`
	User            model.User      `yaml:"user"`
	Project         model.Project   `yaml:"project"`
	TokenExpireTime int             `yaml:"tokenExpireTime"`
}

type Case

type Case struct {
	Name    string     `yaml:"name"`
	Actions string     `yaml:"actions"`
	Skip    bool       `yaml:"skip"`
	Config  CaseConfig `yaml:"config"`
}

type CaseConfig

type CaseConfig struct {
	Flavors        []string `yaml:"flavors"`
	Images         []string `yaml:"images"`
	Workers        int      `yaml:"workers"`
	ActionInterval int      `yaml:"actionInterval"`

	DeleteIfError    bool   `yaml:"deleteIfError"`
	DeleteIfSuccess  bool   `yaml:"deleteIfSuccess"`
	AvailabilityZone string `yaml:"availabilityZone"`
	BootFromVolume   bool   `yaml:"bootFromVolume"`
	BootVolumeSize   uint16 `yaml:"bootVolumeSize"`
	BootVolumeType   string `yaml:"bootVolumeType"`

	BootWithSG string   `yaml:"bootWithSG"`
	Networks   []string `yaml:"networks"`

	VolumeType string `yaml:"volumeType"`
	VolumeSize int    `yaml:"volumeSize"`

	InterfaceHotplug InterfaceHotplug   `yaml:"interfaceHotplug"`
	VolumeHotplug    VolumeHotplug      `yaml:"volumeHotplug"`
	QGAChecker       QGAChecker         `yaml:"qgaChecker"`
	LiveMigrate      LiveMigrateOptions `yaml:"liveMigrate"`
	RevertSystem     RevertSystemConf   `yaml:"revertSystem"`
}

func NewActionCaseConfig

func NewActionCaseConfig(config CaseConfig, def CaseConfig) CaseConfig

type Cli

type Cli[T any] struct {
	Use           string
	Short         string
	ArgNames      []string
	Flags         func(fs *pflag.FlagSet) T
	FlagsRequired []string
	Run           func(args map[string]string, flags T)
}

type Column

type Column struct {
	Name string
	Text string
	// 只有 Table.Style 等于 light 是才会生效
	AutoColor  bool
	ForceColor bool
	Slot       func(item interface{}) interface{}
	SlotColumn func(item interface{}, column Column) interface{}
	Sort       bool
	SortMode   table.SortMode
	Filters    []string
	Marshal    bool
	WidthMax   int
	Align      text.Align
}

type ConfGroup

type ConfGroup struct {
	Debug               bool   `yaml:"debug"`
	Format              string `yaml:"format"`
	Language            string `yaml:"language"`
	HttpTimeoutSecond   int    `yaml:"httpTimeoutSecond"`
	RetryWaitTimeSecond int    `yaml:"retryWaitTimeSecond"`
	RetryCount          int    `yaml:"retryCount"`
	LogFile             string `yaml:"logFile"`
	EnableLogColor      bool   `yaml:"enableLogColor"`
	BarChar             string `yaml:"barchar"`

	Auth     Auth        `yaml:"auth"`
	Identity Identity    `yaml:"identity"`
	Neutron  NeutronConf `yaml:"neutron"`
}

func DefaultConfGroup

func DefaultConfGroup() ConfGroup

type DataRender

type DataRender[T any] interface {
	SetStyle(style table.Style)
	GetJson() (string, error)
	GetYaml() (string, error)
	Print(more ...bool)
}

type Identity

type Identity struct {
	Api Api `yaml:"api"`
}

type InterfaceHotplug

type InterfaceHotplug struct {
	Nums int `yaml:"nums"`
}

type LiveMigrateOptions

type LiveMigrateOptions struct {
	PingEnabled  bool    `yaml:"pingEnabled"`
	PingInterval float32 `yaml:"pingInterval"`
	MaxLoss      int     `yaml:"maxLoss"`
}

type NeutronConf

type NeutronConf struct {
	Endpoint string `yaml:"endpoint"`
}

type PrettyItemTable

type PrettyItemTable struct {
	ShortFields     []Column
	LongFields      []Column
	Item            interface{}
	Title           string
	Style           string
	Number2WidthMax int
}

func (PrettyItemTable) Print

func (pt PrettyItemTable) Print(long bool) string

func (PrettyItemTable) PrintJson

func (dt PrettyItemTable) PrintJson() string

func (PrettyItemTable) PrintYaml

func (dt PrettyItemTable) PrintYaml() string

type PrettyTable

type PrettyTable struct {
	Title             string
	ShortColumns      []Column
	LongColumns       []Column
	Items             []interface{}
	ColumnConfigs     []table.ColumnConfig
	Style             string
	StyleSeparateRows bool
	HideTotalItems    bool

	Filters       map[string]string
	Search        string
	DisplayFields []string
	// contains filtered or unexported fields
}

func (*PrettyTable) AddDisplayFields

func (pt *PrettyTable) AddDisplayFields(fields ...string)

func (*PrettyTable) AddItems

func (pt *PrettyTable) AddItems(items interface{})

func (*PrettyTable) CleanItems

func (pt *PrettyTable) CleanItems()

func (PrettyTable) GetLongColumnIndex

func (pt PrettyTable) GetLongColumnIndex(column string) int

func (PrettyTable) GetShortColumnIndex

func (pt PrettyTable) GetShortColumnIndex(column string) int

func (PrettyTable) Print

func (pt PrettyTable) Print(long bool) string

func (PrettyTable) PrintJson

func (pt PrettyTable) PrintJson() string

func (PrettyTable) PrintYaml

func (pt PrettyTable) PrintYaml() string

func (*PrettyTable) ReInit

func (pt *PrettyTable) ReInit()

func (PrettyTable) RenderToJson

func (pt PrettyTable) RenderToJson() (string, error)

func (PrettyTable) RenderToTable

func (pt PrettyTable) RenderToTable(long bool) string

func (PrettyTable) RenderToYaml

func (pt PrettyTable) RenderToYaml() (string, error)

func (*PrettyTable) SetStyleLight

func (pt *PrettyTable) SetStyleLight()

type QGAChecker

type QGAChecker struct {
	Enabled             bool `yaml:"enabled"`
	GuestConnectTimeout int  `yaml:"guestConnectTimeout"`
	QgaConnectTimeout   int  `yaml:"qgaConnectTimeout"`
}

type RevertSystemConf

type RevertSystemConf struct {
	RepeatEveryTime int `yaml:"repeatEveryTime"`
}

type ServerActionsTestConf

type ServerActionsTestConf struct {
	Web     Web        `yaml:"web"`
	Default CaseConfig `yaml:"default"`
	Cases   []Case     `yaml:"cases"`
}

func LoadTaskConfig

func LoadTaskConfig(taskFile string) (*ServerActionsTestConf, error)

type TableOptions

type TableOptions struct {
	SeparateRows        bool
	More                bool
	ColumnConfigs       []table.ColumnConfig
	SortBy              []table.SortBy
	ValueColumnMaxWidth int
}

type VolumeHotplug

type VolumeHotplug struct {
	Nums int `yaml:"nums"`
}

type Web

type Web struct {
	Port int `yaml:"port"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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