fix(glance): remove image clean (#12377)

Co-authored-by: Qu Xuan <quxuan@yunionyun.com>
This commit is contained in:
屈轩
2021-10-10 12:04:10 +08:00
committed by GitHub
parent aa6b334413
commit c6ced971a5
4 changed files with 15 additions and 10 deletions
+3
View File
@@ -41,6 +41,9 @@ const (
LocalFilePrefix = "file://"
S3Prefix = "s3://"
IMAGE_STORAGE_DRIVER_LOCAL = "local"
IMAGE_STORAGE_DRIVER_S3 = "s3"
// image properties
IMAGE_OS_ARCH = "os_arch"
IMAGE_OS_DISTRO = "os_distribution"
+6 -4
View File
@@ -409,6 +409,9 @@ func (self *SImage) CustomizeCreate(ctx context.Context, userCred mcclient.Token
func (self *SImage) GetPath(format string) string {
path := filepath.Join(options.Options.FilesystemStoreDatadir, self.Id)
if options.Options.StorageDriver == api.IMAGE_STORAGE_DRIVER_S3 {
path = filepath.Join(options.Options.S3MountPoint, self.Id)
}
if len(format) > 0 {
path = fmt.Sprintf("%s.%s", path, format)
}
@@ -1174,10 +1177,9 @@ func (self *SImage) Remove() error {
return errors.Wrapf(err, "remove subimg %s", subimgs[i].GetName())
}
}
if self.Location == "" {
return nil
}
if strings.HasPrefix(self.Location, LocalFilePrefix) {
// 考虑镜像下载中断情况
if len(self.Location) == 0 || strings.HasPrefix(self.Location, LocalFilePrefix) {
return self.RemoveFile()
} else {
return RemoveImage(self.Location)
+4 -4
View File
@@ -71,9 +71,9 @@ func IsCheckStatusEnabled(img *SImage) bool {
func Init(storageBackend string) {
switch storageBackend {
case "local":
case image.IMAGE_STORAGE_DRIVER_LOCAL:
storage = &LocalStorage{}
case "s3":
case image.IMAGE_STORAGE_DRIVER_S3:
storage = &S3Storage{}
default:
storage = &LocalStorage{}
@@ -93,7 +93,7 @@ type Storage interface {
type LocalStorage struct{}
func (s *LocalStorage) Type() string {
return "local"
return image.IMAGE_STORAGE_DRIVER_LOCAL
}
func (s *LocalStorage) SaveImage(imagePath string) (string, error) {
@@ -132,7 +132,7 @@ func imagePathToName(imagePath string) string {
}
func (s *S3Storage) Type() string {
return "s3"
return image.IMAGE_STORAGE_DRIVER_S3
}
func (s *S3Storage) SaveImage(imagePath string) (string, error) {
+2 -2
View File
@@ -101,7 +101,7 @@ func StartService() {
go models.CheckImages()
models.Init(options.Options.StorageDriver)
if options.Options.StorageDriver == "s3" {
if options.Options.StorageDriver == api.IMAGE_STORAGE_DRIVER_S3 {
initS3()
}
@@ -128,7 +128,7 @@ func StartService() {
if options.Options.EnableTorrentService {
torrent.StopTorrents()
}
if options.Options.StorageDriver == "s3" {
if options.Options.StorageDriver == api.IMAGE_STORAGE_DRIVER_S3 {
procutils.NewCommand("umount", options.Options.S3MountPoint).Run()
}
})