feat(region,climc): support disk-rebuild

This commit is contained in:
Zexi Li
2024-04-11 11:17:06 +08:00
parent c3e5304a6b
commit 5664981943
5 changed files with 37 additions and 0 deletions
+1
View File
@@ -42,6 +42,7 @@ import (
func init() {
cmd := shell.NewResourceCmd(&modules.Disks)
cmd.Perform("set-class-metadata", &options.ResourceMetadataOptions{})
cmd.Perform("rebuild", &options.ResourceIdOptions{})
type DiskListOptions struct {
options.BaseListOptions
+2
View File
@@ -327,3 +327,5 @@ type DiskResetInput struct {
type DiskSnapshotpolicyInput struct {
SnapshotpolicyId string `json:"snapshotpolicy_id"`
}
type DiskRebuildInput struct{}
+15
View File
@@ -2985,3 +2985,18 @@ func (manager *SDiskManager) ListItemExportKeys(ctx context.Context,
}
return q, nil
}
func (disk *SDisk) PerformRebuild(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
input *api.DiskRebuildInput,
) (jsonutils.JSONObject, error) {
guests := disk.GetGuests()
for _, guest := range guests {
if guest.GetStatus() != api.VM_READY {
return nil, httperrors.NewInvalidStatusError("Guest %s status is %s", guest.GetId(), guest.GetStatus())
}
}
return nil, disk.StartDiskCreateTask(ctx, userCred, true, disk.SnapshotId, "")
}
+7
View File
@@ -130,6 +130,13 @@ func (self *DiskCreateTask) OnDiskReady(ctx context.Context, disk *models.SDisk,
Obj: disk,
Action: notifyclient.ActionCreate,
})
if !self.IsSubtask() {
guest := disk.GetGuest()
if guest != nil {
// just sync guest status
guest.StartSyncstatus(ctx, self.GetUserCred(), "")
}
}
self.SetStageComplete(ctx, nil)
}
+12
View File
@@ -129,6 +129,18 @@ func (opts *DomainTagValueTreeOptions) Property() string {
return "domain-tag-value-tree"
}
type ResourceIdOptions struct {
ID string `help:"ID or name of the resource" json:"-"`
}
func (o *ResourceIdOptions) GetId() string {
return o.ID
}
func (o *ResourceIdOptions) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type ResourceMetadataOptions struct {
ID string `help:"ID or name of resources" json:"-"`
TAGS []string `help:"Tags info, eg: hypervisor=aliyun、os_type=Linux、os_version"`