Skip to content

Commit

Permalink
feat(region): Structured diskinfo and add 'Id', 'Name' field
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed Apr 23, 2020
1 parent e55bb82 commit 8c4b025
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
24 changes: 21 additions & 3 deletions pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package compute
import (
"time"

"yunion.io/x/jsonutils"

"yunion.io/x/onecloud/pkg/apis"
"yunion.io/x/onecloud/pkg/apis/billing"
)
Expand Down Expand Up @@ -153,7 +151,7 @@ type ServerDetails struct {
Disks string `json:"disks"`

// 磁盘详情
DisksInfo *jsonutils.JSONArray `json:"disks_info"`
DisksInfo []GuestDiskInfo `json:"disks_info"`
// 虚拟机Ip列表
VirtualIps string `json:"virtual_ips"`
// 安全组规则
Expand Down Expand Up @@ -228,6 +226,26 @@ type ServerDetails struct {
ScalingGroupId string `json:"scaling_group_id"`
}

// GuestDiskInfo describe the information of disk on the guest.
type GuestDiskInfo struct {
Id string `json:"id"`
Name string `json:"name"`
FsFormat string `json:"fs,omitempty"`
DiskType string `json:"disk_type"`
Index int8 `json:"index"`
SizeMb int `json:"size"`
DiskFormat string `json:"disk_format"'`
Driver string `json:"driver"`
CacheMode string `json:"cache_mode"`
AioMode string `json:"aio_mode"`
MediumType string `json:"medium_type"`
StorageType string `json:"storage_type"`
Iops int `json:"iops"`
Bps int `json:"bps"`
ImageId string `json:"image_id,omitempty"`
Image string `json:"image,omitemtpy"`
}

type GuestJointResourceDetails struct {
apis.VirtualJointResourceBaseDetails

Expand Down
42 changes: 24 additions & 18 deletions pkg/compute/models/guestdisks.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,35 +257,41 @@ func (self *SGuestdisk) GetJsonDescAtHost(host *SHost) jsonutils.JSONObject {
return desc
}

func (self *SGuestdisk) GetDetailedJson() *jsonutils.JSONDict {
desc := jsonutils.NewDict()
func (self *SGuestdisk) GetDetailedInfo() api.GuestDiskInfo {
desc := api.GuestDiskInfo{}
disk := self.GetDisk()
storage := disk.GetStorage()
if fs := disk.GetFsFormat(); len(fs) > 0 {
desc.Add(jsonutils.NewString(fs), "fs")
if disk == nil {
return desc
}
desc.Add(jsonutils.NewString(disk.DiskType), "disk_type")
desc.Add(jsonutils.NewInt(int64(self.Index)), "index")
desc.Add(jsonutils.NewInt(int64(disk.DiskSize)), "size")
desc.Add(jsonutils.NewString(disk.DiskFormat), "disk_format")
desc.Add(jsonutils.NewString(self.Driver), "driver")
desc.Add(jsonutils.NewString(self.CacheMode), "cache_mode")
desc.Add(jsonutils.NewString(self.AioMode), "aio_mode")
desc.Add(jsonutils.NewString(storage.MediumType), "medium_type")
desc.Add(jsonutils.NewString(storage.StorageType), "storage_type")
desc.Add(jsonutils.NewInt(int64(self.Iops)), "iops")
desc.Add(jsonutils.NewInt(int64(self.Bps)), "bps")
desc.Id = disk.Id
desc.Name = disk.Name
desc.FsFormat = disk.FsFormat
desc.DiskType = disk.DiskType
desc.Index = self.Index
desc.SizeMb = disk.DiskSize
desc.DiskFormat = disk.DiskFormat
desc.Driver = self.Driver
desc.CacheMode = self.CacheMode
desc.AioMode = self.AioMode
desc.Iops = self.Iops
desc.Bps = self.Bps

imageId := disk.GetTemplateId()
if len(imageId) > 0 {
desc.Add(jsonutils.NewString(imageId), "image_id")
desc.ImageId = imageId
cachedImageObj, _ := CachedimageManager.FetchById(imageId)
if cachedImageObj != nil {
cachedImage := cachedImageObj.(*SCachedimage)
desc.Add(jsonutils.NewString(cachedImage.GetName()), "image")
desc.Image = cachedImage.GetName()
}
}

storage := disk.GetStorage()
if storage == nil {
return desc
}
desc.MediumType = storage.MediumType
desc.StorageType = storage.StorageType
return desc
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1947,10 +1947,11 @@ func (self *SGuest) getDisksDetails() string {
return buf.String()
}

func (self *SGuest) getDisksInfoDetails() *jsonutils.JSONArray {
details := jsonutils.NewArray()
for _, disk := range self.GetDisks() {
details.Add(disk.GetDetailedJson())
func (self *SGuest) getDisksInfoDetails() []api.GuestDiskInfo {
disks := self.GetDisks()
details := make([]api.GuestDiskInfo, len(disks))
for i := range details {
details[i] = disks[i].GetDetailedInfo()
}
return details
}
Expand Down

0 comments on commit 8c4b025

Please sign in to comment.