Merge pull request #741 in YUNIONIO/onecloud from ~LIZEXI/onecloud:bugfix/lzx-host-sysinfo-nil to release/2.4.0

* commit 'b64c3b333371987aea51e25d6bc0104194e10ccb':
  region: specs panic when host sysinfo is nil
This commit is contained in:
李泽玺
2018-12-12 17:48:38 +08:00
+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
}