-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(region,host): clvm support (#18979)
- Loading branch information
Showing
16 changed files
with
605 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// 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 storagedrivers | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"time" | ||
|
||
"yunion.io/x/jsonutils" | ||
"yunion.io/x/log" | ||
"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/compute/models" | ||
"yunion.io/x/onecloud/pkg/httperrors" | ||
"yunion.io/x/onecloud/pkg/mcclient" | ||
) | ||
|
||
type SCLVMStorageDriver struct { | ||
SBaseStorageDriver | ||
} | ||
|
||
func init() { | ||
driver := SCLVMStorageDriver{} | ||
models.RegisterStorageDriver(&driver) | ||
} | ||
|
||
func (s *SCLVMStorageDriver) GetStorageType() string { | ||
return api.STORAGE_CLVM | ||
} | ||
|
||
func (s *SCLVMStorageDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.StorageCreateInput) error { | ||
input.CLVMVgName = strings.TrimSpace(input.CLVMVgName) | ||
if len(input.CLVMVgName) == 0 { | ||
return httperrors.NewMissingParameterError("clvm_vg_name") | ||
} | ||
input.StorageConf = jsonutils.NewDict() | ||
input.StorageConf.Set("clvm_vg_name", jsonutils.NewString(input.CLVMVgName)) | ||
return nil | ||
} | ||
|
||
func (self *SCLVMStorageDriver) ValidateSnapshotDelete(ctx context.Context, snapshot *models.SSnapshot) error { | ||
return nil | ||
} | ||
|
||
func (s *SCLVMStorageDriver) ValidateCreateSnapshotData(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, input *api.SnapshotCreateInput) error { | ||
return errors.Errorf("lvm storage unsupported create snapshot") | ||
} | ||
|
||
func (s *SCLVMStorageDriver) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, data jsonutils.JSONObject) { | ||
sc := &models.SStoragecache{} | ||
sc.ExternalId = storage.Id | ||
sc.Name = "clvm-" + storage.Name + time.Now().Format("2006-01-02 15:04:05") | ||
if err := models.StoragecacheManager.TableSpec().Insert(ctx, sc); err != nil { | ||
log.Errorf("insert storagecache for storage %s error: %v", storage.Name, err) | ||
return | ||
} | ||
_, err := db.Update(storage, func() error { | ||
storage.StoragecacheId = sc.Id | ||
storage.Status = api.STORAGE_ONLINE | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Errorf("update storagecache info for storage %s error: %v", storage.Name, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.