diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go new file mode 100644 index 0000000000000000000000000000000000000000..f5b1f2809f444db4ed24b95face9c827715879a7 --- /dev/null +++ b/configmanage/server/internal/hostfile.go @@ -0,0 +1,27 @@ +package internal + +import ( + "encoding/json" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/db" +) + +type HostFile struct { + ID int `gorm:"unique;autoIncrement:true"` + UUID string `gorm:"primary_key;type:varchar(50)" json:"uuid"` + ConfigInfo ConfigInfo `gorm:"Foreignkey:ConfigInfoUUID"` + ConfigInfoUUID string + Path string `json:"path"` + Name string `json:"name"` + Content json.RawMessage `gorm:"type:json" json:"content"` + Version string `gorm:"type:varchar(50)" json:"version"` + IsActive bool `json:"isactive"` + IsFromHost bool `gorm:"default:false" json:"isfromhost"` + Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` + CreatedAt time.Time +} + +func (hf *HostFile) Add() error { + return db.MySQL().Save(&hf).Error +} diff --git a/configmanage/server/router/router.go b/configmanage/server/router/router.go index 70d1a08708bd4d47ffaf7b19e19fc3c9c266b14d..049fc4e3020bb7a052d7e656c641c86c37d2b586 100644 --- a/configmanage/server/router/router.go +++ b/configmanage/server/router/router.go @@ -26,14 +26,14 @@ func RegisterAPIs(router *gin.Engine) { // 提供配置列表 list.GET("/config_infos", controller.ConfigInfosHandler) // 根据列表中的configinfo_uuid获取某一个config信息 - list.GET("/config_info", controller.ConfigInfoHandler) + list.POST("/config_info", controller.ConfigInfoHandler) // 查看某台机器某种类型的的历史配置信息 - list.GET("/config_history", controller.ConfigHistoryHandler) + list.POST("/config_history", controller.ConfigHistoryHandler) } // 添加配置管理 api.POST("/add", controller.AddConfigHandler) // 根据列表中的configinfo_uuid获取某一个具体的正在使用的config信息 - api.GET("/load", controller.LoadConfigHandler) + api.POST("/load", controller.LoadConfigHandler) // 下发配置管理 api.POST("/apply", controller.ApplyConfigHandler) } diff --git a/configmanage/server/service/host.go b/configmanage/server/service/host.go new file mode 100644 index 0000000000000000000000000000000000000000..aa3ff251f6fa46033e929842d87fac7572acb677 --- /dev/null +++ b/configmanage/server/service/host.go @@ -0,0 +1,55 @@ +package service + +import ( + "encoding/json" + "errors" + "fmt" + "time" + + "openeuler.org/PilotGo/configmanage-plugin/internal" +) + +/* +host: 配置文件 + +一般方法: 1、在/etc/hosts中修改内容 + + 2、执行命令systemctl restart NetworkManager重启网络服务 + +考虑的问题: +*/ +type HostFile = internal.HostFile + +type HostConfig struct { + UUID string `json:"uuid"` + ConfigInfoUUID string `json:"configinfouuid"` + Content json.RawMessage `json:"content"` + Version string `json:"version"` + Path string `json:"path"` + Name string `json:"name"` + //下发改变标志位 + IsActive bool `json:"isactive"` +} + +func (hc *HostConfig) toHostFile() HostFile { + return HostFile{ + UUID: hc.UUID, + ConfigInfoUUID: hc.ConfigInfoUUID, + Path: hc.Path, + Name: hc.Name, + Content: hc.Content, + Version: fmt.Sprintf("v%s", time.Now().Format("2006-01-02-15-04-05")), + IsActive: hc.IsActive, + } +} + +func (hc *HostConfig) Record() error { + //检查info的uuid是否存在 + ci, err := GetInfoByUUID(hc.ConfigInfoUUID) + if err != nil || ci.UUID == "" { + return errors.New("configinfo uuid not exist") + } + + hf := hc.toHostFile() + return hf.Add() +} diff --git a/configmanage/server/service/host_test.go b/configmanage/server/service/host_test.go new file mode 100644 index 0000000000000000000000000000000000000000..6d43c3366ca3e6c323c783077e9aa02280048c57 --- /dev/null +++ b/configmanage/server/service/host_test.go @@ -0,0 +1 @@ +package service diff --git a/configmanage/server/service/repo.go b/configmanage/server/service/repo.go index 1b67622d512daa297ee6ba9720561c30bb098b43..d5d091cad432fb74095041961bc59e66c3b00a38 100644 --- a/configmanage/server/service/repo.go +++ b/configmanage/server/service/repo.go @@ -16,6 +16,19 @@ import ( "openeuler.org/PilotGo/configmanage-plugin/internal" ) +/* +repo: 配置文件 + +一般方法: 1、在/etc/yum.repo.d/下创建repo文件 + + 2、执行命令使用repo文件dnf clear all 和 dnf makecache + +考虑的问题:1、路径下存在多个repo文件,使用的时候都生效,用文件中某一字段控制某一链接不生效 + + 2、采集和下发的时候都存在多个repo文件,如果下发的文件同名将如何处理? + + 3、下发之前采集还是创建相关配置的时候采集? +*/ type RepoFile = internal.RepoFile type RepoConfig struct {