for jeff, dirty data
This commit is contained in:
parent
c6442ed68a
commit
d063bc0e78
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue