提交 d063bc0e 编写于 作者: U Ulric Qin

for jeff, dirty data

上级 c6442ed6
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册