Skip to content

Commit

Permalink
fix(region): cephfs set quota (#21482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Oct 28, 2024
1 parent 895e6f8 commit 2229f7c
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 20 deletions.
1 change: 1 addition & 0 deletions cmd/climc/shell/compute/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ func init() {
cmd.Delete(&options.BaseIdOptions{})
cmd.Create(&compute.FileSystemCreateOptions{})
cmd.Perform("syncstatus", &compute.FileSystemIdOption{})
cmd.Perform("set-quota", &compute.FileSystemSetQuotaOption{})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
k8s.io/cri-api v0.22.17
k8s.io/klog/v2 v2.20.0
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091252-df8c7dbcd484
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241028100353-47c8a5c40d6b
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20240930100528-1671a2d0d22f
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091252-df8c7dbcd484 h1:f1TeDeLNujbvNf936juI/aqmEGEm7Xu89DlT1R0SX7E=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091252-df8c7dbcd484/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241028100353-47c8a5c40d6b h1:FcXznm3YP5ThT+nrti3umbmYgbOqlWGq+Xxb7tLDBK0=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241028100353-47c8a5c40d6b/go.mod h1:rj/pb3DitJlQaQD8UW1oxx/KD+PzDZqoywzqRJaFE9A=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/compute/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ type FileSystemRemoteUpdateInput struct {
// 是否覆盖替换所有标签
ReplaceTags *bool `json:"replace_tags" help:"replace all remote tags"`
}

type FileSystemSetQuotaInput struct {
MaxGb *int64
MaxFiles *int64
}
27 changes: 27 additions & 0 deletions pkg/compute/models/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,33 @@ func (fileSystem *SFileSystem) StartSyncstatus(ctx context.Context, userCred mcc
return StartResourceSyncStatusTask(ctx, userCred, fileSystem, "FileSystemSyncstatusTask", parentTaskId)
}

// 设置容量大小(CephFS)
func (fileSystem *SFileSystem) PerformSetQuota(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.FileSystemSetQuotaInput) (jsonutils.JSONObject, error) {
if input.MaxFiles == nil || input.MaxGb == nil {
return nil, httperrors.NewMissingParameterError("max_gb")
}
var openTask = true
count, err := taskman.TaskManager.QueryTasksOfObject(fileSystem, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
if err != nil {
return nil, err
}
if count > 0 {
return nil, httperrors.NewBadRequestError("Nas has %d task active, can't sync status", count)
}

return nil, fileSystem.StartSetQuotaTask(ctx, userCred, input)
}

func (fileSystem *SFileSystem) StartSetQuotaTask(ctx context.Context, userCred mcclient.TokenCredential, input *api.FileSystemSetQuotaInput) error {
params := jsonutils.Marshal(input).(*jsonutils.JSONDict)
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemSetQuotaTask", fileSystem, userCred, params, "", "", nil)
if err != nil {
return err
}
fileSystem.SetStatus(ctx, userCred, api.NAS_STATUS_EXTENDING, "set quota")
return task.ScheduleRun(nil)
}

func (fileSystem *SFileSystem) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
provider, err := fileSystem.GetDriver(ctx)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/compute/models/resource_syncstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ func StartResourceSyncStatusTask(ctx context.Context, userCred mcclient.TokenCre
return err
}
obj.SetStatus(ctx, userCred, apis.STATUS_SYNC_STATUS, "perform_syncstatus")
task.ScheduleRun(nil)
return nil
return task.ScheduleRun(nil)
}
78 changes: 78 additions & 0 deletions pkg/compute/tasks/file_system_set_quota_task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tasks

import (
"context"

"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"

api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
)

type FileSystemSetQuotaTask struct {
taskman.STask
}

func init() {
taskman.RegisterTask(FileSystemSetQuotaTask{})
}

func (self *FileSystemSetQuotaTask) taskFail(ctx context.Context, fs *models.SFileSystem, err error) {
fs.SetStatus(ctx, self.UserCred, api.NAS_STATUS_AVAILABLE, err.Error())
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
}

func (self *FileSystemSetQuotaTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
fs := obj.(*models.SFileSystem)

iFs, err := fs.GetICloudFileSystem(ctx)
if err != nil {
self.taskFail(ctx, fs, errors.Wrapf(err, "GetICloudFileSystem"))
return
}

input := &cloudprovider.SFileSystemSetQuotaInput{}
err = self.GetParams().Unmarshal(input)
if err != nil {
self.taskFail(ctx, fs, errors.Wrapf(err, "Params.Unmarshal"))
return
}

err = iFs.SetQuota(input)
if err != nil {
self.taskFail(ctx, fs, errors.Wrapf(err, "SetQuota"))
return
}

err = iFs.Refresh()
if err != nil {
self.taskFail(ctx, fs, errors.Wrapf(err, "Refresh"))
return
}

err = fs.SyncWithCloudFileSystem(ctx, self.GetUserCred(), iFs)
if err != nil {
self.taskFail(ctx, fs, errors.Wrapf(err, "SyncWithCloudFileSystem"))
return
}

self.SetStageComplete(ctx, nil)
}
10 changes: 10 additions & 0 deletions pkg/mcclient/options/compute/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ type FileSystemCreateOptions struct {
func (opts *FileSystemCreateOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}

type FileSystemSetQuotaOption struct {
FileSystemIdOption
MaxGb int64
MaxFiles int64
}

func (opts *FileSystemSetQuotaOption) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241025091252-df8c7dbcd484
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241028100353-47c8a5c40d6b
## explicit; go 1.21
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
Expand Down
5 changes: 5 additions & 0 deletions vendor/yunion.io/x/cloudmux/pkg/cloudprovider/mount_target.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/yunion.io/x/cloudmux/pkg/cloudprovider/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 37 additions & 14 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/cephfs/dirs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/yunion.io/x/cloudmux/pkg/multicloud/nas_base.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2229f7c

Please sign in to comment.