Skip to content

Commit

Permalink
feat: add cloud common for fc
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie committed Jan 17, 2025
1 parent 45ffb22 commit 7568bf8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 31 deletions.
2 changes: 2 additions & 0 deletions cli/ctl/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
DOMAIN_TYPE_SUGON DomainType = 29 // sugon
DOMAIN_TYPE_VOLCENGINE DomainType = 30 // volcengine
DOMAIN_TYPE_H3C DomainType = 31 // h3c
DOMAIN_TYPE_FUSIONCOMPUTE DomainType = 32 // fusioncompute
)

var DomainTypes []DomainType = []DomainType{
Expand Down Expand Up @@ -91,6 +92,7 @@ var DomainTypes []DomainType = []DomainType{
DOMAIN_TYPE_SUGON,
DOMAIN_TYPE_VOLCENGINE,
DOMAIN_TYPE_H3C,
DOMAIN_TYPE_FUSIONCOMPUTE,
}

func GetDomainTypeByName(domainTypeName string) DomainType {
Expand Down
18 changes: 13 additions & 5 deletions server/controller/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ func NewCloud(orgID int, domain mysqlmodel.Domain, cfg config.CloudConfig, ctx c
}

// maybe all types will be supported later
var triggerTimeString string
switch domain.Type {
case common.QINGCLOUD, common.QINGCLOUD_PRIVATE:
triggerTimeString = cfg.QingCloudConfig.DailyTriggerTime
case common.FUSIONCOMPUTE:
triggerTimeString = cfg.FusionComputeConfig.DailyTriggerTime
default:
}
var triggerTime time.Time
if domain.Type == common.QINGCLOUD || domain.Type == common.QINGCLOUD_PRIVATE {
triggerTime, err = time.ParseInLocation("15:04", cfg.QingCloudConfig.DailyTriggerTime, time.Local)
if triggerTimeString != "" {
triggerTime, err = time.ParseInLocation("15:04", triggerTimeString, time.Local)
if err != nil {
log.Errorf("parse qing config daily trigger time failed: (%s)", err.Error(), logger.NewORGPrefix(orgID))
log.Errorf("parse cloud (%s) daily trigger time config failed: (%s)", domain.Name, err.Error(), logger.NewORGPrefix(orgID))
}
}

Expand Down Expand Up @@ -282,8 +290,8 @@ func (c *Cloud) GetStatter() statsd.StatsdStatter {
}

func (c *Cloud) getCloudGatherInterval() int {
if (c.basicInfo.Type == common.QINGCLOUD || c.basicInfo.Type == common.QINGCLOUD_PRIVATE) && c.cfg.QingCloudConfig.DailyTriggerTime != "" {
log.Infof("qing and qing private daily trigger time is (%s), sync timer is default (%d)s", c.cfg.QingCloudConfig.DailyTriggerTime, cloudcommon.CLOUD_SYNC_TIMER_DEFAULT, logger.NewORGPrefix(c.orgID))
if !c.triggerTime.IsZero() {
log.Infof("cloud (%s) daily trigger time is (%s), sync timer is default (%d)s", c.basicInfo.Name, c.triggerTime.Format("15:04"), cloudcommon.CLOUD_SYNC_TIMER_DEFAULT, logger.NewORGPrefix(c.orgID))
return cloudcommon.CLOUD_SYNC_TIMER_DEFAULT
}
var domain mysqlmodel.Domain
Expand Down
42 changes: 24 additions & 18 deletions server/controller/cloud/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,34 @@ type QingCloudConfig struct {
DisableSyncLBListener bool `default:"false" yaml:"disable_sync_lb_listener"` // disable sync for lb listener and target server
}

type FusionComputeConfig struct {
DailyTriggerTime string `default:"" yaml:"daily_trigger_time"` // %H:%M 05:00
}

type CloudConfig struct {
KubernetesGatherInterval uint32 `default:"30" yaml:"kubernetes_gather_interval"`
AliyunRegionName string `default:"cn-beijing" yaml:"aliyun_region_name"`
AWSRegionName string `default:"cn-north-1" yaml:"aws_region_name"`
HostnameToIPFile string `default:"/etc/hostname_to_ip.csv" yaml:"hostname_to_ip_file"`
DNSEnable bool `default:"false" yaml:"dns_enable"`
HTTPTimeout int `default:"30" yaml:"http_timeout"`
CustomTagLenMax int `default:"256" yaml:"custom_tag_len_max"`
ProcessNameLenMax int `default:"256" yaml:"process_name_len_max"`
DebugEnabled bool `default:"false" yaml:"debug_enabled"`
QingCloudConfig QingCloudConfig `yaml:"qingcloud_config"`
KubernetesGatherInterval uint32 `default:"30" yaml:"kubernetes_gather_interval"`
AliyunRegionName string `default:"cn-beijing" yaml:"aliyun_region_name"`
AWSRegionName string `default:"cn-north-1" yaml:"aws_region_name"`
HostnameToIPFile string `default:"/etc/hostname_to_ip.csv" yaml:"hostname_to_ip_file"`
DNSEnable bool `default:"false" yaml:"dns_enable"`
HTTPTimeout int `default:"30" yaml:"http_timeout"`
CustomTagLenMax int `default:"256" yaml:"custom_tag_len_max"`
ProcessNameLenMax int `default:"256" yaml:"process_name_len_max"`
DebugEnabled bool `default:"false" yaml:"debug_enabled"`
QingCloudConfig QingCloudConfig `yaml:"qingcloud_config"`
FusionComputeConfig FusionComputeConfig `yaml:"fusioncompute_config"`
}

func SetCloudGlobalConfig(c CloudConfig) {
CONF = &CloudConfig{
HostnameToIPFile: c.HostnameToIPFile,
DNSEnable: c.DNSEnable,
HTTPTimeout: c.HTTPTimeout,
DebugEnabled: c.DebugEnabled,
AWSRegionName: c.AWSRegionName,
CustomTagLenMax: c.CustomTagLenMax,
ProcessNameLenMax: c.ProcessNameLenMax,
QingCloudConfig: c.QingCloudConfig,
HostnameToIPFile: c.HostnameToIPFile,
DNSEnable: c.DNSEnable,
HTTPTimeout: c.HTTPTimeout,
DebugEnabled: c.DebugEnabled,
AWSRegionName: c.AWSRegionName,
CustomTagLenMax: c.CustomTagLenMax,
ProcessNameLenMax: c.ProcessNameLenMax,
QingCloudConfig: c.QingCloudConfig,
FusionComputeConfig: c.FusionComputeConfig,
}
}
17 changes: 10 additions & 7 deletions server/controller/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const (
SUGON = 29
VOLCENGINE = 30
H3C = 31
FUSIONCOMPUTE = 32

OPENSTACK_EN = "openstack"
VSPHERE_EN = "vsphere"
Expand Down Expand Up @@ -328,6 +329,7 @@ const (
SUGON_EN = "sugon"
VOLCENGINE_EN = "volcengine"
H3C_EN = "h3c"
FUSIONCOMPUTE_EN = "fusioncompute"

TENCENT_CH = "腾讯云"
ALIYUN_CH = "阿里云"
Expand All @@ -342,13 +344,14 @@ const (
VOLCENGINE_CH = "火山云"
H3C_CH = "华三云"

OPENSTACK_CH = "OpenStack"
VSPHERE_CH = "vSphere"
NSP_CH = "NSP"
AWS_CH = "AWS"
ZSTACK_CH = "ZStack"
KUBERNETES_CH = "Kubernetes"
CLOUD_TOWER_CH = "CloudTower"
OPENSTACK_CH = "OpenStack"
VSPHERE_CH = "vSphere"
NSP_CH = "NSP"
AWS_CH = "AWS"
ZSTACK_CH = "ZStack"
KUBERNETES_CH = "Kubernetes"
CLOUD_TOWER_CH = "CloudTower"
FUSIONCOMPUTE_CH = "FusionCompute"
)

var DomainTypeToIconID = map[int]int{
Expand Down
2 changes: 1 addition & 1 deletion server/controller/recorder/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (d *domain) tryRefresh(cloudData cloudmodel.Resource) error {

func (d *domain) shouldRefresh(cloudData cloudmodel.Resource) error {
if cloudData.Verified {
if (d.metadata.Domain.Type != common.CLOUD_TOWER && len(cloudData.Networks) == 0) || len(cloudData.VInterfaces) == 0 {
if ((d.metadata.Domain.Type != common.CLOUD_TOWER && d.metadata.Domain.Type != common.FUSIONCOMPUTE) && len(cloudData.Networks) == 0) || len(cloudData.VInterfaces) == 0 {
log.Info("domain has no networks or vinterfaces, does nothing", d.metadata.LogPrefixes)
return DataMissingError
}
Expand Down
4 changes: 4 additions & 0 deletions server/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ controller:
daily_trigger_time: ""
# 关闭 lb 监听器及后端主机对接
disable_sync_lb_listener: false
# fc配置
fusioncompute_config:
# 对接 fusioncompute 定时执行,根据配置的时间点每日执行一次,配置后循环执行失效,格式:%H:%M ,例:05:30 ,每日5点30分执行一次对接
daily_trigger_time: ""
recorder:
# recorder模块缓存自愈刷新时间间隔,单位:分钟
cache_refresh_interval: 60
Expand Down

0 comments on commit 7568bf8

Please sign in to comment.