mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #1735 from wanyaoqi/bugfix/wyq/add-verify-storage-mountpoint
region: add verify storage mount point
This commit is contained in:
@@ -17,12 +17,10 @@ package hostdrivers
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SAliyunHostDriver struct {
|
||||
@@ -42,10 +40,6 @@ func (self *SAliyunHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_ALIYUN
|
||||
}
|
||||
|
||||
func (self *SAliyunHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SAliyunHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_CLOUD_EFFICIENCY, api.STORAGE_CLOUD_SSD, api.STORAGE_CLOUD_ESSD}) {
|
||||
if sizeGb < 20 || sizeGb > 32768 {
|
||||
|
||||
@@ -17,12 +17,10 @@ package hostdrivers
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SAwsHostDriver struct {
|
||||
@@ -42,10 +40,6 @@ func (self *SAwsHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_AWS
|
||||
}
|
||||
|
||||
func (self *SAwsHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SAwsHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
if storage.StorageType == api.STORAGE_GP2_SSD {
|
||||
if sizeGb < 1 || sizeGb > 16384 {
|
||||
|
||||
@@ -45,10 +45,6 @@ func (self *SAzureHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_AZURE
|
||||
}
|
||||
|
||||
func (self *SAzureHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SAzureHostDriver) ValidateUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
if data.Contains("name") {
|
||||
return nil, httperrors.NewInputParameterError("cannot support change azure disk name")
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SBaremetalHostDriver struct {
|
||||
@@ -43,10 +42,6 @@ func (self *SBaremetalHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_BAREMETAL
|
||||
}
|
||||
|
||||
func (self *SBaremetalHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SBaremetalHostDriver) CheckAndSetCacheImage(ctx context.Context, host *models.SHost, storageCache *models.SStoragecache, task taskman.ITask) error {
|
||||
return fmt.Errorf("not supported")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (self *SBaseHostDriver) ValidateUpdateDisk(ctx context.Context, userCred mc
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (self *SBaseHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
func (self *SBaseHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewNotImplementedError("Not Implement ValidateAttachStorage")
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
)
|
||||
|
||||
@@ -50,10 +49,6 @@ func (self *SESXiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb i
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SESXiHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SESXiHostDriver) CheckAndSetCacheImage(ctx context.Context, host *models.SHost, storageCache *models.SStoragecache, task taskman.ITask) error {
|
||||
params := task.GetParams()
|
||||
imageId, err := params.GetString("image_id")
|
||||
|
||||
@@ -17,11 +17,8 @@ package hostdrivers
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SHuaweiHostDriver struct {
|
||||
@@ -41,10 +38,6 @@ func (self *SHuaweiHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_HUAWEI
|
||||
}
|
||||
|
||||
func (self *SHuaweiHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
// 系统盘必须至少40G
|
||||
func (self *SHuaweiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
switch storage.StorageType {
|
||||
|
||||
@@ -17,6 +17,7 @@ package hostdrivers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -51,7 +52,7 @@ func (self *SKVMHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_KVM
|
||||
}
|
||||
|
||||
func (self *SKVMHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
func (self *SKVMHostDriver) ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
if !utils.IsInStringArray(storage.StorageType, append([]string{api.STORAGE_LOCAL}, api.SHARED_STORAGE...)) {
|
||||
return httperrors.NewUnsupportOperationError("Unsupport attach %s storage for %s host", storage.StorageType, host.HostType)
|
||||
}
|
||||
@@ -76,6 +77,21 @@ func (self *SKVMHostDriver) ValidateAttachStorage(host *models.SHost, storage *m
|
||||
if host.HostStatus != api.HOST_ONLINE {
|
||||
return httperrors.NewInvalidStatusError("Attach nfs storage require host status is online")
|
||||
}
|
||||
if storage.StorageType == api.STORAGE_GPFS {
|
||||
header := http.Header{}
|
||||
header.Set(mcclient.AUTH_TOKEN, userCred.GetTokenString())
|
||||
header.Set(mcclient.REGION_VERSION, "v2")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("mount_point", jsonutils.NewString(mountPoint))
|
||||
urlStr := fmt.Sprintf("%s/storages/is-mount-point?%s", host.ManagerUri, params.QueryString())
|
||||
_, res, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "GET", urlStr, header, nil, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !jsonutils.QueryBoolean(res, "is_mount_point", false) {
|
||||
return httperrors.NewBadRequestError("%s is not mount point %s", mountPoint, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
package hostdrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SOpenStackHostDriver struct {
|
||||
@@ -39,10 +36,6 @@ func (self *SOpenStackHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_OPENSTACK
|
||||
}
|
||||
|
||||
func (self *SOpenStackHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SOpenStackHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
@@ -43,10 +41,6 @@ func (self *SQcloudHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_OPENSTACK
|
||||
}
|
||||
|
||||
func (self *SQcloudHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SQcloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
if sizeGb%10 != 0 {
|
||||
return fmt.Errorf("The disk size must be a multiple of 10Gb")
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
package hostdrivers
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SZStackHostDriver struct {
|
||||
@@ -39,10 +36,6 @@ func (self *SZStackHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_ZSTACK
|
||||
}
|
||||
|
||||
func (self *SZStackHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error {
|
||||
return httperrors.NewUnsupportOperationError("Not support attach storage for %s host", self.GetHostType())
|
||||
}
|
||||
|
||||
func (self *SZStackHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ type IHostDriver interface {
|
||||
IsReachStoragecacheCapacityLimit(host *SHost, cachedImages []SCachedimage) bool
|
||||
GetStoragecacheQuota(host *SHost) int
|
||||
|
||||
ValidateAttachStorage(host *SHost, storage *SStorage, data *jsonutils.JSONDict) error
|
||||
ValidateAttachStorage(ctx context.Context, userCred mcclient.TokenCredential, host *SHost, storage *SStorage, data *jsonutils.JSONDict) error
|
||||
RequestAttachStorage(ctx context.Context, hoststorage *SHoststorage, host *SHost, storage *SStorage, task taskman.ITask) error
|
||||
RequestDetachStorage(ctx context.Context, host *SHost, storage *SStorage, task taskman.ITask) error
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func (manager *SHoststorageManager) ValidateCreateData(ctx context.Context, user
|
||||
}
|
||||
host := hostTmp.(*SHost)
|
||||
|
||||
if err := host.GetHostDriver().ValidateAttachStorage(host, storage, data); err != nil {
|
||||
if err := host.GetHostDriver().ValidateAttachStorage(ctx, userCred, host, storage, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -49,6 +50,27 @@ func AddStorageHandler(prefix string, app *appsrv.Application) {
|
||||
app.AddHandler("POST",
|
||||
fmt.Sprintf("%s/%s/<storageId>/delete-snapshots", prefix, keyWords),
|
||||
auth.Authenticate(storageDeleteSnapshots))
|
||||
app.AddHandler("GET",
|
||||
fmt.Sprintf("%s/%s/is-mount-point", prefix, keyWords),
|
||||
auth.Authenticate(storageVerifyMountPoint))
|
||||
}
|
||||
}
|
||||
|
||||
func storageVerifyMountPoint(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
_, query, _ := appsrv.FetchEnv(ctx, w, r)
|
||||
mountPoint, err := query.GetString("mount_point")
|
||||
if err != nil {
|
||||
hostutils.Response(ctx, w, httperrors.NewMissingParameterError("mount_point"))
|
||||
return
|
||||
}
|
||||
output, err := procutils.NewCommand("mountpoint", mountPoint).Run()
|
||||
if err == nil {
|
||||
appsrv.SendStruct(w, map[string]interface{}{"is_mount_point": true})
|
||||
} else {
|
||||
appsrv.SendStruct(w, map[string]interface{}{
|
||||
"is_mount_point": false,
|
||||
"error": string(output),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user