gpfs.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package storagedrivers
  15. import (
  16. "context"
  17. "time"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/log"
  20. "yunion.io/x/pkg/util/timeutils"
  21. api "yunion.io/x/onecloud/pkg/apis/compute"
  22. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  23. "yunion.io/x/onecloud/pkg/compute/models"
  24. "yunion.io/x/onecloud/pkg/compute/options"
  25. "yunion.io/x/onecloud/pkg/mcclient"
  26. )
  27. type SGpfsStorageDriver struct {
  28. SBaseStorageDriver
  29. }
  30. func init() {
  31. driver := SGpfsStorageDriver{}
  32. models.RegisterStorageDriver(&driver)
  33. }
  34. func (self *SGpfsStorageDriver) GetStorageType() string {
  35. return api.STORAGE_GPFS
  36. }
  37. func (self *SGpfsStorageDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.StorageCreateInput) error {
  38. return nil
  39. }
  40. func (self *SGpfsStorageDriver) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, data jsonutils.JSONObject) {
  41. sc := &models.SStoragecache{}
  42. sc.Path = options.Options.DefaultImageCacheDir
  43. sc.ExternalId = storage.Id
  44. timeutils.IsoTime(time.Now())
  45. sc.Name = "gpfs-" + storage.Name + timeutils.IsoTime(time.Now())
  46. if err := models.StoragecacheManager.TableSpec().Insert(ctx, sc); err != nil {
  47. log.Errorf("insert storagecache for storage %s error: %v", storage.Name, err)
  48. return
  49. }
  50. _, err := db.Update(storage, func() error {
  51. storage.StoragecacheId = sc.Id
  52. storage.Status = api.STORAGE_ONLINE
  53. return nil
  54. })
  55. if err != nil {
  56. log.Errorf("update storagecache info for storage %s error: %v", storage.Name, err)
  57. }
  58. }