region: specs panic when host sysinfo is nil

This commit is contained in:
Zexi Li
2018-12-12 17:46:56 +08:00
parent 0c9315ec4d
commit b64c3b3333
+13 -8
View File
@@ -733,16 +733,21 @@ func (self *SHost) GetSpec(statusCheck bool) *jsonutils.JSONDict {
}
}
spec.Set("nic_count", jsonutils.NewInt(nicCount))
manufacture, err := self.SysInfo.Get("manufacture")
if err != nil {
manufacture = jsonutils.NewString("Unknown")
var manufacture string
var model string
if self.SysInfo != nil {
manufacture, _ = self.SysInfo.GetString("manufacture")
model, _ = self.SysInfo.GetString("model")
}
spec.Set("manufacture", manufacture)
model, err := self.SysInfo.Get("model")
if err != nil {
model = jsonutils.NewString("Unknown")
if manufacture == "" {
manufacture = "Unknown"
}
spec.Set("model", model)
if model == "" {
model = "Unknown"
}
spec.Set("manufacture", jsonutils.NewString(manufacture))
spec.Set("model", jsonutils.NewString(model))
return spec
}