Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(region): guestdisk list add auto_reset column #22324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/apis/compute/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ type DiskUpdateInput struct {

// 磁盘类型
DiskType string `json:"disk_type"`
// 关机自动重置
AutoReset *bool `json:"auto_reset"`
}

type DiskSaveInput struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/compute/guest_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type GuestDiskDetails struct {
// 磁盘类型
// example: data
DiskType string `json:"disk_type"`
// 关机自动重置
AutoReset bool `json:"auto_reset"`
// 介质类型
// example: ssd
MediumType string `json:"medium_type"`
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type GuestDiskInfo struct {
Driver string `json:"driver"`
CacheMode string `json:"cache_mode"`
AioMode string `json:"aio_mode"`
AutoReset bool `json:"auto_reset"`
MediumType string `json:"medium_type"`
StorageType string `json:"storage_type"`
Iops int `json:"iops"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/compute/models/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ func (self *SDisk) ValidateUpdateData(ctx context.Context, userCred mcclient.Tok
}
}

if input.AutoReset != nil && *input.AutoReset != self.AutoReset {
if guest := self.GetGuest(); guest != nil && guest.Status != api.VM_READY {
return input, httperrors.NewBadRequestError("Can't set disk auto_reset on guest status %s", guest.Status)
}
}

storage, _ := self.GetStorage()
if storage == nil {
return input, httperrors.NewNotFoundError("failed to find storage for disk %s", self.Name)
Expand Down
1 change: 1 addition & 0 deletions pkg/compute/models/guest_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func fetchGuestDisksInfo(guestIds []string) map[string][]api.GuestDiskInfo {
guestdisks.Field("driver"),
guestdisks.Field("cache_mode"),
guestdisks.Field("aio_mode"),
disks.Field("auto_reset"),
storages.Field("medium_type"),
storages.Field("storage_type"),
guestdisks.Field("iops"),
Expand Down
1 change: 1 addition & 0 deletions pkg/compute/models/guestdisks.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (manager *SGuestdiskManager) FetchCustomizeColumns(
rows[i].Status = disk.Status
rows[i].DiskSize = disk.DiskSize
rows[i].DiskType = disk.DiskType
rows[i].AutoReset = disk.AutoReset
storage, _ := disk.GetStorage()
if storage != nil {
rows[i].StorageType = storage.StorageType
Expand Down