service

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TargetTypeVpc targetType = iota
	TargetTypeSwitch
	TargetTypeSecurityGroup
	TargetTypeNetwork
	TargetTypeAccount
	TargetTypeInstanceType

	DefaultRegion        = "cn-qingdao"
	DefaultRegionHuaWei  = "cn-north-4"
	DefaultRegionTencent = "ap-beijing"
	DefaultRegionBaidu   = "bj"
	DefaultRegionAws     = "cn-north-1"
)
View Source
const (
	DirectionIn  = "ingress"
	DirectionOut = "egress"
)

Variables

This section is empty.

Functions

func AddSecurityGroupRule

func AddSecurityGroupRule(ctx context.Context, req AddSecurityGroupRuleRequest) (string, error)

func BatchCreateInstanceType

func BatchCreateInstanceType(ctx context.Context, inss []model.InstanceType) error

func CheckAccountValid

func CheckAccountValid(ak, sk, provider string) error

func CheckClusterParam added in v0.5.0

func CheckClusterParam(clusterInfo *types.ClusterInfo) error

func CheckInstanceConnectable added in v0.4.0

func CheckInstanceConnectable(instances []model.CustomClusterInstance) response.CheckInstanceConnectableResponse

CheckInstanceConnectable 检测机器连通性

func CleanClusterUnusedInstances

func CleanClusterUnusedInstances(clusterInfo *types.ClusterInfo) (int, error)

CleanClusterUnusedInstances 清除由于系统异常导致的云厂商中残留的机器

func ConvertToClusterInfo

func ConvertToClusterInfo(m *model.Cluster, tags []model.ClusterTag) (*types.ClusterInfo, error)

ConvertToClusterInfo 将cluster,和tags转换为一个Cloud clusterInfo

func CountUser

func CountUser(ctx context.Context, orgId int64) (int64, error)

func CreateCloudAccount

func CreateCloudAccount(ctx context.Context, accountName, provider, ak, sk string, orgId int64, username string) error

func CreateCluster4Test

func CreateCluster4Test(clusterName string) error

func CreateClusterTags

func CreateClusterTags(tags []model.ClusterTag) error

func CreateClusterWithTagsAndInstances added in v0.4.0

func CreateClusterWithTagsAndInstances(ctx context.Context, cluster *model.Cluster, tags []*model.ClusterTag, instances []model.Instance, username string, uid int64) error

func CreateExpandTask

func CreateExpandTask(ctx context.Context, clusterName string, count int, taskName string, uid int64) (int64, error)

func CreateKeyPair added in v0.7.0

func CreateKeyPair(ctx context.Context, ak, provider, regionId, keyPairName string) error

func CreateKeyPairByPrivateKey added in v0.7.0

func CreateKeyPairByPrivateKey(ctx context.Context, provider, regionId, keyPairId, keyPairName, privateKey string) (*model.KeyPair, error)

func CreateOrg

func CreateOrg(ctx context.Context, orgName, username, password, createBy string) error

func CreateSecurityGroup

func CreateSecurityGroup(ctx context.Context, req CreateSecurityGroupRequest) (securityGroupId string, err error)

func CreateShrinkAllTask added in v0.1.5

func CreateShrinkAllTask(ctx context.Context, clusterName, taskName string, uid int64) (int64, error)

func CreateShrinkTask

func CreateShrinkTask(ctx context.Context, clusterName string, count int, ips string, taskName string, uid int64) (int64, error)

func CreateSwitch

func CreateSwitch(ctx context.Context, req CreateSwitchRequest) (switchId string, err error)

func CreateUser

func CreateUser(ctx context.Context, orgId int64, username, password, createBy string, userType int8) error

func CreateVPC

func CreateVPC(ctx context.Context, req CreateVPCRequest) (vpcId string, err error)

func DecryptAccount added in v0.2.1

func DecryptAccount(pepper, salt, key, encrypted string) (string, error)

func DecryptAccounts added in v0.2.1

func DecryptAccounts(accounts []*model.Account)

DecryptAccounts same as decryptAccounts(accounts, false).

func DeleteCloudAccount

func DeleteCloudAccount(ctx context.Context, ids []int64, orgId int64) error

func DeleteClusterTags added in v0.1.5

func DeleteClusterTags(tags []model.ClusterTag) error

func DeleteClusters

func DeleteClusters(ctx context.Context, ids []int64, orgId int64) error

func DescribeSecurityGroups added in v0.7.0

func DescribeSecurityGroups(provider, ak, regionId, vpcId string) ([]cloud.SecurityGroup, error)

func DoesSecurityGroupBelongsVpc added in v0.7.0

func DoesSecurityGroupBelongsVpc(provider string) bool

func EditCloudAccount

func EditCloudAccount(ctx context.Context, id int64, accountName, provider, username string) error

func EditCluster

func EditCluster(cluster *model.Cluster, username string) error

func EditClusterTags added in v0.1.5

func EditClusterTags(tags []model.ClusterTag) error

func EditOrg

func EditOrg(ctx context.Context, orgId int64, orgName string) error

func EncryptAccount added in v0.2.1

func EncryptAccount(pepper, salt, key, text string) (string, error)

func ExistAdmin added in v0.5.1

func ExistAdmin(ctx context.Context, usernames []string) (bool, error)

func Expand

func Expand(clusterInfo *types.ClusterInfo, tags []cloud.Tag, num int) (instanceIds []string, err error)

func ExpandCluster

func ExpandCluster(c *types.ClusterInfo, num int, taskId int64) ([]string, []string, error)

func ExpandInDeed added in v0.5.0

func ExpandInDeed(c *types.ClusterInfo, num int, taskId int64) ([]string, error)

func ExtractLogs added in v0.4.0

func ExtractLogs(ctx context.Context, conds model.ExtractCondition) ([]model.OperationLog, int64, error)

func GetAccount added in v0.1.5

func GetAccount(provider, accountKey string) (*model.Account, error)

GetAccount query account info by provider and accountKey

func GetAccountSecretByAccountKey added in v0.2.1

func GetAccountSecretByAccountKey(ctx context.Context, ak string) (string, error)

GetAccountSecretByAccountKey get sk(decrypt) by ak

func GetAccounts

func GetAccounts(provider, accountName, accountKey string, pageNum, pageSize int) ([]*model.Account, int64, error)

GetAccounts search accounts by condition.

func GetAccountsByOrgId

func GetAccountsByOrgId(orgId int64) (*types.OrgKeys, error)

func GetAksByOrgAk added in v0.4.0

func GetAksByOrgAk(ctx context.Context, orgId int64, ak string) ([]string, error)

func GetAksByOrgId

func GetAksByOrgId(orgId int64) ([]string, error)

func GetAllCustomInstanceInCluster added in v0.4.0

func GetAllCustomInstanceInCluster(ctx context.Context, user *authorization.CustomClaims, clusterName string) ([]model.Instance, error)

GetAllCustomInstanceInCluster 获取自定义集群中所有节点实例

func GetAllInstanceInCluster added in v0.2.1

func GetAllInstanceInCluster(ctx context.Context, user *authorization.CustomClaims, clusterName string) ([]model.Instance, error)

GetAllInstanceInCluster 获取集群中所有节点实例

func GetBridgxUnusedCluster added in v0.2.1

func GetBridgxUnusedCluster(ctx context.Context, user *authorization.CustomClaims, pageSize, pageNum int) ([]*gf_cluster.BridgxUnusedCluster, int, error)

GetBridgxUnusedCluster 获取所有没有被占用的集群

func GetCloudInstancesByClusterName

func GetCloudInstancesByClusterName(clusterInfo *types.ClusterInfo) (instances []cloud.Instance, err error)

func GetClusterAccount added in v0.2.1

func GetClusterAccount(cluster *types.ClusterInfo) (*model.Account, error)

GetClusterAccount 根据集群获取Account信息

func GetClusterById

func GetClusterById(ctx context.Context, Id int64) (*model.Cluster, error)

func GetClusterByName

func GetClusterByName(ctx context.Context, name string) (*model.Cluster, error)

func GetClusterCount

func GetClusterCount(ctx context.Context, accountKeys []string) (count int64, err error)

func GetClusterInfo added in v0.2.1

func GetClusterInfo(ctx context.Context, clusterName string) (*types.ClusterInfo, error)

GetClusterInfo 根据集群名称获取集群名称

func GetClusterTags added in v0.1.5

func GetClusterTags(ctx context.Context, clusterName, tagKey string, pageNum, pageSize int) ([]model.ClusterTag, int64, error)

func GetClusterTagsByClusterName

func GetClusterTagsByClusterName(ctx context.Context, name string) ([]model.ClusterTag, error)

func GetClusterTagsByClusters added in v0.1.5

func GetClusterTagsByClusters(ctx context.Context, clusters []model.Cluster) (map[string]map[string]string, error)

func GetClustersByNames

func GetClustersByNames(ctx context.Context, names []string) ([]model.Cluster, error)

func GetClustersByTags added in v0.1.5

func GetClustersByTags(ctx context.Context, tags map[string]string, pageSize, pageNum int) ([]model.Cluster, int64, error)

func GetDefaultAccount

func GetDefaultAccount(provider string) (*types.OrgKeys, error)

func GetEnabledClusterNamesByAccount

func GetEnabledClusterNamesByAccount(ctx context.Context, accountKey string) ([]string, error)

func GetEnabledClusterNamesByCond

func GetEnabledClusterNamesByCond(ctx context.Context, provider, clusterName string, aks []string, strict bool) ([]string, error)

func GetImages

func GetImages(ctx context.Context, req GetImagesRequest) ([]cloud.Image, error)

func GetInstance

func GetInstance(ctx context.Context, instanceId string) (*model.Instance, error)

func GetInstanceByTag

func GetInstanceByTag(c *types.ClusterInfo, tags []cloud.Tag) (instances []cloud.Instance, err error)

func GetInstanceCount

func GetInstanceCount(ctx context.Context, accountKeys []string, clusterName string) (int64, error)

func GetInstanceCountByCluster

func GetInstanceCountByCluster(ctx context.Context, clusters []model.Cluster) map[string]int64

func GetInstanceUsageStatistics

func GetInstanceUsageStatistics(ctx context.Context, clusterName string, specifyDay time.Time, orgId int64, pageNum, pageSize int) ([]model.Instance, int64, error)

func GetInstanceUsageTotal

func GetInstanceUsageTotal(ctx context.Context, clusterName string, specifyDay time.Time, orgId int64) (int64, error)

func GetInstances

func GetInstances(clusterInfo *types.ClusterInfo, instancesIds []string) (instances []cloud.Instance, err error)

func GetInstancesByAccount

func GetInstancesByAccount(ctx context.Context, accountKey string, pageNum, pageSize int) (instances []model.Instance, total int64, err error)

func GetInstancesByAccounts

func GetInstancesByAccounts(ctx context.Context, cond GetInstancesCond) (clusterNames []string, instances []model.Instance, total int64, err error)

func GetInstancesByCond

func GetInstancesByCond(ctx context.Context, cond InstancesSearchCond) (ret []model.Instance, total int64, err error)

func GetInstancesByTaskId

func GetInstancesByTaskId(ctx context.Context, taskId string, taskAction string) ([]model.Instance, error)

func GetKeyPair added in v0.7.0

func GetKeyPair(ctx context.Context, keyId int64) (*model.KeyPair, error)

func GetKeyPairByKeyIds added in v0.7.0

func GetKeyPairByKeyIds(ctx context.Context, keyIds []int64) (map[int64]model.KeyPair, error)

func GetOrgInfoById

func GetOrgInfoById(ctx context.Context, id int64) (*model.Org, error)

func GetOrgKeysByAk

func GetOrgKeysByAk(ctx context.Context, ak string) (*types.OrgKeys, error)

func GetOrgList

func GetOrgList(ctx context.Context) (ret []model.Org, err error)

func GetRegions

func GetRegions(ctx context.Context, req GetRegionsRequest) ([]cloud.Region, error)

func GetStandardClusterNamesByAccounts added in v0.4.0

func GetStandardClusterNamesByAccounts(ctx context.Context, accountKeys []string) ([]string, error)

func GetTask

func GetTask(ctx context.Context, taskId string) (*model.Task, error)

func GetTaskCount

func GetTaskCount(ctx context.Context, accountKeys []string) (int64, error)

func GetTaskListByAk

func GetTaskListByAk(ctx context.Context, accountKey string, pageNum, pageSize int) ([]model.Task, int64, error)

func GetTaskListByAks

func GetTaskListByAks(ctx context.Context, accountKeys []string, pageNum, pageSize int) ([]model.Task, int64, error)

func GetTaskListByCond

func GetTaskListByCond(ctx context.Context, accountKey []string, cond model.TaskSearchCond) ([]model.Task, int64, error)

func GetUserById

func GetUserById(ctx context.Context, uid int64) (*model.User, error)

func GetUserList

func GetUserList(ctx context.Context, orgId int64, pageNum, pageSize int) ([]model.User, int64, error)

func GetVPCFromCloud

func GetVPCFromCloud(ctx context.Context, req GetVPCFromCloudRequest) (vpc cloud.VPC, err error)

func GetZones

func GetZones(ctx context.Context, req GetZonesRequest) ([]cloud.Zone, error)

func ImportKeyPair added in v0.7.0

func ImportKeyPair(ctx context.Context, ak, provider, regionId, keyPairName, publicKey, privateKey string) error

func Init

func Init(workerCount int)

func IsInstanceReady added in v0.7.0

func IsInstanceReady(instance cloud.Instance, needPublicIp bool) bool

func IsNeedAkSk added in v0.4.0

func IsNeedAkSk(clusterInfo *types.ClusterInfo) bool

IsNeedAkSk 标准类型集群存在AK的自定义类型集群,需要获取AKSK信息;自定义类型集群不区分是否配置aksk

func ListClusters

func ListClusters(ctx context.Context, cond model.ClusterSearchCond) ([]model.Cluster, int, error)

func ListInstanceType

func ListInstanceType(req ListInstanceTypeRequest) ([]cloud.InstanceType, error)

func ListKeyPairs added in v0.7.0

func ListKeyPairs(ctx context.Context, ak, provider, regionId string, page types.PageReq) ([]*model.KeyPair, *types.PageRsp, error)

func Login

func Login(ctx context.Context, username, password string) *model.User

func ModifyAdminPassword

func ModifyAdminPassword(ctx context.Context, userId int64, userName, oldPassword, newPassword string) error

func ModifyUsername

func ModifyUsername(ctx context.Context, uid int64, newUsername string) error

func ModifyUsertype added in v0.5.1

func ModifyUsertype(ctx context.Context, userIds []int64, userType int8) error

func MustDecryptAccounts added in v0.2.1

func MustDecryptAccounts(accounts []*model.Account) error

MustDecryptAccounts same as decryptAccounts(accounts, true).

func QueryOrders

func QueryOrders(accName, provider, ak, regionId string, startTime, endTime time.Time) error

func RecordOperationLog added in v0.4.0

func RecordOperationLog(ctx context.Context, oplog OperationLog) error

func RefreshAccount added in v0.7.0

func RefreshAccount(t *SimpleTask) error

func RefreshCache

func RefreshCache() error

func RepairCluster

func RepairCluster(c *types.ClusterInfo, taskId int64, availableIds []string, allIds []string) int

func SaveOrders

func SaveOrders(accName, provider string, cloudOrder []cloud.Order) error

func Shrink

func Shrink(clusterInfo *types.ClusterInfo, instanceIds []string) error

func ShrinkCluster

func ShrinkCluster(c *types.ClusterInfo, num int, taskId int64) (err error)

func ShrinkClusterBySpecificIps

func ShrinkClusterBySpecificIps(c *types.ClusterInfo, deletingIPs string, count int, taskId int64) (err error)

func SyncInstanceExpireTime added in v0.1.5

func SyncInstanceExpireTime(ctx context.Context, clusterName string) error

func SyncInstanceTypes

func SyncInstanceTypes(ctx context.Context, provider string) error

func SyncNetwork added in v0.7.0

func SyncNetwork(ctx context.Context, req SyncNetworkRequest) error

func TagBridgxClusterUsage added in v0.2.1

func TagBridgxClusterUsage(clusterName, systemName string) error

TagBridgxClusterUsage 将集群设置为被系统占用

func UpdateUserStatus

func UpdateUserStatus(ctx context.Context, usernames []string, status string) error

func UserMapByIDs added in v0.4.0

func UserMapByIDs(ctx context.Context, ids []int64) map[int64]string

Types

type AddSecurityGroupRuleRequest

type AddSecurityGroupRuleRequest struct {
	AK              string
	RegionId        string
	VpcId           string
	SecurityGroupId string
	Rules           []GroupRule
}

type CreateNetworkRequest

type CreateNetworkRequest struct {
	Provider          string
	RegionId          string
	CidrBlock         string
	VpcName           string
	ZoneId            string
	SwitchCidrBlock   string
	GatewayIp         string
	SwitchName        string
	SecurityGroupName string
	SecurityGroupType string
	AK                string
	Rules             []GroupRule
}

type CreateNetworkResponse

type CreateNetworkResponse struct {
	VpcId           string
	SwitchId        string
	SecurityGroupId string
}

func CreateNetwork

func CreateNetwork(ctx context.Context, req *CreateNetworkRequest) (vpcRes CreateNetworkResponse, err error)

type CreateSecurityGroupRequest

type CreateSecurityGroupRequest struct {
	AK                string
	VpcId             string
	SecurityGroupName string
	SecurityGroupType string
}

type CreateSwitchRequest

type CreateSwitchRequest struct {
	AK         string
	SwitchName string
	ZoneId     string
	VpcId      string
	CidrBlock  string
	GatewayIp  string
}

type CreateVPCRequest

type CreateVPCRequest struct {
	Provider  string
	RegionId  string
	VpcName   string
	CidrBlock string
	AK        string
}

type GetImagesRequest

type GetImagesRequest struct {
	Account   *types.OrgKeys
	Provider  string
	RegionId  string
	InsType   string
	ImageType string
}

type GetInstancesCond added in v0.4.0

type GetInstancesCond struct {
	AccountKeys []string
	Status      []string
	InstanceId  string
	Ip          string
	ClusterName string
	Provider    string
	PageNum     int
	PageSize    int
}

type GetRegionsRequest

type GetRegionsRequest struct {
	Provider string
	Account  *types.OrgKeys
}

type GetSecurityGroupRequest

type GetSecurityGroupRequest struct {
	AK                string
	SecurityGroupName string
	VpcId             string
	PageNumber        int
	PageSize          int
}

type GetSwitchRequest

type GetSwitchRequest struct {
	SwitchName string
	VpcId      string
	ZoneId     string
	PageNumber int
	PageSize   int
}

type GetVPCFromCloudRequest

type GetVPCFromCloudRequest struct {
	Provider   string
	RegionId   string
	VpcName    string
	PageNumber int32
	PageSize   int32
	VpcId      string
	AK         string
}

type GetVPCRequest

type GetVPCRequest struct {
	Provider   string
	RegionId   string
	VpcName    string
	PageNumber int
	PageSize   int
	AccountKey string
}

type GetZonesRequest

type GetZonesRequest struct {
	Provider string
	RegionId string
	Account  *types.OrgKeys
}

type Group

type Group struct {
	VpcId             string
	SecurityGroupId   string
	SecurityGroupName string
	SecurityGroupType string
	CreateAt          string
}

type GroupRule

type GroupRule struct {
	Protocol     string `json:"protocol"`
	PortFrom     int    `json:"port_from"`
	PortTo       int    `json:"port_to"`
	Direction    string `json:"direction"`
	GroupId      string `json:"group_id"`
	CidrIp       string `json:"cidr_ip"`
	PrefixListId string `json:"prefix_list_id"`
}

type GroupRuleRsp added in v0.7.0

type GroupRuleRsp struct {
	Protocol     string `json:"protocol"`
	PortRange    string `json:"port_range"`
	Direction    string `json:"direction"`
	GroupId      string `json:"group_id"`
	CidrIp       string `json:"cidr_ip"`
	PrefixListId string `json:"prefix_list_id"`
}

type InstanceTypeByZone

type InstanceTypeByZone struct {
	InstanceTypeFamily string `json:"instance_type_family"`
	InstanceType       string `json:"instance_type"`
	Core               int    `json:"core"`
	Memory             int    `json:"memory"`
}

func GetInstanceTypeByName added in v0.1.2

func GetInstanceTypeByName(instanceTypeName string) InstanceTypeByZone

func (*InstanceTypeByZone) GetDesc added in v0.1.4

func (i *InstanceTypeByZone) GetDesc() string

type InstancesSearchCond

type InstancesSearchCond struct {
	TaskId      int64
	TaskAction  string
	Status      string
	ClusterName string
	PageNumber  int
	PageSize    int
}

type ListInstanceTypeRequest

type ListInstanceTypeRequest struct {
	Provider string
	RegionId string
	ZoneId   string
	Account  *types.OrgKeys
}

type ListInstanceTypeResponse

type ListInstanceTypeResponse struct {
	InstanceTypes []InstanceTypeByZone `json:"instance_types"`
}

type Operation added in v0.4.0

type Operation string
const (
	OperationCreate Operation = "CREATE"
	OperationUpdate Operation = "UPDATE"
	OperationDelete Operation = "DELETE"
)

type OperationLog added in v0.4.0

type OperationLog struct {
	Operation Operation
	Operator  int64

	Old schema.Tabler
	New schema.Tabler
}

type SecurityGroupResponse

type SecurityGroupResponse struct {
	Groups []Group
	Pager  types.Pager
}

type SecurityGroupWithRule added in v0.7.0

type SecurityGroupWithRule struct {
	SgId   string         `json:"security_group_id"`
	SgName string         `json:"security_group_name"`
	SgType string         `json:"security_group_type"`
	Rules  []GroupRuleRsp `json:"rules"`
}

func GetSecurityGroupWithRules added in v0.7.0

func GetSecurityGroupWithRules(ctx context.Context, securityGroupId string) (SecurityGroupWithRule, error)

type SimpleTask

type SimpleTask struct {
	VpcId        string
	VpcName      string
	RegionId     string
	Provider     cloud.Provider
	ProviderName string
	SwitchId     string
	AccountKey   string
	TargetType   targetType
	Retry        int
}

type SimpleTaskHandler

type SimpleTaskHandler struct {
	Tasks chan *SimpleTask
	// contains filtered or unexported fields
}

func (*SimpleTaskHandler) SubmitTask

func (s *SimpleTaskHandler) SubmitTask(t *SimpleTask)

type Switch

type Switch struct {
	VpcId                   string
	SwitchId                string
	ZoneId                  string
	SwitchName              string
	CidrBlock               string
	GatewayIp               string
	VStatus                 string
	CreateAt                string
	IsDefault               string
	AvailableIpAddressCount int
}

func GetSwitchById added in v0.7.0

func GetSwitchById(ctx context.Context, vpcId, switchId string) (Switch, error)

type SwitchResponse

type SwitchResponse struct {
	Switches []Switch
	Pager    types.Pager
}

func GetSwitch

func GetSwitch(ctx context.Context, req GetSwitchRequest) (resp SwitchResponse, err error)

type SyncNetworkRequest added in v0.7.0

type SyncNetworkRequest struct {
	Provider   string
	RegionId   string
	AccountKey string
}

type VPCResponse

type VPCResponse struct {
	Vpcs  []Vpc
	Pager types.Pager
}

func GetVPC

func GetVPC(ctx context.Context, req GetVPCRequest) (resp VPCResponse, err error)

type Vpc

type Vpc struct {
	VpcId     string
	VpcName   string
	CidrBlock string
	Provider  string
	Status    string
	CreateAt  string
}

func GetVpcById added in v0.7.0

func GetVpcById(ctx context.Context, vpcId string) (Vpc, error)

Jump to

Keyboard shortcuts

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