|
|
|
@@ -100,8 +100,8 @@ func (manager *SFileSystemManager) GetContextManagers() [][]db.IModelManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) GetCloudproviderId() string {
|
|
|
|
|
return self.ManagerId
|
|
|
|
|
func (fileSystem *SFileSystem) GetCloudproviderId() string {
|
|
|
|
|
return fileSystem.ManagerId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (manager *SFileSystemManager) ListItemFilter(
|
|
|
|
@@ -187,26 +187,26 @@ func (man *SFileSystemManager) ValidateCreateData(ctx context.Context, userCred
|
|
|
|
|
return input, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
|
|
|
|
self.SStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
|
|
|
|
self.StartCreateTask(ctx, userCred, jsonutils.GetAnyString(data, []string{"network_id"}), "")
|
|
|
|
|
func (fileSystem *SFileSystem) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
|
|
|
|
fileSystem.SStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
|
|
|
|
fileSystem.StartCreateTask(ctx, userCred, jsonutils.GetAnyString(data, []string{"network_id"}), "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) StartCreateTask(ctx context.Context, userCred mcclient.TokenCredential, networkId string, parentTaskId string) error {
|
|
|
|
|
func (fileSystem *SFileSystem) StartCreateTask(ctx context.Context, userCred mcclient.TokenCredential, networkId string, parentTaskId string) error {
|
|
|
|
|
var err = func() error {
|
|
|
|
|
params := jsonutils.NewDict()
|
|
|
|
|
params.Add(jsonutils.NewString(networkId), "network_id")
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemCreateTask", self, userCred, params, parentTaskId, "", nil)
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemCreateTask", fileSystem, userCred, params, parentTaskId, "", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(err, "NewTask")
|
|
|
|
|
}
|
|
|
|
|
return task.ScheduleRun(nil)
|
|
|
|
|
}()
|
|
|
|
|
if err != nil {
|
|
|
|
|
self.SetStatus(userCred, api.NAS_STATUS_CREATE_FAILED, err.Error())
|
|
|
|
|
fileSystem.SetStatus(userCred, api.NAS_STATUS_CREATE_FAILED, err.Error())
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
self.SetStatus(userCred, api.NAS_STATUS_CREATING, "")
|
|
|
|
|
fileSystem.SetStatus(userCred, api.NAS_STATUS_CREATING, "")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -303,9 +303,9 @@ func (manager *SFileSystemManager) OrderByExtraFields(
|
|
|
|
|
return q, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SCloudregion) GetFileSystems() ([]SFileSystem, error) {
|
|
|
|
|
func (fileSystem *SCloudregion) GetFileSystems() ([]SFileSystem, error) {
|
|
|
|
|
ret := []SFileSystem{}
|
|
|
|
|
q := FileSystemManager.Query().Equals("cloudregion_id", self.Id)
|
|
|
|
|
q := FileSystemManager.Query().Equals("cloudregion_id", fileSystem.Id)
|
|
|
|
|
err := db.FetchModelObjects(FileSystemManager, q, &ret)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
|
|
|
@@ -313,24 +313,24 @@ func (self *SCloudregion) GetFileSystems() ([]SFileSystem, error) {
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SCloudregion) SyncFileSystems(
|
|
|
|
|
func (fileSystem *SCloudregion) SyncFileSystems(
|
|
|
|
|
ctx context.Context,
|
|
|
|
|
userCred mcclient.TokenCredential,
|
|
|
|
|
provider *SCloudprovider,
|
|
|
|
|
filesystems []cloudprovider.ICloudFileSystem,
|
|
|
|
|
xor bool,
|
|
|
|
|
) ([]SFileSystem, []cloudprovider.ICloudFileSystem, compare.SyncResult) {
|
|
|
|
|
lockman.LockRawObject(ctx, self.Id, FileSystemManager.Keyword())
|
|
|
|
|
defer lockman.ReleaseRawObject(ctx, self.Id, FileSystemManager.Keyword())
|
|
|
|
|
lockman.LockRawObject(ctx, fileSystem.Id, FileSystemManager.Keyword())
|
|
|
|
|
defer lockman.ReleaseRawObject(ctx, fileSystem.Id, FileSystemManager.Keyword())
|
|
|
|
|
|
|
|
|
|
result := compare.SyncResult{}
|
|
|
|
|
|
|
|
|
|
localFSs := []SFileSystem{}
|
|
|
|
|
remoteFSs := []cloudprovider.ICloudFileSystem{}
|
|
|
|
|
|
|
|
|
|
dbFSs, err := self.GetFileSystems()
|
|
|
|
|
dbFSs, err := fileSystem.GetFileSystems()
|
|
|
|
|
if err != nil {
|
|
|
|
|
result.Error(errors.Wrapf(err, "self.GetFileSystems"))
|
|
|
|
|
result.Error(errors.Wrapf(err, "fileSystem.GetFileSystems"))
|
|
|
|
|
return localFSs, remoteFSs, result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -365,7 +365,7 @@ func (self *SCloudregion) SyncFileSystems(
|
|
|
|
|
result.Update()
|
|
|
|
|
}
|
|
|
|
|
for i := 0; i < len(added); i += 1 {
|
|
|
|
|
newFs, err := self.newFromCloudFileSystem(ctx, userCred, provider, added[i])
|
|
|
|
|
newFs, err := fileSystem.newFromCloudFileSystem(ctx, userCred, provider, added[i])
|
|
|
|
|
if err != nil {
|
|
|
|
|
result.AddError(err)
|
|
|
|
|
continue
|
|
|
|
@@ -379,55 +379,55 @@ func (self *SCloudregion) SyncFileSystems(
|
|
|
|
|
return localFSs, remoteFSs, result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) syncRemove(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
lockman.LockObject(ctx, self)
|
|
|
|
|
defer lockman.ReleaseObject(ctx, self)
|
|
|
|
|
func (fileSystem *SFileSystem) syncRemove(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
lockman.LockObject(ctx, fileSystem)
|
|
|
|
|
defer lockman.ReleaseObject(ctx, fileSystem)
|
|
|
|
|
|
|
|
|
|
self.DeletePreventionOff(self, userCred)
|
|
|
|
|
fileSystem.DeletePreventionOff(fileSystem, userCred)
|
|
|
|
|
|
|
|
|
|
err := self.ValidateDeleteCondition(ctx, nil)
|
|
|
|
|
err := fileSystem.ValidateDeleteCondition(ctx, nil)
|
|
|
|
|
if err != nil { // cannot delete
|
|
|
|
|
return self.SetStatus(userCred, api.NAS_STATUS_UNKNOWN, "sync to delete")
|
|
|
|
|
return fileSystem.SetStatus(userCred, api.NAS_STATUS_UNKNOWN, "sync to delete")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = self.RealDelete(ctx, userCred)
|
|
|
|
|
err = fileSystem.RealDelete(ctx, userCred)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
|
|
|
|
Obj: self,
|
|
|
|
|
Obj: fileSystem,
|
|
|
|
|
Action: notifyclient.ActionSyncDelete,
|
|
|
|
|
})
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
|
|
|
|
func (fileSystem *SFileSystem) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
|
|
|
|
|
|
|
|
|
return self.StartDeleteTask(ctx, userCred, "")
|
|
|
|
|
return fileSystem.StartDeleteTask(ctx, userCred, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
|
|
|
|
func (fileSystem *SFileSystem) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
|
|
|
|
var err = func() error {
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemDeleteTask", self, userCred, nil, parentTaskId, "", nil)
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemDeleteTask", fileSystem, userCred, nil, parentTaskId, "", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(err, "NewTask")
|
|
|
|
|
}
|
|
|
|
|
return task.ScheduleRun(nil)
|
|
|
|
|
}()
|
|
|
|
|
if err != nil {
|
|
|
|
|
self.SetStatus(userCred, api.NAS_STATUS_DELETE_FAILED, err.Error())
|
|
|
|
|
fileSystem.SetStatus(userCred, api.NAS_STATUS_DELETE_FAILED, err.Error())
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
self.SetStatus(userCred, api.NAS_STATUS_DELETING, "")
|
|
|
|
|
fileSystem.SetStatus(userCred, api.NAS_STATUS_DELETING, "")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
func (fileSystem *SFileSystem) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
mts, err := self.GetMountTargets()
|
|
|
|
|
func (fileSystem *SFileSystem) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
mts, err := fileSystem.GetMountTargets()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(err, "GetMountTargets")
|
|
|
|
|
}
|
|
|
|
@@ -437,43 +437,43 @@ func (self *SFileSystem) RealDelete(ctx context.Context, userCred mcclient.Token
|
|
|
|
|
return errors.Wrapf(err, "mount target %s real delete", mts[i].DomainName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self.SInfrasResourceBase.Delete(ctx, userCred)
|
|
|
|
|
return fileSystem.SInfrasResourceBase.Delete(ctx, userCred)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
|
|
|
|
if self.DisableDelete.IsTrue() {
|
|
|
|
|
func (fileSystem *SFileSystem) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error {
|
|
|
|
|
if fileSystem.DisableDelete.IsTrue() {
|
|
|
|
|
return httperrors.NewInvalidStatusError("FileSystem is locked, cannot delete")
|
|
|
|
|
}
|
|
|
|
|
return self.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
|
|
|
|
return fileSystem.SStatusInfrasResourceBase.ValidateDeleteCondition(ctx, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) SyncAllWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
|
|
|
|
syncFileSystemMountTargets(ctx, userCred, self, fs, false)
|
|
|
|
|
return self.SyncWithCloudFileSystem(ctx, userCred, fs)
|
|
|
|
|
func (fileSystem *SFileSystem) SyncAllWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
|
|
|
|
syncFileSystemMountTargets(ctx, userCred, fileSystem, fs, false)
|
|
|
|
|
return fileSystem.SyncWithCloudFileSystem(ctx, userCred, fs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) SyncWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
|
|
|
|
diff, err := db.Update(self, func() error {
|
|
|
|
|
func (fileSystem *SFileSystem) SyncWithCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, fs cloudprovider.ICloudFileSystem) error {
|
|
|
|
|
diff, err := db.Update(fileSystem, func() error {
|
|
|
|
|
if options.Options.EnableSyncName {
|
|
|
|
|
newName, _ := db.GenerateAlterName(self, fs.GetName())
|
|
|
|
|
newName, _ := db.GenerateAlterName(fileSystem, fs.GetName())
|
|
|
|
|
if len(newName) > 0 {
|
|
|
|
|
self.Name = newName
|
|
|
|
|
fileSystem.Name = newName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.Status = fs.GetStatus()
|
|
|
|
|
self.StorageType = fs.GetStorageType()
|
|
|
|
|
self.Protocol = fs.GetProtocol()
|
|
|
|
|
self.Capacity = fs.GetCapacityGb()
|
|
|
|
|
self.UsedCapacity = fs.GetUsedCapacityGb()
|
|
|
|
|
self.FileSystemType = fs.GetFileSystemType()
|
|
|
|
|
self.MountTargetCountLimit = fs.GetMountTargetCountLimit()
|
|
|
|
|
fileSystem.Status = fs.GetStatus()
|
|
|
|
|
fileSystem.StorageType = fs.GetStorageType()
|
|
|
|
|
fileSystem.Protocol = fs.GetProtocol()
|
|
|
|
|
fileSystem.Capacity = fs.GetCapacityGb()
|
|
|
|
|
fileSystem.UsedCapacity = fs.GetUsedCapacityGb()
|
|
|
|
|
fileSystem.FileSystemType = fs.GetFileSystemType()
|
|
|
|
|
fileSystem.MountTargetCountLimit = fs.GetMountTargetCountLimit()
|
|
|
|
|
if zoneId := fs.GetZoneId(); len(zoneId) > 0 {
|
|
|
|
|
region, err := self.GetRegion()
|
|
|
|
|
region, err := fileSystem.GetRegion()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(err, "self.GetRegion")
|
|
|
|
|
return errors.Wrapf(err, "fileSystem.GetRegion")
|
|
|
|
|
}
|
|
|
|
|
self.ZoneId, _ = region.getZoneIdBySuffix(zoneId)
|
|
|
|
|
fileSystem.ZoneId, _ = region.getZoneIdBySuffix(zoneId)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
@@ -482,16 +482,16 @@ func (self *SFileSystem) SyncWithCloudFileSystem(ctx context.Context, userCred m
|
|
|
|
|
}
|
|
|
|
|
if len(diff) > 0 {
|
|
|
|
|
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
|
|
|
|
Obj: self,
|
|
|
|
|
Obj: fileSystem,
|
|
|
|
|
Action: notifyclient.ActionSyncUpdate,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
syncMetadata(ctx, userCred, self, fs)
|
|
|
|
|
syncMetadata(ctx, userCred, fileSystem, fs)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SCloudregion) getZoneIdBySuffix(zoneId string) (string, error) {
|
|
|
|
|
zones, err := self.GetZones()
|
|
|
|
|
func (fileSystem *SCloudregion) getZoneIdBySuffix(zoneId string) (string, error) {
|
|
|
|
|
zones, err := fileSystem.GetZones()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrapf(err, "region.GetZones")
|
|
|
|
|
}
|
|
|
|
@@ -503,11 +503,11 @@ func (self *SCloudregion) getZoneIdBySuffix(zoneId string) (string, error) {
|
|
|
|
|
return "", errors.Wrapf(cloudprovider.ErrNotFound, zoneId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, fs cloudprovider.ICloudFileSystem) (*SFileSystem, error) {
|
|
|
|
|
func (region *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, fs cloudprovider.ICloudFileSystem) (*SFileSystem, error) {
|
|
|
|
|
nas := SFileSystem{}
|
|
|
|
|
nas.SetModelManager(FileSystemManager, &nas)
|
|
|
|
|
nas.ExternalId = fs.GetGlobalId()
|
|
|
|
|
nas.CloudregionId = self.Id
|
|
|
|
|
nas.CloudregionId = region.Id
|
|
|
|
|
nas.ManagerId = provider.Id
|
|
|
|
|
nas.Status = fs.GetStatus()
|
|
|
|
|
nas.CreatedAt = fs.GetCreatedAt()
|
|
|
|
@@ -518,7 +518,7 @@ func (self *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred m
|
|
|
|
|
nas.FileSystemType = fs.GetFileSystemType()
|
|
|
|
|
nas.MountTargetCountLimit = fs.GetMountTargetCountLimit()
|
|
|
|
|
if zoneId := fs.GetZoneId(); len(zoneId) > 0 {
|
|
|
|
|
nas.ZoneId, _ = self.getZoneIdBySuffix(zoneId)
|
|
|
|
|
nas.ZoneId, _ = region.getZoneIdBySuffix(zoneId)
|
|
|
|
|
}
|
|
|
|
|
fileSystem, err := func() (*SFileSystem, error) {
|
|
|
|
|
lockman.LockRawObject(ctx, FileSystemManager.Keyword(), "name")
|
|
|
|
@@ -543,9 +543,9 @@ func (self *SCloudregion) newFromCloudFileSystem(ctx context.Context, userCred m
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步NAS状态
|
|
|
|
|
func (self *SFileSystem) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.FileSystemSyncstatusInput) (jsonutils.JSONObject, error) {
|
|
|
|
|
func (fileSystem *SFileSystem) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.FileSystemSyncstatusInput) (jsonutils.JSONObject, error) {
|
|
|
|
|
var openTask = true
|
|
|
|
|
count, err := taskman.TaskManager.QueryTasksOfObject(self, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
|
|
|
|
count, err := taskman.TaskManager.QueryTasksOfObject(fileSystem, time.Now().Add(-3*time.Minute), &openTask).CountWithError()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@@ -553,21 +553,21 @@ func (self *SFileSystem) PerformSyncstatus(ctx context.Context, userCred mcclien
|
|
|
|
|
return nil, httperrors.NewBadRequestError("Nas has %d task active, can't sync status", count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, self.StartSyncstatus(ctx, userCred, "")
|
|
|
|
|
return nil, fileSystem.StartSyncstatus(ctx, userCred, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
|
|
|
|
return StartResourceSyncStatusTask(ctx, userCred, self, "FileSystemSyncstatusTask", parentTaskId)
|
|
|
|
|
func (fileSystem *SFileSystem) StartSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
|
|
|
|
return StartResourceSyncStatusTask(ctx, userCred, fileSystem, "FileSystemSyncstatusTask", parentTaskId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
|
|
|
|
provider, err := self.GetDriver(ctx)
|
|
|
|
|
func (fileSystem *SFileSystem) GetIRegion(ctx context.Context) (cloudprovider.ICloudRegion, error) {
|
|
|
|
|
provider, err := fileSystem.GetDriver(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrapf(err, "self.GetDriver")
|
|
|
|
|
return nil, errors.Wrapf(err, "fileSystem.GetDriver")
|
|
|
|
|
}
|
|
|
|
|
region, err := self.GetRegion()
|
|
|
|
|
region, err := fileSystem.GetRegion()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrapf(err, "self.GetRegion")
|
|
|
|
|
return nil, errors.Wrapf(err, "fileSystem.GetRegion")
|
|
|
|
|
}
|
|
|
|
|
iRegion, err := provider.GetIRegionById(region.ExternalId)
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -576,15 +576,15 @@ func (self *SFileSystem) GetIRegion(ctx context.Context) (cloudprovider.ICloudRe
|
|
|
|
|
return iRegion, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) GetICloudFileSystem(ctx context.Context) (cloudprovider.ICloudFileSystem, error) {
|
|
|
|
|
if len(self.ExternalId) == 0 {
|
|
|
|
|
func (fileSystem *SFileSystem) GetICloudFileSystem(ctx context.Context) (cloudprovider.ICloudFileSystem, error) {
|
|
|
|
|
if len(fileSystem.ExternalId) == 0 {
|
|
|
|
|
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "empty externalId")
|
|
|
|
|
}
|
|
|
|
|
iRegion, err := self.GetIRegion(ctx)
|
|
|
|
|
iRegion, err := fileSystem.GetIRegion(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrap(err, "self.GetIRegion")
|
|
|
|
|
return nil, errors.Wrap(err, "fileSystem.GetIRegion")
|
|
|
|
|
}
|
|
|
|
|
return iRegion.GetICloudFileSystemById(self.ExternalId)
|
|
|
|
|
return iRegion.GetICloudFileSystemById(fileSystem.ExternalId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (manager *SFileSystemManager) getExpiredPostpaids() ([]SFileSystem, error) {
|
|
|
|
@@ -598,12 +598,12 @@ func (manager *SFileSystemManager) getExpiredPostpaids() ([]SFileSystem, error)
|
|
|
|
|
return fs, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) doExternalSync(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
iFs, err := self.GetICloudFileSystem(ctx)
|
|
|
|
|
func (fileSystem *SFileSystem) doExternalSync(ctx context.Context, userCred mcclient.TokenCredential) error {
|
|
|
|
|
iFs, err := fileSystem.GetICloudFileSystem(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrapf(err, "GetICloudFileSystem")
|
|
|
|
|
}
|
|
|
|
|
return self.SyncWithCloudFileSystem(ctx, userCred, iFs)
|
|
|
|
|
return fileSystem.SyncWithCloudFileSystem(ctx, userCred, iFs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (manager *SFileSystemManager) DeleteExpiredPostpaids(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
|
|
|
|
@@ -624,26 +624,40 @@ func (manager *SFileSystemManager) DeleteExpiredPostpaids(ctx context.Context, u
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.FileSystemRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
|
|
|
|
return nil, self.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
|
|
|
|
func (fileSystem *SFileSystem) PerformRemoteUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.FileSystemRemoteUpdateInput) (jsonutils.JSONObject, error) {
|
|
|
|
|
return nil, fileSystem.StartRemoteUpdateTask(ctx, userCred, (input.ReplaceTags != nil && *input.ReplaceTags), "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
|
|
|
|
func (fileSystem *SFileSystem) StartRemoteUpdateTask(ctx context.Context, userCred mcclient.TokenCredential, replaceTags bool, parentTaskId string) error {
|
|
|
|
|
data := jsonutils.NewDict()
|
|
|
|
|
if replaceTags {
|
|
|
|
|
data.Add(jsonutils.JSONTrue, "replace_tags")
|
|
|
|
|
}
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemRemoteUpdateTask", self, userCred, data, parentTaskId, "", nil)
|
|
|
|
|
task, err := taskman.TaskManager.NewTask(ctx, "FileSystemRemoteUpdateTask", fileSystem, userCred, data, parentTaskId, "", nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, "NewTask")
|
|
|
|
|
}
|
|
|
|
|
self.SetStatus(userCred, api.NAS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
|
|
|
|
fileSystem.SetStatus(userCred, api.NAS_UPDATE_TAGS, "StartRemoteUpdateTask")
|
|
|
|
|
return task.ScheduleRun(nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *SFileSystem) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
|
|
|
|
if len(self.ExternalId) == 0 {
|
|
|
|
|
func (fileSystem *SFileSystem) OnMetadataUpdated(ctx context.Context, userCred mcclient.TokenCredential) {
|
|
|
|
|
if len(fileSystem.ExternalId) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
self.StartRemoteUpdateTask(ctx, userCred, true, "")
|
|
|
|
|
fileSystem.StartRemoteUpdateTask(ctx, userCred, true, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fileSystem *SFileSystem) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
|
|
|
|
desc := fileSystem.SStatusInfrasResourceBase.GetShortDesc(ctx)
|
|
|
|
|
region, _ := fileSystem.GetRegion()
|
|
|
|
|
provider := fileSystem.GetCloudprovider()
|
|
|
|
|
info := MakeCloudProviderInfo(region, nil, provider)
|
|
|
|
|
desc.Set("file_system_type", jsonutils.NewString(fileSystem.FileSystemType))
|
|
|
|
|
desc.Set("storage_type", jsonutils.NewString(fileSystem.StorageType))
|
|
|
|
|
desc.Set("protocol", jsonutils.NewString(fileSystem.Protocol))
|
|
|
|
|
desc.Set("capacity", jsonutils.NewInt(fileSystem.Capacity))
|
|
|
|
|
desc.Set("used_capacity", jsonutils.NewInt(fileSystem.UsedCapacity))
|
|
|
|
|
desc.Update(jsonutils.Marshal(&info))
|
|
|
|
|
return desc
|
|
|
|
|
}
|
|
|
|
|