Merge pull request #110 in YUNIONIO/onecloud from ~WANYAOQI/onecloud:bugfix/wyq/fix-server-start-logevent to release/2.1.0

* commit 'd113017c338c3a0b7bf68960e624aa4d45b5f606':
  remove temp code
  server shot desc
This commit is contained in:
邱剑
2018-08-25 13:59:51 +08:00
5 changed files with 213 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package models
const (
BAREMETAL_INIT = "init"
BAREMETAL_PREPARE = "prepare"
BAREMETAL_PREPARE_FAIL = "prepare_fail"
BAREMETAL_READY = "ready"
BAREMETAL_RUNNING = "running"
BAREMETAL_MAINTAINING = "maintaining"
BAREMETAL_START_MAINTAIN = "start_maintain"
BAREMETAL_DELETING = "deleting"
BAREMETAL_DELETE = "delete"
BAREMETAL_DELETE_FAIL = "delete_fail"
BAREMETAL_UNKNOWN = "unknown"
BAREMETAL_SYNCING_STATUS = "syncing_status"
BAREMETAL_SYNC = "sync"
BAREMETAL_SYNC_FAIL = "sync_fail"
BAREMETAL_START_CONVERT = "start_convert"
BAREMETAL_CONVERTING = "converting"
BAREMETAL_START_FAIL = "start_fail"
BAREMETAL_STOP_FAIL = "stop_fail"
)
+21
View File
@@ -701,6 +701,27 @@ func parseIsoInfo(ctx context.Context, userCred mcclient.TokenCredential, info s
return image.Id, nil
}
// def get_disk_spec_v2(conf):
// def _get_spec(storages):
// spec = {}
// for adapter, ss in group_by_adapter(storages).items():
// if len(ss) == 0:
// continue
// spec[adapter] = get_disk_spec(ss)
// return spec
// spec = {}
// for driver in DISK_DRIVERS:
// storages = [s for s in conf if s['driver'] == driver]
// if len(storages) != 0:
// spec[driver] = _get_spec(storages)
// return spec
func GetDiskSpecV2(storageInfo jsonutils.JSONObject) *jsonutils.JSONDict {
// ToDo
return nil
}
func (self *SDisk) fetchDiskInfo(diskConfig *SDiskConfig) {
if len(diskConfig.ImageId) > 0 {
self.TemplateId = diskConfig.ImageId
+100
View File
@@ -3027,6 +3027,106 @@ func (manager *SGuestManager) FetchGuestById(guestId string) *SGuest {
return guest.(*SGuest)
}
func (self *SGuest) GetSpec(checkStatus bool) *jsonutils.JSONDict {
if checkStatus {
if !utils.IsInStringArray(self.Status, []string{VM_SCHEDULE_FAILED}) {
return nil
}
}
spec := jsonutils.NewDict()
spec.Set("cpu", jsonutils.NewInt(int64(self.VcpuCount)))
spec.Set("mem", jsonutils.NewInt(int64(self.VmemSize)))
// get disk spec
guestdisks := self.GetDisks()
diskSpecs := jsonutils.NewArray()
for _, guestdisk := range guestdisks {
disk := guestdisk.GetDisk()
diskSpec := jsonutils.NewDict()
diskSpec.Set("size", jsonutils.NewInt(int64(disk.DiskSize)))
s := disk.GetStorage()
diskSpec.Set("backend", jsonutils.NewString(s.StorageType))
diskSpec.Set("medium_type", jsonutils.NewString(s.MediumType))
diskSpecs.Add(diskSpec)
}
spec.Set("disk", diskSpecs)
// get nic spec
guestnics := self.GetNetworks()
nicSpecs := jsonutils.NewArray()
for _, guestnic := range guestnics {
nicSpec := jsonutils.NewDict()
nicSpec.Set("bandwidth", jsonutils.NewInt(int64(guestnic.getBandwidth())))
t := "int"
if guestnic.IsExit() {
t = "ext"
}
nicSpec.Set("type", jsonutils.NewString(t))
nicSpecs.Add(nicSpec)
}
spec.Set("nic", nicSpecs)
// get isolate device spec
guestgpus := self.GetIsolatedDevices()
gpuSpecs := jsonutils.NewArray()
for _, guestgpu := range guestgpus {
if strings.HasPrefix(guestgpu.DevType, "GPU") {
gs := guestgpu.GetSpec(false)
if gs != nil {
gpuSpecs.Add(gs)
}
}
}
spec.Set("gpu", gpuSpecs)
return spec
}
func (self *SGuest) GetTemplateId() string {
guestdisks := self.GetDisks()
for _, guestdisk := range guestdisks {
disk := guestdisk.GetDisk()
if disk != nil {
templateId := disk.GetTemplateId()
if len(templateId) > 0 {
return templateId
}
}
}
return ""
}
func (self *SGuest) GetShortDesc() *jsonutils.JSONDict {
desc := self.SStandaloneResourceBase.GetShortDesc()
desc.Set("mem", jsonutils.NewInt(int64(self.VmemSize)))
desc.Set("cpu", jsonutils.NewInt(int64(self.VcpuCount)))
templateId := self.GetTemplateId()
if len(templateId) > 0 {
desc.Set("cpu", jsonutils.NewString(templateId))
}
extBw := self.getBandwidth(true)
intBw := self.getBandwidth(false)
if extBw > 0 {
desc.Set("ext_bandwidth", jsonutils.NewInt(int64(extBw)))
}
if intBw > 0 {
desc.Set("int_bandwidth", jsonutils.NewInt(int64(intBw)))
}
desc.Set("hypervisor", jsonutils.NewString(self.GetHypervisor()))
spec := self.GetSpec(false)
if self.GetHypervisor() == HYPERVISOR_BAREMETAL {
host := self.GetHost()
if host != nil {
hostSpec := host.GetSpec(false)
hostSpecIdent := host.GetSpecIdent(hostSpec)
spec.Set("host_spec", jsonutils.NewString(strings.Join(hostSpecIdent, "/")))
}
}
if spec != nil {
desc.Update(spec)
}
return desc
}
func (self *SGuest) saveOsType(osType string) error {
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
self.OsType = osType
+52
View File
@@ -506,6 +506,58 @@ func (self *SHost) ClearSchedDescCache() error {
return HostManager.ClearSchedDescCache(self.Id)
}
func (self *SHost) GetSpec(statusCheck bool) *jsonutils.JSONDict {
if statusCheck {
if utils.IsInStringArray(self.Status, []string{BAREMETAL_INIT, BAREMETAL_PREPARE_FAIL, BAREMETAL_PREPARE}) ||
self.getBaremetalServer() != nil {
return nil
}
if self.MemSize == 0 || self.CpuCount == 0 {
return nil
}
}
spec := self.GetHardwareSpecification()
spec.Remove("storage_info")
netInfo := jsonutils.NewArray()
nifs := self.GetNetInterfaces()
for _, nif := range nifs {
netDesc := nif.getBaremetalJsonDesc()
nicType, err := netDesc.GetString("nic_type")
if err != nil && nicType != NIC_TYPE_IPMI {
netInfo.Add(netDesc)
}
}
spec.Set("nic_count", jsonutils.NewInt(int64(netInfo.Length())))
manufacture, err := self.SysInfo.Get("manufacture")
if err != nil {
manufacture = jsonutils.NewString("Unknown")
}
spec.Set("manufacture", manufacture)
model, err := self.SysInfo.Get("model")
if err != nil {
model = jsonutils.NewString("Unknown")
}
spec.Set("model", model)
return nil
}
func (self *SHost) GetSpecIdent(spec *jsonutils.JSONDict) []string {
// Todo
return []string{}
}
func (self *SHost) GetHardwareSpecification() *jsonutils.JSONDict {
spec := jsonutils.NewDict()
spec.Set("cpu", jsonutils.NewInt(int64(self.CpuCount)))
spec.Set("mem", jsonutils.NewInt(int64(self.MemSize)))
if self.StorageInfo != nil {
spec.Set("disk", GetDiskSpecV2(self.StorageInfo))
spec.Set("driver", jsonutils.NewString(self.StorageDriver))
spec.Set("storage_info", self.StorageInfo)
}
return spec
}
type SStorageCapacity struct {
Capacity int
Used int
+18
View File
@@ -380,6 +380,24 @@ func (self *SIsolatedDevice) getDesc() *jsonutils.JSONDict {
return desc
}
func (self *SIsolatedDevice) GetSpec(checkStatus bool) *jsonutils.JSONDict {
if checkStatus {
if len(self.GuestId) > 0 {
return nil
}
host := self.getHost()
if host.Status != BAREMETAL_RUNNING || !host.Enabled {
return nil
}
}
spec := jsonutils.NewDict()
spec.Set("dev_type", jsonutils.NewString(self.DevType))
spec.Set("model", jsonutils.NewString(self.Model))
spec.Set("pci_id", jsonutils.NewString(self.VendorDeviceId))
spec.Set("vendor", jsonutils.NewString(self.getVendor()))
return spec
}
func (self *SIsolatedDevice) GetShortDesc() *jsonutils.JSONDict {
desc := self.getDesc()
desc.Add(jsonutils.NewString(self.Keyword()), "res_name")