mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-31 02:38:07 +08:00
Merge pull request #5971 from rainzm/fix/guest_disk
feat(region): Structured diskinfo and add 'Id', 'Name' field
This commit is contained in:
@@ -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"
|
||||
)
|
||||
@@ -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"`
|
||||
// 安全组规则
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user