mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
update models with db.Update interface
This commit is contained in:
@@ -116,7 +116,7 @@ func (manager *SImagePropertyManager) NewProperty(ctx context.Context, userCred
|
||||
}
|
||||
|
||||
func (self *SImageProperty) UpdateValue(ctx context.Context, userCred mcclient.TokenCredential, value string) error {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.Value = value
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -106,7 +106,7 @@ func (self *SImageSubformat) Save(image *SImage) error {
|
||||
return nil // httperrors.NewInvalidStatusError("cannot save in status %s", self.Status)
|
||||
}
|
||||
location := image.GetPath(self.Format)
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.Status = IMAGE_STATUS_SAVING
|
||||
self.Location = fmt.Sprintf("%s%s", LocalFilePrefix, location)
|
||||
return nil
|
||||
@@ -135,7 +135,7 @@ func (self *SImageSubformat) Save(image *SImage) error {
|
||||
log.Errorf("fileutils2.fastChecksum fail %s", err)
|
||||
return err
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.Status = IMAGE_STATUS_ACTIVE
|
||||
self.Location = fmt.Sprintf("%s%s", LocalFilePrefix, location)
|
||||
self.Checksum = checksum
|
||||
@@ -159,7 +159,7 @@ func (self *SImageSubformat) SaveTorrent() error {
|
||||
}
|
||||
imgPath := self.getLocalLocation()
|
||||
torrentPath := filepath.Join(options.Options.TorrentStoreDir, fmt.Sprintf("%s.torrent", filepath.Base(imgPath)))
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.TorrentStatus = IMAGE_STATUS_SAVING
|
||||
self.TorrentLocation = fmt.Sprintf("%s%s", LocalFilePrefix, torrentPath)
|
||||
return nil
|
||||
@@ -178,7 +178,7 @@ func (self *SImageSubformat) SaveTorrent() error {
|
||||
log.Errorf("fileutils2.Md5 fail %s", err)
|
||||
return err
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.TorrentStatus = IMAGE_STATUS_ACTIVE
|
||||
self.TorrentLocation = fmt.Sprintf("%s%s", LocalFilePrefix, torrentPath)
|
||||
self.TorrentChecksum = checksum
|
||||
@@ -281,7 +281,7 @@ func (self *SImageSubformat) isTorrentActive() bool {
|
||||
}
|
||||
|
||||
func (self *SImageSubformat) setStatus(status string) error {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.Status = status
|
||||
return nil
|
||||
})
|
||||
@@ -289,7 +289,7 @@ func (self *SImageSubformat) setStatus(status string) error {
|
||||
}
|
||||
|
||||
func (self *SImageSubformat) setTorrentStatus(status string) error {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.TorrentStatus = status
|
||||
return nil
|
||||
})
|
||||
@@ -306,7 +306,7 @@ func (self *SImageSubformat) checkStatus(useFast bool) {
|
||||
if err != nil {
|
||||
log.Errorf("checkStatus fileutils2.FastChecksum fail %s", err)
|
||||
} else {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.FastHash = fastHash
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -144,7 +144,7 @@ func (manager *SImageManager) InitializeData() error {
|
||||
}
|
||||
for i := 0; i < len(images); i += 1 {
|
||||
if len(images[i].ProjectId) == 0 {
|
||||
manager.TableSpec().Update(&images[i], func() error {
|
||||
db.Update(&images[i], func() error {
|
||||
images[i].ProjectId = images[i].Owner
|
||||
return nil
|
||||
})
|
||||
@@ -407,7 +407,7 @@ func (self *SImage) SaveImageFromStream(reader io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
db.Update(self, func() error {
|
||||
self.Size = sp.Size
|
||||
self.Checksum = sp.CheckSum
|
||||
self.FastHash = fastChksum
|
||||
@@ -663,7 +663,7 @@ func (self *SImage) DoPendingDelete(ctx context.Context, userCred mcclient.Token
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.Status = IMAGE_STATUS_PENDING_DELETE
|
||||
return nil
|
||||
})
|
||||
@@ -675,7 +675,7 @@ func (self *SImage) DoCancelPendingDelete(ctx context.Context, userCred mcclient
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.Status = IMAGE_STATUS_ACTIVE
|
||||
return nil
|
||||
})
|
||||
@@ -829,7 +829,7 @@ func (self *SImage) MigrateSubImage() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err = db.Update(self, func() error {
|
||||
self.Location = fmt.Sprintf("%s%s", LocalFilePrefix, newLocalpath)
|
||||
return nil
|
||||
})
|
||||
@@ -1017,7 +1017,7 @@ func (self *SImage) DoCheckStatus(ctx context.Context, userCred mcclient.TokenCr
|
||||
if err != nil {
|
||||
log.Errorf("DoCheckStatus fileutils2.FastChecksum fail %s", err)
|
||||
} else {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.FastHash = fastHash
|
||||
return nil
|
||||
})
|
||||
@@ -1070,7 +1070,7 @@ func (self *SImage) PerformMarkPublicProtected(
|
||||
isPublic := jsonutils.QueryBoolean(data, "is-public", false)
|
||||
protected := jsonutils.QueryBoolean(data, "protected", false)
|
||||
if isPublic != self.IsPublic || (self.Protected == nil && protected) || (self.Protected != nil && *self.Protected != protected) {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
_, err := db.Update(self, func() error {
|
||||
self.IsPublic = isPublic
|
||||
self.Protected = &protected
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user