for jeff, dirty data

This commit is contained in:
Ulric Qin 2020-12-01 23:39:03 +08:00
parent c6442ed68a
commit d063bc0e78
1 changed files with 19 additions and 1 deletions

View File

@ -301,12 +301,17 @@ func v1HostRegister(c *gin.Context) {
"disk": struct{}{},
}
var dels []string
for k := range f.Fields {
if _, ok := hFixed[k]; !ok {
delete(f.Fields, k)
dels = append(dels, k)
}
}
for i := 0; i < len(dels); i++ {
delete(f.Fields, dels[i])
}
if host == nil {
var err error
host, err = models.HostNew(f.SN, f.IP, f.Ident, f.Name, f.Cate, f.Fields)
@ -350,6 +355,19 @@ func v1HostRegister(c *gin.Context) {
res, err := models.ResourceGet("uuid=?", fmt.Sprintf("host-%d", host.Id))
dangerous(err)
if res == nil {
// 数据不干净ams里有这个host而且是已分配状态但是resource表里没有重新注册一下
dangerous(models.ResourceRegister([]models.Host{*host}, host.Tenant))
// 注册完了,重新查询一下试试
res, err = models.ResourceGet("uuid=?", fmt.Sprintf("host-%d", host.Id))
dangerous(err)
if res == nil {
bomb("resource register fail, unknown error")
}
}
res.Ident = f.Ident
res.Name = f.Name
res.Cate = f.Cate